Multi-core processor, operation method and instructions

By monitoring competition degree indicators in multi-core processors, it automatically switches lock modes and prioritizes running processes on the same NUMA node. This solves the problem of low performance when competing for shared resources in multi-core processors and improves system performance and resource allocation efficiency.

CN118567720APending Publication Date: 2024-08-30VIA ALLIANCE SEMICON CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202410706525.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-31
Publication Date
2024-08-30

AI Technical Summary

Technical Problem

In the non-uniform memory access (NUMA) architecture of multi-core processors, existing technologies lead to low system performance when competing for shared resources, mainly due to increased access latency and inefficiency due to data synchronization requirements across NUMA nodes.

Method used

Propose an elastic lock scheme that automatically switches the lock mode by monitoring competition degree indicators, switching from the original lock mode to the NUMA lock mode, giving priority to running processes on the same NUMA node, reducing cross-node data synchronization, and switching back when the competition level decreases Original lock mode to adapt to different concurrency and competition environments.

Benefits of technology

It improves the performance of multi-core processor systems, especially in high-concurrency and fiercely competitive environments. By reducing the number of cross-node accesses and optimizing lock resource allocation, it dynamically adjusts system performance and avoids memory usage problems caused by excessive use of NUMA locks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118567720A
    Figure CN118567720A
Patent Text Reader

Abstract

The invention provides a multi-core processor, an operation method and instructions. The multi-core processor includes processor instructions related to lock contention and methods of operation. In the multi-core processor, a plurality of central processing unit cores, a memory controller and a local memory form a non-uniform memory access node. Different processes executed by each CPU core are arranged into a waiting queue through a lock application instruction so as to obtain locks for operating the shared computing resources one by one. The execution of the lock application instruction is accompanied by the monitoring of the competition degree index. As the index satisfies a first switching condition, the lock sharing the computing resources is switched from the original lock mode to the NUMA lock mode. The execution of the NUMA lock mode lock application instruction is more accompanied by the monitoring of the competition degree index. And when the index meets a second switching condition, the lock sharing the computing resources is switched to the original lock mode from the NUMA lock mode. In the original lock mode, regardless of the NUMA node, the lock sharing the computing resources is obtained first by the first applied process. The NUMA lock mode allows processes of the same NUMA node to preferentially obtain a lock that shares computing resources.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to a multi-core processor of a non-uniform memory access (NUMA) architecture, and an optimized operation of competing for shared resources, comprising an operation method and a central processing unit (CPU) instruction. Background Art

[0002] In order to coordinate the execution of multiple processes on a multi-core platform, the operating system (such as Linux) kernel and application software layer provide locking design to ensure the order in which multiple processes access shared computing resources (such as memory, etc.) so that parallel programs can be executed in an orderly manner.

[0003] The concept of locking is to give the core that gets the lock exclusive rights to the shared computing resources. The operating system generally provides primitive locks; for example, spinlock locks, or osq locks. The use of primitive locks must follow the first-in-first-out rule.

[0004] However, multi-core platforms are often designed as non-uniform access memory (NUMA) architectures. The CPU cores of a processor can be configured to form NUMA nodes. The access speed between the processor and memory on the same node is significantly faster than the access speed across nodes. In order to issue primitive locks in a first-in-first-out manner, cross-NUMA node events often occur, and the resulting data synchronization requirements will cause system performance to degrade. Summary of the invention

[0005] This application proposes a flexible solution that allows the original lock to be issued to the process in a first-in-first-out manner, and also changes to a NUMA lock depending on the system status. The NUMA lock allows the process to run on the same NUMA node first, reducing data synchronization between NUMA nodes.

[0006] A multi-core processor implemented according to one embodiment of the present application includes multiple CPU cores, which are configured to form multiple non-uniform memory access (NUMA) nodes. The CPU cores use a lock request instruction to queue processes that want to access a shared resource to obtain a lock (access right) to operate the shared computing resource. The processes in the waiting queue obtain locks one by one and sequentially and exclusively access the shared resource. The execution of the lock request instruction is also accompanied by the monitoring of a competition degree indicator. As the competition degree indicator meets a first switching condition, the lock of the shared computing resource is switched from an original lock mode to a NUMA lock mode. In the original lock mode, regardless of the NUMA node, the process that applies first obtains the lock of the shared computing resource first. The NUMA lock mode allows processes on the same NUMA node to obtain the lock of the shared computing resource first. In this way, shared computing resources can be adaptively configured to be used by competing processes with higher efficiency.

[0007] In one embodiment, after the first switching condition is met, the lock application instruction refuses new processes applying for locks to enter the queue again, until all processes that have entered the queue have obtained the original lock for operation, and then allow the process to queue again to obtain the NUMA lock. In this way, the original lock mode to the NUMA lock mode is switched in a reliable manner.

[0008] In one embodiment, as the contention level indicator satisfies a second switching condition, the lock of the shared computing resource is switched from the NUMA lock mode back to the original lock mode. The bidirectional switching enables flexible adjustment of system performance.

[0009] In one implementation, a data structure of a NUMA lock includes address information. When the address information matches an original lock address corresponding to the NUMA lock, the NUMA lock is reliable, otherwise it is unreliable.

[0010] In one implementation, a data structure of a NUMA lock includes lock flag information. When the lock flag information matches a unique identifier of an original lock corresponding to the NUMA lock, the NUMA lock is reliable, otherwise it is unreliable.

[0011] The following is a detailed description of the present invention with reference to the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] Figure 1 According to one embodiment of the present application, a processor 100 is illustrated, wherein a plurality of CPU cores are configured to form a plurality of non-uniform memory access (NUMA) nodes NUMA#1, NUMA#2, NUMA#3, and NUMA#4;

[0013] Figure 2 According to an implementation of the present application, a lock data structure raw_spinlock extended from the original lock spinlock is illustrated;

[0014] Figure 3 According to an implementation of the present application, a lock data structure optimistic_spin_queue extended from the original lock osq_lock is illustrated;

[0015] Figure 4 According to an implementation of the present application, the data structure numa_lock of the NUMA lock is illustrated;

[0016] Figure 5 is a flow chart illustrating an operation method of a multi-core processor to handle a lock application of a shared computing resource according to an embodiment of the present application;

[0017] Figure 6 is a flow chart illustrating the release of the original lock osq-lock according to an embodiment of the present application; and

[0018] Fig. 7A , Figure 7B The flowchart illustrates the application process of the original lock osq-lock according to an implementation mode of the present application.

[0019]

Explanation of symbols

[0020] 100: Processor

[0021] CPU11…CPU14CPU core

[0022] IO1: Input and output device

[0023] MCon1: memory controller

[0024] Mem11, Mem12: Memory

[0025] NUMA#1…NUMA#4: NUMA nodes

[0026] numa_lock, optimistic_spin_queue, raw_spinlock: lock data structures

[0027] S502: Step: a process applies for a lock

[0028] S504: Step, already in NUMA lock mode?

[0029] S506: Step: Does the competition degree index meet the first switching condition?

[0030] S508: Step, the original lock mode is reliably switched to the NUMA lock mode

[0031] S510: Step, original lock mode

[0032] S512: Step: Does the competition degree index satisfy the second switching condition?

[0033] S514: Step, NUMA lock mode is reliably switched to original lock mode

[0034] S516: Step, NUMA lock mode

[0035] S602…S626, S702…S720: Steps DETAILED DESCRIPTION

[0036] The following description lists various embodiments of the present application, but is not intended to limit the content of the present application. The actual scope of the invention should be defined in accordance with the claims. The various units, modules, or functional blocks mentioned below can be implemented by hardware, software, firmware combination, and can also include special circuits. The various units, modules, or functional blocks are not limited to being implemented separately, but can also be combined together to share certain functional units.

[0037] Figure 1 According to one embodiment of the present application, a processor 100 is illustrated, wherein a plurality of central processing unit (CPU) cores are configured to form a plurality of non-uniform memory access (NUMA) nodes NUMA#1, NUMA#2, NUMA#3, and NUMA#4. Taking NUMA node NUMA#1 as an example, it includes a plurality of CPU cores CPU11, CPU12, CPU13, and CPU14, and a plurality of memories Mem11-Mem12 and an input-output device IO1 are controlled by a memory controller MCon1. Other NUMA nodes NUMA#2-NUMA#4 may have similar architectures.

[0038] Processor is not limited to Figure 1 For example, in another embodiment, eight CPU cores may be grouped together to form a NUMA node. Eight NUMA nodes constitute a 64-core processor.

[0039] CPU cores in the same group can synchronize data in the second-level cache (L2 cache). Cross-NUMA node operations involve access to system memory (such as DRAM). Cross-NUMA node operations will result in considerable performance loss.

[0040] Regarding the operational requirements of multiple processes for shared computing resources, primitive locks (such as spinlock locks or osq locks) are generally used for allocation. In primitive lock mode, regardless of NUMA nodes, the process that applies first obtains the lock of the shared computing resource first. Each primitive lock is only 4 bytes and does not take up space. The locking program is concise and can run efficiently. However, such configuration rules of primitive locks are not applicable to the NUMA architecture. For example, the first, second, and third processes in time sequence may occur on NUMA nodes NUMA#1, NUMA#2, and NUMA#1, respectively. According to the first-in-first-out feature, the process unlocking operation will first occur on NUMA node NUMA#1, then switch to NUMA node NUMA#2, and then switch back to NUMA node NUMA#1. A large amount of data is transmitted back and forth between NUMA node NUMA#1 and NUMA node NUMA#2, which is extremely inefficient.

[0041] In addition to using the original lock, this application can also switch to a NUMA lock suitable for the NUMA architecture. The NUMA lock mode allows processes on the same NUMA node to obtain the lock of the shared computing resource first. After processing all waiting processes of the node or the number of processed processes exceeds the preset maximum number of times, the first-in-first-out principle is considered and the process belonging to the next NUMA node that applied first is processed. Similarly, in the aforementioned examples of the first process (NUMA#1), the second process (NUMA#2), and the third process (NUMA#1), the NUMA lock mode is to unlock the first process (NUMA#1) and the third process (NUMA#1) first, and then unlock the second process (NUMA#2). The number of accesses across NUMA nodes is significantly reduced, and the system speed is improved.

[0042] The NUMA lock mode is particularly suitable for environments with high concurrency and intense competition (for example, multiple processes require access to the same computing resources). In particular, the NUMA lock algorithm can be adjusted accordingly to different processor architectures, and the control is fine. However, the NUMA lock algorithm is much more complex than the original lock. When concurrency is low and competition is not so intense, the performance of the NUMA lock is not as good as the original lock. This application dynamically switches between the original lock mode and the NUMA lock mode according to the intensity of competition.

[0043] Such adaptive lock switching has its benefits. Each NUMA lock must occupy a number of cache lines equal to the number of NUMA nodes. The Linux operating system will initialize more than 30,000 locks from boot to desktop operation. If NUMA locks are overused, too much memory will be occupied.

[0044] Even though there are so many locks when the Linux kernel is running, most of them are not highly contested. According to the present application technology, NUMA locks do not need to be fully introduced, so dynamic lock switching can reduce the performance impact on processes that are not highly contested.

[0045] This application provides an efficient contention detection mechanism and a reliable lock operation mechanism for switching between the original lock mode and the NUMA lock mode. In this way, when there are fewer processes participating in the competition and the competition is relaxed, the configuration of shared computing resources is reliably implemented with the original lock. When there are more processes participating in the competition and the competition is fierce, the configuration of shared computing resources is reliably implemented with the NUMA lock.

[0046] This application allows different processes executed by different CPU cores to queue up to obtain a lock for operating a shared computing resource through a lock request instruction. The execution of the lock request instruction is further accompanied by monitoring of a contention level indicator.

[0047] As the competition index satisfies a first switching condition, the lock of the shared computing resource is switched from the original lock mode to the NUMA lock mode. In order to reliably switch to the NUMA lock mode, after the first switching condition is met, the lock application instruction refuses new processes applying for locks to enter the queue again until all queued processes obtain the original lock for operation, and then allows the process to queue again to obtain the NUMA lock.

[0048] After switching to the NUMA lock mode, as the contention level indicator satisfies a second switching condition, the lock of the shared computing resource is switched back to the original lock mode. In order to reliably switch to the NUMA lock mode, the present application also provides a related mechanism.

[0049] In one embodiment, the contention level indicator includes a depth data (depth) showing the number of processes that have applied for locks and have not yet released the locks. In one embodiment, the depth data is incremented by 1 when a process applies for a lock and decremented by 1 when a process releases the lock. In response to the depth data exceeding a threshold for a predetermined number of times, the lock of the shared computing resource is switched from the original lock mode to the NUMA lock mode. The predetermined number of times can be 1 or a greater value.

[0050] In another embodiment, the contention index includes a cross-NUMA node count. When a threshold is exceeded for a predetermined number of times, the lock of the shared computing resource is switched from the original lock mode to the NUMA lock mode. The predetermined number of times may be 1 or a greater value.

[0051] The above contention level indicator monitoring and reliable means of lock mode switching can be implemented not only by software, but also by extended instructions (for example, extended x86 microprocessor instructions). Extended instructions can more efficiently implement dynamic lock mode switching and avoid other performance losses introduced by pure software implementation.

[0052] The following is a special explanation of the monitoring of depth data. The same concept can be implemented in monitoring the number of cross-NUMA nodes.

[0053] First, the software implementation is discussed. In one implementation, regardless of whether a lock request instruction indicates that the access target is locked or not, the depth data of the access target is increased by 1; and when the access target is unlocked, the depth data is decreased by 1. The larger the depth data, the more intense the competition. In one implementation, when the corresponding cumulative prediction times exceed the threshold value of the depth data, the lock mode is switched from the original lock to the NUMA lock.

[0054] However, lock contention requires synchronization between CPU cores. For example, when a first CPU core competes to access a target, it first invalidates the lock data structure lock and depth data (depth) in the cache of other CPU cores, synchronizes the cache line to the first CPU core, and then performs the lock data member operation, and then performs the depth member operation. When a second CPU core joins the competition and also accesses the target, the lock data structure lock and depth data (depth) in the cache of the first CPU core will also be invalid. If the management of depth data (depth) and the management of lock data structure lock are executed as two instructions, the first CPU core obtains the cache line content, and after operating the lock member, it is possible that the second processor grabs the cache line content and also performs the lock member operation. The first CPU core has to process the depth member and synchronize the cache line to the first CPU core again, which increases the synchronization overhead.

[0055] One implementation is to make the lock request instruction include the management of the depth data. Accordingly, one implementation extends an original lock data structure to make it carry more depth data.

[0056] Taking the original spinlock as an example, the compare-and-exchange instruction cmpxchg is generally used to apply for the lock. The traditional compare-and-exchange instruction cmpxchg compares the register AL, AX, EAX, or RAX with the target operand. If the comparison result is equal, the source operand is updated to the target operand (i.e., exchanged). If the comparison result is not equal, the source operand is not exchanged to the target operand, and the target operand is loaded with the register AL, AX, EAX, or RAX.

[0057] The compare-and-exchange instruction cmpxchg can be used to queue processes competing for access to targets. When multiple CPU cores apply for access, the execution of the compare-and-exchange instruction cmpxchg can determine whether the access target has been locked. For example, when a process applies for access to a shared computing resource, a compare-and-exchange instruction cmpxchg is executed, and the lock data structure lock (target operand) of the access target is compared with the unlocked state 0 to determine whether it has already been switched to the locked state 1 (source operand). If the access target is unlocked state 0, this process is able to operate the shared computing resource, and the lock data structure lock of the access target is updated to locked state 1. If another process applies for access, the locked state 1 (different from the unlocked state 0) of the access target will be identified by the compare-and-exchange instruction cmpxchg, and the process applying for access will enter the queue. The queued process will obtain access rights only after the access target is unlocked.

[0058] One implementation is to propose a new lock request instruction, which, in addition to being used as a compare-and-exchange instruction, also includes the management of depth data, where two data are adjacent and located in the same cache line. In this way, the lock data structure lock and the depth data (depth) can be processed at one time, reducing the loss of CPU core synchronization.

[0059] An implementation of the expansion of the corresponding instruction includes expanding the lock data structure lock. Figure 2 The lock data structure raw_spinlock is extended from the original lock spinlock. raw_lock is the content of the original lock spinlock. depth is the depth data, which shows the number of processes that have applied for the lock and have not yet released the lock. If a process applies for the lock, it is +1, and if the lock is released, it is -1. numa_eable is used as a control flag for NUMA lock enablement, original lock spinlock enablement, lock suspension, etc. count represents the cumulative number of times the depth data depth exceeds the threshold, which is used to determine whether to switch to NUMA lock mode. numa_lock_index is the index label of the memory used by the NUMA lock; after the NUMA lock is enabled, the index numa_lock_index is used to find the memory corresponding to the lock in the pre-allocated memory table. In one implementation, the NUMA lock data structure can be pre-organized (such as when the computer is turned on) in the system memory. When the NUMA lock is enabled, a pointer can be recorded in the index table to point to the corresponding NUMA lock data structure in the system memory.

[0060] Based on the lock data structure raw_spinlock extended by the original lock spinlock, the traditional compare-exchange instruction cmpxchg can be expanded to the compare-exchange accumulation instruction cmpxchg64_inc. The instruction operand is 64 bits (2N bits), but it is not limited to it. The lower 32 bits (lower N bits) are the same as the traditional compare-exchange instruction cmpxchg. The upper 32 bits (upper N bits) realize the accumulation of the depth data (depth). The compare-exchange accumulation instruction cmpxchg64_inc is used as a new lock application instruction to ensure that the two 32-bit numbers are independently and simultaneously operated normally. In other implementations, the instruction operand is M+N bits (M and N are numbers), the upper N bits realize the accumulation of the depth data (depth), and the lower M bits are used as the traditional compare-exchange instruction cmpxchg.

[0061] In one implementation, the lock application instruction is:

[0062] CMPXCHG_INC r / m64,r32

[0063] The upper 32 bits of register r / m64 are accumulated; the lower 32 bits of register r / m64 are compared with register EAX; when the lower 32 bits of register r / m64 are equal to register EAX, register ZF is 1, register r / m64 is loaded into register RAX, and register r32 is loaded into the lower 32 bits of register r / m64; and when the lower 32 bits of register r / m64 are not equal to register EAX, register ZF is cleared to 0, and register r / m64 is loaded into register RAX.

[0064] The exchange instruction xchg can also be used for processes to compete for access to a shared computing resource. For example, the competition for the original lock osq_lock uses the exchange instruction xchg. The traditional exchange instruction xchg outputs the content of the first operand and exchanges the second operand to the first operand. The mantissa of the lock data structure lock of an access target is 0 when it is not locked. When a corresponding process applies for access to a shared computing resource, an exchange instruction xchg is executed, the mantissa of the lock data structure lock of the access target is output, and the mantissa of the lock data structure lock is updated to the process flag curr of the process (such as the CPU number). If the output of the exchange instruction xchg is 0, it means that the access target is not locked. This process is able to operate the shared computing resource. If another process applies for access, the mantissa of the lock data structure lock that has already been updated to the process flag (non-0) will be identified. The process applying for access enters the queue. The queued process will obtain access rights only after the access target is unlocked.

[0065] Figure 3 The lock data structure optimistic_spin_queue is extended from the primitive lock osq_lock. As in the primitive lock spinlock example above, the primitive lock osq_lock includes not only the basic lock tail but also the fields depth, numa_eable, count, and numa_lock_index.

[0066] Based on the lock data structure optimistic_spin_queue extended by the original lock osq_lock, the traditional exchange instruction xchg can be expanded to the exchange accumulation instruction xchg64_inc. The instruction operand is 64 bits (2N bits), but it is not limited. The lower 32 bits (lower N bits) are the same as the traditional exchange instruction xchg. The upper 32 bits (higher N bits) implement the accumulation of the depth data (depth). The exchange accumulation instruction xchg64_inc is used as a new lock application instruction to ensure that the two 32-bit numbers are independent and operate normally at the same time. In other implementations, the instruction operand is M+N bits (M and N are numbers), the upper N bits implement the accumulation of the depth data (depth), and the lower M bits are used as the traditional exchange instruction xchg.

[0067] In one implementation, the lock application instruction is:

[0068] CMPNEXCHGINC r / m64, r32

[0069] The lower 32 bits of register r / m64 are compared with register EAX. When the lower 32 bits of register r / m64 are equal to register EAX, register ZF is 1 and register r / m64 is loaded into register RAX. When the lower 32 bits of register r / m64 are not equal to register EAX, register ZF is cleared, the upper 32 bits of register r / m64 are accumulated, register r / m64 is loaded into register RAX, and register r32 is loaded into the lower 32 bits of register r / m64.

[0070] The original lock osq_lock implemented by the corresponding exchange accumulation instruction xchg64_inc, its unlocking instruction can also be expanded to include the depth data (depth) minus 1. In one embodiment, the unlocking of the original lock osq_lock also uses the concept of the comparison exchange instruction cmpxchg. One embodiment of the present application is to propose a comparison exchange decrement instruction cmpxchg64_dec, which is used as a new lock release instruction. The instruction operand is 64 bits (2N bits), but not limited to it. The lower 32 bits (lower N bits) are the same as the traditional comparison exchange instruction cmpxchg. The upper 32 bits (higher N bits) realize the decrement of the depth data (depth). In other embodiments, the instruction operand is M+N bits (M and N are numbers), the upper N bits realize the decrement of the depth data (depth), and the lower M bits are used as the traditional comparison exchange instruction cmpxchg.

[0071] In one implementation, the lock release instruction is:

[0072] CMPXCHG_DEC r / m64,r32

[0073] The upper 32 bits of register r / m64 are decremented. The lower 32 bits of register r / m64 are compared with register EAX. When the lower 32 bits of register r / m64 are equal to register EAX, register ZF is 1, register r / m64 is loaded into register RAX, and register r32 is loaded into the lower 32 bits of register r / m64. When the lower 32 bits of register r / m64 are not equal to register EAX, register ZF is cleared to 0, and register r / m64 is loaded into register RAX.

[0074] This application uses a data structure to track the degree of contention and then automatically switches the lock mode. Since the changes are limited to the lock implementation program itself, and there is no need to allocate memory for all locks and initialize them into complex NUMA locks, the amount of changes is within the acceptable range of the Linux kernel organization.

[0075] The following discusses how to safely switch from the original lock mode to the NUMA lock mode so that the queue of the original lock can reliably enter the locked state.

[0076] The present application improves the traditional exchange instruction xchg and proposes an equal no-exchange instruction, which not only has the function of the exchange instruction xchg, but also includes a comparison between the target operand and the source operand. When the target operand and the source operand are the same, no exchange is performed.

[0077] As mentioned above, the exchange instruction xchg is used in the queue for the original lock osq_lock competition. Different from the comparison exchange function cmpxchg, which originally means to exchange only when they are equal, the exchange instruction xchg directly exchanges data regardless of what they are. This concept is used in the queue for the original lock osq_lock competition. However, when the switching condition of the lock mode is met, the process should no longer be allowed to enter the queue to compete for the original lock osq_lock. The equal non-exchange instruction xchg_new proposed in this application is used to improve the traditional exchange instruction xchg to achieve this purpose.

[0078] In the original lock mode, the equal no-exchange instruction xchg_new implements the competition queue of the original lock. In addition to implementing the exchange instruction xchg function, it also observes a lock variable (the mantissa of the lock data structure lock) and a default value (all F). When the mantissa of the lock data structure lock is not all F, the equal no-exchange instruction xchg_new behaves the same as the exchange instruction xchg, and the process applying for the lock is pushed into the queue. When switching from the original lock mode to the NUMA lock mode, the mantissa of the lock data structure lock is set to all F, and is identified by the equal no-exchange instruction xchg_new, and no exchange is performed. This process therefore does not enter the queue and enters a loop. After the remaining processes in the queue have digested the original lock osq_lock, the process is allowed to queue again and compete for the NUMA lock. In this way, the kernel lock mode can be switched reliably.

[0079] The following discusses how to return from NUMA lock mode to native lock mode.

[0080] When switching from the original lock mode to the NUMA lock mode, a block of memory will be occupied in a pre-allocated memory table. When switching from the NUMA lock mode back to the original lock mode, the block of memory needs to be released and returned. However, when switching from the NUMA lock mode back to the original lock mode, there may be a process that is trying to apply for a lock. Since the memory has been released long ago, a deadlock occurs. This application establishes a check mechanism for this purpose. The process applying for a lock will check whether the current address still belongs to this lock. If not, the process will enter a loop, and after it is indeed switched to the original lock mode, the process will exit the loop and reapply for the lock.

[0081] Regarding the above inspection mechanism, Figure 4The diagram shows the corresponding designed NUMA lock data structure numa_lock, which contains the corresponding original lock information. As shown in the figure, the NUMA lock data structure numa_lock, the high 32 bits lock_id record the original lock memory address, and the low 32 bits tail record a tail representing the access amount. The number of processes applying for locks on each NUMA node can be an indicator of the degree of competition. When the sum is lower than a threshold (such as 0), it means that the lock competition is not fierce, and the NUMA lock mode switches back to the original lock mode. Alternatively, the aforementioned depth data can also be used as a switching indicator. The variable lock_id contained in the NUMA lock data structure numa_lock is cleared to disconnect the NUMA lock from the original lock. Under such a design, when competing for the NUMA lock, it is necessary to check whether the variable lock_id of the NUMA lock data structure numa_lock matches the address of the corresponding original lock. If so, the NUMA lock is reliable. Otherwise, it means that the switch from the NUMA lock mode to the original lock mode has occurred, and there is no reliable NUMA lock. The process needs to wait for the switch to be completed before competing for the lock again.

[0082] In some implementations, the NUMA lock data structure may record the memory address lock_id of the original lock in 48 bits, and the tail may only retain 16 bits.

[0083] In one embodiment, a NUMA lock data structure includes other lock flag information in addition to the memory address lock_id, replacing the original lock memory address recorded in the high 32 bits of the lock_id record. When the lock flag information matches a unique flag information of an original lock corresponding to the NUMA lock, the NUMA lock is reliable, otherwise it is unreliable.

[0084] The present application extends a high-bit detection comparison exchange instruction CMPNEXCHG as a lock application instruction; in addition to realizing lock competition queuing, the above matching identification is also realized with a high bit.

[0085] In one implementation, the lock application instruction is:

[0086] CMPNEXCHG r / m64,r16

[0087] The register r / m64 is compared with the register RAX for the high 48 bits. When the register r / m64 and the register EAX are not equal in the high 48 bits, or when the low 16 bits of the register r / m64 are 0xffff, the register ZF is cleared to 0, and the register r / m64 is loaded into the register RAX. Otherwise, the register ZF is set to 1, the register r / m64 is loaded into the register EAX, and the register r16 is exchanged with the low 16 bits of the register r / m64. In addition, the present application also designs a memory release code for the NUMA lock mode cutout.

[0088] The following flowchart illustrates the application and release of locks. The design concept is that when multiple processes compete for the same lock, if the number of competing processes (depth data, or the number of cross-NUMA nodes) continues to exceed the default value, it will switch to using NUMA locks.

[0089] The switch from the original lock mode to the NUMA lock mode occurs when multiple processes compete. The switch program must ensure that all processes (including processes that are about to apply, processes that have already applied, processes that have already queued, and processes that have started unlocking) can be processed correctly. For example, after all processes that have entered the queue have finished running, the original lock is actually stopped and converted to a NUMA lock.

[0090] Figure 5 The flowchart illustrates an operation method of a multi-core processor to handle a lock application of a shared computing resource according to an embodiment of the present application.

[0091] In step S502, a process applies for a lock. In step S504, it is determined whether the process is already in NUMA lock mode. If not, in step S506, it is checked whether the contention index satisfies a first switching condition. If so, in step S508, the original lock mode is reliably switched to NUMA lock mode. If not, in step S510, the operation of the original lock mode is maintained. The reliable switching of step S508 can be implemented in the following manner. After the first switching condition is met, the corresponding lock application instruction refuses the process applying for the lock to re-enter the queue until all the processes in the queue obtain the original lock for operation, and then the process is allowed to re-queue to obtain the NUMA lock.

[0092] If step S504 determines that the NUMA lock mode has been switched, step S512 checks whether the contention index satisfies a second switching condition. If so, step S514 switches the NUMA lock mode reliably to the original lock mode. If not, step S516 maintains the operation of the NUMA lock mode. The reliable switching of step S514 can be implemented in the following manner. Let a data structure of a NUMA lock include address information. When the address information matches an original lock address corresponding to the NUMA lock, the NUMA lock is reliable, otherwise it is unreliable.

[0093] The following discussion specifically takes the original lock osq-lock as an example.

[0094] Figure 6 The flowchart illustrates the release of the original lock osq-lock according to one embodiment of the present application.

[0095] Corresponding step S602 releases the original lock osq-lock, and step S604 checks whether the NUMA lock algorithm has been enabled. If the NUMA lock has been enabled, step S606 enters the NUMA lock release function. If not, step S608 continues to track the contention level pointer (including decrementing depth data, or counting the number of NUMA node accesses) during the lock release process. Step S610 checks whether the switching conditions from the original lock mode to the NUMA lock mode are met. If met, step S612 sets the switching flag and starts the switching process. Step S614 executes the program to release the original lock osq-lock and checks whether the tail of the lock queue has been reached. After checking that the tail of the lock queue has been reached, since the switch mark has been set, step S616 sets the tail to a locked state. Step S618 orders the parallel program to execute. Step S620 processes the next original lock osq-lock application.

[0096] If step S614 determines that the queue has not been reached, step S622 unlocks the next process in the waiting queue, and then enters step S618 to perform parallel program execution.

[0097] If step S610 determines that the switching condition from the original lock mode to the NUMA lock mode is not met, step S624 executes the program to release the original lock osq-lock and checks whether the tail of the lock queue has been reached. After checking that the tail of the lock queue has been reached, step S626 sets the tail to unlocked state, and then enters step S618 to execute the parallel program. If step S624 determines that the tail has not been reached, step S622 unlocks the next process in the waiting queue, and then enters step S618 to execute the parallel program.

[0098] Fig. 7A , Figure 7B The flowchart illustrates the application process of the original lock osq-lock according to one embodiment of the present application. Multiple processes apply for locks on their respective corresponding multiple central processing units CPU0 to CPUn. The central processing unit CPU0 is specifically described below.

[0099] After a process completes a round of unlocking execution, it can come to the original lock osq-lock application entrance to apply for the next round of operation. Step S702, the central processing unit CPU0 applies for the original lock osq-lock. Step S704 determines whether the NUMA lock algorithm has been enabled. If so, step S706 instructs the central processing unit CPU0 to apply for the NUMA lock. If not, step S708 checks the switch NUMA flag. The setting of the switch NUMA flag represents the start of multi-core coordination control, and step S710 loops to detect the lock state. If it does not enter the locked state, it loops and waits repeatedly. When the original lock osq-lock enters the locked state, the multi-core coordination control is completed, and the switch to the NUMA lock begins. Step S712, after detecting the lock, marks that the original lock osq-lock programs of all Linux kernels are already in the stopped state. The competition selects the only process to initialize the NUMA lock data structure, enable the NUMA lock, and then call the original lock osq-lock application again.

[0100] If the set NUMA switch flag is not read in step S708, step S714 loops to detect locking and swapping the tail. If it is not locked, step S716 queues the process normally. Step 718 makes the queued process wait for unlocking, and then enters step S720. Figure 6 If step S714 determines that the lock is locked, it means that the released lock has reached the end of the queue, and the lock application program is called again.

[0101] in particular, Figure 6 After step S612 sets the switch flag, for the new process that applies for the original lock, the switch flag is set accordingly, and the process waits in steps S710 and S712. For the process that is already executing, when it executes to step S714, if it is not locked, it will enter the queue. At this time, the lock release program will have the next process to be unlocked and will not reach the end of the queue. The process that executes beyond step S714 has entered the queue and is waiting to be unlocked. Step S714 is an atomic operation, which can maintain consistency when executed by multiple CPU cores at the same time. When all processes detect the lock, complete the NUMA initialization, and call the original lock osq-lock application again, the program will enter the S606 / S706 branch, that is, the Linux kernel original lock and NUMA lock switching is completed.

[0102] Step S714 reliably locks the current queue, which is the key to correct switching.

[0103] This application combines the advantages of the original lock and the NUMA lock, and can automatically switch between the NUMA lock and the original lock according to the degree of competition. The original lock is used when there is low competition, and the NUMA lock is automatically switched when there is high competition. According to the adaptive lock switching technology of this application, when the benchmark program (benchmark) or multi-core application is running, there are actually only a dozen or less highly contended locks, and the memory consumption of the NUMA lock can be basically or negligible.

[0104] The present application lock application instruction has the following implementation modes.

[0105] In one implementation, the lock application instruction is a high-bit comparison and exchange instruction, and an exchange is performed when a high-bit value is equal to an original lock flag and a low-bit value is not equal to a preset lock value.

[0106] In one implementation, the lock application instruction is a high-bit comparison and exchange instruction, and the exchange is stopped when a high-bit value is not equal to the original lock flag, or a low-bit value is equal to a preset lock value.

[0107] In one implementation, when the second switching condition for switching from the corresponding NUMA lock to the original lock is met and all queued processes obtain the NUMA lock for operation, the low bit of the variable is set to the preset lock value, and the high bit deletes the original lock flag value. Subsequent lock exchange operations will be rejected until the original lock resources are restored and re-imported into the original lock queue.

[0108] Although the present invention has been disclosed as above in terms of preferred embodiments, it is not intended to limit the present invention. Those skilled in the art may make some changes and modifications without departing from the spirit and scope of the present invention. Therefore, the scope of protection of the present invention shall be based on the scope defined in the attached claims.

Claims

1. A multi-core processor, comprising: Multiple central processing unit (CPU) cores, configured to form multiple non-uniform memory access (NUMA) nodes, in: Different processes executed by the CPU core are queued to obtain locks for operating shared computing resources through lock request instructions; The execution of the lock application instruction is also accompanied by the monitoring of the competition degree index; As the contention level indicator satisfies the first switching condition, the lock of the shared computing resource is switched from the original lock mode to the NUMA lock mode; The original lock mode is regardless of the NUMA node, and the process that applies first obtains the lock of the shared computing resource first; and The NUMA lock mode allows processes on the same NUMA node to obtain the lock of the shared computing resource first.

2. The multi-core processor of claim 1, wherein: The contention level indicator includes in-depth data showing the number of processes that have requested locks and have not yet released them; and In response to the depth data exceeding the threshold for a predetermined number of times, the lock of the shared computing resource is switched from the original lock mode to the NUMA lock mode.

3. The multi-core processor of claim 2, wherein: The depth data is accumulated when a process makes a lock request and decremented when a process releases the lock.

4. The multi-core processor of claim 3, wherein: The depth data is contained in the data structure of the original lock; and The lock request instruction includes the management of the depth data.

5. The multi-core processor of claim 4, wherein: M, N are numbers; and The instruction operand of the lock request instruction is M+N bits, the upper N bits implement the accumulation of the depth data, and the lower M bits are used for comparison and exchange instructions.

6. The multi-core processor as claimed in claim 5, wherein the lock request instruction is: CMPXCHG_INCr / m64,r32 The high 32 bits of register r / m64 are accumulated; The lower 32 bits of register r / m64 are compared with register EAX; If the lower 32 bits of register r / m64 are equal to register EAX, register ZF is 1, register r / m64 is loaded into register RAX, and register r32 is loaded into the lower 32 bits of register r / m64; and If the lower 32 bits of register r / m64 are not equal to register EAX, register ZF is cleared and register r / m64 is loaded into register RAX.

7. The multi-core processor of claim 4, wherein: M, N are numbers; and The instruction operand of the lock request instruction is M+N bits, the upper N bits implement the accumulation of the depth data, and the lower M bits are used as a swap instruction.

8. The multi-core processor as claimed in claim 7, wherein the lock request instruction is: CMPNEXCHGINCr / m64,r32 The lower 32 bits of register r / m64 are compared with register EAX; If the lower 32 bits of register r / m64 are equal to register EAX, register ZF is 1, and register r / m64 is loaded into register RAX; If the lower 32 bits of register r / m64 are not equal to register EAX, register ZF is cleared, the upper 32 bits of register r / m64 are accumulated, register r / m64 is loaded into register RAX, and register r32 is loaded into the lower 32 bits of register r / m64.

9. The multi-core processor of claim 4, wherein: The process that acquires the lock releases the lock to the process in the queue through the lock release instruction; M, N are numbers; and The instruction operand of the lock release instruction is M+N bits, the upper N bits realize the decrement of the depth data, and the lower M bits are used for comparison and exchange instructions.

10. The multi-core processor as claimed in claim 9, wherein the lock release instruction is: CMPXCHG_DECr / m64,r32 Decrement the upper 32 bits of register r / m64; The lower 32 bits of register r / m64 are compared with register EAX; If the lower 32 bits of register r / m64 are equal to register EAX, register ZF is 1, register r / m64 is loaded into register RAX, and register r32 is loaded into the lower 32 bits of register r / m64; and If the lower 32 bits of register r / m64 are not equal to register EAX, register ZF is cleared and register r / m64 is loaded into register RAX.

11. The multi-core processor of claim 1, wherein: The competition degree indicator includes the number of times the competition exceeds the threshold; and When the threshold is exceeded for a predetermined number of times, the lock of the shared computing resource is switched from the original lock mode to the NUMA lock mode.

12. The multi-core processor of claim 1, wherein: After the first switching condition is satisfied, the lock application instruction refuses the process applying for the lock to re-enter the queue until all queued processes obtain the original lock for operation, and then allows the process to queue again to obtain the NUMA lock.

13. The multi-core processor of claim 12, wherein: The lock application instruction is an equal no-exchange instruction. When the lock variable is equal to the default value, the exchange is stopped. Otherwise, the behavior is the same as the exchange instruction. and Corresponding to the satisfaction of the first switching condition, after all queued processes obtain the original lock for operation, the lock variable is set to the default value, and subsequent lock exchange operations will be rejected until the NUMA lock resources are ready, and all new application processes will be imported into the NUMA lock queue.

14. The multi-core processor of claim 1, wherein: As the contention level indicator satisfies the second switching condition, the lock of the shared computing resource is switched from the NUMA lock mode back to the original lock mode.

15. The multi-core processor of claim 14, wherein: The contention level indicator includes the number of processes applying for locks on each NUMA node. When the total number is lower than a threshold, the second switching condition is met.

16. The multi-core processor of claim 14, wherein: The NUMA lock data structure includes lock flag information; and If the lock flag information matches the unique flag information of the original lock corresponding to the NUMA lock, the NUMA lock association is reliable; otherwise, it is unreliable.

17. The multi-core processor of claim 16, wherein: The lock mark information may be the address information corresponding to the original lock; and When the address information matches the original lock address corresponding to the NUMA lock, the NUMA lock association is reliable, otherwise it is unreliable.

18. The multi-core processor of claim 16, wherein: Whether the lock flag information matches or not is identified by the high bit of the high bit detection compare and exchange instruction.

19. The multi-core processor of claim 17, wherein the lock request instruction is: CMPNEXCHG r / m64,r16 Register r / m64 is compared with register RAX to perform a comparison of the upper 48 bits; and When the upper 48 bits of register r / m64 and register EAX are not equal, or the lower 16 bits of register r / m64 are a preset lock value 0xffff, register ZF is cleared to 0 and register r / m64 is loaded into register RAX. Otherwise, register ZF is set to 1, register r / m64 is loaded into register EAX, and the lower 16 bits of register r16 and register r / m64 are exchanged.

20. The multi-core processor of claim 16, wherein: The lock application instruction is a high-order comparison and exchange instruction, and an exchange is performed when the high-order value is equal to the original lock flag and the low-order value is not equal to the preset lock value.

21. The multi-core processor of claim 16, wherein: The lock application instruction is a high-order comparison and exchange instruction, and the exchange is stopped when the high-order value is not equal to the original lock flag, or the low-order value is equal to the preset lock value.

22. The compare-and-exchange instruction of claim 19, wherein: Corresponding to the satisfaction of the second switching condition, after all queued processes obtain the NUMA lock for operation, the low bit of the variable is set to the preset lock value, and the high bit deletes the original lock flag value. Subsequent lock exchange operations will be rejected until the original lock resources are restored and re-imported into the original lock queue.

23. A method for operating a multi-core processor, comprising: configuring multiple central processing unit (CPU) cores to form multiple non-uniform memory access (NUMA) nodes; and Provide lock application instructions; in: Different processes executed by the CPU core obtain locks for operating shared computing resources through the lock request instruction queue; The execution of the lock application instruction is also accompanied by the monitoring of the competition degree index; As the contention level indicator satisfies the first switching condition, the lock of the shared computing resource is switched from the original lock mode to the NUMA lock mode; The original lock mode is regardless of the NUMA node, and the process that applies first obtains the lock of the shared computing resource first; and The NUMA lock mode allows processes on the same NUMA node to obtain the lock of the shared computing resource first.

24. The method for operating a multi-core processor according to claim 23, wherein: After the first switching condition is satisfied, the lock application instruction refuses the process applying for the lock to re-enter the queue until all queued processes obtain the original lock for operation, and then allows the process to queue again to obtain the NUMA lock.

25. The method for operating a multi-core processor according to claim 23, wherein: As the contention level indicator satisfies the second switching condition, the lock of the shared computing resource is switched from the NUMA lock mode back to the original lock mode.

26. The method for operating a multi-core processor according to claim 25, wherein: The NUMA lock data structure includes lock flag information; and When the lock flag information matches the original lock unique flag information corresponding to the NUMA lock, the NUMA lock is reliable, otherwise it is unreliable.

Citation Information

Cited By

  • Cipher card concurrent access control method and system based on NUMA perception

    CN122241742A

  • NUMA-aware mickey concurrent access control method and system

    CN122241742B