A method for task allocation of real-time operating system on a multi-core processor
By employing distributed task sub-queues and a dynamic adaptive load balancing strategy and elastic core binding mechanism on multi-core homogeneous processors, the task allocation problem of multi-core homogeneous processors is solved, achieving efficient task scheduling and resource utilization.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-18
- Publication Date
- 2026-04-10
AI Technical Summary
Existing task allocation methods for multi-core homogeneous processors suffer from problems such as large scheduling latency due to global lock contention, weak load balancing capabilities, and low resource utilization due to inflexible static binding, which fail to fully leverage the parallel computing advantages of multi-core processors.
Tasks are assigned to distributed sub-queues using mapping rules based on pre-defined task attributes. Combined with dynamically adjusted load balancing strategies and elastic core binding mechanisms, task allocation is optimized through hash sharding and priority step-size algorithms to achieve inter-core load balancing and efficient scheduling.
It reduces lock contention, shortens task scheduling latency, improves CPU resource utilization and system scalability, ensures timely execution of high-priority tasks, and enhances the overall performance of multi-core processors.
Smart Images

Figure CN121233307B_ABST
Abstract
Description
Technical Field
[0001] The present invention is entitled "A Method for Task Allocation in a Real-Time Operating System on a Multi-Core Processor", which belongs to the field of system task management technology. Background Technology
[0002] For understanding the technical content of this invention:
[0003] With the development of semiconductor technology, multi-core processors have become the mainstream choice for improving computing performance. Among them, multi-core homogeneous processors, because all cores use the same instruction set and microarchitecture design, and share system resources such as memory and bus, have advantages in simplifying software development, ensuring data consistency, and achieving efficient parallel processing, and are widely used in embedded systems, servers, storage controllers and other fields.
[0004] When running an embedded real-time operating system on a multi-core homogeneous processor, the quality of task allocation and scheduling strategies directly determines the overall system performance, real-time responsiveness, and resource utilization efficiency. Currently, a common task allocation method is for the system to maintain a globally shared local task queue to store newly created tasks not bound to a specific core. When a processor core is idle, it accesses this global queue mutually exclusively through locking and retrieves a task for execution locally. For tasks requiring interaction with specific hardware or with special performance requirements, a static binding approach can be used, fixing them to the local task queue of a specific processor core.
[0005] However, the aforementioned conventional task allocation methods have revealed many inherent flaws in practical applications, especially in scenarios with an increased number of cores and complex task loads. These flaws become increasingly severe, limiting the full potential of multi-core processors:
[0006] First, all processor cores share a local task queue globally, which necessitates frequent use of locking mechanisms for mutual exclusion during task creation and acquisition. As the number of processor cores increases, competition for this shared resource intensifies, leading to longer lock holding and waiting times. This directly results in increased task scheduling latency and limited system scalability.
[0007] Second, in the global queue model, a high-priority task may be acquired by one core, then suspended due to waiting for resources or being preempted, and its subsequent processing may be completed by another core. This cross-core task migration and communication introduces additional latency.
[0008] Third, traditional load balancing strategies are too simplistic and lack initiative. When a processor core becomes overloaded due to executing long tasks or concentrated task allocation, the system does not proactively migrate tasks to cores with lower loads. This passive waiting for cores to become idle before retrieving tasks from the global queue cannot effectively handle dynamically changing task loads, resulting in severe load imbalances between cores.
[0009] Relevant patent documents retrieved:
[0010] The document, published in China (CN118295810A) on July 5, 2024, discloses a real-time task hybrid scheduling method based on multi-core heterogeneous processors. Its core idea is to determine the priority of tasks based on the "completion time variance" of tasks on different types of cores and to allocate core-type sensitive tasks as early as possible.
[0011] This document, published in China (CN108958944A) on December 7, 2018, discloses a multi-core processing system and its task allocation method. The system designates one CPU as the "master CPU," dedicated to task scheduling. Other CPUs serve as working cores. Tasks are bound to I / O interfaces, which in turn are bound to specific cores. The master CPU allocates tasks to specific I / O interfaces, ensuring that tasks can only execute on the cores they are bound to.
[0012] The prior art represented by the aforementioned documents has at least the following unresolved technical problems or defects:
[0013] Regarding the aforementioned patent document CN118295810A, the technical solution aims to solve the resource matching problem of asymmetric cores. However, its technical premise and solution are not applicable to homogeneous processor environments with identical core capabilities, and it fails to solve the core problems of lock contention and dynamic load balancing caused by a single shared resource in homogeneous processor environments.
[0014] Regarding the aforementioned patent document CN108958944A, its task allocation method is completely static. Once the binding relationship is established, it cannot be dynamically adjusted to adapt to load changes.
[0015] In summary, existing task allocation methods for multi-core homogeneous processors suffer from problems such as large scheduling latency due to global lock contention, weak load balancing capabilities, and low resource utilization due to inflexible static binding. These methods fail to fully leverage the parallel computing advantages of multi-core processors and are ill-suited to meeting the high performance and real-time requirements of modern embedded real-time systems. Therefore, a new task allocation method is urgently needed to address these technical issues. Summary of the Invention
[0016] The purpose of this invention is to solve the problems of poor system performance caused by global lock contention, simple load balancing strategies, and rigid static binding, and to provide a method for task allocation in a real-time operating system on a multi-core processor.
[0017] This invention provides a method for task allocation in a real-time operating system on a multi-core processor, comprising the following steps:
[0018] S1: Based on the preset attributes of the tasks, the global task set is processed into multiple distributed task sub-queues using preset mapping rules, wherein each processor core is configured to preferentially obtain tasks from its corresponding distributed task sub-queue.
[0019] S2: Obtain the current busy level metric for each processor core, and calculate the load difference between the maximum and minimum busy levels among all cores; and, based on the comparison result of the load difference with a preset threshold, dynamically adjust the task allocation strategy parameters in the mapping rules to change the mapping relationship between tasks and the distributed task sub-queues, thereby achieving load balancing between cores.
[0020] S3: When the local task queue of a processor core is empty, the core obtains tasks to be executed in a predetermined hierarchical order. The predetermined hierarchical order is as follows: First, it steals tasks from its corresponding distributed task sub-queue; second, if the corresponding distributed task sub-queue is also empty, it steals tasks from the local task queue of at least one processor core other than the current processor core according to a preset task stealing strategy.
[0021] Furthermore, the task preset attributes mentioned in step S1 include at least one of task priority, task type, or task resource requirements.
[0022] Furthermore, the busyness metric mentioned in step S2 includes at least one of CPU load rate, local task queue length, average task wait time, core cache miss rate, or core power consumption.
[0023] Furthermore, the task preset attribute is the task priority, and the task allocation strategy parameter is the priority step size;
[0024] Step S2 further includes: when the load difference exceeds a preset high threshold, reducing the priority step size to increase the chance of task migration between different distributed task subqueues;
[0025] When the load difference is lower than a preset low threshold, the priority step size is increased to reduce task switching frequency and migration overhead.
[0026] Furthermore, the preset task-stealing strategy in step S3 includes stealing a task from the tail of the local task queue of at least one processor core other than the current processor core.
[0027] Furthermore, the method also includes temporarily increasing the priority of a task when the waiting status indicator of a task meets the preset priority escalation conditions, and setting a maximum upper limit value for the temporarily increased priority; when the task completes execution, its priority is restored to its initial priority.
[0028] Furthermore, the waiting status indicators include the number of times a task fails to complete execution within a set time slice or the total waiting time of a task in the queue.
[0029] Furthermore, the method also includes, for a task bound to a first processor core, allowing the task to be migrated to a second processor core with a lower load than the first processor core when a preset migration trigger condition is met; and, when the task needs to be scheduled again later, prioritizing its scheduling back to the first processor core.
[0030] Furthermore, the migration triggering conditions include: the load of the first processor core is continuously higher than a preset load threshold within a preset time window, and there is at least one processor core in the system whose load is lower than a preset idle threshold, other than the current processor core.
[0031] The present invention has at least the following beneficial effects:
[0032] 1. This invention improves the single global queue into a distributed multi-sub-queue architecture based on hash sharding, thereby reducing access conflicts to shared resources between processor cores and enhancing the scalability and overall processing speed of the system.
[0033] 2. This invention enables the system to perceive and automatically adjust its load balancing strategy in real time through the "priority step size dynamic sharding" algorithm. Combined with the "steal load balancing" and "elastic core binding" mechanisms, it ensures that computing tasks are efficiently allocated and improves the overall CPU resource utilization.
[0034] 3. This invention directly reduces task scheduling latency by minimizing lock contention. Simultaneously, load balancing ensures high-priority tasks are executed promptly, while the "dynamic priority promotion" mechanism guarantees that all tasks receive a response. Attached Figure Description
[0035] Figure 1 This is a flowchart of the task scheduling process of the present invention. Detailed Implementation
[0036] The following non-limiting embodiments are intended to enable those skilled in the art to gain a more comprehensive understanding of the present invention, but do not limit the invention in any way. The following content is merely an exemplary description of the scope of protection claimed by the present invention, and those skilled in the art can make various changes and modifications to the present invention based on the disclosed content, and such changes should also fall within the scope of protection claimed by the present invention.
[0037] The present invention will be further described below by way of specific embodiments. Unless otherwise specified, all instruments, devices, equipment, reagents, products, etc., used in the embodiments of the present invention are obtained through conventional commercial means.
[0038] This invention discloses a method for task allocation in a real-time operating system on a multi-core processor. Through coordinated improvements across multiple dimensions, including local task queue architecture, scheduling algorithm dynamism, task priority management, core binding flexibility, and load balancing strategies, a highly efficient task allocation scheduling system is achieved.
[0039] Example 1
[0040] In this embodiment, the system's local task queue architecture is designed as a hierarchical structure. Each processor core has an independent local task queue to store tasks bound to that core and tasks obtained from other queues. In addition, the system maintains a global sharded queue composed of multiple distributed task sub-queues, also known as sub-queues of the global sharded queue. This global sharded queue uses a hash sharding algorithm to distribute all unbound new tasks into different sub-queues based on task priority, thus replacing the traditional single global queue.
[0041] Furthermore, the hash sharding algorithm is based on a preset mapping rule. Besides priority, the preset task attributes used for sharding can be extended to task type (e.g., I / O-intensive, compute-intensive) or task resource requirements. The number of distributed task sub-queues can be configured to the number of processor cores or an integer multiple thereof to balance lock contention and management overhead. The mapping relationship between processor cores and their corresponding distributed task sub-queues can be statically fixed or dynamically adjusted.
[0042] Reference Figure 1 When a processor core needs to schedule a new task, its task acquisition process follows a cost-optimal hierarchical principle:
[0043] S1: The scheduler first checks whether the local task queue of the current core is empty.
[0044] S2: If the local task queue is not empty (the condition is "no"), then directly retrieve the next task from the local queue and run it.
[0045] S3: If the local task queue is empty (judged as "yes"), the scheduler then checks whether its corresponding global shard queue (i.e., distributed task sub-queue) is empty.
[0046] S4: If the global sharded queue is not empty (determined as "no"), steal a task from it and run it locally. This step involves limited lock contention, but since the task has been sharded into multiple sub-queues, the probability of conflict is much lower than in the traditional global queue model.
[0047] S5: If the global shard queue is also empty (judged as "yes"), then initiate the final stealing operation to determine whether the local task queues of other processor cores besides the current core are empty.
[0048] S6: If the local task queues of other processor cores besides the current core are not empty (determined as "No"), then a task is "stole" from the tail of the local task queue of one of those cores for execution. Stealing from the tail typically involves selecting the task with the longest waiting time, which minimizes the impact on the cache locality of the core being stolen from. In other embodiments, the latest task can also be stolen from the head of the queue, or a task can be stolen randomly. The core to be stolen from can be selected using strategies such as random selection, round-robin, or selecting the core with the highest current load.
[0049] S7: If all other core queues are empty (judged as "yes"), it indicates that there are no pending tasks in the system, and the core runs an idle task or enters standby mode.
[0050] This three-tiered task acquisition strategy ensures that the system only performs cross-core stealing operations when necessary, thereby minimizing interference with the system bus and cache and achieving a highly efficient and non-invasive load balancing.
[0051] Example 2
[0052] The core of this embodiment lies in introducing a dynamic and adaptive adjustment mechanism to the aforementioned hash sharding queue architecture. This mechanism continuously optimizes the fairness and efficiency of task allocation through a feedback control loop. The specific implementation steps are as follows:
[0053] S1: The system periodically acquires the current CPU load rate for each processor core. The CPU load rate is a measure of workload; in other embodiments, it may also be the core local task queue length, average task wait time, and core cache miss rate. The CPU load rate can be calculated by reading from the processor's built-in performance monitoring unit (PMU) or by sampling the core's idle time within a fixed time window.
[0054] S2: Calculate the maximum and minimum CPU load rates across all cores to obtain the load difference.
[0055] S3: Compare the load difference with a preset threshold, for example, a high threshold of 40% and a low threshold of 10%. Both the high and low thresholds can be adjusted. A high threshold indicates that the system load is unbalanced, while a low threshold indicates that the system is in a relatively balanced state.
[0056] S4: Dynamically adjust the task allocation strategy parameters in the hash sharding algorithm based on the comparison results. The task allocation strategy parameter is the priority step size. This priority step size determines the priority range covered by each distributed task sub-queue.
[0057] S5: When the load difference exceeds a high threshold (e.g., 40%), it indicates severe system load imbalance. At this point, the algorithm reduces the step size. A smaller step size narrows the priority range covered by each sub-queue, allowing tasks to be distributed more evenly across the sub-queues. This increases the chance of low-load cores acquiring high-priority tasks, promoting cross-core task migration and achieving rapid load balancing.
[0058] S6: When the load difference is below a low threshold (e.g., 10%), it indicates that the system load is relatively balanced. At this point, the algorithm increases the step size. Increasing the step size allows each sub-queue to cover a wider priority range, and the distribution of tasks across different sub-queues remains relatively fixed. This helps reduce unnecessary task switching and migration, thereby improving the system's operating efficiency in a stable state.
[0059] Example 3
[0060] To further enhance the system's flexibility, this invention also introduces the following two mechanisms:
[0061] (1) Dynamic priority boosting:
[0062] S1: Set a time slice for each task to be completed.
[0063] S2: When a task's time slice expires but it remains unfinished, the system temporarily raises its priority based on the cumulative number of times it has failed to complete. The more times it has failed to complete, the higher the priority. Here, "number of times it has failed to complete" is a waiting status indicator. Alternatively, priority can also be increased based on the task's total waiting time in the ready queue; the longer the total waiting time, the higher the priority.
[0064] S3: To prevent this temporary priority increase from affecting the highest priority critical tasks in the system, the system sets a maximum upper limit for the temporary priority increase.
[0065] S4: When the task is finally completed, the system will reset its priority to its initial value. This mechanism effectively prevents low-priority tasks from "starving" due to continuous preemption.
[0066] (2) Elastic core binding
[0067] This mechanism improves upon traditional static core binding. Under normal circumstances, a task bound to a first processor core will always be scheduled on that core. However, when the system detects an anomaly, the task can be temporarily migrated to a second processor core with a lower load, such as when that core's load is consistently high while other cores are idle. Crucially, this mechanism includes a priority return strategy: when the migrated task needs to be scheduled again, the scheduler will prioritize attempting to reschedule it back to its original bound core. This mechanism combines the advantages of core binding with addressing its fatal flaw in handling load imbalances.
[0068] In summary, this invention combines multiple technical features such as hierarchical scheduling architecture, dynamic sharding algorithm, priority management, elastic binding, and stealing load balancing to construct a highly stable and efficient multi-core task allocation system, which can effectively improve the performance of embedded real-time systems on multi-core homogeneous processors.
[0069] Finally, it should be noted that the above content is only used to illustrate the technical solution of the present invention, and is not intended to limit the scope of protection of the present invention. Simple modifications or equivalent substitutions made by those skilled in the art to the technical solution of the present invention do not depart from the essence and scope of the technical solution of the present invention.
Claims
1. A method for real-time operating system task allocation on a multi-core processor, the method comprising: The method comprises the following steps: S1: based on the task preset attribute, using a hash fragmentation algorithm based on the task preset attribute to process the global task set into a plurality of distributed task sub-queues, wherein each processor core is configured to preferentially obtain tasks from the corresponding distributed task sub-queue; S2: obtaining the current busy degree metric of each processor core, and calculating the load difference between the maximum busy degree and the minimum busy degree in all cores; and, according to the comparison result of the load difference and the preset threshold, dynamically adjusting the task allocation strategy parameter in the mapping rule to change the mapping relationship of tasks to the distributed task sub-queue, so as to realize core load balancing; S3: when the local task queue of a processor core is empty, the core obtains the to-be-executed task according to a predetermined hierarchical order, and the predetermined hierarchical order is: first, stealing tasks from the corresponding distributed task sub-queue; second, if the corresponding distributed task sub-queue is also empty, stealing tasks from the local task queue of at least one processor core other than the current processor core according to a preset task stealing strategy.
2. The method for task allocation of real-time operating system on a multi-core processor according to claim 1, wherein: The task preset attribute in step S1 includes at least one of task priority, task type or task resource requirement.
3. The method for task allocation of real-time operating system on a multi-core processor according to claim 1, wherein: The busy degree metric in step S2 includes at least one of CPU load rate, local task queue length, task average waiting time, core cache miss rate or core power consumption.
4. The method for task allocation of real-time operating system on a multi-core processor according to claim 1, wherein: The task preset attribute is task priority, and the task allocation strategy parameter is priority step; The step S2 further comprises: when the load difference exceeds a preset high threshold, reducing the priority step to increase the migration opportunity of tasks between different distributed task sub-queues; When the load difference is lower than a preset low threshold, the priority step is increased to reduce the task switching frequency and migration overhead.
5. The method for task allocation of real-time operating system on a multi-core processor according to claim 1, wherein: The preset task stealing strategy in step S3 includes stealing a task from the tail of the local task queue of at least one processor core other than the current processor core.
6. The method for task allocation of real-time operating system on a multi-core processor according to claim 1, wherein: The method further comprises: when a task's waiting state metric meets a preset privilege raising condition, temporarily raising the priority of the task, and setting a maximum upper limit value for the temporarily raised priority; and when the task completes execution, restoring its priority to its initial priority.
7. The method for task allocation of a real-time operating system on a multi-core processor according to claim 6, wherein: The waiting state metric includes the number of times a task does not complete execution within a set time slice or the total waiting time of a task in a queue.
8. The method for task allocation of real-time operating system on a multi-core processor according to claim 1, wherein: The method further comprises: for a task bound to a first processor core, when a preset migration trigger condition is met, allowing the task to be migrated to a second processor core with lower load than the first processor core for execution; and when the task needs to be scheduled again subsequently, preferentially scheduling it back to the first processor core.
9. The method for task allocation of a real-time operating system on a multi-core processor according to claim 8, wherein: The migration trigger condition includes: the load of the first processor core continuously being higher than a preset load threshold within a preset time window, and there being at least one processor core other than the current processor core with load lower than a preset idle threshold in the system.
Citation Information
Patent Citations
Real-time task hybrid scheduling method, scheduler, chip, medium and device based on multi-core heterogeneous processor
CN118295810A
Parallel scheduling method for satellite-borne multi-core SoC (System on a Chip) task-level load balance
CN107463442A
A multi-core processing system and a task allocation method thereof
CN108958944A