Task stealing method and apparatus, chip, and computer device

Through the block management mechanism, the circular queue is managed in blocks, which solves the cache miss and competition problems caused by task stealing operations in multi-processor core parallel processing, improves system performance and reliability, and achieves more efficient load balancing and throughput.

WO2024217332A1PCT designated stage expired Publication Date: 2024-10-24HUAWEI TECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2024/087294
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-04-21
Filing Date
2024-04-11
Publication Date
2024-10-24

AI Technical Summary

Technical Problem

In a multi-processor core parallel processing task scenario, task stealing operations may cause cache misses, reducing system performance and reliability, and competition exists when different processor cores perform different operations on the same circular queue, affecting efficiency.

Method used

The block management mechanism is used to manage the circular queue associated with the processor core in blocks, allowing tasks to be stolen starting from blocks with stealing permissions in the circular queue, and operations are performed based on metadata within the blocks, reducing the need for global metadata. dependency to reduce synchronization overhead.

Benefits of technology

It improves the system performance and reliability of task stealing, reduces the competition between processor cores, improves the load balancing and throughput of the system, and makes the system performance close to the throughput of the serial queue.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024087294_24102024_PF_FP_ABST
    Figure CN2024087294_24102024_PF_FP_ABST
Patent Text Reader

Abstract

Disclosed are a task stealing method and apparatus, a chip, and a computer device, relating to the field of computers. The computer device comprises a plurality of processor cores, the plurality of processor cores comprising a first processor core and a second processor core. The method is executed by the first processor core and comprises: when a circular queue associated with the first processor core is empty, stealing, from a first block having a stealing permission in a circular queue associated with the second processor core, a first task to be processed, and processing said first task. Therefore, by using a block management mechanism to carry out block management on a circular queue associated with a processor core, it is allowed to start to steal a task from a block having a stealing permission in the circular queue, and a write operation or acquisition operation can also be performed on other blocks in the circular queue. Compared with acquiring a task from the head or tail of a circular queue, the possibility of different processor cores competing to perform different operations on a same circular queue is reduced, thereby improving system performance and the reliability of task stealing.
Need to check novelty before this filing date? Find Prior Art

Description

Task stealing method, device, chip and computer equipment

[0001] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office on April 21, 2023, with application number 202310471525.2 and application name “Task Stealing Method, Device, Chip and Computer Equipment”, all contents of which are incorporated by reference into this application. Technical Field

[0002] The present application relates to the field of computers, and in particular to a task stealing method, device, chip, and computer equipment. Background Art

[0003] In scenarios where multiple processor cores are processing tasks in parallel, a load balancing mechanism is used to distribute tasks that exceed the number of cores as evenly as possible across a limited number of cores. This improves the overall system's task processing efficiency and avoids situations where some cores are overloaded while others are idle. For example, an idle core can select a non-idle core and steal tasks from its circular queue, effectively dispatching tasks from the non-idle core to the idle core for execution, thereby improving the overall load balance of the system. A core can also write tasks to or retrieve tasks from the circular queue for processing. However, the core must perform write, retrieve, and steal operations based on the global metadata of the circular queue. Furthermore, when a core performs a stealing operation, cache misses may occur during the write and retrieve operations, resulting in significant system performance overhead. Therefore, improving the performance and reliability of task stealing systems is an urgent issue.

[0004] Summary of the Invention

[0005] The present application provides a task stealing method, apparatus, chip, and computer equipment, thereby improving the system performance and reliability of task stealing.

[0006] In a first aspect, a task stealing method is provided, which is applied to a processor core in a computer device. For example, the computer device includes multiple processor cores, including a first processor core and a second processor core. The method is performed by the first processor core, and includes: when a circular queue associated with the first processor core is empty, stealing a first pending task from a first block with stealing permission in a circular queue associated with the second processor core, and processing the first task. The circular queue associated with the second processor core includes multiple blocks, and the block with stealing permission and the block with acquire permission among the multiple blocks are different blocks.

[0007] In this way, a block management mechanism is used to manage the circular queue associated with the processor core in blocks, realizing the "middle stealing" of the circular queue, that is, allowing tasks to be stolen from the block with stealing permission in the circular queue, and also allowing write operations or get operations to be performed on other blocks in the circular queue. Compared with stealing tasks from the head or tail of the circular queue, the possibility of competition among different processor cores to perform different operations on the same circular queue is reduced, thereby improving system performance and the reliability of task stealing.

[0008] In a possible implementation, stealing the first task to be processed from the first block with stealing permission in the circular queue associated with the second processor core includes: stealing the first task according to a stealing identifier in the first block, where the stealing identifier is used to indicate a stealing starting position in the first block.

[0009] In another possible implementation, after stealing the first task to be processed from the first block with stealing permission in the circular queue associated with the second processor core, the method further includes: updating the stealing identifier and the stealing counter in the first block, where the stealing counter is used to indicate the number of completed stolen tasks.

[0010] Therefore, the block management mechanism based on intra-block metadata (local variables within the block) realizes the "middle stealing" of the circular queue. Compared with the global metadata (global variables of the circular queue) stealing task based on the circular queue, it effectively reduces the synchronization overhead and improves the system performance.

[0011] In another possible implementation, stealing the first task to be processed from the first block with stealing permission in the circular queue associated with the second processor core includes: selecting the second processor core from the plurality of processor cores according to a processor core selection method, and randomly selecting the first block from the circular queue associated with the second processor core to steal the first task. The processor core selection method includes any one of non-uniform memory access (NUMA)-aware, equal probability, and random.

[0012] In another possible implementation, selecting a second processor core from a plurality of processor cores according to a processor core selection method includes: selecting a third processor core from a plurality of processor cores according to the processor core selection method; and selecting a second processor core from a plurality of processor cores according to the processor core selection method when a third block is randomly selected from a circular queue associated with the third processor core and the third block does not have stealing permission.

[0013] Therefore, the processor core can obtain local variables in the block through random sampling, and achieve high-probability stealing of longer circular queues while minimizing the impact of read and write contention caused by the processor core's stealing operation on the circular queue, thereby improving system performance.

[0014] In another possible implementation, stealing the first task based on the stealing identifier in the first block includes: when the stealing identifier of the second block in the circular queue associated with the second processor core indicates a block boundary of the second block, stealing the first task based on the stealing identifier and the round identifier in the first block adjacent to the second block.

[0015] In another possible implementation manner, the method further includes: updating the round identifier of the first block according to the round identifier of the second block.

[0016] Therefore, the reliability of task stealing is guaranteed through a small amount of synchronization operations in inter-block operations and a sophisticated round control mechanism. Each round identification update only depends on the round value of its adjacent block, avoiding dependence on global metadata and improving the performance of round updates.

[0017] In another possible implementation, the method further includes: switching the stealing permission of the first block to the acquisition permission according to the acquisition request; acquiring the second task to be processed from the first block according to the front identifier and the rear identifier in the first block, the front identifier and the rear identifier being used to indicate the acquisition position.

[0018] Therefore, a block management mechanism based on intra-block metadata assigns different permissions to blocks in a circular queue. A takeover mechanism is used in inter-block operations. When a block in the circular queue needs to acquire a task, a permission transfer is performed, switching the steal permission to the acquire permission. This avoids executing both acquire and steal operations on the same block, eliminating most of the synchronization overhead in intra-block operations. This brings the system throughput close to that of a serial queue, improving system performance and the reliability of task stealing.

[0019] In another possible implementation, before stealing the first task to be processed from the first block with stealing permission in the circular queue associated with the second processor core, the method also includes: writing the first task and the second task to the first block based on the rear identifier of the first block, switching the write permission of the first block to the stealing permission, and the rear identifier is used to indicate the write position.

[0020] Therefore, a block management mechanism based on intra-block metadata assigns different permissions to blocks in the circular queue. A grant mechanism is used in inter-block operations. After writing a task to a block in the circular queue, a permission transfer is performed, switching the write permission to the steal permission. This allows the processor core to steal from the block with steal permission in the circular queue. This reduces the possibility of different processor cores competing to execute different operations on the same circular queue, thereby improving system performance and the reliability of task stealing.

[0021] In a second aspect, a task stealing device is provided, which includes modules for executing the method in the first aspect or any possible design of the first aspect. For example, the task stealing device includes a stealing module, an acquiring module, and a writing module.

[0022] The stealing module is used to steal the first task to be processed from the first block with stealing permission in the circular queue associated with the second processor core when the circular queue associated with the first processor core is empty, the circular queue associated with the second processor core includes multiple blocks, and the block with stealing permission and the block with acquisition permission in the multiple blocks are not the same block.

[0023] The acquisition module is used to switch the stealing permission of the first block to the acquisition permission according to the acquisition request; obtain the second task to be processed from the first block according to the front identifier and the rear identifier in the first block, and the front identifier and the rear identifier are used to indicate the acquisition position.

[0024] The writing module is used to write the first task and the second task into the first block based on the rear identifier of the first block, and switch the writing permission of the first block to the stealing permission. The rear identifier is used to indicate the writing position.

[0025] In a third aspect, a chip is provided, comprising: a processor and a power supply circuit; wherein the power supply circuit is used to supply power to the processor; and the processor is used to execute the operating steps of the method in the first aspect or any possible implementation of the first aspect.

[0026] In a fourth aspect, a processor is provided, comprising: a plurality of processor cores; the processor cores are used to execute the operation steps of the method in the first aspect or any possible implementation of the first aspect.

[0027] In a fifth aspect, a computer device is provided, which includes a processor and a memory, the processor including multiple processor cores, and the memory is used to store a set of computer instructions. When the processor core executes the set of computer instructions, the operating steps of the method in the first aspect or any possible implementation of the first aspect are executed.

[0028] In a sixth aspect, a computer-readable storage medium is provided, comprising: computer software instructions; when the computer software instructions are executed in a computer device, the computer device executes the operating steps of the method described in the first aspect or any possible implementation of the first aspect.

[0029] In a seventh aspect, a computer program product is provided. When the computer program product is run on a computer, the computer device executes the operating steps of the method described in the first aspect or any possible implementation of the first aspect.

[0030] The technical effects brought about by any design method in the second to seventh aspects can be referred to the technical effects brought about by the first aspect or different design methods in the first aspect, and will not be repeated here.

[0031] Based on the implementation methods provided in the above aspects, this application can also be further combined to provide more implementation methods. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] FIG1 is a schematic diagram of a task stealing mechanism provided by the prior art;

[0033] FIG2 is a schematic diagram of the composition of a computer device provided by the present application;

[0034] FIG3 is a schematic diagram of an enqueue operation and a dequeue operation of a block-based circular queue provided by the present application;

[0035] FIG4 is a schematic diagram of an application scenario of task stealing provided by this application;

[0036] FIG5 is a flow chart of a task stealing method provided by the present application;

[0037] FIG6 is a schematic diagram of an intra-block operation provided by the present application;

[0038] FIG7 is a schematic diagram of updating a round identifier provided by the present application;

[0039] FIG8 is a schematic diagram of a round control provided by this application;

[0040] FIG9 is a schematic diagram of an inter-block operation provided by the present application;

[0041] FIG10 is a schematic diagram of a task stealing scenario provided by this application;

[0042] FIG11 is a schematic diagram of another task stealing scenario provided by this application;

[0043] FIG12 is a schematic diagram of the structure of a task stealing device provided by the present application. DETAILED DESCRIPTION

[0044] For the convenience of description, the terms involved in this application are first briefly introduced.

[0045] In the computer memory hierarchy, the closer the memory is to the central processing unit (CPU), the faster it is to access and the smaller its storage capacity. Memory is categorized, in descending order of distance from the CPU, as registers, cache memory, main memory, and disk.

[0046] Main memory, also known as internal memory (abbreviated as main memory or memory), is a crucial component of a computer system, serving as the bridge between external memory and the central processing unit (CPU). Main memory temporarily stores computational data within the CPU and data exchanged between the CPU and external memory devices such as hard disks. For example, when a computer starts running, data to be calculated is loaded from main memory into the CPU for computation. Once the computation is complete, the CPU stores the result in main memory. Examples of main memory include dynamic random access memory (DRAM) and double data rate synchronous DRAM (DDR SDRAM).

[0047] External storage, also known as auxiliary storage (or simply external memory or auxiliary storage), has a larger storage capacity than main memory but slower access speeds. Examples of external storage include network storage, solid-state drives (SSDs), and hard disk drives (HDDs).

[0048] Cache memory is a high-speed, small-capacity memory located between the CPU and main memory. Cache memory is also referred to as cache. Compared to main memory, cache has a smaller storage capacity and faster access speeds. Cache includes Level 1 (L1 cache), Level 2 (L2 cache), and Level 3 (L3 cache). Level 1 cache is located inside the processor core. Level 2 cache can be located inside or outside the processor core. Level 1 and Level 2 caches are typically exclusive to the processor core they are located in. Level 3 cache is typically located outside the processor core and is shared by multiple processor cores.

[0049] A cache line is a unit of memory that a computer device uses to read or write data to memory. For example, a cache line can be 64 bytes (bytes).

[0050] A memory block, the same size as a cache line, is the smallest unit of data exchange between the cache and main memory. The size of a memory block is limited to the length of data that can be accessed in one main memory clock cycle.

[0051] A queue (buffer / queue) is a linear list with restricted operations. The restrictions are that deletions can only be performed at the front of the list, and insertions can only be performed at the back of the list. Queues operate in a first-in, first-out (FIFO) order. Queues include sequential queues and circular queues.

[0052] A ring buffer (or ring queue) connects the head and tail of a sequential queue, logically viewing the linear list as a ring. A circular queue can be understood as a section of memory where the last position is connected to the first position, forming a logical ring.

[0053] A stack, also known as a stack, is a linear list with restricted operations, where insertion and deletion operations are restricted to the end of the list. The end of the list can be called the top of the stack, while the beginning of the list can be called the bottom of the stack. Inserting a new element into a stack is also called pushing, pushing, or pushing, and the new element is placed on top of the top element, making it the new top element. Deleting an element from a stack is also called popping or popping, and the top element is removed, making the adjacent element the new top element. Operations on a stack can be called last-in, first-out (LIFO).

[0054] In a weak memory model (WMM), the memory access sequence executed by a program may differ from the order in which the code was written, given an architecture defined by a specific processor core and toolchain combination. Architectures that allow for arbitrary memory access reordering are called weak memory order architectures, and the rules governing this reordering are called weak memory models.

[0055] Memory barriers refer to a type of synchronization barrier instruction that ensures that the processor or compiler strictly follows a specific order when performing memory operations. This ensures that instructions before and after the memory barrier are not reordered due to system optimization or other reasons. This is also a fundamental means of preventing program semantic errors caused by weak memory reordering. Memory barriers are also classified into different levels based on their degree of protection and performance overhead. These levels, from highest to lowest performance overhead, are: sequential barrier, acquire barrier, release barrier, and relaxed barrier.

[0056] Concurrency control is a mechanism that ensures timely prevention or correction of errors that may be caused by concurrent operations.

[0057] Atomic operation is a classic concurrency control mechanism, which refers to an operation that will not be interrupted by the thread scheduling mechanism. Once this operation starts, it will run until it ends without switching to another thread in the middle.

[0058] Compare and swap (CAS), an atomic operation, is used to implement uninterrupted data exchange operations in multi-threaded programming, thereby avoiding data inconsistencies caused by the uncertainty of execution order and unpredictable interruptions when multiple threads simultaneously rewrite the same data.

[0059] Task (work), each task is a piece of execution logic. Depending on the complexity of the execution logic, there will be different execution times. There may be logical or data dependencies between tasks, and a task may also generate subtasks during the running process.

[0060] Work stealing is a dynamic task scheduling mechanism that steals tasks from the circular queue associated with a non-idle processor core when the circular queue associated with the processor core is empty.

[0061] The processor core can be the owner of the circular queue associated with the processor core. The processor core or the thread running on the processor core can be called a worker. When performing different operations, the worker can play different roles.

[0062] For example, the processor core acts as a producer and writes tasks into the circular queue based on a put operation.

[0063] The processor core acts as a consumer and obtains tasks from the circular queue based on the get operation and executes them.

[0064] The processor core acts as a thief and steals tasks from the circular queue associated with other processor cores based on the steal operation and executes them.

[0065] For example, as shown in Figure 1, producers are responsible for writing new tasks to a circular queue, and during task execution, they also write subtasks. Consumers are responsible for sequentially retrieving tasks from the circular queue and executing them. During system operation, some processor cores' associated circular queues may still have multiple pending tasks, while others may be idle.

[0066] When the circular queue is empty, the processor core switches roles, that is, the consumer switches to the stealer, stealing tasks from the circular queues associated with other processor cores. This is equivalent to scheduling tasks from the original processor core to the new idle processor core for execution, thereby improving the overall load balancing of the system.

[0067] The circular queue is the underlying logic implementation of the task stealing mechanism. Enqueueing a circular queue involves writing tasks, while dequeuing a circular queue involves both getting and stealing tasks. Furthermore, due to the presence of stealers, multiple processor cores may access a circular queue simultaneously. Therefore, concurrency control of the circular queue is implemented during system operation to ensure correct access by multiple processor cores.

[0068] In task scheduling scenarios, the mechanisms for enqueuing and dequeuing tasks in circular queues vary depending on the top-level logic of different applications. For application scenarios that focus on overall execution efficiency (such as multi-threaded fork-join programs in parallel computing scenarios), tasks are processed in a last-in-first-out order. For application scenarios that need to pay attention to task processing latency (such as network packet processing), tasks are processed in a first-in-first-out order.

[0069] Compared to sequential queues, circular queues are more complex to implement. In the task-stealing scenario, circular queues primarily employ a single producer multiple consumer (SPMC) architecture. These queues present concurrency issues: concurrency between producers and stealers (put-steal), concurrency between consumers and stealers (get-steal), and concurrency between stealers and stealers (steal-steal). These complexities, such as potential contention between these related operations, pose significant implementation challenges, particularly in weak memory models where read and write ordering is uncertain.

[0070] In order to solve the problem of low system performance and reliability of task stealing, the present application provides a task stealing method, that is, when the circular queue associated with the first processor core is empty, the first task to be processed is stolen from the first block with stealing authority in the circular queue associated with the second processor core. The circular queue associated with the second processor core includes multiple blocks, and the block with stealing authority and the block with acquisition authority in the multiple blocks are not the same block. Since the circular queue is managed in blocks, it is allowed to steal tasks from the block with stealing authority in the circular queue, and it is also possible to perform write operations or acquisition operations on other blocks in the circular queue, thereby realizing the "middle stealing" of the circular queue, reducing the possibility of competition between different processor cores performing different operations on the same circular queue, thereby improving system performance and the reliability of task stealing.

[0071] The embodiments of the present application are described in detail below with reference to the accompanying drawings.

[0072] FIG2 is a schematic diagram of the composition of a computer device provided in the present application. As shown in FIG2 , the computer device 200 includes a processor 210 , a main memory 220 , and a cache memory 211 .

[0073] The processor 210 is the control center of the computer device 200. The processor 210 can be a computing unit with computing capabilities, such as a central processing unit (CPU), a graphics processing unit (GPU), a data processing unit (DPU), or a neural processing unit (NPU).

[0074] In some embodiments, the processor 210 includes multiple processor cores. For example, the processor 210 shown in FIG2 includes N processor cores. Multiple processor cores can run multiple threads and process multiple different tasks in parallel, thereby improving the processing performance of the system.

[0075] The cache memory 211 is used to store instructions or data that may be accessed multiple times by the processor core in the processor 210 , thereby increasing the speed at which the processor processes data and preventing the processor from frequently accessing the main memory 220 .

[0076] In the present application, cache memory 211 can be used to provide storage space for a circular queue associated with a processor core. The processor core manages the circular queue in blocks, i.e., it divides the storage space of the circular queue into multiple blocks and performs enqueue and dequeue operations on the circular queue based on the blocks. For ease of description, a block may also be referred to as a partition in the present application.

[0077] Enqueue and dequeue operations within a block are referred to as intra-block operations or the fast path. Enqueue and dequeue operations between blocks are referred to as inter-block operations or the slow path. If a block cannot be enqueued or dequeued, an inter-block migration (adv_blk) is performed to enqueue or dequeue the next block, switching from the fast path to the slow path.

[0078] In a task stealing scenario, the processor core can grant write, get, or steal permissions to blocks in the circular queue. The processor core can write to blocks with write permissions, get to blocks with get permissions, and steal to blocks with steal permissions. This allows for synchronization between different operations on the circular queue, ensuring the correctness and efficiency of reading and writing tasks to the circular queue.

[0079] The block-based design separates write, get, and steal operations into a fast path (intra-block operations) and a slow path (inter-block operations, including inter-block migrations (adv_blk)). This avoids most synchronization overhead in the fast path, while ensuring global correctness through a small amount of synchronization on the slow path. It is important to note that the following rules must be adhered to when performing intra-block and inter-block operations.

[0080] 1) Write operations will not overwrite unconsumed tasks.

[0081] 2) Stealing and acquiring operations will not acquire tasks in the same block at the same time.

[0082] 3) Stealing and acquiring operations will not acquire tasks that have been acquired before.

[0083] 4) An ongoing steal operation cannot prevent an acquire operation from acquiring tasks in the same block. If this happens, according to 2), the steal operation will stop stealing data from the block.

[0084] For example, FIG3 is a schematic diagram of the enqueue operation and dequeue operation of a block-based circular queue provided by the present application. As shown in (a) in FIG3, it is a circular queue based on the last-in-first-out mode. The circular queue includes 6 blocks, namely block 0 to block 5. Starting from the head of the queue (block 0), tasks are written to the blocks in the circular queue in sequence. When a block is full, inter-block migration is performed and tasks are written to the next block. As shown in the figure, blocks 0 to 2 are full blocks. When block 3 is full, inter-block migration (adv_blk put ), you can write tasks to block 4.

[0085] Because the circular queue operates in a last-in, first-out (LIFO) mode, block 0, where the task was written first, is at the bottom of the stack, and block 3, where the task was written later, is at the top. When retrieving tasks from the circular queue, tasks are retrieved from the top of the stack. For example, if you switch the write permission for block 3 to the get permission, you can perform a get operation on the tasks in block 3.

[0086] Since read and write operations cannot be performed on a full block, a grant is performed, allowing steal operations on the full block. For example, the write permissions for blocks 0 through 2 are switched to steal permissions. When block 3 is full, an inter-block migration is performed, switching the write permissions for block 3 back to steal permissions.

[0087] If the task in block 3 has been acquired and needs to continue acquiring tasks, perform inter-block migration (adv_blk get ) and takeover, that is, switching the stealing permission of block 2 to the obtaining permission, and obtaining the task from block 2.

[0088] If the task in block 0 has been stolen and needs to be stolen again, perform inter-block migration (adv_blk steal ), steal tasks from block 1.

[0089] As shown in (b) of Figure 3, it is a circular queue based on the first-in-first-out mode. The circular queue includes 6 blocks, namely block 0 to block 5. Starting from the head of the queue (block 0), tasks are written to the blocks in the circular queue in sequence. When a block is full, inter-block migration is performed and tasks are written to the next block. As shown in the figure, blocks 0 to 2 are full blocks. When block 3 is full, inter-block migration (adv_blk put ), you can write tasks to block 4.

[0090] Because the circular queue operates in a first-in, first-out mode, block 0, the first task written to it, is at the head of the queue, and block 3, the last task written to it, is at the tail. When retrieving tasks from the circular queue, tasks are retrieved from the head of the queue. For example, if you switch the write permission for block 0 to the get permission, you can perform a get operation on the tasks in block 0.

[0091] If the task in block 0 has been acquired and needs to be acquired again, perform inter-block migration (adv_blk get ) and takeover, switching the stealing permission of block 1 to the acquiring permission, and acquiring tasks from block 1.

[0092] Since the acquire permission is higher than the steal permission, granting permission to the block of the write task allows the steal operation to be performed on the block of the write task. For example, switching the write permission of block 3 to the steal permission allows the steal operation to be performed on the task in block 3.

[0093] Since writing to a full block is not possible, if you need to continue stealing, you can also grant permission to steal from a full block. For example, switch the write permission from block 1 to block 2 to steal permission. When block 3 is full, perform inter-block migration (adv_blk put ), the write permission of block 3 is switched to steal permission.

[0094] In this way, by taking over and granting in inter-block operations, it is ensured that stealing and obtaining operations will not be performed on the same block. Then, each block is either occupied by the consumer or the thief at a certain time point, thereby improving system performance and the reliability of task stealing.

[0095] In terms of physical form, the cache memory 211 can be a random access memory (RAM), a static random-access memory (SRAM), a dynamic random access memory (DRAM), or other types of storage devices that can store information and instructions.

[0096] In terms of logical form, the cache memory 211 can be a level 1 cache (L1 cache), a level 2 cache (L2 cache), a level 3 cache (L3 cache), or any other level of cache. For example, as shown in FIG2 , the cache memory 211 disposed inside the processor core can be a level 1 cache (L1 cache) and a level 2 cache (L2 cache). The cache memory 211 disposed outside the processor core can be a level 3 cache (L3 cache).

[0097] The processor core is connected to the cache memory 211 via bus 212 and accesses the cache memory 211 via bus 212. For example, the processor core transmits a write instruction or a read instruction to the cache memory 211 via bus 212, causing the cache memory 211 to write to a block in the circular queue according to the write instruction or read from the block in the circular queue according to the read instruction. Bus 212 can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or a proprietary bus standard of a non-standard system. This bus can be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, FIG2 shows only one thick line, but this does not mean that there is only one bus or only one type of bus.

[0098] The connection between the processor core and cache memory 211 in FIG2 is merely illustrative. In one possible implementation, the processor core is connected to cache memory 211 via a ring bus, and accesses cache memory 211 via the ring bus. In another possible implementation, the processor core and cache memory 211 are connected via a mesh bus, and the processor core accesses cache memory 211 via the mesh bus.

[0099] The processor 210 is connected to the main memory 220 via a memory controller (MC) 213. The processor 210 can perform various functions of the computer device 200 by running or executing software programs stored in the main memory 220 and accessing data stored in the main memory 220. For example, the processor 210 writes data in a circular queue back to the main memory 220 via the memory controller (MC) 213.

[0100] The main memory 220 may be a read-only memory (ROM) or other static storage device capable of storing static information and instructions, a random access memory (RAM) or other dynamic storage device capable of storing information and instructions, or an electrically erasable programmable read-only memory (EEPROM). The main memory 220 is also used to store programs related to this embodiment and data related to the circular queue.

[0101] The processor 210 may further include an external device 230 and a peripheral management module 214. The peripheral device 230 is connected to the peripheral management module 214 via a bus 212. The peripheral device 230 may be an application specific integrated circuit (ASIC). For example, a microprocessor (digital signal processor, DSP), or one or more field programmable gate arrays (FPGA), or a graphics processing unit (GPU), or a neural network processing unit (NPU). The peripheral device 230 may also transmit a write instruction or a read instruction to the cache memory 211 via the bus 212, causing the cache memory 211 to write to a block in the circular queue according to the write instruction or read from a block in the circular queue according to the read instruction.

[0102] The device structure shown in FIG2 does not constitute a limitation on the computer device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.

[0103] The task stealing method provided in this application can be widely used in language runtimes (such as the garbage collection mechanism and thread library of the Java runtime, the thread library of the Rust Tokio runtime, the goroutine of the Go runtime, and the runtimes of other programming languages ​​such as Cilk and Kotlin), operating systems (such as Intel OneAPI thread basic mechanism (Thread Building Blocks, TBB) and other thread / task related libraries, FreeBSD SKQ, Data Plane Development Kit (Data Plane Development Kit, DPDK) Shenango and other network stacks), parallel computing frameworks (such as OpenMP high-performance computing framework, TaskFlow parallel heterogeneous programming framework, etc.), key components of heterogeneous system operating environments (such as Compute Unified Device Architecture (CUDA), Open Computing Language (OpenCL), etc.), mainly responsible for load balancing of computing resources in concurrent scenarios.

[0104] For example, as shown in Figure 4, it is a schematic diagram of a lightweight thread application scenario. As shown in the figure, the process of network communication in Linux relies on the Tokio asynchronous input / output (Input / Output, I / O) component. The asynchronous runtime includes relevant components of the task stealing method provided in this application. Business requests are processed and scheduled through the asynchronous runtime in the black box. When a business request arrives at the current system, it will be placed in a circular queue as a task. The working thread will then take out tasks from other circular queues for processing. If the current circular queue is empty, it will try to steal from other circular queues to achieve load balancing.

[0105] Next, the task stealing method provided by this application is described in detail with reference to the accompanying drawings. Here, the task stealing method using processor core 1 and processor core 2 shown in FIG2 is used as an example for description. For other processor cores, reference can be made to the relevant description of processor core 1 and processor core 2.

[0106] Referring to Figure 5 , which is a flow chart of a task stealing method provided by the present application, the method includes the following steps.

[0107] Step 510 : Processor core 1 performs a write operation on a block in a circular queue associated with processor core 1 .

[0108] In order to manage the circular queue associated with the processor core 1 in blocks, the processor core 1 sets a position identifier for each block in the circular queue. The position identifier is used to indicate the starting position when performing write operations, get operations and steal operations on the block.

[0109] In some embodiments, the processor core 1 uses a front position (f_pos) and a back position (b_pos) to control write and retrieve operations on a block. The front position indicates the starting position of data within a block. The back position indicates the ending position of data within a block.

[0110] For example, as shown in (a) in Figure 6, when processor core 1 performs a write operation on a block, processor core 1, as a producer, determines whether the front identifier reaches the block boundary (number of entries, NE). If the front identifier does not reach the block boundary, it indicates that the write operation is allowed on the block and the block has write permission. If the front identifier reaches the block boundary, it indicates that the write operation is not allowed on the block and the block does not have write permission, and block_done is returned. Then, it is determined whether the rear identifier reaches the block boundary. If the rear identifier does not reach the block boundary, the block is written based on the position indicated by the rear identifier, and the rear identifier is pointed to the next node (entry) in the block. If the rear identifier reaches the block boundary, inter-block migration is performed, and a write operation is performed on the next block based on the front identifier and the rear identifier of the next block.

[0111] Step 520 : Processor core 1 performs an acquisition operation on the blocks in the circular queue associated with processor core 1 .

[0112] After processor core 1 writes a task to a block in the circular queue, it can retrieve tasks from the block in the circular queue and execute them. When processor core 1 performs a retrieve operation on a block in the circular queue, the write permission of the block is switched to retrieve permission. Processor core 1, acting as a consumer, retrieves tasks from the block in the circular queue based on the leading and trailing identifiers.

[0113] Processor core 1 determines whether the front marker reaches the block boundary. If the front marker does not reach the block boundary, it indicates that the block is allowed to perform the acquisition operation, and the block has the acquisition permission. If the front marker reaches the block boundary, it indicates that the block is not allowed to perform the acquisition operation, and the block does not have the acquisition permission. The processor core 1 returns block_done. Alternatively, the processor core 1 determines whether the position indicated by the front marker and the position indicated by the rear marker are the same. If the position indicated by the front marker and the position indicated by the rear marker are the same (f_pos == b_pos), it indicates that the block is empty. The processor core 1 returns empty. If the position indicated by the front marker and the position indicated by the rear marker are different, the processor core 1 obtains the task from the block in the circular queue.

[0114] For example, as shown in FIG6 (b), according to the mode of getting tasks from the block of the circular queue, the processor core 1 uses get f and get b Two operations. Based on the FIFO mode, the task is obtained from the block of the circular queue. The processor core 1 uses the front mark as the current position of the task to be obtained (get f ), NE as the block boundary, the rear mark as the boundary of the available data. Based on the LIFO mode, the task is obtained from the block of the circular queue. The processor core 1 uses the rear mark as the current position of the task to obtain (get b ), 0 as the block boundary, and the leading mark as the boundary of available data.

[0115] When processor core 1 completes processing of tasks in all blocks in the circular queue, that is, the circular queue associated with processor core 1 is empty, processor core 1 steals tasks from blocks in the circular queues associated with other processor cores in the system based on the task stealing method provided in this application, that is, executes step 530.

[0116] Step 530: Processor core 1 performs a stealing operation on the blocks in the circular queue associated with processor core 2, and processes the stolen tasks.

[0117] To manage the block-by-block circular queue associated with processor core 1, processor core 1 sets a stealing flag (s_pos) and a stealing counter (s_cnt) for each block in the circular queue. The stealing flag indicates the starting position for stealing when performing a stealing operation on the block. The stealing counter indicates the number of completed stealing tasks.

[0118] When the circular queue associated with processor core 1 is empty, when processor core 1 performs a steal operation on the block in the circular queue associated with processor core 2, it indicates that a steal operation and a write operation compete with each other in the block in the circular queue. The write permission of the block is switched to the steal permission. Processor core 1 acts as a thief and steals tasks from the block with steal permission in the circular queue based on the steal identifier, and updates the steal identifier and steal counter in the block.

[0119] Exemplarily, as shown in (c) of FIG. 6, the processor core 1 determines whether the steal flag reaches the block boundary. If the steal flag does not reach the block boundary, it indicates that stealing operation on the block is allowed, and the block has the stealing permission. If the steal flag reaches the block boundary, it indicates that stealing operation on the block is not allowed, and the block does not have the stealing permission, then return block_done. Alternatively, the processor core 1 determines whether the position indicated by the steal flag and the position indicated by the rear flag are the same. If the position indicated by the steal flag and the position indicated by the rear flag are the same (s_pos == b_pos), it indicates that the block is empty, and return empty. If the position indicated by the steal flag and the position indicated by the rear flag are different, then use an atomic operation (e.g., CAS) to point the steal flag to the next block node, perform the stealing task, and use an atomic operation (e.g.: fetch and add, FAA) to update the steal counter. If CAS fails, then return conflict.

[0120] In some embodiments, the present application provides a strategy that combines performance and load balancing, and through a low-overhead mechanism, selects a circular queue of multiple data with a high probability. Since the present application adopts a block-based circular queue, it inherently has the characteristic of "stealable in the middle", that is, after selecting the circular queue, tasks can be stolen starting from the middle block, which improves the flexibility of the entire system to perform stealing operations.

[0121] Based on this, the processor core 1 selects the block of the task to be stolen in two stages. Stage 1: The processor core 1 selects a processor core from multiple processor cores according to the processor core selection method; Stage 2: Randomly select the block of the task to be stolen from the circular queue associated with the processor core. When the block of the task to be stolen does not have the stealing permission, the processor core 1 executes Stage 1 and Stage 2 again until a block with the stealing permission is selected, and perform the stealing operation on the block with the stealing permission. Among them, the processor core selection method includes any one of non-uniform memory access architecture awareness (NUMA-aware), equal probability, and random.

[0122] For example, the processor core 1 selects the processor core 3 from multiple processor cores according to the processor core selection method. When randomly selecting block 3 from the circular queue associated with the processor core 3, and block 3 does not have the stealing permission, then select the processor core 2 from multiple processor cores according to the processor core selection method, and randomly select block 1 from the circular queue associated with the processor core 2. Since block 1 has the stealing permission, steal the task from block 1.

[0123] Among them, the action of "randomly selecting a block and determining non-empty" only involves the read operation of the metadata of one block, that is, determining that s_pos.idx < b_pos.idx in the block. Therefore, the probability of conflict between the stealer and the owner is very small, so the performance overhead of the action of "selecting the queue" can be greatly reduced.

[0124] In FIFO mode, the default random strategy is used, and the randomly selected block can be used as the starting point for stealing tasks, with essentially zero overhead. Once all tasks in a block have been stolen, a new round of random block selection begins. In LIFO mode, if the random strategy is enabled, random sampling is first used to determine whether to steal from the circular queue. Tasks are then stolen from the bottom of the circular queue. Once a block has been stolen, tasks are stolen from the next block.

[0125] In other embodiments, in order to prevent the unretrieved tasks in the block of the circular queue from being overwritten by the newly written tasks, or to prevent the acquisition operation and the stealing operation from being performed on the same task in the block, a round identifier (or round variable) is set for each block in the circular queue block, and round control is used to control the execution of write operations, acquisition operations and stealing operations on the blocks of the circular queue.

[0126] 1) When the producer tries to write the task of round r in a block, it ensures that the consumer and stealer have completed reading the task of round r-1 in the block, so as to ensure that the producer does not overwrite the unread task.

[0127] 2) When a consumer or stealer tries to read the round r task in a block, ensure that the round of the task written by the producer in the block is r, so as to prevent repeated reading of tasks or reading tasks that have never been written.

[0128] For example, as shown in FIG7, a schematic diagram of the update of the round identifier provided by the present application is shown. When an inter-block migration (adv_blk) operation occurs, the round variable is updated: in addition to the n When wrapping back to b0, the round variable corresponding to b0 will be increased by one (i.e. b0.round = b n .round+1, indicating a new round), in other cases the round variable of the current block is directly assigned to the next block (i.e. b n .round=b n-1 .round).

[0129] For example, suppose that processor core 1 performs a steal operation on block 2 in the circular queue associated with processor core 2. When the steal identifier of block 1 in the circular queue associated with processor core 2 indicates the block boundary of block 1, the steal task is performed according to the steal identifier and round identifier in block 2 adjacent to block 1, and the round identifier of block 2 is updated according to the round identifier of block 1.

[0130] In order to implement the round control described above, the four metadata of each block (front identifier, back identifier, stealing identifier and stealing counter) are assigned to the index variable idx and the round variable rnd respectively. The index variable and the round variable can be 64-bit variables (to ensure that updates to the two variables are atomic). The index variable and the round variable are used to represent the metadata corresponding to the producer (f_pos), the metadata corresponding to the consumer (f_pos in LIFO mode and b_pos in FIFO mode), and the metadata corresponding to the stealer (s_pos) in each block. For example, as shown in Figure 8, the round control in FIFO mode is used to illustrate this.

[0131] For the producer, when the index variable reaches the block boundary (step ①), the inter-block migration (adv_blk put ), calculate the round variable of the next block (nblk) based on the method mentioned above (step ②): x = blk.rnd + nblk.start, and check whether the consumer and the thief have completed the task reading of x-1 rounds (step ③): c / t.rnd == x-1&&c / t.idx == NE. If the conditions are met, write x and 0 into the round variable and index variable of the next block respectively (step ④).

[0132] For consumers, the situation is similar. When judging whether they can obtain the task of the next block, the judgment conditions are different. It is only necessary to judge whether the producer's round variable in the next block is equal to the value x (step ③). If so, it means that there is a task that can be obtained in the next block.

[0133] It should be noted that when a processor core encounters a block boundary while executing a write, get, or steal operation, it performs an inter-block migration and moves to the next block. First, the round variable is used to check whether inter-block migration is allowed. If so, the following inter-block operations occur and the corresponding metadata (previous flag, next flag, steal flag, and steal counter) are updated.

[0134] The following examples illustrate inter-block migration based on the LIFO and FIFO modes respectively.

[0135] As shown in Figure 9(a), it is a schematic diagram of inter-block migration in LIFO mode. Assume that the circular queue includes block 0 (b0) and block 1 (b1).

[0136] 1) The producer writes four tasks (a-d) to b0 and two tasks (e-f) to b1. Then, b0 is granted permission (grant), switching its write permission to steal. This allows the stealer to steal from b0, the producer to write to b1, and the consumer to retrieve from b1. The back-end flags (b_pos) of b0 and b1 are assigned values ​​of 4 and 2, respectively. The front-end flag (f_pos) and steal flag (s_pos) are both assigned their initial values ​​(state ①).

[0137] 2) The two thieves steal tasks a and b from b0 respectively, update the stealing flag in b0 to 2, and start copying data; the consumer needs to obtain 3 tasks, obtain tasks f and e from b1, and update the rear flag in b1 to 0 (state ②).

[0138] 3) Since there are no tasks in b1, inter-block migration occurs (adv_blk get ), migrate from b1 to b0, perform a takeover on b0, return the ownership of b0 to the consumer, switch b0's stealing permission to obtain permission, assign the stealing flag in b0 to the block boundary value 4, and set the front flag to the value before the stealing flag 2 (state ③).

[0139] 4) The consumer obtains task d from b0, and the producer writes task g to b0. At this point, a previous steal operation completes the data copy (steal'), setting the steal counter to 1 (state ④).

[0140] 5) Since b0 is full, inter-block migration occurs (adv_blk put ), migrating from b0 to b1. The producer writes tasks h and i to b1 and grants b0, switching b0's write permission to steal permission, allowing the stealer to steal from b0. The steal flag is assigned the value 2 of f_pos (state ⑤).

[0141] 6) The stealer steals tasks c and g from b0, and finally steals the remaining three tasks (c, g, b / a) from b0. At this time, the value of the stealing flag is updated to 4, which is equal to the value of the block boundary (state ⑥).

[0142] As shown in Figure 9(b), it is a schematic diagram of inter-block migration in FIFO mode. Assume that the circular queue includes block 0 (b0), block 1 (b1), and block 2 (b2).

[0143] 1) The producer writes four tasks (a-d) to b0 and three tasks (e-g) to b1. The consumer is allowed to perform an acquire operation on b0 and authorize b1, switching b1's write permission to steal, allowing the stealer to steal on b1 and the producer to write to b1. The trailing flags of b0 and b1 are assigned values ​​of 4 and 3, respectively, and the steal flag is assigned value 0 (state ①).

[0144] 2) Two stealers steal tasks e and f from b1, respectively, updating the steal flag in b1 to 2 and starting to copy data. One of the stealing operations completes the data copy earlier (steal'), setting the steal counter to 1. Meanwhile, the consumer acquires all tasks a through d from b0 (state ②).

[0145] 3) The front mark in b0 reaches the block boundary, and inter-block migration occurs (adv_blk get ), takes over b1, returns b1's ownership to the consumer, and switches b1's stealing privileges to acquiring privileges. Similar to the LIFO model, the stealing flag in b1 is first assigned to the block boundary value 4, and the front flag is set to the value before the stealing flag, 2. Furthermore, the stealing counter is incremented by the difference between the block boundary and the front flag, i.e., s_cnt + = (block_size – f_pos) = 3 (state ③). In this way, when all stealing operations are completed, the stealing counter will be equal to the block boundary value.

[0146] 4) The producer writes task h to b1, and inter-block migration occurs (adv_blk put ), migrate from b1 to b2, write task i to b2, perform authorization on b2, switch the write permission of b2 to steal permission, and allow the thief to perform stealing operations on b2 (state ④).

[0147] 5) The consumer obtains tasks g and h from b1. The remaining stolen task is also completed. The leading flag and steal counter are both set to the block boundary value 4 (state ⑤). The producer then uses the values ​​of these metadata to determine whether the block can contain new tasks.

[0148] The task stealing method provided in this application adopts a block management mechanism to perform block management on the circular queue associated with the processor core, realizing the "middle stealing" of the circular queue, that is, allowing tasks to be stolen from the block with stealing permission in the circular queue, and at the same time, performing write operations or acquisition operations on other blocks in the circular queue to ensure that stealing operations and acquisition operations are not performed on the same block. In addition, the "global metadata" is converted into "intra-block metadata", reducing the possibility of competition between the owner and the thief, thereby improving system performance and the reliability of task stealing.

[0149] The following is an example of the implementation code of the task stealing method provided by this application.

[0150] Program 1: Pseudocode for the top-level operations of Write, Get, and Steal.

[0151] The first step for all three operations is to select a block to operate on (lines 3, 14, and 27). After selecting the block, each operation executes the fast path (lines 4, 15, and 28), which may return one of the following three results:

[0152] 1) Success (lines 5, 16, and 29), the write operation returns true, and the get and steal operations return the obtained values.

[0153] 2) Failure may be caused by an empty queue (lines 18 and 31), in which case the get and steal operations return null, or by a conflict between the steal operation and the write or get operation (line 33), in which case the steal operation will be retried (line 34).

[0154] 3) The intra-block operation reaches the block boundary (lines 7, 20, and 35). That is, for write operations, the block is full, and for get and steal operations, the block is empty. At this point, the inter-block migration (adv_blk) operation (lines 8, 21, and 36) is performed to enter the next block. If the inter-block migration operation succeeds, a retry is performed (lines 9, 22, and 38). Otherwise, a false or invalid value is returned (lines 10, 23, and 39).

[0155] The following is an example of the task stealing method provided by this application.

[0156] Example 1: Garbage collection (GC) is a key component in high-level languages. For example, in Java, users create numerous objects in different threads, and after use, garbage collection is executed to reclaim the threads. Based on the pointing and creation relationships, the objects to be reclaimed can be abstracted into a graph, as shown in Figure 10, with targets as vertices and pointers as edges. During memory reclamation, this graph must be traversed multiple times to find objects that are no longer needed and reclaim them. To minimize the impact of reclamation operations on application performance, these traversals are typically performed by multiple worker threads to reduce latency. Since the number of objects created by different threads may be uneven, this raises the issue of load balancing. Currently, the most common approach in the industry is to use a task stealing mechanism. This is where each worker thread, while traversing the graph, places the successor of the currently traversed point into its own circular queue. After traversing this point, it retrieves the successor from the circular queue and traverses it again. If the current worker thread does not have a point to traverse, it steals tasks from the circular queues of other worker threads.

[0157] In the Java GC, the original task-stealing scheme was replaced with the scheme of this application, and 25 common use cases were tested. Compared with the original scheme, 17 tests of this application on the x86 platform showed performance improvement, with an average improvement of 3.55% and a maximum improvement of 25.3%. On the ARM platform, 18 tests showed performance improvement, with an average improvement of 5.20% and a maximum improvement of 17.2%.

[0158] In a second example, in a lightweight threading scenario (such as Goroutine), users create a large number of tasks (i.e., lightweight threads) and execute them on multiple cores. Since task execution durations are unpredictable, dynamic allocation is often used to address load balancing across multiple cores. As shown in Figure 11, an efficient execution method is to assign a circular queue (run queue) to each core, from which tasks are retrieved for execution. If the circular queue is empty, tasks are stolen from other circular queues for execution. This core component of the lightweight threading scenario is the task stealing mechanism.

[0159] After replacing the run-queue in the Go language, this application performed a performance test on the go-json library benchmark compared to the original solution. In the x86 scenario, the average performance increased by 25.8%, and in the ARM scenario, the average performance increased by 28.2%.

[0160] The core idea of ​​this application is to divide the circular queue in the underlying logic of the task stealing mechanism into blocks and separate the operations within the block from the operations between blocks. Block division and separation bring many benefits:

[0161] First, block partitioning transforms the "global metadata" in the original scheme into "intra-block metadata", significantly reducing the possibility of competition between owners and thieves, thereby reducing synchronization overhead;

[0162] Second, separation ensures system correctness through minimal synchronization and sophisticated round control in inter-block operations. It also maintains a fast path close to the throughput of a serial queue during most of the time, bringing overall performance close to the theoretical optimal value.

[0163] Third, blocking improves the modularity of circular queue design and implementation, and also brings benefits to the formal verification of blocking logic, enabling step-by-step verification.

[0164] Fourth, chunking enables the stealer to “steal from the middle of the circular queue,” which on the one hand reduces the probability of contention between the owner and the stealer, and on the other hand provides greater room for optimization of the stealing strategy.

[0165] This block and separation method can also be applied in the future to GPU (or CPU-GPU) heterogeneous computing scenarios and high-performance computing schedulers, which all rely heavily on task stealing mechanisms. In addition, for other data structures that are mostly accessed serially and only require concurrent access in a few cases, the method of this application can also be used as a reference for design and implementation.

[0166] The blocking mechanism poses a higher challenge to the correct implementation of circular queues, especially in hardware with a weak memory model. How to correctly use the minimum memory barriers, how to implement correct and efficient concurrency control, and how to ensure that the logical behavior of such a complex circular queue is as expected require a set of formal methods to solve these problems.

[0167] This application uses the GenMC model checking tool, which verifies through traversal that all possible paths satisfy predefined properties, such as memory safety, termination, and user-defined assertions. A carefully constructed test case (see Program 2) with three threads triggers all conceivable race conditions. This test case is checked using the GenMC model checking tool, and the memory barriers involved are optimized using the VSync framework.

[0168] Program 2: Test code for formal verification.

[0169] This application's solution was verified and optimized for both LIFO and FIFO modes, and also compared to the industry's leading LIFO solution, ABP. Table 1 shows the final verification and optimization results: #SEQ represents a sequential barrier, which has the highest performance overhead; #ACQ and #REL represent acquire and release barriers, respectively, with lower performance overhead than #SEQ; and #RLX represents a relaxed barrier, which has virtually no performance overhead (essentially equivalent to a normal memory access). Use <#SEQ,#ACQ,#REL,#RLX> to represent the number of barriers. In the original ABP scheme, the barriers for all write operations, get operations, and steal operations are <4,3,1,7>. In this application, the barriers are <0,2,2,14> in the LIFO scheme and <0,3,3,16> in the FIFO scheme. In addition, in the original ABP scheme, the number of barriers involved by the owner is <2,1,1,0>. In this application, the barriers involved by the owner's fast channel in the LIFO mode are <0,0,0,5> and <0,1,0,4> in the FIFO mode.

[0170] Table 1

[0171] Formal verification based on model checking also ensures that the current barrier optimization results are optimal. Counterexamples can be found regardless of weakening any barrier. Furthermore, an attempt was made to expand the test case to four threads, verifying it using GenMC and VSync for three days (nearly 200 million execution paths), ultimately passing verification and further proving the correctness of the algorithm implemented in this application.

[0172] Based on the experience of this application in formal verification, it is believed that with the increase in hardware complexity (such as weak memory order, concurrency mechanism, consistency synchronization, etc.), software will become more and more complex. A series of practical formal methods similar to those used in this application can provide more radical and reliable performance optimization possibilities while ensuring the correctness of complex software design and implementation.

[0173] It is understood that in order to implement the functions in the above embodiments, the processor includes hardware structures and / or software modules corresponding to the execution of each function. It should be readily apparent to those skilled in the art that, in combination with the units and method steps of each example described in the embodiments disclosed in this application, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application scenario and design constraints of the technical solution.

[0174] The task stealing method provided in accordance with the present embodiment is described in detail above with reference to FIG. 1 to FIG. 11 . The task stealing device provided in accordance with the present embodiment will be described below with reference to FIG. 12 .

[0175] FIG12 is a schematic diagram of the structure of a possible task stealing device provided by this application. These task stealing devices can be used to implement the functions of the processor core in the above method embodiment, thereby also achieving the beneficial effects of the above method embodiment. In this embodiment, the task stealing device can be a processor core as shown in FIG5, or a module (such as a chip) applied to a server.

[0176] As shown in Figure 12, the task stealing device 1200 includes a communication module 1210, a stealing module 1220, and a memory 1230. The task stealing device 1200 is used to implement the functions of the processor core in the method embodiment shown in Figure 5 above.

[0177] The communication module 1210 is used for transmitting tasks.

[0178] The stealing module 1220 is configured to steal the first task to be processed from the first block with stealing permission in the circular queue associated with the second processor core when the circular queue associated with the first processor core is empty, and process the first task. For example, the stealing module 1220 is configured to execute step 530 in FIG5 .

[0179] Optionally, the stealing module 1220 is further configured to steal the first task according to a stealing identifier in the first block, where the stealing identifier is used to indicate a stealing start position in the first block.

[0180] Optionally, the stealing module 1220 is further configured to select a second processor core from the plurality of processor cores according to a processor core selection method, and randomly select a first block from a circular queue associated with the second processor core to steal the first task.

[0181] The memory 1230 is used to store metadata of the blocks in the circular queue and tasks, so as to facilitate the stealing module 1220 to steal tasks. The memory 1230 may include a cache memory and a memory.

[0182] The task stealing device 1200 further includes an acquisition module 1240 and a write module 1250. The acquisition module 1240 is configured to switch the stealing permission of the first block to the acquisition permission according to the acquisition request; and to acquire the second task to be processed from the first block according to the front identifier and the back identifier in the first block, where the front identifier and the back identifier are used to indicate the acquisition position.

[0183] The writing module 1250 is configured to write the first task and the second task into the first block based on the rear identifier of the first block, and switch the write permission of the first block to the steal permission. The rear identifier is used to indicate the write position.

[0184] It should be understood that the task stealing device 1200 of the embodiment of the present application can be implemented by an application-specific integrated circuit (ASIC) or a programmable logic device (PLD), wherein the PLD can be a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof. Alternatively, when the task stealing method shown in FIG. 5 is implemented by software, the various modules thereof can also be software modules, and the various modules of the task stealing device 1200 can also be software modules.

[0185] According to the embodiment of the present application, the task stealing device 1200 can correspond to the execution of the method described in the embodiment of the present application, and the above-mentioned and other operations and / or functions of each unit in the task stealing device 1200 are respectively for implementing the corresponding processes of each method in Figure 5. For the sake of brevity, they will not be repeated here.

[0186] The present application also provides a computer system, which includes multiple computer devices, each of which includes multiple processor cores. The processor cores in the multiple computer devices are used to execute the operating steps of the methods described in the above embodiments.

[0187] The method steps in this embodiment can be implemented by hardware or by a processor executing software instructions. The software instructions can be composed of corresponding software modules, which can be stored in random access memory (RAM), flash memory, read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), registers, hard disks, mobile hard disks, CD-ROMs, or any other form of storage medium known in the art. An exemplary storage medium is coupled to the processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be an integral part of the processor. The processor and storage medium can be located in an ASIC. In addition, the ASIC can be located in a computing device. Of course, the processor and storage medium can also exist as discrete components in a computing device.

[0188] In the above embodiments, all or part of the embodiments can be implemented by software, hardware, firmware or any combination thereof. When implemented using software, all or part of the embodiments can be implemented in the form of a computer program product. The computer program product includes one or more computer programs or instructions. When the computer program or instructions are loaded and executed on a computer, the process or function described in the embodiments of the present application is performed in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, a network device, a user device or other programmable device. The computer program or instruction can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer program or instruction can be transmitted from one website, computer, server or data center to another website, computer, server or data center via wired or wireless means. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium, such as a floppy disk, a hard disk, or a tape; it can also be an optical medium, such as a digital video disc (DVD); it can also be a semiconductor medium, such as a solid state drive (SSD). The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present application, and such modifications or substitutions should be included in the scope of protection of the present application. Therefore, the scope of protection of the present application should be based on the scope of protection of the claims.

Claims

1. A task stealing method, characterized in that: The computer device includes a plurality of processor cores, the plurality of processor cores including a first processor core and a second processor core, and the method includes: When the circular queue associated with the first processor core is empty, the first task to be processed is stolen from the first block with stealing authority in the circular queue associated with the second processor core, and the first task is processed. The circular queue associated with the second processor core includes multiple blocks, and the block with stealing authority and the block with acquisition authority in the multiple blocks are not the same block.

2. The method according to claim 1, characterized in that Stealing a first task to be processed from a first block with stealing permission in a circular queue associated with the second processor core includes: The first task is stolen according to a stealing identifier in the first block, where the stealing identifier is used to indicate a stealing start position in the first block.

3. The method according to claim 1 or 2, characterized in that: Stealing a first task to be processed from a first block with stealing permission in a circular queue associated with the second processor core includes: Selecting the second processor core from the plurality of processor cores according to a processor core selection method, wherein the processor core selection method includes any one of NUMA-aware, equal probability, and random; The first block is randomly selected from a circular queue associated with the second processor core to steal the first task.

4. The method according to claim 3, characterized in that Selecting the second processor core from the multiple processor cores according to the processor core selection method includes: selecting a third processor core from the plurality of processor cores according to the processor core selection method; When a third block is randomly selected from the circular queue associated with the third processor core and the third block does not have the stealing authority, the second processor core is selected from the multiple processor cores according to the processor core selection method.

5. The method according to any one of claims 2 to 4, characterized in that: After stealing the first task to be processed from the first block with stealing permission in the circular queue associated with the second processor core, the method further includes: The first processor core updates the stealing identifier and the stealing counter in the first block, where the stealing counter is used to indicate the number of completed stealing tasks.

6. The method according to any one of claims 2 to 5, characterized in that: Stealing the first task according to the theft identifier in the first block includes: When the stealing identifier of the second block in the circular queue associated with the second processor core indicates a block boundary of the second block, the first task is stolen according to the stealing identifier and the round identifier in the first block adjacent to the second block.

7. The method according to claim 6, characterized in that The method further comprises: The round identifier of the first block is updated according to the round identifier of the second block.

8. The method according to any one of claims 1 to 7, characterized in that The method further comprises: The second processor core switches the stealing permission of the first block to the acquiring permission according to the acquiring request; The second processor core obtains a second task to be processed from the first block according to a front identifier and a rear identifier in the first block, where the front identifier and the rear identifier are used to indicate an acquisition position.

9. The method according to any one of claims 1 to 8, characterized in that Before stealing the first task to be processed from the first block with stealing permission in the circular queue associated with the second processor core, the method further includes: The second processor core writes the first task and the second task into the first block based on the rear identifier of the first block, and switches the write permission of the first block to the steal permission, wherein the rear identifier is used to indicate a write position.

10. A task stealing device, characterized in that: Applied to a computer device, the computer device includes a plurality of processor cores, the plurality of processor cores include a first processor core and a second processor core, the apparatus includes: A stealing module is used to steal a first task to be processed from a first block with stealing authority in a circular queue associated with the second processor core when the circular queue associated with the first processor core is empty, and process the first task, wherein the circular queue associated with the second processor core includes multiple blocks, and the block with stealing authority and the block with acquisition authority in the multiple blocks are not the same block.

11. The device according to claim 10, characterized in that When the stealing module steals the first task to be processed from the first block with stealing authority in the circular queue associated with the second processor core, it is specifically used to: The first task is stolen according to the theft identifier in the first block, wherein the theft identifier is used to indicate the theft in the first block. Take the starting position.

12. The device according to claim 10 or 11, characterized in that When the stealing module steals the first task to be processed from the first block with stealing authority in the circular queue associated with the second processor core, it is specifically used to: Selecting the second processor core from the plurality of processor cores according to a processor core selection method, wherein the processor core selection method includes any one of NUMA-aware, equal probability, and random; The first block is randomly selected from a circular queue associated with the second processor core to steal the first task.

13. The device according to claim 12, characterized in that When the stealing module selects the second processor core from the multiple processor cores according to the processor core selection mode, it is specifically used to: selecting a third processor core from the plurality of processor cores according to the processor core selection method; When a third block is randomly selected from the circular queue associated with the third processor core and the third block does not have the stealing authority, the second processor core is selected from the multiple processor cores according to the processor core selection method.

14. The device according to any one of claims 11 to 13, characterized in that The stealing module is also used for: The theft identifier and the theft counter in the first block are updated, wherein the theft counter is used to indicate the number of completed theft tasks.

15. The device according to any one of claims 11 to 14, characterized in that When the stealing module steals the first task according to the stealing identifier in the first block, it is specifically used to: When the stealing identifier of the second block in the circular queue associated with the second processor core indicates a block boundary of the second block, the first task is stolen according to the stealing identifier and the round identifier in the first block adjacent to the second block.

16. The device according to claim 15, characterized in that The stealing module is also used for: The round identifier of the first block is updated according to the round identifier of the second block.

17. The device according to any one of claims 10 to 16, characterized in that The device further includes an acquisition module; the acquisition module is used to: According to the acquisition request, the stealing permission of the first block is switched to the acquisition permission; A second task to be processed is acquired from the first block according to a front identifier and a rear identifier in the first block, wherein the front identifier and the rear identifier are used to indicate an acquisition position.

18. The device according to any one of claims 10 to 17, characterized in that The device further includes a writing module; the writing module is used to: The first task and the second task are written into the first block based on the rear identifier of the first block, and the write permission of the first block is switched to the steal permission, wherein the rear identifier is used to indicate a write position.

19. A chip, characterized in that: include: A processor and a power supply circuit; wherein the power supply circuit is used to supply power to the processor; The processor is configured to implement the method according to any one of claims 1 to 9.

20. A computer device, characterized in that: The computer device includes a processor and a memory, the processor includes multiple processor cores, and the memory is used to store a group of computer instructions. When the processor core executes the group of computer instructions, the method described in any one of claims 1 to 9 is implemented.

Citation Information

Patent Citations

  • Task stealing method and device, chip and computer equipment

    CN118819749A

  • Work stealing in heterogeneous computing systems

    CN106164881A

  • Proactive resource management for parallel work-stealing processing systems

    CN108139939A

  • Processing data using dynamic partitioning

    CN108475212A

  • Fence elision for work stealing

    US20090320027A1