Task scheduling method and device for multi-core real-time system, equipment and storage medium
By dynamically adjusting the priority of tasks in a multi-verifiable real-time system and upgrading to spin priority according to resource locking conditions, the problem of low task scheduling efficiency in the existing technology is solved, and more efficient task scheduling and resource management are achieved.
Patent Information
- Application Number
- CN202510048616.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-13
- Publication Date
- 2025-05-09
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The spin lock-based task scheduling scheme in existing multi-verifiable real-time systems is relatively inefficient and resource access management is complex, making it difficult to effectively balance the priority between tasks.
A task scheduling method for multi-credit real-time systems is proposed. By configuring the priority of the task as the basic priority, and when the task requests the resource, the priority is upgraded to spin priority according to the locking situation of the resource, and entering the first-in-first-out queue to wait for resources.
It improves task scheduling efficiency in multi-verification real-time systems, reduces task waiting time, balances the priority between tasks, and enhances the scheduling ability of the system.
Smart Images

Figure CN119960941A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a task scheduling method, device, equipment and storage medium for a multi-core real-time system. Background Art
[0002] In a multi-core real-time system, tasks on different cores usually need to share resources (for example, memory, I / O devices, etc.). In order to ensure data consistency, a variety of resource sharing protocols for multi-core real-time systems have been proposed to provide resource access management and latency constraints for tasks. These resource sharing protocols usually use "locks" to manage resources. Locks are usually divided into two types, namely spin locks and suspension locks. Under the suspension lock-based protocol, when the task's request for resources cannot be met immediately, the scheduler will cut off the task. Under the spin lock-based protocol, the task will continue to occupy the processor while waiting until the requested resources are obtained.
[0003] At present, protocols based on spinlocks may lead to frequent task switching, bring significant overhead, and have the disadvantage of difficult delay constraint analysis. Spinlock-based protocols solve these problems well, have the advantage of low complexity, and are widely used in the industry. However, each of the common existing spinlock-based protocols defines a set of unified rules for specifying the resource access behavior of all tasks, including the priority that tasks should use when spinning and using resources. However, the task scheduling schemes in the prior art still have the problem of low efficiency. Summary of the invention
[0004] The main purpose of the embodiments of the present application is to provide a task scheduling method, device, equipment and storage medium for a multi-core real-time system to improve the task scheduling efficiency in the multi-core real-time system.
[0005] To achieve the above purpose, an embodiment of the present application provides a task scheduling method for a multi-core real-time system, the method comprising the following steps:
[0006] configuring the current priority of each task in the multi-core real-time system as a basic priority and assigning each of the tasks to a corresponding core processor in the multi-core real-time system;
[0007] Taking any one of the tasks as a given task, determining whether the resource requested by the given task is locked by other tasks;
[0008] If the resource requested by the given task is locked by other tasks, the current priority of the given task is upgraded from the corresponding basic priority to the spinning priority;
[0009] Make the given task enter the first-in-first-out queue for requesting the resource and spin-wait at the spin priority;
[0010] When the core processor corresponding to the given task grants the resource to the given task, the given task exits the first-in-first-out queue and ends spinning, and then uses the resource to execute the given task; wherein, during the period from when the resource is granted to when the resource is released, the given task cannot be preempted by other tasks for the resource.
[0011] In some embodiments, before upgrading the current priority of the given task from the corresponding basic priority to the spinning priority, the method further comprises the following steps:
[0012] Identifying the blocking to which the given task may be subjected;
[0013] The spin priority corresponding to the given task is determined according to the blocking that the given task can suffer.
[0014] In some embodiments, identifying the blockage that the given task may suffer comprises the following steps:
[0015] Identifying the blocking that the given task can suffer includes reaching blocking and canceling blocking;
[0016] The arrival blocking means that the current priority of the given task is raised to a higher priority than the current priority of the given task by the low-priority task due to requesting the resource, thereby blocking the given task;
[0017] The unblocking is when the given task is blocked by other tasks during the spin-waiting period, which causes the given task to exit the FIFO queue and then re-enter the FIFO queue.
[0018] In some embodiments, determining the spin priority corresponding to the given task according to the blocking that the given task may suffer comprises the following steps:
[0019] determining whether the given task will be subject to the arrival blocking and the cancellation blocking due to the resource;
[0020] If so, configuring the spin priority of the given task to be the highest priority;
[0021] If not, the spin priority of the given task is configured to correspond to the basic priority.
[0022] In some embodiments, the identifying the blockage that the given task may suffer further comprises the following steps:
[0023] Identifying the blocking that the given task may suffer also includes spin blocking; wherein the spin blocking is that the given task or other tasks with a higher priority than the given task are blocked by a task on a remote processor;
[0024] After determining the spin priority corresponding to the given task according to the blocking that the given task may suffer, the method further comprises the following steps:
[0025] Calculating the response time of the given task according to the spin blocking, the reach blocking and the cancel blocking;
[0026] determining a set of resources causing the arrival congestion;
[0027] If the response time is greater than the deadline corresponding to the given task and the resource set is not empty, determining the resource causing the arrival blockage in the resource set as the target resource;
[0028] Lowering the current priority of the low-priority task accessing the target resource from the corresponding spin priority, and removing the target resource from the resource set;
[0029] Return to the step of determining the resource causing the arrival blockage as the target resource in the resource set if the response time is greater than the deadline corresponding to the given task and the resource set is not empty, until the response time is less than or equal to the deadline corresponding to the given task, or the resource set is empty.
[0030] In some embodiments, the calculating the response time of the given task according to the spin blocking, the arrival blocking and the cancellation blocking comprises the following steps:
[0031] Determine the blocking time of the given task caused by the other tasks with higher priority preempting the resource as the preemption blocking time;
[0032] Determine the sum of the worst execution time of the given task and the time of executing the critical section during the release of the given task as the comprehensive execution time;
[0033] The preemption blocking time, the comprehensive execution time, the time required for the spin blocking, the time required for the arrival blocking, and the time required for the cancellation blocking are accumulated as the response time of the given task.
[0034] In some embodiments, the method further comprises the following steps:
[0035] If the given task is preempted by other tasks while spinning in the FIFO queue, the given task is made to exit the FIFO queue and canceled;
[0036] When the resource is completely preempted, the given task is made to re-enter the first-in-first-out queue to spin-wait at the spin priority level.
[0037] To achieve the above purpose, another aspect of the embodiment of the present application provides a task scheduling device for a multi-core real-time system, the device comprising:
[0038] A pre-configuration unit, configured to configure the current priority of each task in the multi-core real-time system as a basic priority and allocate each of the tasks to a corresponding core processor in the multi-core real-time system;
[0039] A task traversal unit, used for taking any one of the tasks as a given task, and determining whether a resource requested by the given task is locked by other tasks;
[0040] A priority promotion unit, configured to upgrade the current priority of the given task from the corresponding basic priority to the spinning priority if the resource requested by the given task is locked by other tasks;
[0041] A spin-wait unit, used for making the given task enter a first-in-first-out queue for requesting the resource and spin-wait at the spin priority level;
[0042] A task scheduling unit is used for, when the core processor corresponding to the given task grants the resource to the given task, the given task exits the first-in-first-out queue and ends spinning, and then uses the resource to execute the given task; wherein, during the period from when the resource is granted to the given task to when the resource is released, the given task cannot be preempted by other tasks for the resource.
[0043] To achieve the above-mentioned purpose, another aspect of an embodiment of the present application proposes an electronic device, which includes a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the task scheduling method of the multi-core real-time system mentioned above is implemented.
[0044] To achieve the above objectives, another aspect of an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the task scheduling method of the multi-core real-time system is implemented.
[0045] The embodiments of the present application include at least the following beneficial effects:
[0046] The present application can configure the current priority of each task in a multi-core real-time system as a basic priority and assign each task to the corresponding core processor in the multi-core real-time system; take any task as a given task, and determine whether the resources requested by the given task are locked by other tasks; if the resources requested by the given task are locked by other tasks, the current priority of the given task is upgraded from the corresponding basic priority to the spin priority; make the given task enter the first-in-first-out queue of the requested resource and spin-wait with the spin priority; when the core processor corresponding to the given task grants resources to the given task, the given task exits the first-in-first-out queue and ends the spin, and then uses the resources to execute the given task; wherein, during the period from when the resources are granted to the given task to when the resources are released, the given task cannot be preempted by other tasks. The priority of each task in the present application during spin waiting can be flexibly configured, balancing the priorities between the tasks, thereby improving the scheduling performance of each task, reducing the waiting time of each task, and improving the scheduling efficiency of the task. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0048] Figure 1 A flowchart of a task scheduling method for a multi-core real-time system provided in an embodiment of the present application;
[0049] Figure 2 A schematic diagram of the change of the runtime task priority provided by an embodiment of the present application;
[0050] Figure 3 A flowchart of a priority allocation algorithm provided in an embodiment of the present application;
[0051] Figure 4 A schematic diagram of the structure of a task scheduling device for a multi-core real-time system provided in an embodiment of the present application;
[0052] Figure 5 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0053] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application is further described in detail below in conjunction with the accompanying drawings and examples. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the embodiments of the present application. They are only examples of devices and methods consistent with some aspects of the embodiments of the present application as detailed in the attached claims.
[0054] It is understood that the terms "first", "second", etc. used in this application can be used to describe various concepts in this article, but unless otherwise specified, these concepts are not limited by these terms. These terms are only used to distinguish one concept from another concept. For example, without departing from the scope of the embodiment of the present application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the words "if" and "if" as used herein can be interpreted as "at the time of" or "when" or "in response to determination".
[0055] The terms "at least one", "multiple", "each", "any", etc. used in this application, at least one includes one, two or more, multiple includes two or more, each refers to each of the corresponding multiple, and any refers to any one of the multiple.
[0056] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0057] Before describing the embodiments of the present application in detail, some nouns and terms involved in the embodiments of the present application are first described. The nouns and terms involved in the embodiments of the present application are subject to the following interpretations:
[0058] Real-time system: A computer system that has clear time constraints for all tasks.
[0059] Fully Partitioned Scheduling: The corresponding processor is selected when executing a task, allowing tasks to migrate between all processors in the system;
[0060] Fixed Priority Scheduling: The priority (base priority) of each task is statically assigned before running, and the priority is fixed throughout the life cycle of the task.
[0061] Preemptive Scheduling: When a task is running, if a higher priority task is released, the system will immediately switch to the high priority task and the low priority task will be preempted.
[0062] FIFO Spin Lock: A synchronization mechanism. In the case of a spinlock, if a thread tries to acquire a lock that is already held by another thread, it will wait (i.e. "spin") in a loop until the lock becomes available. "First-In-First-Out (FIFO)" means that the lock is acquired in the order in which the threads arrive, that is, the thread that first requests the lock will be the first thread to acquire the lock.
[0063] Worst Case Computation Time (WCET): The longest time a task takes to execute without being interrupted (blocked, preempted, etc.), that is, the time it takes to execute instructions. It usually needs to be measured through some static analysis tools or experiments.
[0064] Worst Case Response Time (WCRT): The longest time required for a task to go from start to finish, including WCET, interference caused by preemption, blocking time due to accessing resources, etc.
[0065] Suspension Lock: A synchronization mechanism used to manage access to shared resources in a multithreaded environment. When a thread cannot immediately obtain a required lock, it is suspended (or blocked) until the lock becomes available.
[0066] Critical Section: A section of code in a multithreaded program that requires mutually exclusive access, usually involving operations on shared resources. The code in the critical section is only allowed to be executed by one thread at any time to prevent data conflicts and ensure data consistency.
[0067] The schemes related to the present application include: (1) tasks managed by the Multiprocessor Stack Resource Protocol (MSRP) spin and use resources in a non-preemptive manner. (2) Preemptible Wait Lock Protocol (PWLP) spins at its base priority level in a preemptible situation and executes non-preemptively.
[0068] MSRP: Using non-preemptive first-in-first-out spin locks, tasks access resources strictly in the order of request, and tasks remain non-preemptive when spinning waiting for resources and executing critical sections.
[0069] PWLP: Using preemptive FIFO spin locks, tasks access resources strictly in the order of request. Tasks maintain their basic priority while spinning and waiting for resources. If a high-priority task is released to preempt, the resource request issued is canceled and removed from the FIFO queue. Once the task is resumed, the request will enter the end of the queue again. Tasks are non-preemptive when executing resources.
[0070] In real-world multi-core real-time systems, the urgency of task completion and the demand for resources vary, for example, the lengths of critical sections of resources vary. When a unified spin priority is applied to all tasks and resources in the system without considering the urgency of each task, a large spin blocking will be imposed on the task, causing the task to miss the deadline, thereby endangering the schedulability of the system. Since the MSRP protocol is non-preemptive during the entire process of waiting and executing resources, it may cause high-priority tasks to be blocked by low-priority tasks for a long time, that is, priority inversion, which is particularly unfavorable for long resources. In contrast, if tasks according to PWLP are frequently preempted while spinning waiting for resources, it may cause a high amount of additional blocking for low-priority tasks, thereby endangering the schedulability of the system. Therefore, when facing various resource access scenarios in the system, the existing spin lock-based protocols use fixed spin priority rules without considering the situation of requesting tasks or resources, and lack effectiveness.
[0071] Therefore, some embodiments of the present application provide a set of flexible, high-performance spin lock protocols, using the same preemption cancellation mechanism as PWLP, but different from it in that the priority of tasks when waiting for resources (i.e., spin priority) is flexible, and for each resource accessed by each task, the task can spin at any priority from the basic priority to the highest priority. The spin priority allocation algorithm of the protocol allocates a spin priority to each task-resource pair, and the allocation algorithm is derived from the analysis of each blocking type, fully considering the urgency of task completion and the demand for resources, and solving the shortcomings of the prior art.
[0072] The embodiment of the present application provides a task scheduling method, device, equipment and storage medium for a multi-core real-time system. The technical solution of the present application includes: configuring the current priority of each task in the multi-core real-time system as a basic priority and assigning each task to the corresponding core processor in the multi-core real-time system; taking any task as a given task, judging whether the resources requested by the given task are locked by other tasks; if the resources requested by the given task are locked by other tasks, upgrading the current priority of the given task from the corresponding basic priority to the spin priority; making the given task enter the first-in-first-out queue of the requested resource and spin-wait with the spin priority; when the core processor corresponding to the given task grants the resource to the given task, the given task exits the first-in-first-out queue and ends the spin, and then uses the resource to execute the given task; wherein, during the period from when the resource is granted to the given task to when the resource is released, the given task cannot be preempted by other tasks. The priority of each task in the present application during spin waiting can be flexibly configured, balancing the priorities between the tasks, thereby improving the scheduling performance of each task, reducing the waiting time of each task, and improving the scheduling efficiency of the task.
[0073] The embodiments of the present application provide a task scheduling method, device, equipment and storage medium for a multi-core real-time system, and relate to the field of computer technology. The task scheduling method, device, equipment and storage medium for a multi-core real-time system provided in the embodiments of the present application can be applied to a terminal, can also be applied to a server, and can also be software running in a terminal or a server. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, and a car terminal, etc., but is not limited to this; the server side can be configured as an independent physical server, or it can be configured as a server cluster or distributed system composed of multiple physical servers, and can also be configured to provide cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and cloud servers for basic cloud computing services such as big data and artificial intelligence platforms. The server can also be a node server in a blockchain network; the software can be an application that implements a knowledge extraction method, etc., but is not limited to the above forms.
[0074] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0075] Reference Figure 1 The embodiment of the present application provides a task scheduling method for a multi-core real-time system. The method may include but is not limited to S110 to S150, which are as follows:
[0076] S110: configuring the current priority of each task in the multi-core real-time system as a basic priority and assigning each task to a corresponding core processor in the multi-core real-time system.
[0077] S120: Taking any one of the tasks as a given task, determining whether the resources requested by the given task are locked by other tasks.
[0078] S130: If the resource requested by the given task is locked by other tasks, the current priority of the given task is upgraded from the corresponding basic priority to the spinning priority.
[0079] In some optional implementations, the embodiment of the present application may further include the following steps S101-S102 before S120:
[0080] S101: Identify the blocking that the given task may suffer.
[0081] Further, S101 may include the following steps S1011:
[0082] S1011: Identify that the blocking that the given task may suffer includes arrival blocking and cancellation blocking;
[0083] The arrival blocking means that the current priority of the given task is raised to a higher priority than the current priority of the given task by the low-priority task due to requesting the resource, thereby blocking the given task;
[0084] The unblocking is when the given task is blocked by other tasks during the spin-waiting period, which causes the given task to exit the FIFO queue and then re-enter the FIFO queue.
[0085] S102: Determine the spin priority corresponding to the given task according to the blocking that the given task may suffer.
[0086] Further, S102 may include the following steps S1021 to S1023:
[0087] S1021: Determine whether the given task will be subject to the arrival blocking and the cancellation blocking due to the resource;
[0088] S1022: If yes, configuring the spin priority of the given task to be the highest priority;
[0089] S1023: If not, configure the spin priority of the given task to correspond to the basic priority.
[0090] In some embodiments, S101 may further include the following steps S1012:
[0091] S1012: Identify that the blocking that the given task may suffer also includes spin blocking; wherein the spin blocking is that the given task or other tasks with a higher priority than the given task are blocked by a task on a remote processor.
[0092] After S102, the embodiment of the present application may further include the following steps S103 to S106:
[0093] S103: Calculating the response time of the given task according to the spin blocking, the arrival blocking and the cancellation blocking;
[0094] S104: Determine a resource set causing the arrival congestion;
[0095] S105: If the response time is greater than the deadline corresponding to the given task and the resource set is not empty, determining the resource causing the arrival blockage in the resource set as the target resource;
[0096] S106: lowering the current priority of the low-priority task accessing the target resource from the corresponding spinning priority, and removing the target resource from the resource set;
[0097] Return to the step of determining the resource causing the arrival blockage as the target resource in the resource set if the response time is greater than the deadline corresponding to the given task and the resource set is not empty, until the response time is less than or equal to the deadline corresponding to the given task, or the resource set is empty.
[0098] More specifically, S103 may include the following steps S1031 to S1033:
[0099] S1031: Determine the blocking time of the given task caused by the other tasks with higher priorities preempting the resource as the preemption blocking time;
[0100] S1032: Determine the sum of the worst execution time of the given task and the time of executing the critical section during the release of the given task as the comprehensive execution time;
[0101] S1033: Accumulate the preemption blocking time, the comprehensive execution time, the time required for the spin blocking, the time required for the arrival blocking, and the time required for the cancellation blocking as the response time of the given task.
[0102] S140: Make the given task enter the first-in-first-out queue for requesting the resource and spin-wait at the spin priority.
[0103] S150: When the core processor corresponding to the given task grants the resource to the given task, the given task exits the first-in-first-out queue and ends spinning, and then uses the resource to execute the given task; wherein, during the period from when the resource is granted to when the resource is released, the given task cannot be preempted by other tasks for the resource.
[0104] Furthermore, the embodiment of the present application may further include the following steps S161-S162:
[0105] S161: If the given task is preempted by other tasks while spinning in the FIFO queue, the given task is exited from the FIFO queue and the given task is cancelled;
[0106] S162: When the resource is completely preempted, the given task is made to re-enter the FIFO queue and spin-wait at the spin priority level.
[0107] Next, the solution of the embodiment of the present application will be introduced and explained in detail with reference to specific application examples.
[0108] First, the parameters involved in this embodiment are described:
[0109] The real-time system based on this embodiment adopts the fully-partitioned fixed-priority preemptive scheduling (FP-FPPS) scheme, that is, the priority and core of the task have been determined before running, and low-priority tasks can be preempted by higher-priority tasks. The system includes a set of sporadic tasks, each of which can be used as a given task. The given task is represented by the symbol τ i It is defined as τ i ={C i ,T i ,D i ,P i ,A i}, where C i Represents the task τ i Worst Case Execution Time (WCET), T i Indicates the period, D i represents the deadline, P i Indicates the basic priority of a task when it does not access resources. i Represents the task τ i The processor to be assigned.
[0110] In addition, the multi-core real-time system of this embodiment includes a set of mutually exclusive shared resources, each resource r k The critical section length is c k It represents the time required for the task to execute this critical section. i During a release, you can request resources r k The number of times is expressed as When a task needs a locked resource, it busy-waits at a specified spin priority until the resource is granted. i Access Resources k The spin priority of The spin priority is calculated by the priority allocation algorithm of this embodiment.
[0111] This embodiment may include three key solutions: 1. defining the working mechanism of the flexible spin lock access protocol; 2. identifying the types of blocking that a task may suffer; 3. allocating priorities using an algorithm for allocating task spin priorities.
[0112] 1. Define the working mechanism of the flexible spinlock access protocol.
[0113] Similar to MSRP and PWLP, the flexible spinlock access protocol of this embodiment uses a first-in-first-out spinlock to manage global resources and uses the priority ceiling protocol (PCP) in a single-core system to manage local resources. For tasks accessing global resources, implementation plans 1.1 to 1.3 are specified. The schematic diagram of the change of task priority at runtime is shown in FIG. Figure 2 shown.
[0114] 1.1 If the task τ i Requested resource k Already locked by other tasks, task τ i It will be prioritized Enter Resources k FIFO queue, and actively spin wait in the queue r k was awarded. The range is τ i Base priority to highest priority.
[0115] 1.2 When the task τ i Awarded k (or at the head of the queue) until resource r k Before being released, the task τ i They are all non-preemptible.
[0116] 1.3 If the task τ i is preempted during spinning, then τ i The request will be canceled, the FIFO queue will be exited and the wait will be resumed. When the preemption ends, τ i Continue execution and rejoin the end of the FIFO queue with spin priority For r k Spin.
[0117] 2. Identify the types of blocking that a task may experience.
[0118] By thoroughly analyzing the running and blocking behaviors of tasks under the flexible spinlock access protocol, we identify the following three types of blocking that tasks may encounter:
[0119] Spin Delay: Task τ i or a high-priority task is blocked by a task on a remote processor while accessing a resource;
[0120] Arrival Blocking: Task τ i Blocked by a local low-priority task (which is being promoted to a higher activity priority due to requesting resources);
[0121] Additional / Cancellation Blocking: Task τ i Being preempted during spinning, tasks may be subject to additional blocking when requeuing when resuming execution under the cancellation mechanism.
[0122] Furthermore, the task will be interfered by the preemption of high-priority tasks. i To represent spin blocking, the symbol J is used. i Indicates that the arrival blockage uses the symbol K i Indicates that unblocking is done using the symbol L i Therefore, the task τ i The response time R i It can be expressed using the following formula, where Represents the task τ i The worst execution time WCET and the time to execute the critical section during the release, the response time expression is:
[0123]
[0124] 3. Assign priorities using an algorithm that assigns task spin priorities.
[0125] Based on the working mechanism of the flexible spin lock access protocol, the purpose of the spin priority allocation algorithm (hereinafter referred to as the allocation algorithm) is to allocate a spin priority for each "task -> resource", maximize the benefits that can be brought to the system under the flexible spin lock access protocol mechanism, balance the blocking between tasks in the system, and increase the schedulability of the system. The purpose of the allocation algorithm is to find out the direct impact of the choice of spin priority on task blocking in the invention for a given task τ i and low priority tasks τ l , reduce τ l of Can reduce the task τ i The arrival blockage K i , but it will increase τ of low priority tasks l Unblocking L l Therefore, the assignment of spin priorities essentially involves managing K i and L l The trade-off between the two is to effectively reduce the blocking of tasks with shorter deadlines, thereby improving the performance of the protocol.
[0126] According to the above concept, the flow chart of the priority allocation algorithm is as follows: Figure 3 shown. Figure 3 The following is a linear search algorithm, the core idea of which is:i From the perspective of l of To reduce the task τ i Arrival blocking K i While maintaining each low priority task τ l Unblocking L l Within a reasonable range, so that every task in the system can meet its deadline.
[0127] Figure 3 The algorithm shown may include the following 3 steps:
[0128] 3.1 For each core, examine each task τ i , for those who will not i The resource that caused the arrival blocking and unblocking k ,but That is, the basic priority; and for resources that will cause arrival blocking and unblocking, k , That is the highest priority.
[0129] 3.2 For each core, examine the tasks τ in order of priority from high to low i , calculate the response time R i and the set of resources that cause the arrival block When the task response time does not meet the deadline, that is, R i >D i And when the resource set is not empty, go to step 3.3. If this condition is not met, the algorithm ends (that is, a schedulable solution is found, or a schedulable solution cannot be found).
[0130] 3.3 Find the resource r in the resource collection that causes the arrival block k , the low priority task τ that will access the resource l of And from the collection Remove resources from k , return to step 3.2 for judgment.
[0131] In summary, this embodiment includes the following key technical features:
[0132] 1. For multi-core real-time systems, a flexible spin lock access scheme is proposed, which allows tasks to have different spin priorities when waiting for different resources under the premise of cancellation mechanism.
[0133] 2. A linear search spin priority assignment algorithm is proposed to effectively assign priorities in a large number of spin priority solution spaces with low complexity.
[0134] The beneficial effects of this embodiment include:
[0135] 1. A flexible spin lock access scheme in a multi-core real-time system is implemented: The scheme of this embodiment applies the cancellation mechanism in the spin lock protocol PWLP to handle spin priority preemption and allows tasks to have different spin priorities when waiting for different resources.
[0136] 2. A linear search spin priority allocation algorithm is provided: Under the flexible spin lock access scheme, the allocation algorithm uses a linear search method to balance the various blockages in the system and improve the system's schedulability.
[0137] 3. Low complexity, easy to analyze the worst-case blocking. The flexible spinlock access protocol uses spinlocks, which has such advantages compared with the protocol based on hanging locks.
[0138] 4. High resource access granularity and strong flexibility. Compared with the existing spin lock solutions MSRP and PWLP, in the flexible spin lock access protocol of this embodiment, each task has a different priority for each resource, which provides advantages for resource access control and improving system schedulability.
[0139] Reference Figure 4 The embodiment of the present application further provides a task scheduling device for a multi-core real-time system, which can implement the task scheduling method for the multi-core real-time system described above, and the device includes:
[0140] A pre-configuration unit, configured to configure the current priority of each task in the multi-core real-time system as a basic priority and allocate each of the tasks to a corresponding core processor in the multi-core real-time system;
[0141] A task traversal unit, used for taking any one of the tasks as a given task, and determining whether a resource requested by the given task is locked by other tasks;
[0142] A priority promotion unit, configured to upgrade the current priority of the given task from the corresponding basic priority to the spinning priority if the resource requested by the given task is locked by other tasks;
[0143] A spin-wait unit, used for making the given task enter a first-in-first-out queue for requesting the resource and spin-wait at the spin priority level;
[0144] A task scheduling unit is used for, when the core processor corresponding to the given task grants the resource to the given task, the given task exits the first-in-first-out queue and ends spinning, and then uses the resource to execute the given task; wherein, during the period from when the resource is granted to the given task to when the resource is released, the given task cannot be preempted by other tasks for the resource.
[0145] It can be understood that the contents of the above method embodiments are all applicable to the present device embodiments, the functions specifically implemented by the present device embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0146] The embodiment of the present application also provides an electronic device, the electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the task scheduling method of the multi-core real-time system when executing the computer program. The electronic device can be any intelligent terminal including a tablet computer, a car computer, etc.
[0147] It can be understood that the contents of the above method embodiments are all applicable to the present device embodiments, the functions specifically implemented by the present device embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0148] See also Figure 5 , Figure 5 The hardware structure of an electronic device of another embodiment is illustrated, and the electronic device includes:
[0149] The processor 501 may be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present application;
[0150] The memory 502 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 502 can store an operating system and other application programs. When the technical solution provided in the embodiment of this specification is implemented by software or firmware, the relevant program code is stored in the memory 502, and the processor 501 calls and executes the task scheduling method of the multi-core real-time system of the embodiment of this application;
[0151] Input / output interface 503, used to implement information input and output;
[0152] Communication interface 504, used to realize communication interaction between the device and other devices, which can be realized by wired mode (such as USB, network cable, etc.) or wireless mode (such as mobile network, WIFI, Bluetooth, etc.);
[0153] A bus 505 that transmits information between the various components of the device (e.g., the processor 501, the memory 502, the input / output interface 503, and the communication interface 504);
[0154] The processor 501 , the memory 502 , the input / output interface 503 and the communication interface 504 are connected to each other in communication within the device via the bus 505 .
[0155] An embodiment of the present application further provides a computer-readable storage medium storing a computer program, which implements the task scheduling method of the multi-core real-time system when executed by a processor.
[0156] It can be understood that the contents of the above method embodiments are all applicable to the present storage medium embodiments, the functions specifically implemented by the present storage medium embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0157] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0158] The embodiments described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0159] Those skilled in the art will appreciate that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than shown in the figures, or a combination of certain steps, or different steps.
[0160] The device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0161] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination thereof.
[0162] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0163] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0164] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the above units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0165] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0166] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0167] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including multiple instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store programs.
[0168] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but the scope of the rights of the present invention is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present invention should be within the scope of the rights of the present invention.
Claims
1. A task scheduling method for a multi-core real-time system, characterized in that: The method comprises the following steps: configuring the current priority of each task in the multi-core real-time system as a basic priority and assigning each of the tasks to a corresponding core processor in the multi-core real-time system; Taking any one of the tasks as a given task, determining whether the resource requested by the given task is locked by other tasks; If the resource requested by the given task is locked by other tasks, the current priority of the given task is upgraded from the corresponding basic priority to the spinning priority; Make the given task enter the first-in-first-out queue for requesting the resource and spin-wait at the spin priority; When the core processor corresponding to the given task grants the resource to the given task, the given task exits the first-in-first-out queue and ends spinning, and then uses the resource to execute the given task; wherein, during the period from when the resource is granted to when the resource is released, the given task cannot be preempted by other tasks for the resource.
2. The task scheduling method of the multi-core real-time system according to claim 1, characterized in that: Before upgrading the current priority of the given task from the corresponding basic priority to the spinning priority, the method further comprises the following steps: Identifying the blocking to which the given task may be subjected; The spin priority corresponding to the given task is determined according to the blocking that the given task can suffer.
3. The task scheduling method of the multi-core real-time system according to claim 2, characterized in that: The identifying of the blocking that the given task may suffer comprises the following steps: Identifying the blocking that the given task can suffer includes reaching blocking and canceling blocking; The arrival blocking means that the current priority of the given task is raised to a higher priority than the current priority of the given task by the low-priority task due to requesting the resource, thereby blocking the given task; The unblocking is when the given task is blocked by other tasks during the spin-waiting period, which causes the given task to exit the FIFO queue and then re-enter the FIFO queue.
4. The task scheduling method of the multi-core real-time system according to claim 3, characterized in that: Determining the spin priority corresponding to the given task according to the blocking that the given task may suffer comprises the following steps: determining whether the given task will be subject to the arrival blocking and the cancellation blocking due to the resource; If so, configuring the spin priority of the given task to be the highest priority; If not, the spin priority of the given task is configured to correspond to the basic priority.
5. The task scheduling method of the multi-core real-time system according to claim 4, characterized in that: The identifying of the blocking that the given task may suffer also includes the following steps: Identifying the blocking that the given task may suffer also includes spin blocking; wherein the spin blocking is that the given task or other tasks with a higher priority than the given task are blocked by a task on a remote processor; After determining the spin priority corresponding to the given task according to the blocking that the given task may suffer, the method further comprises the following steps: Calculating the response time of the given task according to the spin blocking, the reach blocking and the cancel blocking; determining a set of resources causing the arrival congestion; If the response time is greater than the deadline corresponding to the given task and the resource set is not empty, determining the resource causing the arrival blockage in the resource set as the target resource; Lowering the current priority of the low-priority task accessing the target resource from the corresponding spin priority, and removing the target resource from the resource set; Return to the step of determining the resource causing the arrival blockage as the target resource in the resource set if the response time is greater than the deadline corresponding to the given task and the resource set is not empty, until the response time is less than or equal to the deadline corresponding to the given task, or the resource set is empty.
6. The task scheduling method of the multi-core real-time system according to claim 5, characterized in that: The step of calculating the response time of the given task according to the spin blocking, the arrival blocking and the cancellation blocking comprises the following steps: Determine the blocking time of the given task caused by the other tasks with higher priority preempting the resource as the preemption blocking time; Determine the sum of the worst execution time of the given task and the time of executing the critical section during the release of the given task as the comprehensive execution time; The preemption blocking time, the comprehensive execution time, the time required for the spin blocking, the time required for the arrival blocking, and the time required for the cancellation blocking are accumulated as the response time of the given task.
7. The task scheduling method for a multi-core real-time system according to any one of claims 1 to 6, characterized in that: The method further comprises the following steps: If the given task is preempted by other tasks while spinning in the FIFO queue, the given task is made to exit the FIFO queue and canceled; When the resource is completely preempted, the given task is made to re-enter the first-in-first-out queue to spin-wait at the spin priority level.
8. A task scheduling device for a multi-core real-time system, characterized in that: The device comprises: A pre-configuration unit, configured to configure the current priority of each task in the multi-core real-time system as a basic priority and allocate each of the tasks to a corresponding core processor in the multi-core real-time system; A task traversal unit, used for taking any one of the tasks as a given task, and determining whether a resource requested by the given task is locked by other tasks; A priority promotion unit, configured to upgrade the current priority of the given task from the corresponding basic priority to the spinning priority if the resource requested by the given task is locked by other tasks; A spin-wait unit, used for making the given task enter a first-in-first-out queue for requesting the resource and spin-wait at the spin priority level; A task scheduling unit is used for, when the core processor corresponding to the given task grants the resource to the given task, the given task exits the first-in-first-out queue and ends spinning, and then uses the resource to execute the given task; wherein, during the period from when the resource is granted to the given task to when the resource is released, the given task cannot be preempted by other tasks for the resource.
9. An electronic device, characterized in that: The electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the task scheduling method of the multi-core real-time system according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the task scheduling method for a multi-core real-time system according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Parallel scheduling method for satellite-borne multi-core SoC (System on a Chip) task-level load balance
CN107463442A
Task scheduling method and system
CN114911591A
Cited By
Scheduling control method and device of multi-core real-time processing system, and computer storage medium
CN121387563A