An operating system lock-free cross-core communication method in a task binding scheduling mode
By establishing an independent queue structure of the queue matrix under the task binding scheduling mode and adopting the inter-core asynchronous notification mechanism for cross-core communication, the deadlock and task starvation problems in multi-core parallel execution are solved, the lock-free cross-core communication of the operating system is realized, and the reliability and determinism of the system are improved.
Patent Information
- Application Number
- CN202411957010.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-29
- Publication Date
- 2025-10-21
- Estimated Expiration
- 2044-12-29
AI Technical Summary
In real-time operating systems in the embedded field, there are problems of deadlock and task starvation during multi-core parallel execution, and traditional locking mechanisms lead to insufficient determinism.
A lock-free cross-core communication method under the task binding scheduling mode is adopted. By establishing a special queue matrix independent queue structure, the sending processor core and the receiving processor core operate independent queues respectively, and the inter-core asynchronous notification mechanism is used for cross-core communication to avoid spin locks and mutexes.
It improves the reliability and determinism of multi-core communication in the operating system, avoids deadlock and task starvation, and improves system stability.
Smart Images

Figure CN119883682B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of computer system software, and in particular relates to a lock-free cross-core communication method for an operating system in a task binding scheduling mode. Background Art
[0002] With the development of virtualized operating systems, mixed-key embedded operating systems have gradually been promoted and used on a large scale in the embedded field. However, the real-time operating system in the embedded field faces the deterministic problem of multi-core parallel execution. The traditional locking mechanism may lead to deadlock or task starvation. Summary of the Invention
[0003] In view of this, the present invention provides a lock-free cross-core communication method for an operating system under a task binding scheduling mode, and provides a lock-free cross-core communication mechanism for an operating system under a task binding scheduling mode, which can enable cross-core communication without spin locks or mutexes between multiple cores of an operating system under a task binding scheduling mode.
[0004] The technical solution of the present invention:
[0005] A lock-free cross-core communication method for operating systems in task binding scheduling mode: establishing a special queue matrix independent queue structure in task binding scheduling mode;
[0006] The sending processor core and the receiving processor core operate the independent queue in a lock-free manner;
[0007] Wherein: the structure of the independent queue can only be operated by the sending processor core, and the receiving processor core only operates the flag in the element information in the received independent queue.
[0008] Furthermore, a special queue matrix independent queue structure is established under the task binding mode scheduling based on the following method: the operating system running in the task binding scheduling mode is set to bind the running of tasks to each physical core; the cross-core call request element information is set to be stored in the task control block of each core; when each core is initialized, the cross-core call request element information is initialized;
[0009] In the system architecture where the sending processor core and the receiving processor core are located, each core uses a one-way queue with other cores to process cross-core call requests. Specifically, each sending processor core has a set of independent queues connected to other processor cores.
[0010] Furthermore, the specific operations within each communication's one-way queue are only changed by the task on the sending processor core. Under task binding scheduling, cross-core execution is not performed during task operation. When operating on an independent queue, local core scheduling is turned off to ensure the atomicity of critical section operations.
[0011] Furthermore, the lock-free cross-core communication method adopts unidirectional independent queues between two processor cores in the queue matrix. The object of each independent queue is the task running on each core. The critical section is protected by closing scheduling to prevent the switching of the task of the core from interrupting the operation of adding and removing the request element information from the independent queue.
[0012] Furthermore, the receiving processor core only checks the independent queue to determine whether there is an element that needs to be processed on the independent queue;
[0013] Before the current task on the sending processor core connects the request element information in the task control block to the independent queue, it changes the flag bit of the request element information to clearly indicate that the receiving processor core needs to process it;
[0014] The current task of the sending processor core puts the request element information that the receiving processor core needs to process into an independent queue, and uses the inter-core asynchronous method provided by the operating system to notify the receiving processor core, triggering the processing of the independent queue in the queue matrix.
[0015] Furthermore, the processing method of inter-core asynchronous notification adopts inter-core interrupt notification processing or each core starts the task polling reception processing of its own core: on the receiving processor core, when the notification of the arrival of element information is received, the independent queue corresponding to the sending processor core is checked, and then the element information of the independent queue is processed. When each element information is processed, the flag of the element is set to the request completion flag; when the element information in an independent queue is processed, a completion inter-core asynchronous notification is sent to the corresponding sending processor core; when the sending processor core receives the inter-core asynchronous notification from the receiving processor core, it traverses the independent queue of the processor core and processes all completed element information, and dequeues the processed element information from the independent queue; if it is found that there is still unprocessed element information in the independent queue, the inter-core asynchronous notification is sent to the receiving processor core again.
[0016] Furthermore, the lock-free cross-core communication method of the operating system implements cross-core communication based on the following steps:
[0017] Step 1: Initialize each core of the system, perform cross-core call request element information and allocate queue matrix during initialization.
[0018] Step 2: Before the current task on the sending processor core connects the request element information in the task control block to the independent queue, it clearly marks that the receiving processor core needs to process it;
[0019] Step 3: Use inter-core interrupt notification processing or each core initiates task polling reception processing; on the receiving processor core, check the independent queue corresponding to the sending processor core, process the element information of the independent queue, and set the request completion flag;
[0020] Step 4: When the element information in an independent queue is processed, a completion inter-core asynchronous notification is sent to the corresponding sending processor core;
[0021] Step 5: When the sending processor core receives the inter-core asynchronous notification from the receiving processor core, it traverses and processes all completed element information in the independent queue.
[0022] Beneficial effects of the present invention:
[0023] The present invention realizes a lock-free cross-core communication mechanism of an operating system in a task binding scheduling mode, which can enable lock-free cross-core communication between multiple cores of an operating system in the task binding scheduling mode, thereby improving system reliability and certainty. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0025] Figure 1 This is the overall architecture diagram of the lock-free cross-core communication mechanism. DETAILED DESCRIPTION
[0026] The embodiments of the present disclosure are described in detail below with reference to the accompanying drawings.
[0027] The following describes the embodiments of the present disclosure through specific examples, and those skilled in the art can easily understand other advantages and effects of the present disclosure from the contents disclosed in this specification. Obviously, the described embodiments are only a part of the embodiments of the present disclosure, rather than all of the embodiments. The present disclosure can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present disclosure. It should be noted that, in the absence of conflict, the following embodiments and features in the embodiments can be combined with each other. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present disclosure.
[0028] It should be noted that various aspects of the embodiments within the scope of the appended claims are described below. It should be apparent that the aspects described herein can be embodied in a wide variety of forms, and any specific structure and / or function described herein is merely illustrative. Based on this disclosure, it should be understood by those skilled in the art that an aspect described herein can be implemented independently of any other aspect, and two or more of these aspects can be combined in various ways. For example, any number of aspects described herein can be used to implement an apparatus and / or practice a method. In addition, other structures and / or functionalities other than one or more of the aspects described herein can be used to implement this apparatus and / or practice this method.
[0029] It should also be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present disclosure. The illustrations only show components related to the present disclosure and are not drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component can be changed at will, and the component layout type may also be more complicated.
[0030] Additionally, in the following description, specific details are provided to provide a thorough understanding of the examples. However, one skilled in the art will appreciate that the aspects described may be practiced without these specific details.
[0031] In one embodiment of the present invention, a lock-free cross-core communication method for an operating system in a task binding scheduling mode is proposed: a special queue matrix independent queue structure is established in the task binding mode scheduling;
[0032] The sending processor core and the receiving processor core operate the independent queue in a lock-free manner;
[0033] Wherein: the structure of the independent queue can only be operated by the sending processor core, and the receiving processor core only operates the flag in the element information in the received independent queue.
[0034] In this embodiment, a special queue matrix independent queue structure is established under the task binding mode scheduling based on the following method: the operating system running in the task binding scheduling mode is set to bind the execution of tasks to each physical core; the cross-core call request element information is set to be stored in the task control block of each core; when each core is initialized, the cross-core call request element information is initialized;
[0035] In the system architecture where the sending processor core and the receiving processor core are located, each core uses a one-way queue with other cores to process cross-core call requests. Specifically, each sending processor core has a set of independent queues connected to other processor cores.
[0036] In this embodiment, the specific operations within each communication's one-way queue are only changed by the task on the sending processor core. Under task binding scheduling, cross-core execution is not performed during the task operation process. When operating independent queues, the local core scheduling is turned off to ensure the atomicity of critical section operations.
[0037] In this embodiment, the lock-free cross-core communication method adopts unidirectional independent queues of two processor cores in the queue matrix, and the object of each independent queue is the task running on each core. The critical section is protected by closing scheduling to prevent the switching of the task of the core from interrupting the operation of adding and removing the request element information from the independent queue.
[0038] In this embodiment, the receiving processor core only checks the independent queue to determine whether there is an element that needs to be processed on the independent queue;
[0039] Before the current task on the sending processor core connects the request element information in the task control block to the independent queue, it changes the flag bit of the request element information to clearly indicate that the receiving processor core needs to process it;
[0040] The current task of the sending processor core puts the request element information that the receiving processor core needs to process into an independent queue, and uses the inter-core asynchronous method provided by the operating system to notify the receiving processor core, triggering the processing of the independent queue in the queue matrix.
[0041] In this embodiment, the processing method of inter-core asynchronous notification adopts inter-core interrupt notification processing or each core starts task polling reception processing of its own core: on the receiving processor core, when the notification of the arrival of element information is received, the independent queue corresponding to the sending processor core is checked, and then the element information of the independent queue is processed. When each element information is processed, the flag of the element is set to the request completion flag; when the element information in an independent queue is processed, a completion inter-core asynchronous notification is sent to the corresponding sending processor core; when the sending processor core receives the inter-core asynchronous notification from the receiving processor core, it traverses the independent queue of the processor core and processes all completed element information, and dequeues the processed element information from the independent queue; if it is found that there is still unprocessed element information in the independent queue, the inter-core asynchronous notification is sent to the receiving processor core again.
[0042] In this embodiment, the lock-free cross-core communication method of the operating system implements cross-core communication based on the following steps:
[0043] Step 1: Initialize each core of the system, perform cross-core call request element information and allocate queue matrix during initialization.
[0044] Step 2: Before the current task on the sending processor core connects the request element information in the task control block to the independent queue, it clearly marks that the receiving processor core needs to process it;
[0045] Step 3: Use inter-core interrupt notification processing or each core initiates task polling reception processing; on the receiving processor core, check the independent queue corresponding to the sending processor core, process the element information of the independent queue, and set the request completion flag;
[0046] Step 4: When the element information in an independent queue is processed, a completion inter-core asynchronous notification is sent to the corresponding sending processor core;
[0047] Step 5: When the sending processor core receives the inter-core asynchronous notification from the receiving processor core, it traverses and processes all completed element information in the independent queue.
[0048] See Figure 1 In this embodiment, the operating system runs in task binding scheduling mode, and tasks are bound to each physical core. The cross-core call request element information is stored in the task control block on each core, and the cross-core call request element information is initialized when each core is initialized.
[0049] In the cross-core call architecture of this embodiment, each core uses an independent, one-way queue for communication with another core to process cross-core call requests. Specifically, each sending processor core has a set of independent queues connecting to other processor cores. For example, a processor has N processor cores, and CPU0 has N-1 queues connecting the other N-1 processor cores, CPU1, to CPU N-1. For the entire processor, N*(N-1) queue matrices need to be allocated.
[0050] To achieve a lock-free design, this embodiment uses a one-way queue for each communication, where specific operations are modified only by the task on the sending processor core. Task binding scheduling prevents cross-core execution during task operations, and local core scheduling is disabled during independent queue operations to ensure atomicity of critical section operations. A queue matrix employs two-core, one-way independent queues. Each independent queue is operated on by the currently running task on each core, so closed scheduling is used to protect critical sections and prevent local core task switching from interrupting the addition and removal of request element information from the independent queue.
[0051] To achieve a lock-free design in this embodiment, the receiving processor core only checks the independent queue to determine if there are any elements that need processing. Before the current task on the sending processor core connects the request element information in its control block to the independent queue, it clearly indicates that the receiving processor core needs to process it. The current task on the sending processor core places the request element information in its control block into the independent queue and uses the operating system's inter-core asynchronous notification to the receiving processor core to trigger the processing of the independent queue in the queue matrix.
[0052] Inter-core asynchronous notifications are handled using either inter-core interrupt notifications or by each core initiating task polling for reception. Upon receiving a notification of an element arrival, the receiving core checks the independent queue corresponding to the sending core. The elements in the independent queue are processed, and as each element is processed, the flag for that element is set to the request completion flag. When all elements in an independent queue are processed, a completion inter-core asynchronous notification is sent to the sending core.
[0053] When the sending processor core receives an inter-core asynchronous notification from the receiving processor core, it traverses the independent queue of the processor core and processes all completed element information, dequeuing the processed element information from the independent queue. If it finds that there are still unprocessed element information in the independent queue (perhaps because the information sent by the core task to the receiving processor core has not been processed in time), it sends another inter-core asynchronous notification to the receiving processor core.
[0054] This embodiment does not use spin locks and does not allow the receiving processor core to manipulate the entire independent queue structure. It only sets the flag bit of the element information to indicate the processing status of the element information. All structural operations on the independent queues of the matrix queue are performed by the sending processor core. Task scheduling is only disabled for this core in structures that operate on the independent queues of the matrix queue.
[0055] The above description is merely a specific embodiment of the present disclosure, but the scope of protection of the present disclosure is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this disclosure should be included in the scope of protection of the present disclosure. Therefore, the scope of protection of the present disclosure should be based on the scope of protection of the claims.
Claims
1. A lock-free cross-core communication method for an operating system in a task binding scheduling mode, characterized by: A special queue matrix independent queue structure is established under the task binding mode scheduling. The sending processor core and the receiving processor core operate the independent queue in a lock-free manner. The structure of the independent queue can only be operated by the sending processor core, and the receiving processor core only operates the flag in the element information in the received independent queue. A special queue matrix independent queue structure is established under the task binding mode scheduling based on the following method: the operating system running in the task binding scheduling mode is set to bind the running of tasks to each physical core; the cross-core call request element information is set to be stored in the task control block on each core; when each core is initialized, the cross-core call request element information is initialized, wherein, in the system architecture where the sending processor core and the receiving processor core are located, each core uses a one-way queue with other cores to process the cross-core call request, specifically: each sending processor core has a set of independent queues connected to other processor cores; The lock-free cross-core communication method of the operating system is based on the following steps to achieve cross-core communication, including: Step 1: Initialize each core of the system, perform cross-core call request element information and allocate queue matrix during initialization; Step 2: Before the current task on the sending processor core connects the request element information in the task control block to the independent queue, it clearly marks that the receiving processor core needs to process it; Step 3: Use inter-core interrupt notification processing or each core initiates task polling reception processing; on the receiving processor core, check the independent queue corresponding to the sending processor core, process the element information of the independent queue, and set the request completion flag; Step 4: When the element information in an independent queue is processed, a completion inter-core asynchronous notification is sent to the corresponding sending processor core; Step 5: When the sending processor core receives the inter-core asynchronous notification from the receiving processor core, it traverses and processes all completed element information in the independent queue.
2. The method for lock-free cross-core communication of an operating system in a task binding scheduling mode according to claim 1, characterized in that: The specific operations within each communication's one-way queue are only changed by the task on the sending processor core. Under task binding scheduling, cross-core execution is not performed during task operation. When operating in an independent queue, local core scheduling is disabled to ensure the atomicity of critical section operations.
3. The method for lock-free cross-core communication of an operating system in a task binding scheduling mode according to claim 2, characterized in that: The lock-free cross-core communication method uses unidirectional independent queues between two processor cores in the queue matrix. The object of each independent queue is the task running on each core. Close scheduling is used to protect the critical section to prevent the switching of tasks on the current core from interrupting the operation of adding and removing request element information from the independent queue.
4. The method for lock-free cross-core communication of an operating system in a task binding scheduling mode according to claim 3, characterized in that: The receiving processor core only checks the independent queue to determine whether there is an element that needs to be processed on the independent queue; Before the current task on the sending processor core connects the request element information in the task control block to the independent queue, it changes the flag bit of the request element information to clearly indicate that the receiving processor core needs to process it; The current task of the sending processor core puts the request element information that the receiving processor core needs to process into an independent queue, and uses the inter-core asynchronous method provided by the operating system to notify the receiving processor core, triggering the processing of the independent queue in the queue matrix.
5. The method for lock-free cross-core communication of an operating system in a task binding scheduling mode according to claim 4, characterized in that: The processing method of inter-core asynchronous notification is to use inter-core interrupt notification processing or each core starts the task polling reception processing of its own core: on the receiving processor core, when the notification of the arrival of element information is received, the independent queue corresponding to the sending processor core is checked, and then the element information of the independent queue is processed. When each element information is processed, the flag of the element is set to the request completion flag; when the element information in an independent queue is processed, a completion inter-core asynchronous notification is sent to the corresponding sending processor core; when the sending processor core receives the inter-core asynchronous notification from the receiving processor core, it traverses the independent queue of the processor core and processes all completed element information, and dequeues the processed element information from the independent queue; if it is found that there is still unprocessed element information in the independent queue, the inter-core asynchronous notification is sent to the receiving processor core again.
Citation Information
Patent Citations
Method and system for communication between lockless processors
CN114356834A
Synchronization scheduling apparatus and method in real-time mult-core system
US20120159501A1