[go: up one dir, main page]

CN116204303A - Implementation method of spin lock capable of optimizing interrupt delay - Google Patents

Implementation method of spin lock capable of optimizing interrupt delay Download PDF

Info

Publication number
CN116204303A
CN116204303A CN202211626148.7A CN202211626148A CN116204303A CN 116204303 A CN116204303 A CN 116204303A CN 202211626148 A CN202211626148 A CN 202211626148A CN 116204303 A CN116204303 A CN 116204303A
Authority
CN
China
Prior art keywords
thread
phase
lock
threads
stage
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211626148.7A
Other languages
Chinese (zh)
Inventor
郝继锋
任晓瑞
周霆
尹超
虞保忠
朱晓宁
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Xian Aeronautics Computing Technique Research Institute of AVIC
Original Assignee
Xian Aeronautics Computing Technique Research Institute of AVIC
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Xian Aeronautics Computing Technique Research Institute of AVIC filed Critical Xian Aeronautics Computing Technique Research Institute of AVIC
Priority to CN202211626148.7A priority Critical patent/CN116204303A/en
Publication of CN116204303A publication Critical patent/CN116204303A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • G06F9/5038Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals considering the execution order of a plurality of tasks, e.g. taking priority or time dependency constraints into consideration
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/52Program synchronisation; Mutual exclusion, e.g. by means of semaphores
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The application provides a realization method of spin lock capable of optimizing interrupt delay, which belongs to the technical field of computer system software, and specifically comprises the steps of controlling a plurality of threads to access resources by adopting a two-stage spin lock, wherein the two-stage spin lock comprises a first stage of a plurality of first threads; receiving a request for a thread to acquire a resource, placing the thread on a first queue associated with a first phase of a two-phase spin lock, determining whether at least one predetermined slot is available in a second phase of the two-phase spin lock, when the slot is not available, processing an interrupt serviced by the selected thread based on a number of attempts by the selected thread to enter the second phase, and when at least one slot is available, selecting one of the first threads to enter the second phase based on a time priority order. Two-stage spin locks can take advantage of various features to maintain a deterministic approach while still providing an opportunity to service interrupts, allowing interrupts to be handled while waiting, while ultimately successfully obtaining a lock without the risk of deadlock.

Description

一种可优化中断延迟的自旋锁的实现方法A Spinlock Implementation Method That Can Optimize Interrupt Latency

技术领域technical field

本申请涉及计算机系统软件的领域,尤其是涉及一种可优化中断延迟的自旋锁的实现方法。The present application relates to the field of computer system software, in particular to an implementation method of a spin lock capable of optimizing interrupt delay.

背景技术Background technique

锁用于控制对计算资源的访问。例如,当多个不同的线程试图访问该资源时,锁会对该资源的访问进行限制。自旋锁是一种特殊类型的锁,它允许正在等待访问被占用资源的请求线程循环等待,同时,反复检查资源的自旋锁是否可用。自旋锁主要有两类型:任务自旋锁和中断自旋锁。任务自旋锁在循环中,请求线程可能仍然处于活动状态并执行其他任务;但是,中断自旋锁不允许请求线程执行其他任务。Locks are used to control access to computing resources. For example, a lock restricts access to a resource when multiple different threads attempt to access the resource. A spin lock is a special type of lock that allows requesting threads that are waiting to access an occupied resource to wait in a loop, while repeatedly checking whether the resource's spin lock is available. There are two main types of spin locks: task spin locks and interrupt spin locks. While a task spinlock is in a loop, the requesting thread may still be active and perform other tasks; however, an interrupt spinlock does not allow the requesting thread to perform other tasks.

自旋锁会引入延迟和低效。例如,资源可能被分配到不积极使用该资源的请求线程。在这种情况下,由于线程没有释放自旋锁,资源可能会在很长一段时间内不可访问。Spinlocks introduce latency and inefficiency. For example, a resource might be allocated to a requesting thread that is not actively using the resource. In this case, the resource may become inaccessible for a long period of time because the thread does not release the spinlock.

可以通过确定性方式配置计算环境来有效处理线程,但是,可能需要禁止中断。由于中断表示立即需要关注以及中断相对非系统的性质,环境可能会选择在排队、获取和释放自旋锁时禁止中断。Computing environments can be configured in a deterministic manner to handle threads efficiently, however, interrupts may need to be disabled. Because of the immediate need for attention and the relatively unsystematic nature of interrupts, environments may choose to disable interrupts when queuing, acquiring, and releasing spinlocks.

传统的中断自旋锁必须在本地CPU核上禁止中断的情况下进行自旋,以便获得该锁。任何路由到该CPU核的中断都可能需要等待很长时间(而且可能不确定)。在传统的中断自旋锁实现中,在使能中断条件下自旋很容易导致死锁。Traditional interrupt spin locks must be spun with interrupts disabled on the local CPU core in order to acquire the lock. Any interrupts routed to that CPU core will likely have to wait a long time (and possibly indeterminately). In traditional interrupt spinlock implementations, spinning with interrupts enabled can easily lead to deadlock.

发明内容Contents of the invention

有鉴于此,本申请提供一种可优化中断延迟的自旋锁的实现方法,解决了现有技术中的问题,中断自旋锁实现中,在使能中断条件下自旋很不容易死锁。In view of this, this application provides an implementation method of a spin lock that can optimize the interrupt delay, which solves the problems in the prior art. In the implementation of the interrupt spin lock, the spin is not easy to deadlock when the interrupt is enabled .

本申请提供的一种可优化中断延迟的自旋锁的实现方法采用如下的技术方案:The implementation method of a spin lock that can optimize the interrupt delay provided by this application adopts the following technical solution:

一种可优化中断延迟的自旋锁的实现方法,包括:A method for implementing a spin lock capable of optimizing interrupt latency, comprising:

采用两阶段自旋锁控制多个线程对资源进行访问,所述两阶段自旋锁包括多个第一线程的第一阶段;Using a two-stage spin lock to control multiple threads to access resources, the two-stage spin lock includes a first stage of multiple first threads;

接收线程的请求来获取资源,把线程放在与两阶段自旋锁的第一阶段关联的第一队列上,确定两阶段自旋锁的第二阶段中是否至少有一个预定的插槽可用,当插槽不可用时,根据所选线程进入第二阶段的尝试次数,处理由所选线程服务的中断,当至少一个插槽可用时,根据时间优先级顺序选择第一线程之一进入第二阶段;receiving a thread's request to acquire a resource, placing the thread on the first queue associated with the first phase of the two-phase spinlock, determining whether at least one reserved slot is available in the second phase of the two-phase spinlock, Handle the interrupt serviced by the selected thread according to the number of attempts made by the selected thread to enter the second phase when the slot is not available, and select one of the first threads to enter the second phase according to the temporal priority order when at least one slot is available ;

确定访问资源的锁是否可用,当锁可用时,从两阶段自旋锁的第二阶段中的多个第二线程中选择一个来获取锁,确定所选第二线程的年龄,当年龄不是Determines whether a lock to access a resource is available, when the lock is available, selects one of multiple second threads in the second phase of the two-phase spinlock to acquire the lock, determines the age of the selected second thread, and when the age is not

第二阶段的第二线程中最老的,禁止任何第一线程进入第二阶段;否则,当年5龄是第二阶段的第二线程中最老的,选择最老的第一线程进入第二阶段;The oldest of the second threads in the second stage, prohibit any first thread from entering the second stage; otherwise, when 5 years old is the oldest of the second threads in the second stage, choose the oldest first thread to enter the second stage;

接收来自所选线程的进一步请求,并将所选线程放在第一队列中。Receives further requests from the selected thread and places the selected thread in the first queue.

可选的,将线程放在第一队列中的操作基于原子的获取和增加操作,获取和增加操作包括:根据时间优先级顺序为每个线程分配各自的票号。Optionally, the operation of putting the threads in the first queue is based on atomic acquisition and addition operations, and the acquisition and addition operations include: assigning respective ticket numbers to each thread according to time priority order.

可选的,确定跟踪第一数字的第一计数器是否已经耗尽,第一数字对应于0所选线程进入第二阶段的尝试次数;Optionally, determining whether a first counter tracking a first number corresponding to 0 attempts for the selected thread to enter the second phase has been exhausted;

当第一计数器耗尽时,不能服务中断,并保持在第一队列中;When the first counter is exhausted, the interrupt cannot be serviced and remains in the first queue;

当第一计数器指示对应组尝试的至少一个第一机会时,确定第二计数器是否通过所选线程跟踪第二数字,第二数字对应进入第二阶段的每次尝试;When the first counter indicates at least one first opportunity for the corresponding set of attempts, determining whether the second counter tracks a second number by the selected thread, the second number corresponding to each attempt entering the second phase;

当第二计数器指示至少一个第二尝试机会时,在选所线程执行尝试之后递5减第二计数器;When the second counter indicates at least one second attempt opportunity, decrementing the second counter by 5 after the selected thread performs the attempt;

当第二计数器耗尽时,接收选所线程已服务的中断,递减第一计数器。When the second counter is exhausted, receiving an interrupt that the selected thread has serviced, decrementing the first counter.

可选的,当年龄在第二阶段的第二线程中不是最老时,并且,当所选第二线程释放锁后锁是可用的,从第二阶段剩余的第二线程中进行选择以获得锁。Optionally, when the age is not the oldest among the second threads in the second stage, and the lock is available when the selected second thread releases the lock, select from the remaining second threads in the second stage to obtain Lock.

可选的,所选第二线程获取锁基于原子测试和设置操作,在所选第二线程获取锁操作中,第二线程竞争锁。Optionally, the selected second thread acquires the lock based on an atomic test and set operation, and in the selected second thread's lock acquisition operation, the second thread competes for the lock.

可选的,每个线程都在最大持续时间内得到服务。Optionally, each thread is serviced for a maximum duration.

可选的,最大持续时间基于第一队列中的一个线程的时间顺序条目,第二阶段配置的第二线程的最大数量以及具有较低时间顺序条目的线程的数量。Optionally, the maximum duration is based on a chronological entry of a thread in the first queue, the maximum number of second threads configured in the second stage, and the number of threads with lower chronological entries.

综上所述,本申请包括以下有益技术效果:In summary, the application includes the following beneficial technical effects:

本申请自旋锁机制创建确定性自旋锁,同时允许等待线程在等待锁获取时服务中断,自旋锁可以为请求资源的线程分配票,以将它们放在第一阶段,而在第一阶段,线程可能仍然服务于中断,当进入第二阶段时,自旋锁可基于对资源的竞争将资源分配给线程。两阶段自旋锁可利用各种特性来保持确定性方法,同时仍然提供服务中断的机会,允许在等待时处理中断,同时最终成功获得锁时没有发生死锁的风险。The spin lock mechanism of this application creates a deterministic spin lock, and at the same time allows waiting threads to be interrupted in service while waiting for the lock to be acquired. In the first stage, the thread may still service the interrupt. When entering the second stage, the spin lock can allocate resources to threads based on competition for resources. Two-phase spinlocks can take advantage of various properties to maintain a deterministic approach while still providing the opportunity for service interruptions, allowing interruptions to be handled while waiting, without the risk of deadlock when the lock is eventually successfully acquired.

两阶段自旋锁配置为线程获取锁时确保“获取”内存语义;解锁操作提供“释放”内存语义。因此,具有自旋锁操作的确定性方式,同时仍然提供服务中断的机会,两阶段自旋锁可以比传统自旋锁以更高效和更快的方式操作。The two-phase spinlock configuration ensures "acquire" memory semantics when a thread acquires the lock; the unlock operation provides "release" memory semantics. Thus, having a deterministic manner of spinlock operation while still providing the opportunity for service interruption, two-phase spinlocks can operate in a more efficient and faster manner than traditional spinlocks.

附图说明Description of drawings

为了更清楚地说明本申请实施例的技术方案,下面将对实施例中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其它的附图。In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the accompanying drawings that need to be used in the embodiments. Obviously, the accompanying drawings in the following description are only some embodiments of the present application. Those of ordinary skill in the art can also obtain other drawings based on these drawings without any creative effort.

图1为本申请两阶段自旋锁的示例性系统;Fig. 1 is the exemplary system of two-stage spin lock of the present application;

图2为本申请两阶段自旋锁的第一阶段的示例性方法;Fig. 2 is the exemplary method of the first stage of the two-stage spin lock of the present application;

图3为本申请两阶段自旋锁的第二阶段的示例性方法。FIG. 3 is an exemplary method of the second stage of the two-stage spinlock of the present application.

具体实施方式Detailed ways

下面结合附图对本申请实施例进行详细描述。Embodiments of the present application will be described in detail below in conjunction with the accompanying drawings.

以下通过特定的具体实例说明本申请的实施方式,本领域技术人员可由本说明书所揭露的内容轻易地了解本申请的其他优点与功效。显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。本申请还可以通过另外不同的具体实施方式加以实施或应用,本说明书中的各项细节也可以基于不同观点与应用,在没有背离本申请的精神下进行各种修饰或改变。需说明的是,在不冲突的情况下,以下实施例及实施例中的特征可以相互组合。基于本申请中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。Embodiments of the present application are described below through specific examples, and those skilled in the art can easily understand other advantages and effects of the present application from the content disclosed in this specification. Apparently, the described embodiments are only some of the embodiments of this application, not all of them. The present application can also be implemented or applied through other different specific implementation modes, and various modifications or changes can be made to the details in this specification based on different viewpoints and applications without departing from the spirit of the present application. It should be noted that, in the case of no conflict, the following embodiments and features in the embodiments can be combined with each other. Based on the embodiments in this application, all other embodiments obtained by persons of ordinary skill in the art without creative efforts fall within the protection scope of this application.

要说明的是,下文描述在所附权利要求书的范围内的实施例的各种方面。应显而易见,本文中所描述的方面可体现于广泛多种形式中,且本文中所描述的任何特定结构及/或功能仅为说明性的。基于本申请,所属领域的技术人员应了解,本文中所描述的一个方面可与任何其它方面独立地实施,且可以各种方式组合这些方面中的两者或两者以上。举例来说,可使用本文中所阐述的任何数目个方面来实施设备及/或实践方法。另外,可使用除了本文中所阐述的方面中的一或多者之外的其它结构及/或功能性实施此设备及/或实践此方法。It is noted that the following describes various aspects of the embodiments that are within the scope of the appended claims. It should be apparent that the aspects described herein may be embodied in a wide variety of forms and that any specific structure and/or function described herein is illustrative only. Based on the present application one skilled in the art should appreciate that an aspect described herein may be implemented independently of any other aspects and that two or more of these aspects may be combined in various ways. For example, any number of the aspects set forth herein can be used to implement an apparatus and/or practice a method. In addition, such an apparatus may be implemented and/or such a method practiced using other structure and/or functionality than one or more of the aspects set forth herein.

还需要说明的是,以下实施例中所提供的图示仅以示意方式说明本申请的基本构想,图式中仅显示与本申请中有关的组件而非按照实际实施时的组件数目、形状及尺寸绘制,其实际实施时各组件的型态、数量及比例可为一种随意的改变,且其组件布局型态也可能更为复杂。It should also be noted that the diagrams provided in the following embodiments are only schematically illustrating the basic idea of the application, and only the components related to the application are shown in the drawings rather than the number, shape and number of components in actual implementation. Dimensional drawing, the type, quantity and proportion of each component can be changed arbitrarily during actual implementation, and the component layout type may also be more complicated.

另外,在以下描述中,提供具体细节是为了便于透彻理解实例。然而,所属领域的技术人员将理解,可在没有这些特定细节的情况下实践所述方面。Additionally, in the following description, specific details are provided to facilitate a thorough understanding of examples. However, it will be understood by those skilled in the art that the described aspects may be practiced without these specific details.

本申请实施例提供一种可优化中断延迟的自旋锁的实现方法。An embodiment of the present application provides a method for implementing a spin lock that can optimize interrupt latency.

示例性实施例涉及用于实现具有饥饿保护特性的自旋锁机制的设备、系统和方法,该自旋锁机制创建确定性自旋锁,同时允许等待线程在等待锁获取时服务中断。自旋锁可以为请求资源的线程分配票,以将它们放在第一阶段。而在第一阶段,线程可能仍然服务于中断。当进入第二阶段时,自旋锁可基于对资源的竞争将资源分配给线程。两阶段自旋锁可利用各种特性来保持确定性方法,同时仍然提供服务中断的机会。示例性实施例允许在等待时处理中断,同时最终成功获得锁时没有发生死锁的风险。Exemplary embodiments relate to apparatus, systems, and methods for implementing a spinlock mechanism with starvation protection properties that create deterministic spinlocks while allowing waiting threads to service interruptions while waiting for lock acquisition. Spinlocks can assign tickets to threads requesting resources to put them in the first phase. While in the first phase, the thread may still be servicing the interrupt. When entering the second phase, spinlocks can allocate resources to threads based on contention for the resource. Two-phase spinlocks can take advantage of various properties to maintain a deterministic approach while still providing the opportunity for service interruption. Exemplary embodiments allow interrupts to be handled while waiting without the risk of deadlock when the lock is eventually successfully acquired.

所述示例性实施例提供两阶段自旋锁,通过多个请求实体(例如,处理器)控制对资源的访问。两阶段自旋锁可包括提供第一队列的第一阶段,在该队列中请求资源的线程可以自旋。在第一阶段,线程可服务中断;两阶段自旋锁包括提供第二队列的第二阶段,其中,请求资源的线程竞争资源。在第二阶段,会禁止线程为中断服务。The exemplary embodiments provide a two-phase spin lock to control access to resources by multiple requesting entities (eg, processors). A two-phase spinlock may include a first phase that provides a first queue in which threads requesting resources may spin. In the first phase, threads may service interrupts; the two-phase spinlock includes a second phase providing a second queue in which threads requesting resources compete for resources. In the second phase, the thread is disabled from servicing interrupts.

根据示例性实施例的两阶段自旋锁配置为线程获取锁时确保“获取”内存语义;解锁操作提供“释放”内存语义。因此,示例性实施例具有自旋锁操作的确定性方式,同时仍然提供服务中断的机会,两阶段自旋锁可以比传统自旋锁以更高效和更快的方式操作。A two-phase spinlock configuration according to an exemplary embodiment ensures "acquire" memory semantics when a thread acquires a lock; an unlock operation provides "release" memory semantics. Thus, the exemplary embodiments have a deterministic manner of spinlock operation, while still providing opportunities for service interruptions, two-phase spinlocks can operate in a more efficient and faster manner than traditional spinlocks.

图1表示两阶段自旋锁的示例性系统Figure 1 represents an exemplary system for a two-phase spinlock

系统包括多个处理器、自旋锁和资源。A system includes multiple processors, spinlocks, and resources.

“处理器”描述试图访问资源的实体。“处理器”可代表一个硬件处理器、一个软件应用程序、请求访问资源的执行线程等。A "handler" describes an entity attempting to access a resource. "Processor" may represent a hardware processor, a software application, a thread of execution requesting access to a resource, and the like.

资源可以是任何具有有限容量的资源,禁止超过预定数量的处理器(或请求实体)并发访问资源。例如,资源可能是一段共享内存空间,一个外设等。A resource can be any resource with a limited capacity, and more than a predetermined number of processors (or requesting entities) are prohibited from concurrently accessing the resource. For example, a resource might be a shared memory space, a peripheral, etc.

自旋锁可以是两阶段自旋锁,其中线程可以进入自旋锁的第一阶段或第二阶段。在第一阶段,线程可以进入自旋状态,等待进入第二阶段。而在第二阶段,线程可在竞争资源时保持自旋状态,直到获得资源。A spinlock can be a two-phase spinlock, where a thread can enter either the first phase or the second phase of the spinlock. During the first phase, the thread can enter the spin state, waiting to enter the second phase. In the second phase, threads can keep spinning while competing for resources until they are acquired.

根据所述示例性实施例,锁定过程分为两个阶段。在第一阶段,自旋锁为每个请求资源的线程在一个“票”计数器上执行一个原子的获取-递增操作。在第一阶段,正在自旋的线程可在适当的时候继续为中断服务。在第一阶段,自旋锁不会实现在第一阶仍在自旋的线程的最大数量。在第二阶段,自旋锁对在第二阶段自旋的线程执行获取-释放操作。在第二阶段,自旋锁可实现在第二阶段保持自旋的线程的最大数量。According to the exemplary embodiment, the locking process is divided into two phases. In the first phase, the spinlock performs an atomic acquire-increment operation on a "ticket" counter for each thread requesting the resource. During the first phase, the spinning thread can continue to service interrupts when appropriate. In the first stage, the spinlock does not achieve the maximum number of threads still spinning in the first stage. In the second phase, the spin lock performs an acquire-release operation on the thread that was spinning in the second phase. In the second phase, the spin lock enables the maximum number of threads that are held spinning in the second phase.

根据所述示例性实施例,自旋锁可保证在获取所述资源之前,线程具有最大的有界等待时间。例如,根据所述示例性实施例,具有票N的线程可以在不晚于N+D+W个线程被授予锁之后被服务。W是在第一阶段中运行的票号小于N的线程数,W是一个动态组件,它取决于锁竞争的程度,其中W不超过系统中的线程数减1;D是一个挂起的CPU线程在第一阶段丢弃票的最大次数。在使能本地中断之前,应先丢弃票。一旦本地中断被使能,任何挂起的中断都将被服务。因此,通过自旋锁的执行机制,示例性实施例可以确保对于正在自旋的某个线程在被授予锁之前必须等待的次数有一个上限。According to the exemplary embodiment, a spin lock can guarantee a maximum bounded wait time for a thread before acquiring the resource. For example, according to the exemplary embodiment, a thread with ticket N may be serviced no later than N+D+W threads are granted the lock. W is the number of threads with ticket numbers less than N running in the first phase, W is a dynamic component that depends on the degree of lock contention, where W does not exceed the number of threads in the system minus 1; D is a hung CPU The maximum number of times a thread discards a ticket in the first phase. Tickets should be discarded before enabling local interrupts. Once local interrupts are enabled, any pending interrupts will be serviced. Thus, through the spinlock enforcement mechanism, exemplary embodiments can ensure that there is an upper bound on the number of times a thread that is spinning must wait before being granted the lock.

本申请实施例提供一种可优化中断延迟的自旋锁的实现方法。An embodiment of the present application provides a method for implementing a spin lock that can optimize interrupt latency.

一种可优化中断延迟的自旋锁的实现方法,包括:A method for implementing a spin lock capable of optimizing interrupt latency, comprising:

采用两阶段自旋锁控制多个线程对资源进行访问,所述两阶段自旋锁包括多个第一线程的第一阶段。Access to resources by multiple threads is controlled by using a two-stage spin lock, and the two-stage spin lock includes a first stage of multiple first threads.

接收线程的请求来获取资源,把线程放在与两阶段自旋锁的第一阶段关联的第一队列上,因为第一线程与两阶段自旋锁的第一阶段相关联,确定两阶段自旋锁的第二阶段中是否至少有一个预定的插槽可用,当插槽不可用时,根据所选线程进入第二阶段的尝试次数,处理由所选线程服务的中断,当至少一个插槽可用时,根据时间优先级顺序选择第一线程之一进入第二阶段,确定访问资源的锁是否可用。Receive a thread's request to acquire resources, put the thread on the first queue associated with the first phase of the two-phase spinlock, because the first thread is associated with the first phase of the two-phase spinlock, determine the two-phase self Whether at least one of the scheduled slots is available in the second phase of the spinlock, and when a slot is unavailable, handles the interrupt serviced by the selected thread, based on the number of attempts the selected thread made to enter the second phase, when at least one slot is available , select one of the first threads to enter the second stage according to the order of time priority, and determine whether the lock to access the resource is available.

确定访问资源的锁是否可用,当锁可用时,从两阶段自旋锁的第二阶段中的多个第二线程中选择一个来获取锁,确定所选第二线程的年龄,当年龄不是第二阶段的第二线程中最老的,禁止任何第一线程进入第二阶段;否则,当年龄是第二阶段的第二线程中最老的,选择最老的第一线程进入第二阶段。其中确定锁是否可用的方法是设置标志,该标志表示锁是否可用。其中第二线程禁止服务中断。Determine whether a lock to access a resource is available, when the lock is available, select one of multiple second threads in the second stage of the two-stage spinlock to acquire the lock, determine the age of the selected second thread, and when the age is not the first The oldest of the second threads in the second stage, prohibit any first thread from entering the second stage; otherwise, when the age is the oldest of the second threads in the second stage, select the oldest first thread to enter the second stage. One of the ways to determine whether a lock is available is to set a flag that indicates whether the lock is available. Wherein the second thread disables service interruption.

接收来自所选线程的进一步请求,并将所选线程放在第一队列中。Receives further requests from the selected thread and places the selected thread in the first queue.

将线程放在第一队列中的操作基于原子的获取和增加操作,获取和增加操作包括:根据时间优先级顺序为每个线程分配各自的票号。The operation of putting threads in the first queue is based on atomic acquire and add operations, and the acquire and add operations include: assigning respective ticket numbers to each thread according to time priority order.

确定跟踪第一数字的第一计数器是否已经耗尽,第一数字对应于所选线程5进入第二阶段的尝试次数;当第一计数器耗尽时,不能服务中断,并保持在第一队列中;当第一计数器指示对应组尝试的至少一个第一机会时,确定第二计数器是否通过所选线程跟踪第二数字,第二数字对应进入第二阶段的每次尝试;当第二计数器指示至少一个第二尝试机会时,在选所线程执行尝试之后递减第Determines whether the first counter tracking the first number corresponding to the number of attempts to enter the second phase by the selected thread 5 has been exhausted; when the first counter is exhausted, interrupts cannot be serviced and remain in the first queue ; when the first counter indicates at least one first opportunity for the corresponding set of attempts, determine whether the second counter tracks a second number by the selected thread, the second number corresponding to each attempt to enter the second phase; when the second counter indicates at least A second chance to try, after the selected thread execution attempt is decremented

二计数器;当第二计数器耗尽时,接收选所线程已服务的中断,递减第一计数0器。Two counters; when the second counter is exhausted, receive the interrupt serviced by the selected thread, and decrement the first counter 0.

当年龄在第二阶段的第二线程中不是最老时,并且,当所选第二线程释放锁后锁是可用的,从第二阶段剩余的第二线程中进行选择以获得锁。When the age is not the oldest among the second threads of the second stage, and the lock is available when the selected second thread releases the lock, a selection is made from the remaining second threads of the second stage to acquire the lock.

所选第二线程获取锁基于原子测试和设置操作,在所选第二线程获取锁操作中,第二线程竞争锁。The selected second thread acquires the lock based on an atomic test and set operation in which the selected second thread acquires the lock in which the second thread competes for the lock.

5每个线程都在最大持续时间内得到服务。最大持续时间基于第一队列中的一个线程的时间顺序条目,第二阶段配置的第二线程的最大数量以及具有较低时间顺序条目的线程的数量。5 Each thread is serviced for a maximum duration. The maximum duration is based on the chronological entry of one thread in the first queue, the maximum number of second threads configured in the second stage, and the number of threads with lower chronological entries.

如图2所示,在第一阶段自旋的线程会在等待进入第二阶段的时候提供中断服务。中断服务并不会打断使用自旋锁的确定性方式。例如,一个票号为N的线程不会阻塞一个票号为N+1的线程,这将是一个纯粹基于票的传统自旋锁As shown in Figure 2, the thread spinning in the first phase will provide interrupt service while waiting to enter the second phase. Interrupt servicing does not interrupt the deterministic way spinlocks are used. For example, a thread with ticket number N will not block a thread with ticket number N+1, it will be a purely ticket-based traditional spinlock

实现。假设N是最老的票(例如,自旋锁分发的票号为最低票号),当至少具5有票号N-A的线程已经在第二阶段服务时,具有票号N的线程接下来进入第二阶段。通过这种方式,票可以识别一个年龄,该年龄对应一个票号(例如,最高年龄的票有最低票号,最低年龄的票有最高票号)。accomplish. Assuming N is the oldest ticket (e.g., the ticket number issued by the spinlock is the lowest ticket number), when at least 5 threads with ticket number N-A have been served in the second phase, the thread with ticket number N enters next second stage. In this way, tickets can identify an age, which corresponds to a ticket number (e.g., tickets with the highest age have the lowest ticket number, tickets with the youngest age have the highest ticket number).

主要流程:Main process:

自旋锁从线程接收对资源的请求。自旋锁可以给线程分配一张票。自旋锁0可使用任何基于票的机制来处理请求并分配票。把线程放于自旋锁的第一阶段。Spinlocks receive requests for resources from threads. A spin lock can assign a ticket to a thread. Spinlock 0 can use any ticket-based mechanism to process requests and allocate tickets. Put the thread in the first phase of the spinlock.

例如,线程在第一阶段自旋,等待对资源的访问。For example, threads spin in the first phase, waiting for access to resources.

自旋锁决定第二阶段是否可用。自旋锁的第二阶段有变量“A”,这是可被正在自旋的线程填充的最大插槽数量。因此,自旋锁可识别一个插槽何时是打A spinlock determines whether the second phase is available. The second stage of the spinlock has variable "A", which is the maximum number of slots that can be filled by the thread that is spinning. Thus, a spinlock can identify when a slot is

开的(例如,设置了某个标志)。例如,资源已经可用,因此,处于第二阶段5的线程可以获得资源。当发生这种情况时,获得资源的线程不再自旋,并退出第二阶段,此时被占用的插槽现在是空闲的。On (for example, a flag is set). For example, a resource is already available, so a thread in second phase 5 can acquire the resource. When this happens, the thread that acquired the resource no longer spins, and exits the second phase, at which point the occupied slot is now free.

如果第二阶段的插槽是可用的,自旋锁从第一阶段中自旋的线程中选择一个拥有最老票号的线程。例如,票可以根据时间顺序分配给每个请求资源的线程(例如,从票号1开始,到票号N)。使用这种票号分配方案,可以选择票号最低的票。自旋锁可以将选定的线程置于第二阶段。If a second-stage slot is available, the spinlock selects the thread with the oldest ticket number among the threads spun in the first stage. For example, tickets may be assigned to each thread requesting a resource in chronological order (eg, starting with ticket number 1 and going to ticket number N). With this ticket number assignment scheme, the ticket with the lowest ticket number can be chosen. A spinlock can place selected threads in the second phase.

如果第二阶段的插槽不可用,自旋锁决定处于第一阶段自旋线程是否仍然有机会服务中断。在做这个决定时,自旋锁可以利用丢弃计数器。丢弃计数器可以跟踪进入第二阶段尝试的次数。丢弃计数器可以限制第一阶段的自旋线程服务中断的持续时间。如上所述,CPU线程所能做的最大丢弃数被限制为“D”。根据所述示例性实施例的自旋锁使用处于第一阶段的自旋线程服务中断。然而,持续使用中断可能会导致一个特定的线程无限期地停留在第一阶段而不进入第二阶段,因为每次服务中断时,线程会丢弃票,并失去其在第一阶段队列中的位置。当线程丢弃票并重新进入第一阶段时,自旋锁可重新分配一个新票,它有一个最新的票号(例如,最高的票号)。If the slot in the second stage is not available, the spin lock determines whether the thread spinning in the first stage still has a chance to service the interrupt. In making this decision, spinlocks can take advantage of discard counters. A drop counter keeps track of the number of attempts to enter the second phase. The drop counter can limit the duration of the interruption of the spin thread service in the first phase. As mentioned above, the maximum number of discards a CPU thread can do is limited to "D". A spinlock according to the exemplary embodiment services interrupts using a spin thread in the first phase. However, continued use interruptions may cause a particular thread to stay in the first stage indefinitely without entering the second stage, because each time the service is interrupted, the thread discards the ticket and loses its place in the first stage queue . When a thread discards a ticket and re-enters Phase 1, the spinlock can reallocate a new ticket with an up-to-date ticket number (e.g., the highest ticket number).

当丢弃计数器过期或者耗尽,不再有机会提供中断服务时,线程继续在票所表示的位置自旋。当丢弃计数器表明有更多的机会服务中断时,自旋锁决定处于第一阶段的自旋线程是否还有机会尝试进入第二阶段。在传统自旋锁机制下,自旋锁试图以基本类似的方式获得资源,第一阶段的自旋线程可尝试独立于票进入第二阶段。如上所述,丢弃计数器可跟踪一组由自旋线程从第一阶段进入第二阶段所执行的尝试次数。在第一阶段的每个自旋线程可以进一步利用自旋锁计数器跟踪多个第一阶段的自旋线程尝试进入第二阶段的次数。然而,在自旋锁将自旋线程从第一阶段转移到第二阶段的机制下,第一阶段的自旋线程可保持在第一阶段。假设线程保持在第一阶段,自旋锁将减少给定线程的自旋锁计数器。When the discard counter expires or is exhausted and there is no longer an opportunity to service the interrupt, the thread continues to spin at the position indicated by the ticket. When the discard counter indicates that there are more opportunities to service the interrupt, the spin lock determines whether the spinning thread in the first stage has a chance to try to enter the second stage. Under the traditional spin lock mechanism, the spin lock tries to obtain resources in a basically similar manner, and the spin thread in the first phase can try to enter the second phase independently of the ticket. As mentioned above, the drop counter may track a set of attempts performed by the spinning thread from the first phase to the second phase. Each spin thread in the first stage may further track the number of times a plurality of first stage spin threads attempt to enter the second stage using a spin lock counter. However, under the mechanism of the spin lock to transfer the spinning thread from the first stage to the second stage, the spinning thread of the first stage can remain in the first stage. Assuming the thread remains in the first phase, the spinlock will decrement the spinlock counter for the given thread.

当自旋锁计数器表明在第一阶段的自旋线程没有机会进入第二阶段时,自旋锁继续执行。自旋锁确定当进入第二阶段的所有尝试都被线程耗尽时,发生了一个丢弃计数器的实例。因此,自旋锁允许线程服务中断。当中断被服务时,自旋锁会减少丢弃计数器。在当中断被服务时,自旋锁为线程丢弃票。自旋锁返回,这样线程被分配了一个新票(例如,一个最新的票号)。When the spinlock counter indicates that the spinning thread in the first stage has no chance to enter the second stage, the spinlock continues to execute. The spinlock determines that when all attempts to enter the second phase have been exhausted by the thread, an instance of discarding the counter occurs. Thus, spinlocks allow threads to service interruptions. The spinlock decrements the discard counter when the interrupt is serviced. When the interrupt is serviced, the spin lock discards the ticket for the thread. The spinlock returns so that the thread is assigned a new ticket (eg, an up-to-date ticket number).

如图3所示,在第二阶段,自旋锁可以限制在这个阶段的线程的数量。因此,在第二阶段中自旋的线程不会超过A。第二阶段的线程集可以在锁上自旋直到变为可用状态,然后,通过对锁定的原子标志的执行原子测试和设置操作来竞争锁。因此,线程不一定会按照严格的票顺序获得锁,因为第二阶段中的任何线程可能会“赢得”原子测试和设置以获得锁。可以使用获取内存语义执行测试和设置操作,并且,可以使用解锁路径中的释放语义将相同的变量存储在其中,以便为锁实现适当的内存一致性语义。锁定/解锁路径中的所有其他原子操作可以使用“放松”原子(例如,与任何其他加载/存储没有同步的原子操作),这会更快。As shown in Figure 3, in the second phase, the spin lock can limit the number of threads in this phase. Therefore, no more threads than A will spin in the second phase. The second-stage set of threads can spin on the lock until it becomes available, and then compete for the lock by performing atomic test-and-set operations on the lock's atomic flag. Thus, threads will not necessarily acquire the lock in strict ticket order, since any thread in the second phase may "win" the atomic test-and-set to acquire the lock. Test and set operations can be performed using acquire memory semantics, and the same variable can be stored in it using release semantics in the unlock path to achieve proper memory consistency semantics for the lock. All other atomic operations in the lock/unlock path can use "relaxed" atomics (eg, atomic operations that are not synchronized with any other loads/stores), which will be faster.

自旋锁确定资源的锁的状态。例如,在控制资源访问时,自旋锁可以允许预定数量的线程访问资源。通常,自旋锁是一种互斥机制,只允许一个可写入资源的线程获得锁。但是,在一些示例性实施例中,可以将读者与写者分离,其中只有一个写者但是有多个读者。在确定状态时,自旋锁会检查资源的一个标志,该标志表明可以获得资源。自旋锁决定资源的锁是否可用。例如,当系A spin lock determines the state of a resource's lock. For example, when controlling access to a resource, a spinlock can allow a predetermined number of threads to access the resource. Typically, a spin lock is a mutual exclusion mechanism that allows only one thread that can write to a resource to acquire the lock. However, in some exemplary embodiments, readers may be separated from writers, where there is only one writer but multiple readers. When determining state, a spinlock checks the resource for a flag that indicates that the resource can be acquired. A spin lock determines whether a resource lock is available. For example, when the department

统被激活,而资源没有完全锁定,或者,一个线程最近释放了资源的锁,其中5任何一种情况都导致资源的锁标志被设置为可用,那么该锁则是可用的。在另一个例子中,资源的每个锁都被一个线程占用,这样就没有可用的锁了。如果没有可用的锁,则继续监控资源锁的状态。The lock is available if the system is active and the resource is not fully locked, or if a thread has recently released the resource's lock, either of which causes the resource's lock flag to be set to available. In another example, each lock on a resource is held by a thread such that no locks are available. If no locks are available, continue to monitor the status of resource locks.

如果该资源有一个可用的锁,执行原子的测试和设置操作,第二阶段的每个自旋线程竞争可用的锁以获得资源。If the resource has an available lock, an atomic test-and-set operation is performed, and each spin thread in the second phase competes for the available lock to acquire the resource.

0自旋锁决定退出第二阶段的胜出线程的票,并获得资源的锁。如上所述,The 0-spin lock determines the ticket of the winning thread exiting the second phase and acquires the lock on the resource. As mentioned above,

示例性实施例可以保证在处理该线程(例如,获得资源)之前必须在第一阶段和第二阶段等待的上限。在执行此保证的一个操作中,自旋锁会在某些条件适用时禁止线程进入第二阶段。自旋锁可以确定一个条件,即获胜的线程的票是Exemplary embodiments may guarantee an upper bound on what must wait in the first and second phases before processing the thread (eg, acquiring a resource). In one operation that enforces this guarantee, a spinlock prevents a thread from entering the second phase when certain conditions apply. A spinlock can determine a condition that the winning thread's ticket is

否为最老的票(例如最低号码票)。在这个实例中,赢得锁的线程持有最老的5票,自旋锁为第一阶段的自旋线程打开第二阶段。如上所述,在第一阶段自旋的线程有最老的票被选择放在第二阶段。随后,在第二阶段用新引入的线程重复上述方法;在这个实例中,赢得锁的线程不是最老的,而自旋锁向第一阶段的线程关闭第二阶段。随后,自旋锁返回,重复上述方法,只有剩余的线程在第二阶段进行自旋。No is the oldest ticket (eg lowest numbered ticket). In this instance, the thread that won the lock holds the oldest 5 votes, and the spin lock opens the second phase for the spinning thread of the first phase. As mentioned above, the thread that spins in the first phase has the oldest ticket selected to be placed in the second phase. Subsequently, the above method is repeated in the second phase with newly introduced threads; in this instance, the thread that won the lock is not the oldest, and the spinlock closes the second phase to the thread of the first phase. Subsequently, the spin lock returns, and the above method is repeated, and only the remaining threads spin in the second stage.

在示例场景中,自旋锁最多允许三个线程在第二阶段进行自旋,而资源只有一个锁可用。第二阶段中的线程包括线程A、B和C,从最老的到最新的,而线程D是第一阶段中最老的。在第一个例子中,线程A赢得锁。当线程A释放锁时,自旋锁会确定线程A是最老的,从而允许第一阶段的线程进入第二阶段。因此,线程D可从第一阶段过渡到第二阶段。第二阶段中的线程现在是线程B、C和D。In the example scenario, the spin lock allows up to three threads to spin in the second phase, while only one lock is available for the resource. Threads in the second phase include threads A, B, and C, from oldest to newest, while thread D is the oldest in the first phase. In the first example, thread A wins the lock. When thread A releases the lock, the spinlock determines that thread A is the oldest, allowing the threads in the first phase to enter the second phase. Thus, thread D can transition from the first phase to the second phase. The threads in the second phase are now threads B, C and D.

在第二个例子中,线程B赢得锁。当线程B释放锁时,自旋锁会确定线程B持有最老的票因为线程A还在第二阶段。因此,自旋锁可以禁止一个新线程从第一阶段进入第二阶段。在接下来的竞争中,线程A和线程C会竞争锁。如果线程A获胜,则可以使用第一个示例中执行的操作。因此,当线程A释放锁时,自旋锁会允许第一阶段的线程进入第二阶段。在这种情况下,线程D和线程E可以从第一阶段过渡到第二阶段,因为在第二阶段中有两个可用的插槽。第二阶段中的线程是C、D和E。然而,线程B释放锁之后,如果线程C获胜,则在第二个示例中执行的操作会重复。因此,在线程C释放锁后,唯一剩下的是线程A。在没有其他竞争的情况下,线程A肯定会赢得这个资源的锁。由于线程A是最老的,在线程A释放锁之后,所有三个插槽对第一阶段的线程都是开放的。因此,第二阶段中的线程现在是线程D、E和F。In the second example, thread B wins the lock. When thread B releases the lock, the spinlock will determine that thread B holds the oldest ticket because thread A is still in the second phase. Therefore, a spin lock can prevent a new thread from entering the second phase from the first phase. In the next competition, thread A and thread C will compete for the lock. If thread A wins, you can use what you did in the first example. Therefore, when thread A releases the lock, the spin lock will allow the thread in the first stage to enter the second stage. In this case, thread D and thread E can transition from stage one to stage two because there are two slots available in stage two. The threads in the second phase are C, D and E. However, after thread B releases the lock, the operations performed in the second example are repeated if thread C wins. So after thread C releases the lock, the only thing left is thread A. In the absence of other contention, thread A will definitely win the lock on this resource. Since thread A is the oldest, after thread A releases the lock, all three slots are open to threads in the first stage. Therefore, the threads in the second phase are now threads D, E, and F.

所述示例性实施例提供了一种实现两阶段自旋锁的设备、系统和方法,该两阶段自旋锁以确定的方式使用,同时使中断能够被服务,同时也提供饥饿保护。两阶段自旋锁的第一阶段控制对资源访问,可以使用票机制处理对资源的请求,该机制在接收到请求时按时间顺序排序。第一阶段的线程可以为中断服务,特别是基于一个可跟踪进入两阶段自旋锁第二阶段的尝试次数的丢弃计数器和一个可跟踪每次进入第二阶段的尝试的自旋计数器。两阶段自旋锁的第二阶段可以对允许处于第二阶段的预定最大线程数量执行获取和释放操作。自旋锁可以确保只有当最老的票线程获得了资源的锁时,新线程才能从第一阶段进入第二阶段。The exemplary embodiments provide an apparatus, system, and method that implement a two-phase spinlock that is used in a deterministic manner while enabling interrupts to be serviced while also providing starvation protection. The first stage of a two-stage spinlock controls access to resources, and requests for resources can be processed using a ticket mechanism that sorts requests in chronological order as they are received. Threads in the first phase can service interrupts, specifically based on a drop counter that tracks the number of attempts to enter the second phase of the two-phase spinlock and a spin counter that tracks each attempt to enter the second phase. The second phase of a two-phase spinlock can perform acquire and release operations on a predetermined maximum number of threads allowed to be in the second phase. The spin lock can ensure that only when the oldest ticket thread acquires the resource lock, the new thread can enter the second stage from the first stage.

以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到的变化或替换,都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以权利要求的保护范围为准。The above is only a specific embodiment of the application, but the scope of protection of the application is not limited thereto. Any person familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the application. All should be covered within the scope of protection of this application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims (7)

1. A method for implementing a spin lock that optimizes interrupt latency, comprising:
controlling a plurality of threads to access a resource by adopting a two-stage spin lock, wherein the two-stage spin lock comprises a first stage of a plurality of first threads;
receiving a request for a thread to acquire a resource, placing the thread on a first queue associated with a first phase of the two-phase spin lock, determining whether at least one predetermined slot is available in a second phase of the two-phase spin lock, when the slot is not available, processing an interrupt serviced by the selected thread according to a number of attempts by the selected thread to enter the second phase, when at least one slot is available, selecting one of the first threads to enter the second phase according to a time priority order;
determining whether a lock to access the resource is available, selecting one of a plurality of second threads in a second phase of the two-phase spin lock to acquire the lock when the lock is available, determining an age of the selected second thread, and prohibiting any first thread from entering the second phase when the age is not the oldest of the second threads in the second phase; otherwise, when the age is the oldest in the second threads of the second stage, selecting the oldest first thread to enter the second stage;
further requests from the selected thread are received and the selected thread Cheng Fang is in the first queue.
2. The method of claim 1, wherein the act of placing the thread in the first queue is based on an atomic acquire and add operation, the acquire and add operation comprising: each thread is assigned a respective ticket number according to the time priority order.
3. The method of claim 1, wherein determining whether a first counter tracking a first number has been exhausted, the first number corresponding to a number of attempts by the selected thread to enter the second phase;
when the first counter is exhausted, the interrupt cannot be serviced and remains in the first queue;
determining if the second counter passes the selected line Cheng Genzong a second number corresponding to each attempt to enter the second phase when the first counter indicates at least one first opportunity for a corresponding set of attempts;
decrementing the second counter after the selected thread performs the attempt when the second counter indicates at least one second attempt opportunity;
when the second counter is exhausted, an interrupt is received that the selected thread has serviced, and the first counter is decremented.
4. The method of claim 1, wherein when the age is not the oldest in the second threads of the second phase, and the lock is available after the selected second thread releases the lock, selecting from the remaining second threads of the second phase to obtain the lock.
5. The method of claim 1, wherein the selected second thread acquire lock is based on an atomic test and set operation in which the second thread contends for the lock.
6. The method of claim 1, wherein each thread is serviced for a maximum duration.
7. The method of claim 1, wherein the maximum duration is based on a chronological entry of one thread in the first queue, a maximum number of second threads of the second stage configuration, and a number of threads having a lower chronological entry.
CN202211626148.7A 2022-12-15 2022-12-15 Implementation method of spin lock capable of optimizing interrupt delay Pending CN116204303A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211626148.7A CN116204303A (en) 2022-12-15 2022-12-15 Implementation method of spin lock capable of optimizing interrupt delay

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211626148.7A CN116204303A (en) 2022-12-15 2022-12-15 Implementation method of spin lock capable of optimizing interrupt delay

Publications (1)

Publication Number Publication Date
CN116204303A true CN116204303A (en) 2023-06-02

Family

ID=86510347

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211626148.7A Pending CN116204303A (en) 2022-12-15 2022-12-15 Implementation method of spin lock capable of optimizing interrupt delay

Country Status (1)

Country Link
CN (1) CN116204303A (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100031265A1 (en) * 2008-07-31 2010-02-04 Maarten Koning Method and System for Implementing Realtime Spinlocks
CN111984428A (en) * 2020-07-20 2020-11-24 上海金仕达软件科技有限公司 A method, device and device for implementing spin lock during resource access
CN112306699A (en) * 2019-07-29 2021-02-02 华为技术有限公司 Method and apparatus for accessing critical resources, computer equipment and readable storage medium
US20210216378A1 (en) * 2020-01-10 2021-07-15 Wind River Systems, Inc. Systems and Methods for Interrupting Latency Optimized Two-phase Spinlock
CN113806099A (en) * 2021-09-13 2021-12-17 北京计算机技术及应用研究所 Multi-core spin lock design method based on binary computation

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100031265A1 (en) * 2008-07-31 2010-02-04 Maarten Koning Method and System for Implementing Realtime Spinlocks
CN112306699A (en) * 2019-07-29 2021-02-02 华为技术有限公司 Method and apparatus for accessing critical resources, computer equipment and readable storage medium
US20210216378A1 (en) * 2020-01-10 2021-07-15 Wind River Systems, Inc. Systems and Methods for Interrupting Latency Optimized Two-phase Spinlock
CN111984428A (en) * 2020-07-20 2020-11-24 上海金仕达软件科技有限公司 A method, device and device for implementing spin lock during resource access
CN113806099A (en) * 2021-09-13 2021-12-17 北京计算机技术及应用研究所 Multi-core spin lock design method based on binary computation

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
郝继锋等: "多核操作系统自旋锁技术研究", 航空计算技术, no. 04, 25 July 2017 (2017-07-25) *

Similar Documents

Publication Publication Date Title
US9996402B2 (en) System and method for implementing scalable adaptive reader-writer locks
US8966491B2 (en) System and method for implementing NUMA-aware reader-writer locks
US7979617B2 (en) Quad aware locking primitive
US12099885B2 (en) System and method for promoting reader groups for lock cohorting
US8694706B2 (en) System and method for NUMA-aware locking using lock cohorts
US6622155B1 (en) Distributed monitor concurrency control
US7174552B2 (en) Method of accessing a resource by a process based on a semaphore of another process
US6480918B1 (en) Lingering locks with fairness control for multi-node computer systems
US8707315B2 (en) Method and system for implementing realtime spinlocks
US8918791B1 (en) Method and system for queuing a request by a processor to access a shared resource and granting access in accordance with an embedded lock ID
EP0145889A2 (en) Non-spinning task locking using compare and swap
US9342379B2 (en) Lock free acquisition and release of a semaphore in a multi-core processor environment
US20130080672A1 (en) System, method and computer program product for access control
US9830201B2 (en) Low overhead contention-based switching between ticket lock and queued lock
US20170315942A1 (en) Semaphore for multi-core processor
US11119831B2 (en) Systems and methods for interrupting latency optimized two-phase spinlock
CN116204303A (en) Implementation method of spin lock capable of optimizing interrupt delay
EP3268886A1 (en) Lock manager
JP2804478B2 (en) Task control system and online transaction system
JPH06348661A (en) Exclusive control method between multiple processors
US20250362976A1 (en) Method for managing mutual exclusion access to a critical section in a multi-core processor
EP1228429B1 (en) Sharing resources among entities
JP2001256065A (en) Exclusive control method and computer system
JPH05233561A (en) Shared resources control system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination