Time-based cpu resource cooperative scheduling method and device, and storage medium

By allocating waiting tasks to different queues in the task pool and performing dynamic priority analysis, the problems of high memory overhead and complexity in system resource scheduling are solved, and efficient resource utilization and rationality of task scheduling are achieved.

CN119225926APending Publication Date: 2024-12-31SHENZHEN TIANGONG JUCHUANG TECHNOLOGY CO LTD

Patent Information

Application Number
CN202411243547.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-05
Publication Date
2024-12-31

AI Technical Summary

Technical Problem

The existing system resource scheduling technology has problems such as large memory overhead and high system complexity in environments with limited resources, resulting in waste of resources.

Method used

By creating a task pool, await tasks are allocated to different task queues (Ctask queue and Ntask queue), dynamic priority analysis and scheduling are performed, and scheduling is optimized based on the estimated processing time and static state of the task to avoid independent memory and high Complexity.

Benefits of technology

It reduces system memory usage, improves system fluency and rationality of task scheduling, prevents waiting for tasks to stop for a long time, and effectively utilizes resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119225926A_ABST
    Figure CN119225926A_ABST
Patent Text Reader

Abstract

The invention discloses a time-based cpu resource cooperative scheduling method and device and a storage medium, and relates to the technical field of system resource scheduling, and the method comprises the following steps: creating a task pool, carrying out scheduling distribution on waiting tasks in the task pool, and distributing the waiting tasks to a Ctask queue and an Ntask queue; performing dynamic priority analysis on the waiting tasks in the task queue, endowing each waiting task with a dynamic priority, and performing dynamic scheduling on the waiting tasks in the task queue based on the dynamic priorities; analyzing waiting tasks in the Ntask queue based on time, and judging whether the waiting tasks are in a long-time static state or not; the method and the device are used for solving the problem of waste of system resources caused by relatively high memory overhead and relatively high system complexity in the existing system resource scheduling technology.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of system resource scheduling, and in particular to a time-based CPU resource collaborative scheduling method, device and storage medium. Background Art

[0002] System resource scheduling technology refers to a series of algorithms, strategies and mechanisms used in operating systems or other systems to manage and allocate system resources (such as CPU time, memory, devices, etc.). These technologies are designed to optimize the utilization of system resources, ensure that tasks can be executed according to certain rules and priorities, and improve system performance and efficiency.

[0003] The existing system resource scheduling technology is mainly applied in the traditional real-time operating system by using the preemptive scheduling strategy. The preemptive scheduling has the advantages of strong real-time performance and fast response speed, and thus has been widely used in many applications with high real-time requirements. However, the preemptive scheduling also has some obvious disadvantages, such as the need for independent memory to save the task stack, resulting in large memory overhead; the need to ensure the atomicity of critical section access, which increases the system complexity; at the same time, the high complexity of the preemptive scheduling is not conducive to debugging. Therefore, in some environments with limited resources and low real-time requirements, the preemptive scheduling is not the most suitable choice. For example, in the patent application with the publication number CN118132306A, a "task scheduling method for a small embedded system that saves memory" is disclosed. Although the scheme can save memory to a certain extent, it still requires independent memory to save the task stack, resulting in large memory overhead, and the need to ensure the atomicity of critical section access, which increases the system complexity. The existing system resource scheduling technology also has the problems of large memory overhead and high system complexity, resulting in waste of system resources. Summary of the invention

[0004] The present invention aims to solve one of the technical problems in the prior art to at least a certain extent, by creating a task pool, scheduling and allocating waiting tasks in the task pool, and allocating the waiting tasks to different task queues, wherein the task queues include a Ctask queue and an Ntask queue, and then performing a dynamic priority analysis on the waiting tasks in the task queues, assigning a dynamic priority to each waiting task, and dynamically scheduling the waiting tasks in the task queues based on the dynamic priority, and then analyzing the waiting tasks in the Ntask queue based on time to determine whether they are in a long-term static state. If so, scheduling them to the Ctask queue and executing them with priority, so as to solve the problem that the existing system resource scheduling technology still has large memory overhead and high system complexity, resulting in waste of system resources.

[0005] To achieve the above objectives, in a first aspect, the present application provides a time-based CPU resource collaborative scheduling method, comprising the following steps:

[0006] Create a task pool, schedule and allocate waiting tasks in the task pool, and allocate waiting tasks to different task queues, including Ctask queue and Ntask queue;

[0007] Perform dynamic priority analysis on waiting tasks in the task queue, assign dynamic priority to each waiting task, and dynamically schedule waiting tasks in the task queue based on the dynamic priority;

[0008] The waiting tasks in the Ntask queue are analyzed based on time to determine whether they are in a long-term static state. If so, they are scheduled to the Ctask queue and executed first.

[0009] Furthermore, creating a task pool, scheduling and allocating waiting tasks in the task pool, and allocating waiting tasks to different task queues includes the following sub-steps:

[0010] Get the estimated processing time of the waiting task and set the separation value;

[0011] The estimated processing time of all waiting tasks in the task pool is analyzed based on the separation value, and the waiting tasks are assigned to different task queues.

[0012] Furthermore, obtaining the estimated processing time of the waiting task and setting the separation value include the following sub-steps:

[0013] Create a task pool, which is used to store waiting tasks;

[0014] Obtain an estimated processing time of the waiting task, where the estimated processing time is the estimated time required for the CPU to execute the waiting task;

[0015] Sort the estimated processing time of all waiting tasks in the task pool in ascending order and number them, using the symbol S n It represents, where n is a positive integer and n is the sequence number of S;

[0016] Set the separator value, represented by the symbol m, where m is initially max(n) / 2, where the calculation result of max(n) / 2 retains an integer, max(n) is the maximum value of n, m is a positive integer, and max(n) / 2≤m≤max(n).

[0017] Furthermore, analyzing the estimated processing time of all waiting tasks in the task pool based on the separation value includes the following sub-steps:

[0018] Mark the result of max(n) / 2 as e, and keep e as an integer. Starting from m=e, calculate as well as The calculation results are marked as p and q respectively;

[0019] Compare p and q. If the signs of p and q are the same, a separation increase signal is output; if the signs of p and q are opposite, a separation stop signal is output.

[0020] If a separation increase signal is output, the value of m is increased by 1 and p and q are recalculated until the separation stop signal position is output; if a separation stop signal is output, the value of m+1 at this time is marked as the separation confirmation value, represented by the symbol j;

[0021] S n The waiting tasks corresponding to the estimated processing time of n≤j are integrated into Ntask tasks, and S n The waiting tasks corresponding to the estimated processing time of n>j are integrated into Ctask tasks;

[0022] Assign the Ntask task to the Ntask queue and assign the Ctask task to the Ctask queue.

[0023] Further, performing dynamic priority analysis on the waiting tasks in the task queue, assigning a dynamic priority to each waiting task, and dynamically scheduling the waiting tasks in the task queue based on the dynamic priority includes the following sub-steps:

[0024] Obtain the task parameters required to calculate the dynamic priority, and calculate the dynamic priority of the waiting task based on the task parameters;

[0025] Dynamically schedule waiting tasks in the task queue based on dynamic priorities.

[0026] Furthermore, obtaining the task parameters required for calculating the dynamic priority, and calculating the dynamic priority of the waiting task based on the task parameters includes the following sub-steps:

[0027] Get the time when the waiting task joins the task pool and mark it as the joining time;

[0028] Get the current time, calculate the difference between the current time and the joining time, and mark the calculation result as the waiting time;

[0029] Acquire task types, which include real-time tasks and non-real-time tasks;

[0030] Get the resource usage of waiting tasks;

[0031] The waiting time, task type, resource usage and estimated processing time are collectively referred to as task parameters;

[0032] The task parameters are calculated using the dynamic priority calculation formula to obtain the dynamic priority of the waiting task;

[0033] In the dynamic priority calculation formula, Tt is used to indicate the task type. If the task type is a real-time task, the Tt value is 2; if the task type is a non-real-time task, the Tt value is 1.

[0034] The dynamic priority calculation formula is configured as: Among them, DP is the dynamic priority, Wt is the waiting time, Ro is the resource occupancy, and Ept is the estimated processing time.

[0035] Furthermore, dynamically scheduling the waiting tasks in the task queue based on the dynamic priority includes the following sub-steps:

[0036] For the Ctask queue, name the waiting task in the Ctask queue as C waiting task;

[0037] Arrange the C waiting tasks in descending order of dynamic priority, complete the C waiting tasks with the highest dynamic priority first, and mark the C waiting tasks in execution as execution tasks;

[0038] The dynamic priority of each C waiting task is calculated in real time. If the maximum value of the dynamic priority changes and it is not an executing task, the executing task will be suspended through the Ctask_Delay algorithm, and the C waiting task with the largest dynamic priority will be executed first.

[0039] For the Ntask queue, the waiting tasks in the Ntask queue are named N waiting tasks;

[0040] Arrange the N waiting tasks in descending order of dynamic priority, complete the N waiting tasks with the highest dynamic priority first, and mark the N waiting tasks in execution as execution tasks;

[0041] The dynamic priority of each C waiting task is calculated in real time. If the maximum value of the dynamic priority changes and it is not an execution task, the order of the N waiting tasks except the execution task is updated. After the execution task is completed, the next N waiting task with the largest dynamic priority is executed.

[0042] Further, the waiting tasks in the Ntask queue are analyzed based on time to determine whether they are in a long-term static state. If so, they are scheduled to the Ctask queue and are executed preferentially, including the following sub-steps:

[0043] Get the waiting time of the N-waiting task and name it N-waiting time;

[0044] Compare the N waiting time with the first time threshold, if the N waiting time is greater than or equal to the first time threshold, output a long-time static signal; if the N waiting time is less than the first time threshold, output a normal state signal;

[0045] If a long-time static signal is output, the corresponding N waiting time will be scheduled to the Ctask queue and will be executed first regardless of the order of the C waiting tasks.

[0046] In a second aspect, the present application provides an electronic device, including a processor and a memory, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the steps in the above method are performed.

[0047] In a third aspect, the present application provides a storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps in the above method are performed.

[0048] Beneficial effects of the present invention: The present invention schedules and allocates waiting tasks in the task pool by creating a task pool, and allocates the waiting tasks to different task queues. The advantages are that the Ctask queue and the Ntask queue respectively adopt a preemptive and non-preemptive scheduling mode, and do not require independent memory for storing task stacks, which greatly reduces the memory usage in the system and improves the smoothness of system operation.

[0049] The present invention analyzes the waiting tasks in the task queue dynamically, assigns a dynamic priority to each waiting task, and dynamically schedules the waiting tasks in the task queue based on the dynamic priority. The advantage is that the priority of the waiting tasks is reflected in real time through the dynamic priority, and the waiting tasks with the highest dynamic priority are executed first. Moreover, according to different task queues, the regulation when the dynamic priority changes is also different, which improves the rationality and effectiveness of task scheduling.

[0050] The present invention analyzes the waiting tasks in the Ntask queue based on time to determine whether they are in a long-term dormant state. If so, they are scheduled to the Ctask queue and executed with priority. The advantage is that since the Ntask queue adopts non-preemptive scheduling, some tasks cannot be executed for a long time due to their low dynamic priority. Therefore, such waiting tasks are regulated to the Ctask queue for direct execution, which prevents the waiting tasks from being dormant for a long time and not being able to run, thereby improving the rationality of task scheduling. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] Figure 1 is a flow chart of the steps of the method of the present invention;

[0052] Figure 2A schematic diagram of the relationship between the task pool, waiting tasks and task queue of the present invention;

[0053] Figure 3 It is a schematic structural diagram of the electronic device of the present invention. DETAILED DESCRIPTION

[0054] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0055] Example 1, please refer to Figure 1 As shown, the present application provides a time-based CPU resource collaborative scheduling method, comprising the following steps:

[0056] Step S1, creating a task pool, scheduling and allocating waiting tasks in the task pool, and allocating waiting tasks to different task queues, the task queues include Ctask queue and Ntask queue; Step S1 includes the following sub-steps:

[0057] Step S101, obtaining the estimated processing time of the waiting task and setting the separation value;

[0058] Step S101 includes the following sub-steps:

[0059] See also Figure 2 As shown, step S1011, creating a task pool, the task pool is used to store waiting tasks;

[0060] Step S1012, obtaining the estimated processing time of the waiting task, where the estimated processing time is the estimated time required for the CPU to execute the waiting task;

[0061] Step S1013: sort and number the estimated processing time of all waiting tasks in the task pool in ascending order, using symbol S n It represents, where n is a positive integer and n is the sequence number of S;

[0062] Step S1014, setting a separation value, represented by the symbol m, where m is initially max(n) / 2, wherein the calculation result of max(n) / 2 is an integer, max(n) is the maximum value of n, m is a positive integer and max(n) / 2≤m≤max(n);

[0063] In the specific implementation, a task pool is created. The relationship between the task pool, waiting tasks and task queues is as follows: Figure 2 As shown, there are 8 waiting tasks in the current task pool, so Sn , 1≤n≤8, the estimated processing time is obtained by the CPU; max(n) / 2=4, that is, 4≤m≤8; at this time, S1 to S8 are 13s, 15s, 18s, 25s, 32s, 46s, 58s and 72s respectively;

[0064] Step S102, analyzing the estimated processing time of all waiting tasks in the task pool based on the separation value, and assigning the waiting tasks to different task queues;

[0065] Step S102 includes the following sub-steps:

[0066] Step S1021, mark the calculation result of max(n) / 2 as e, e is an integer, and start from m=e, calculate as well as The calculation results are marked as p and q respectively;

[0067] Step S1022, compare p and q, if p and q are of the same sign, then output a separation increase signal; if p and q are of opposite sign, then output a separation stop signal;

[0068] Step S1023, if a separation increase signal is output, the value of m is increased by 1 and p and q are recalculated until the separation stop signal position is output; if a separation stop signal is output, the value of m+1 at this time is marked as a separation confirmation value, represented by the symbol j;

[0069] Step S1024: n The waiting tasks corresponding to the estimated processing time of n≤j are integrated into Ntask tasks, and S n The waiting tasks corresponding to the estimated processing time of n>j are integrated into Ctask tasks;

[0070] Step S1025, assigning the Ntask task to the Ntask queue, and assigning the Ctask task to the Ctask queue;

[0071] In the specific implementation, when m=5, p=-73 and q=19 are calculated. By comparison, it is found that the positive and negative of p and q are opposite at this time, and a separation stop signal is output. At this time, m=5, so the separation confirmation value j=6, and S n The waiting tasks corresponding to the estimated processing time of n≤6 are integrated into Ntask tasks, and S n The waiting tasks corresponding to the estimated processing time of n>6 are integrated into Ctask tasks; the Ntask tasks are assigned to the Ntask queue, and the Ctask tasks are assigned to the Ctask queue.

[0072] Step S2, performing dynamic priority analysis on the waiting tasks in the task queue, assigning a dynamic priority to each waiting task, and dynamically scheduling the waiting tasks in the task queue based on the dynamic priority; Step S2 includes the following sub-steps:

[0073] Step S201, obtaining task parameters required for calculating dynamic priority, and calculating the dynamic priority of the waiting task based on the task parameters;

[0074] Step S201 includes the following sub-steps:

[0075] Step S2011, obtaining the time for the waiting task to join the task pool, marking it as joining time;

[0076] Step S2012, obtaining the current time, calculating the difference between the current time and the joining time, and marking the calculation result as the waiting time;

[0077] Step S2013, obtaining the task type, which includes real-time tasks and non-real-time tasks;

[0078] Step S2014, obtaining resource occupancy of the waiting task;

[0079] Step S2015, the waiting time, task type, resource occupancy and estimated processing time are collectively referred to as task parameters;

[0080] Step S2016, calculating the task parameters using a dynamic priority calculation formula to obtain the dynamic priority of the waiting task;

[0081] Step S2017, in the dynamic priority calculation formula, Tt is used to represent the task type. If the task type is a real-time task, the Tt amplitude is 2; if the task type is a non-real-time task, the Tt amplitude is 1;

[0082] The dynamic priority calculation formula is configured as: Among them, DP is the dynamic priority, Wt is the waiting time, Ro is the resource occupancy, and Ept is the estimated processing time;

[0083] In the specific implementation, for the waiting task S1, the joining time is obtained as 19:32:46, the current time is 19:32:58, the waiting time Wt is calculated to be 12s, and the estimated processing time Ept of S1 is 13s. The task type of S1 is obtained as a non-real-time task, that is, Tt is 1, and the resource occupancy Ro of S1 is obtained as 8%. The dynamic priority DP of S1 is calculated to be 0.0738, and the calculation result is retained to four decimal places; similarly, the dynamic priorities of S2 to S8 are calculated to be 0.0839, 0.0822, 0.0743, 0.0944, 0.1003, 0.0744 and 0.0878 respectively;

[0084] Step S202, dynamically scheduling waiting tasks in the task queue based on dynamic priorities;

[0085] Step S202 includes the following sub-steps:

[0086] Step S2021, for the Ctask queue, name the waiting task in the Ctask queue as C waiting task;

[0087] Step S2022, arranging the C waiting tasks in descending order of dynamic priority, completing the C waiting tasks with the highest dynamic priority first, and marking the C waiting tasks in execution as execution tasks;

[0088] Step S2023, calculating the dynamic priority of each C waiting task in real time, if the maximum value of the dynamic priority changes and is not an executing task, suspending the executing task through the Ctask_Delay algorithm, and giving priority to executing the C waiting task with the largest dynamic priority;

[0089] In the specific implementation, the C waiting tasks in the Ctask queue are S7 and S8, and the corresponding dynamic priorities are 0.0744 and 0.0878 respectively. They are arranged in order from large to small, that is, S8 is executed first, and then S7. The current execution task is S8. The dynamic priorities of S7 and S8 are calculated in real time. If the dynamic priority of S7 is greater than the dynamic priority of S8, S8 is suspended through the Ctask_Delay algorithm and S7 is executed. The Ctask_Delay algorithm is used to delay tasks;

[0090] Step S2024, for the Ntask queue, name the waiting task in the Ntask queue as N waiting task;

[0091] Step S2025, arranging the N waiting tasks in descending order of dynamic priority, completing the N waiting tasks with the highest dynamic priority first, and marking the N waiting tasks in execution as execution tasks;

[0092] Step S2026, calculate the dynamic priority of each C waiting task in real time. If the maximum value of the dynamic priority changes and it is not an execution task, update the order of the N waiting tasks except the execution task, and execute the next N waiting task with the largest dynamic priority after the execution task is completed;

[0093] In the specific implementation, the N waiting tasks in the Ntask queue are S1 to S6, and the corresponding dynamic priorities are 0.0738, 0.0839, 0.0822, 0.0743, 0.0944 and 0.1003, respectively. They are arranged in descending order as 0.1003, 0.0944, 0.0839, 0.0822, 0.0743 and 0.0738, and the corresponding N waiting tasks are sorted as S6, S5, S2, S3, S4. 4 and S1, the current execution task is S6, and the dynamic priorities of S1 to S6 are calculated in real time. If any dynamic priority of S1 to S5 is greater than the dynamic priority of S6, the corresponding N waiting tasks are inserted before S5. For example, the order of dynamic priorities is changed to S1, S6, S5, S2, S3 and S4. At this time, task S6 has not been completed, so S6 continues to be executed, and the execution order of N waiting tasks is changed to S6, S1, S5, S2, S3 and S4.

[0094] Step S3, analyzing the waiting tasks in the Ntask queue based on time to determine whether they are in a long-term static state, and if so, scheduling them to the Ctask queue and executing them first; Step S3 includes the following sub-steps:

[0095] Step S301, obtaining the waiting time of the N waiting task, and naming it as the N waiting time;

[0096] Step S302, comparing the N waiting time with the first time threshold, if the N waiting time is greater than or equal to the first time threshold, outputting a long-time inactivity signal; if the N waiting time is less than the first time threshold, outputting a normal state signal;

[0097] Step S303, if a long-time static signal is output, the corresponding N waiting time is scheduled to the Ctask queue and the C waiting task is executed first regardless of the order of the C waiting task;

[0098] In the specific implementation, the N waiting tasks include S1 to S6, and the corresponding waiting times are 73s, 75s, 78s, 85s, 92s and 106s respectively. The first time threshold is set to 90s. The setting of the first time threshold is to prevent the problem that the N waiting tasks cannot be executed for a long time. By comparison, it is found that S6 and S5 are both greater than the first time threshold, so a long-term static signal is output. Since S6 is being executed, only S5 is considered, and S5 is transferred to the Ctask queue. At this time, S8 in the Ctask queue has been executed, and S7 is being executed. S7 is paused and S5 is executed first.

[0099] Example 2, please refer to Figure 3 As shown, Figure 3The structural schematic diagram of an electronic device is illustrated, and the electronic device may include: a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus. The memory stores computer-readable instructions, and the processor can call the instructions in the memory. When the computer-readable instructions are executed by the processor, the steps in the time-based CPU resource cooperative scheduling method are executed to achieve the following functions: create a task pool, schedule and allocate waiting tasks in the task pool, and allocate waiting tasks to the Ctask queue and the Ntask queue; perform dynamic priority analysis on waiting tasks in the task queue, assign dynamic priority to each waiting task, and dynamically schedule waiting tasks in the task queue based on the dynamic priority; analyze waiting tasks in the Ntask queue based on time to determine whether they are in a long-term static state.

[0100] In addition, the logic instructions in the above-mentioned memory can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art, and the computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk.

[0101] Embodiment 3, the present application also provides a computer-readable storage medium, the present application provides a storage medium, on which a computer program is stored. When the computer program is executed by the processor, the steps in the above time-based CPU resource collaborative scheduling method are executed to achieve the following functions: create a task pool, schedule and allocate waiting tasks in the task pool, and allocate waiting tasks to the Ctask queue and the Ntask queue; perform dynamic priority analysis on the waiting tasks in the task queue, assign a dynamic priority to each waiting task, and dynamically schedule the waiting tasks in the task queue based on the dynamic priority; analyze the waiting tasks in the Ntask queue based on time to determine whether they are in a long-term static state.

[0102] Through the description of the above implementation methods, the embodiments of the present invention can be provided as methods, systems or computer program products. Based on such an understanding, the above technical solutions can be essentially or partly contributed to the prior art in the form of software products, which can be stored in a computer-readable storage medium, such as ROM / RAM, a magnetic disk, an optical disk, etc., and include several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0103] In the embodiments provided in the present application, it should be understood that the disclosed system or method can be implemented in other ways. The embodiments described above are merely schematic. For example, the division of modules or units is only a logical function division. There may be other division methods in actual implementation. For example, multiple modules or units 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 communication interfaces, and the indirect coupling or communication connection of systems, modules and units can be electrical, mechanical or other forms.

[0104] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A time-based collaborative CPU resource scheduling method, characterized in that: The steps include: Create a task pool, schedule and allocate waiting tasks in the task pool, and allocate waiting tasks to different task queues, including Ctask queue and Ntask queue; Perform dynamic priority analysis on waiting tasks in the task queue, assign dynamic priority to each waiting task, and dynamically schedule waiting tasks in the task queue based on the dynamic priority; The waiting tasks in the Ntask queue are analyzed based on time to determine whether they are in a long-term static state. If so, they are scheduled to the Ctask queue and executed first.

2. The time-based CPU resource collaborative scheduling method according to claim 1, characterized in that: Creating a task pool, scheduling and allocating waiting tasks in the task pool, and allocating waiting tasks to different task queues includes the following sub-steps: Get the estimated processing time of the waiting task and set the separation value; The estimated processing time of all waiting tasks in the task pool is analyzed based on the separation value, and the waiting tasks are assigned to different task queues.

3. The time-based CPU resource collaborative scheduling method according to claim 2, characterized in that: Getting the estimated processing time of waiting tasks and setting the separation value includes the following sub-steps: Create a task pool, which is used to store waiting tasks; Obtain an estimated processing time of the waiting task, where the estimated processing time is the estimated time required for the CPU to execute the waiting task; Sort the estimated processing time of all waiting tasks in the task pool in ascending order and number them, using the symbol S n It represents, where n is a positive integer and n is the sequence number of S; Set the separator value, represented by the symbol m, where m is initially max(n) / 2, where the calculation result of max(n) / 2 retains an integer, max(n) is the maximum value of n, m is a positive integer, and max(n) / 2≤m≤max(n).

4. The time-based CPU resource collaborative scheduling method according to claim 3, characterized in that: Analyzing the estimated processing time of all waiting tasks in the task pool based on the separation value includes the following sub-steps: Mark the result of max(n) / 2 as e, and keep e as an integer. Starting from m=e, calculate as well as The calculation results are marked as p and q respectively; Compare p and q. If the signs of p and q are the same, a separation increase signal is output; if the signs of p and q are opposite, a separation stop signal is output. If a separation increase signal is output, the value of m is increased by 1 and p and q are recalculated until the separation stop signal position is output; if a separation stop signal is output, the value of m+1 at this time is marked as the separation confirmation value, represented by the symbol j; S n The waiting tasks corresponding to the estimated processing time of n≤j are integrated into Ntask tasks, and S n The waiting tasks corresponding to the estimated processing time of n>j are integrated into Ctask tasks; Assign the Ntask task to the Ntask queue and assign the Ctask task to the Ctask queue.

5. The time-based CPU resource collaborative scheduling method according to claim 4, characterized in that: Performing dynamic priority analysis on waiting tasks in the task queue, assigning a dynamic priority to each waiting task, and dynamically scheduling the waiting tasks in the task queue based on the dynamic priority includes the following sub-steps: Obtain the task parameters required to calculate the dynamic priority, and calculate the dynamic priority of the waiting task based on the task parameters; Dynamically schedule waiting tasks in the task queue based on dynamic priorities.

6. The time-based CPU resource cooperative scheduling method according to claim 5, characterized in that: Obtaining the task parameters required for calculating the dynamic priority, and calculating the dynamic priority of the waiting task based on the task parameters includes the following sub-steps: Get the time when the waiting task joins the task pool and mark it as the joining time; Get the current time, calculate the difference between the current time and the joining time, and mark the calculation result as the waiting time; Acquire task types, which include real-time tasks and non-real-time tasks; Get the resource usage of waiting tasks; The waiting time, task type, resource usage and estimated processing time are collectively referred to as task parameters; The task parameters are calculated using the dynamic priority calculation formula to obtain the dynamic priority of the waiting task; In the dynamic priority calculation formula, Tt is used to indicate the task type. If the task type is a real-time task, the Tt value is 2; if the task type is a non-real-time task, the Tt value is 1. The dynamic priority calculation formula is configured as: Among them, DP is the dynamic priority, Wt is the waiting time, Ro is the resource occupancy, and Ept is the estimated processing time.

7. The time-based CPU resource cooperative scheduling method according to claim 6, characterized in that: Dynamically scheduling waiting tasks in the task queue based on dynamic priorities includes the following sub-steps: For the Ctask queue, name the waiting task in the Ctask queue as C waiting task; Arrange the C waiting tasks in descending order of dynamic priority, complete the C waiting tasks with the highest dynamic priority first, and mark the C waiting tasks in execution as execution tasks; The dynamic priority of each C waiting task is calculated in real time. If the maximum value of the dynamic priority changes and it is not an executing task, the executing task will be suspended through the Ctask_Delay algorithm, and the C waiting task with the largest dynamic priority will be executed first. For the Ntask queue, the waiting tasks in the Ntask queue are named N waiting tasks; Arrange the N waiting tasks in descending order of dynamic priority, complete the N waiting tasks with the highest dynamic priority first, and mark the N waiting tasks in execution as execution tasks; The dynamic priority of each C waiting task is calculated in real time. If the maximum value of the dynamic priority changes and it is not an execution task, the order of the N waiting tasks except the execution task is updated. After the execution task is completed, the next N waiting task with the largest dynamic priority is executed.

8. The time-based CPU resource cooperative scheduling method according to claim 7, characterized in that: Analyze the waiting tasks in the Ntask queue based on time to determine whether they are in a long-term static state. If so, schedule them to the Ctask queue and execute them first, including the following sub-steps: Get the waiting time of the N-waiting task and name it N-waiting time; Compare the N waiting time with the first time threshold, if the N waiting time is greater than or equal to the first time threshold, output a long-time static signal; if the N waiting time is less than the first time threshold, output a normal state signal; If a long-time static signal is output, the corresponding N waiting time will be scheduled to the Ctask queue and will be executed first regardless of the order of the C waiting tasks.

9. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores computer-readable instructions. When the computer-readable instructions are executed by the processor, the steps in the method according to any one of claims 1 to 7 are executed.

10. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps in the method according to any one of claims 1 to 7 are executed.

Citation Information

Patent Citations

  • Small embedded system task scheduling method capable of saving memory

    CN118132306A

Cited By

  • A heterogeneous computing power task dynamic scheduling method, device, equipment and program product

    CN123011451A