Multi-factor optimized multi-level dynamic queue task scheduling method and system

By taking into account the impact of Resource and Event in the task scheduling of multi-level dynamic queues, dynamically updating task priority is solved, and the problem of inefficient task scheduling in traditional methods is achieved, shorter task scheduling time and faster response speed are achieved.

CN119718559APending Publication Date: 2025-03-28ANHUI GUOKE ANGHUI TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411522051.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-29
Publication Date
2025-03-28

AI Technical Summary

Technical Problem

The traditional multi-level dynamic queue task scheduling method is susceptible to the influence of Resource and Event when handling high-priority tasks, resulting in inefficient task scheduling and long response time.

Method used

By taking into account the impact of Resource and Event in task scheduling, dynamically update the priority of tasks, ensuring that high-priority tasks can respond in a timely manner, and optimizing the time slice management of task scheduling.

Benefits of technology

It realizes short task scheduling time and fast response speed, significantly reducing the average task scheduling time and improving the response ratio.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119718559A_ABST
    Figure CN119718559A_ABST
Patent Text Reader

Abstract

The invention discloses a multi-factor optimized multi-level dynamic queue task scheduling method, which comprises the following steps of: S1, initializing a multi-level dynamic queue, and setting the size of a corresponding rotation time slice and a corresponding priority of each level of queue of the multi-level dynamic queue; initializing all tasks in the multi-stage dynamic queue, and inserting a ready queue with a priority size corresponding to the multi-stage dynamic queue according to the priority of each task; s2, sequentially traversing 0 to N-1 levels of ready queues of the multi-level dynamic queues according to the sequence, and selecting a first task of a non-empty queue to schedule and run, so that the task occupies a processor; s3, other tasks are scheduled; and S4, if all queues of the multi-stage dynamic queue are empty, selecting idle tasks of the system to occupy the processor and run. The invention further discloses a multi-factor optimized multi-level dynamic queue task scheduling system. The method has the advantages of short task scheduling time and high response speed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a task scheduling method and system for a multi-level dynamic queue with multi-factor optimization. Background Art

[0002] Task scheduling plays a very important role in the implementation of operating systems. The normal operation of operating systems is inseparable from task scheduling. To keep the operating system implementing task scheduling at a faster speed and in a shorter time, an excellent task scheduling method is needed as support. The task scheduling method of traditional operating systems uses either the time slice round-robin scheduling algorithm or the priority-based preemptive scheduling algorithm as the main task scheduling method. However, both task scheduling methods have their own advantages and disadvantages. The characteristic of the time slice round-robin scheduling algorithm is that the processor is fairly allocated to the tasks in the ready task queue, and each task takes turns to occupy the processor and run a time slice. The advantages of the time slice round-robin scheduling algorithm are fairness and timely response. However, the defects of the time slice round-robin scheduling algorithm are also obvious. Because it does not distinguish the priority of tasks, high-priority tasks cannot be responded to first, resulting in major security issues. The characteristic of the priority-based preemptive scheduling algorithm is that a task is given a priority, and then the task with the highest priority among the ready tasks occupies the processor and runs each time. The advantage of the priority-based preemptive scheduling algorithm is that high-priority tasks can be responded to first. However, the priority-based preemptive scheduling algorithm also has its inherent defects. It is unfair to low-priority tasks and may cause low-priority tasks to "starve" because they cannot be scheduled for a long time.

[0003] The task scheduling method of a multi-level dynamic queue based on a mixture of time slice round-robin and priority preemption can better combine the respective advantages of the time slice round-robin scheduling algorithm and the priority preemption scheduling algorithm, while better eliminating the respective defects of the time slice round-robin scheduling algorithm and the priority preemption scheduling algorithm.

[0004] However, the traditional task scheduling method based on a mixed multi-level dynamic queue of time slice rotation and priority preemption also has problems such as low task scheduling efficiency and long task response time. These problems are caused by the fact that the execution of tasks depends on the Resources and Events provided by the operating system. Resources are used to represent resources provided by the operating system that require mutual exclusive access by tasks, and Events are used to synchronize tasks in the operating system and determine the execution order. If a high-priority task needs to obtain a certain resource of the operating system that is occupied by other tasks and cannot be satisfied in time, or a high-priority task needs to wait for an event of the operating system to occur but cannot be satisfied in time, there is a certain probability that the task scheduling efficiency will be low and the task response time will be long.

[0005] The traditional task scheduling method based on a multi-level dynamic queue that is a mixture of time slice rotation and priority preemption, when the rotation time slice of the currently running task is exhausted and the task is scheduled, it simply reduces the priority of the currently running task by one level and puts it at the end of the ready queue of the corresponding priority in the multi-level dynamic queue. However, this method of simply reducing the task priority by one level ignores the impact of the two factors of Resource and Event on the task scheduling efficiency and task response time, so there is a certain probability that it will cause low task scheduling efficiency and long task response time.

[0006] Therefore, there is an urgent need to provide a new multi-factor optimized multi-level dynamic queue task scheduling method and system to solve the above problems. Summary of the invention

[0007] The technical problem to be solved by the present invention is to provide a task scheduling method and system of a multi-level dynamic queue with multi-factor optimization, which better avoids the problems caused by simply lowering the task priority by one level in the traditional task scheduling method of the multi-level dynamic queue, so that the operating system has the advantages of timely response, short total system response time, and priority response to high-priority tasks.

[0008] In order to solve the above technical problems, the first technical solution adopted by the present invention is to provide a task scheduling method of a multi-level dynamic queue with multi-factor optimization, comprising the following steps:

[0009] Step S1: Initialize the multi-level dynamic queue, set the corresponding rotation time slice size and corresponding priority of each level of the multi-level dynamic queue; initialize all tasks in the multi-level dynamic queue, set the priority size of each task and the time required for each task to run; initialize the parameters involved in multi-factor optimization; according to the priority of each task, insert the ready queue of the multi-level dynamic queue corresponding to the priority size;

[0010] Step S2: sequentially traverse the ready queues of levels 0 to N-1 of the multi-level dynamic queue, select the first task in the non-empty queue for scheduling, make the task occupy the processor, change the task state from the ready state to the running state, and delete the task from the ready queue of the multi-level dynamic queue;

[0011] Step S3: Every time a system timer interrupt occurs in the system, the system will check whether the rotation time slice of the currently running task is exhausted. If not, the currently running task continues to run; if the rotation time slice is exhausted, the ready queue and the waiting queue of the multi-level dynamic queue will be checked to see whether a new task has been added. If a new task has been added, the priority of the currently running task will be updated. Otherwise, the task scheduling will be performed directly, which will cause the currently running task to give up occupying the processor and change from the running state to the ready state. According to the new priority of the task, the task will be reinserted into the queue corresponding to the multi-level dynamic queue, and the process returns to step S2;

[0012] Step S4: All queues of the multi-level dynamic queues are empty, indicating that all tasks have been completed, and the idle task of the system is selected to occupy the processor and run.

[0013] In a preferred embodiment of the present invention, in step S1, the parameters involved in the multi-factor optimization are initialized including: a first lower limit lowerbound1, a first upper limit upperboun1d, a second lower limit lowerbound2, and a second upper limit upperbound2.

[0014] In a preferred embodiment of the present invention, step S1 further includes the following initialization steps:

[0015] Initialize the system waiting event matrix: All values ​​of the system waiting event matrix are initialized to 0, indicating that the task does not wait for the occurrence of the event; when the operating system is running, a new task is inserted into the ready queue of the multi-level dynamic queue. If the task requests the occurrence of an event, the task number is used as the row index and the number of the event requested by the task is used as the column index, and the value of the corresponding position in the event matrix is ​​set to 1;

[0016] Initialize the system waiting Resource matrix: The values ​​of the system waiting Resource matrix are all initialized to 0, indicating that the task does not request the Resource; when the operating system is running, a new task is inserted into the ready queue of the multi-level dynamic queue. If the task requests a Resource, the task number is used as the row index and the number of the resource requested by the task is used as the column index, and the value of the corresponding position in the matrix is ​​set to 1; the importance of each Resource is saved by the Resource_Level_Array array.

[0017] Furthermore, the specific steps of step S3 include:

[0018] S301: Initialize a running task list table, which is used to record the resources that are occupied but not released by the currently running task, and the events that are about to be set by the currently running task but have not been set yet;

[0019] S302: triggering system counter interrupt;

[0020] S303: Enter the system counter interrupt processing function to determine whether the rotation time slice of the currently running task is exhausted. If the rotation time slice is not exhausted, enter the next step S304; if the rotation time slice is exhausted, enter step S306;

[0021] S304: The system counter interrupt processing function ends and exits the system counter interrupt processing function;

[0022] S305: The current running task continues to run, and the process goes to step S302;

[0023] S306: Determine whether a new task is inserted into the ready queues of each level of the multi-level dynamic queue. If a new task is inserted, proceed to step S307; if no new task is inserted, proceed to step S308;

[0024] S307: registering the inserted new task, and updating the system waiting resource matrix according to the resource requested by the inserted new task;

[0025] S308: Determine whether a new task is inserted into the ready queue of the multi-level dynamic queue. If a new task is inserted, proceed to step S309; ​​if no new task is inserted, proceed to step S310;

[0026] S309: registering the inserted new task, and updating the system waiting event matrix according to the event that the inserted new task is waiting to occur;

[0027] S310: Calculate a new priority according to the running task list table, the system waiting Resource matrix, the system waiting Event matrix, and the Resource_Level_Array array, round the new priority, and update the priority of the current running task to the calculated new priority;

[0028] S311: The currently running task changes from the running state to the ready state, is inserted into the end of the ready queue of the corresponding priority of the multi-level dynamic queue, releases the occupied processor, and returns to step S2.

[0029] Furthermore, in step S310, the method for calculating the new priority includes:

[0030]

[0031] Among them, Np is the new priority, Op is the old priority; Rs i Resource influence switch, Es i Event affects the switch; the first Tp i Rl is the priority of the task newly inserted into the ready queue of each level of the multi-level dynamic queue. j The importance of the Resource requested by the task newly inserted into the ready queue of each level of the multi-level dynamic queue. The second Tp i is the priority of the task waiting in the queue; w1 is the weight of the impact of the old priority, w 2i is the weight of the impact of the Resource on whether the task can be completed in time, w 3i The weight of the impact of the event on whether the task can be completed in time;

[0032] Delta=Np-Op+1

[0033] if(lowerbound1≤Delta≤upperbound1)

[0034] {Np=Op-1} (2)

[0035] Delta=Np-Op+1

[0036] if(Delta≤lowerbound2)

[0037] {Np=Op+loewrbound2}

[0038] if(Delta≥upperbound2)

[0039] {Np=Op+upperbound2} (3)

[0040] The Delta in formula (2) is the change of the new priority compared to the old priority. If the size of Delta is within the preset lower limit - lowerbound1 and upper limit - upperbound1, it means that the change of the new priority compared to the old priority is too small, that is, the two factors Event and Resource have too little influence on the new priority. In this case, the traditional multi-level dynamic queue approach is still followed and the new priority is directly set to the old priority minus 1.

[0041] The Delta in formula (3) is the change of the new priority compared to the old priority. If the size of Delta is lower than the preset lower limit lowerbound2, then in order to control the change of the new priority Np, the change of Np compared to the old priority Op is controlled to lowerbound2; if the size of Delta is higher than the preset upper limit upperbound2, then in order to control the change of the new priority Np, the change of Np compared to the old priority Op is controlled to upperbound2.

[0042] In order to solve the above technical problems, the second technical solution adopted by the present invention is to provide a task scheduling system of a multi-level dynamic queue with multi-factor optimization, comprising:

[0043] The multi-level dynamic queue and task initialization module is used to initialize the multi-level dynamic queue, set the corresponding rotation time slice size and corresponding priority of each level of the multi-level dynamic queue; initialize all tasks in the multi-level dynamic queue, set the priority size of each task and the time required for each task to run; initialize the parameters involved in multi-factor optimization; according to the priority of each task, insert the ready queue of the corresponding priority size of the multi-level dynamic queue;

[0044] The first task scheduling and running module is used to sequentially traverse the ready queues of levels 0 to N-1 of the multi-level dynamic queue, select the first task in the non-empty queue for scheduling and running, so that the task occupies the processor, the task state changes from the ready state to the running state, and at the same time delete the task from the ready queue of the multi-level dynamic queue;

[0045] The multi-level dynamic queue and task scheduling module is used to check whether the rotation time slice of the current running task is exhausted every time the system timer interrupt occurs. If not, the current running task continues to run; if the rotation time slice is exhausted, it will check whether there is a new task added to the ready queue and waiting queue of the multi-level dynamic queue. If a new task is added, the priority of the current running task will be updated. Otherwise, the task scheduling will be performed directly, which will cause the current running task to give up the processor and change from the running state to the ready state. According to the new priority of the task, the task will be reinserted into the queue corresponding to the multi-level dynamic queue;

[0046] The multi-level dynamic queue detection module is used to select the idle task of the system to occupy the processor and run when all queues of the multi-level dynamic queues are empty, indicating that all tasks have been completed.

[0047] In a preferred embodiment of the present invention, the multi-level dynamic queue and task initialization module includes a multi-level dynamic queue initialization unit, a task initialization unit, a multi-factor optimization parameter initialization unit, a system waiting Event matrix initialization unit, and a system waiting Resource matrix initialization unit.

[0048] To solve the above technical problems, the third technical solution adopted by the present invention is: to provide an electronic device, comprising at least one processor and a memory communicatively connected to the at least one processor; the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the task scheduling method of the multi-factor optimized multi-level dynamic queue described in any one of the above items.

[0049] In order to solve the above technical problems, the fourth technical solution adopted by the present invention is: to provide a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable the computer to execute the task scheduling method of the multi-level dynamic queue with multi-factor optimization described in any of the above items.

[0050] In order to solve the above technical problems, the fifth technical solution adopted by the present invention is: to provide a computer program product, including a computer program; its characteristic is that when the computer program is executed by a processor, it implements the task scheduling method of the multi-level dynamic queue with multi-factor optimization described in any of the above items.

[0051] The beneficial effects of the present invention are:

[0052] (1) When the rotation time slice of the currently running task is exhausted and task scheduling is performed, the change of the priority of the currently running task comprehensively considers the influence of the two factors of Resource and Event, thereby better avoiding the problems caused by the traditional multi-level dynamic queue task scheduling method due to the method of simply reducing the task priority by one level;

[0053] (2) The present invention implements a task scheduling method for a multi-level dynamic queue that takes into account multi-factor optimization, and has the advantages of short task scheduling time and fast response speed. After experimental testing, for task sets that request fewer resources and events, the scheduling method implemented by the present invention can shorten the average task scheduling time by 5% to 9% compared to the traditional multi-level dynamic queue task scheduling method; for task sets that need to frequently request resources and events, the scheduling method implemented by the present invention can shorten the average task scheduling time by 8% to 14% compared to the traditional multi-level dynamic queue task scheduling method. It can be seen that the task scheduling method implemented by the present invention can significantly reduce the average task scheduling time for task sets that need to frequently request resources and events, and for task sets that request fewer resources and events, it also has a certain optimization effect of shortening the average task scheduling time;

[0054] (3) The present invention also has the advantage of high task scheduling efficiency. Compared with the traditional multi-level dynamic queue task scheduling method, for task sets that need to frequently request resources and events, the scheduling method implemented by the present invention can improve the response ratio by 10% to 17% (the response ratio is task turnaround time / task execution time). For task sets that request fewer resources and events, the scheduling method implemented by the present invention can also improve the response ratio by 6% to 11%. BRIEF DESCRIPTION OF THE DRAWINGS

[0055] Figure 1 It is a flow chart of the task scheduling method of the multi-level dynamic queue with multi-factor optimization of the present invention;

[0056] Figure 2 is a specific step flow chart of step S1;

[0057] Figure 3 is a specific step flow chart of step S3;

[0058] Figure 4 It is a structural block diagram of the task scheduling system of the multi-level dynamic queue with multi-factor optimization. DETAILED DESCRIPTION

[0059] The preferred embodiments of the present invention are described in detail below in conjunction with the accompanying drawings so that the advantages and features of the present invention can be more easily understood by those skilled in the art, thereby making a clearer and more definite definition of the protection scope of the present invention.

[0060] First, the concepts involved in the present invention are described to facilitate understanding of the technical solution:

[0061] The task has three states and corresponding transition processes, among which:

[0062] From ready state to running state: the ready task in the multi-level dynamic queue occupies the processor, and the task state changes from ready state to running state. At the same time, the task is deleted from the ready queue of the multi-level dynamic queue.

[0063] From running state to ready state: the task that currently occupies the processor and is in the running state abandons the processor, and the task state changes from the running state to the ready state. At the same time, the task is reinserted into the ready queue of the multi-level dynamic queue.

[0064] From waiting state to ready state: If the waiting event of the task in the waiting queue occurs, the state of the task will change from waiting state to ready state, and then it will be deleted from the waiting queue and inserted into the ready queue of the multi-level dynamic queue.

[0065] See also Figure 1 In order to solve the problems faced by the task scheduling method of the traditional operating system based on the multi-level dynamic queue mixed with time slice rotation and priority preemption, such as low response efficiency, too long total system response time or failure to give priority to high priority tasks due to ignoring the two factors of Resource and Event, the present invention provides an improved task scheduling method of the multi-level dynamic queue that takes into account the optimization of Resource and Event factors, including the following steps:

[0066] Step S1: Initialize the multi-level dynamic queue, set the corresponding rotation time slice size and corresponding priority of each level of the multi-level dynamic queue; initialize all tasks in the multi-level dynamic queue, set the priority size of each task and the time required for each task to run; initialize the parameters involved in multi-factor optimization; according to the priority of each task, insert the ready queue of the multi-level dynamic queue corresponding to the priority size;

[0067] Combination Figure 2 , the specific initialization steps include:

[0068] Step A1: Initialize a multi-level dynamic queue;

[0069] Step A2: setting the corresponding rotation time slice size of each level of the multi-level dynamic queue;

[0070] Step A3: setting the corresponding priorities of the ready queues at each level of the multi-level dynamic queue;

[0071] Step A4: Initialize all tasks;

[0072] Step A5: Set the priority of all tasks;

[0073] Step A6: Set the time required for all tasks to run;

[0074] Step A7: insert the task into the ready queue of the same priority of the multi-level dynamic queue;

[0075] Step A8: Initialize the parameters of multi-factor optimization, which are: lowerbound1n, upperbound1, lowerbound2, upperbound2;

[0076] Step A9: Initialize the system waiting event matrix. The system waiting event matrix is ​​as follows. The values ​​of the matrix are all initialized to 0, indicating that the task does not wait for the occurrence of the event. When a new task is inserted into the ready queue of the multi-level dynamic queue during the subsequent operation of the operating system, if the task requests the occurrence of an event, the number of the task is used as the row index, and the number of the event requested by the task is used as the column index, and the value of the corresponding position in the matrix is ​​set to 1.

[0077]

[0078] Step A10: Initialize the system waiting Resource matrix. The system waiting Resource matrix is ​​as follows. The values ​​of the matrix are all initialized to 0, indicating that the task does not request the Resource. When a new task is inserted into the ready queue of the multi-level dynamic queue during the subsequent operation of the operating system, if the task requests a Resource, the number of the task is used as the row index, and the number of the resource requested by the task is used as the column index, and the value of the corresponding position in the matrix is ​​set to 1. The importance of each Resource is saved by the Resource_Level_Array array.

[0079]

[0080] Step S2: sequentially traverse the ready queues of levels 0 to N-1 of the multi-level dynamic queue, select the first task in the non-empty queue for scheduling, make the task occupy the processor, change the task state from the ready state to the running state, and delete the task from the ready queue of the multi-level dynamic queue;

[0081] Step S3: Every time a system timer interrupt occurs in the system, the system will check whether the rotation time slice of the currently running task is exhausted. If not, the currently running task continues to run; if the rotation time slice is exhausted, the ready queue and the waiting queue of the multi-level dynamic queue will be checked to see whether a new task has been added. If a new task has been added, the priority of the currently running task will be updated. Otherwise, the task scheduling will be performed directly, which will cause the currently running task to give up occupying the processor and change from the running state to the ready state. According to the new priority of the task, the task will be reinserted into the queue corresponding to the multi-level dynamic queue, and the process returns to step S2;

[0082] Combination Figure 3 , the specific scheduling process steps include:

[0083] S301: Initialize a running task list table, which is used to record the resources that are occupied but not released by the currently running task, and the events that are about to be set by the currently running task but have not been set yet;

[0084] S302: triggering system counter interrupt;

[0085] S303: Enter the system counter interrupt processing function to determine whether the rotation time slice of the currently running task is exhausted. If the rotation time slice is not exhausted, enter the next step S304; if the rotation time slice is exhausted, enter step S306;

[0086] S304: The system counter interrupt processing function ends and exits the system counter interrupt processing function;

[0087] S305: The current running task continues to run, and the process goes to step S302;

[0088] S306: Determine whether a new task is inserted into the ready queues of each level of the multi-level dynamic queue. If a new task is inserted, proceed to step S307; if no new task is inserted, proceed to step S308;

[0089] S307: registering the inserted new task, and updating the system waiting resource matrix according to the resource requested by the inserted new task;

[0090] S308: Determine whether a new task is inserted into the ready queue of the multi-level dynamic queue. If a new task is inserted, proceed to step S309; ​​if no new task is inserted, proceed to step S310;

[0091] S309: registering the inserted new task, and updating the system waiting event matrix according to the event that the inserted new task is waiting to occur;

[0092] S310: Calculate the new priority according to the running task list table, the system waiting Resource matrix, the system waiting Event matrix, and the Resource_Level_Array array, round the new priority, and update the priority of the current running task to the calculated new priority; the specific calculation process is as follows:

[0093] Compared with the traditional multi-level dynamic queue, the core of the improved task scheduling method of the multi-level dynamic queue of the present invention, which takes into account the optimization of Resource and Event factors, is that when the current running task needs to change its priority after the rotation time slice is exhausted, compared with the traditional multi-level dynamic queue, which simply reduces the priority of the current running task by one level, the present invention changes the priority of the current running task according to the following strategy:

[0094]

[0095] Where Np is the new priority and Op is the old priority. i Resource influence switch, Es i The first Tp is the event affecting the switch. i Rl is the priority of the task newly inserted into the ready queue of each level of the multi-level dynamic queue. j The importance of the resource requested by the task newly inserted into the ready queue of each level of the multi-level dynamic queue. i is the priority of the task in the waiting queue. w1 is the weight of the impact of the old priority, w 2i is the weight of the impact of the Resource on whether the task can be completed in time, w 3i The weight of the impact of the event on whether the task can be completed in time.

[0096] The effect of formula (1) is that the new priority Np of the currently running task that has exhausted its rotation time slice depends not only on the old priority Op of the task, but also on the two factors of the ready task requesting the Resource and the waiting task waiting for the Event to occur. If the Resource requested by the high-priority task in the ready queue of the multi-level dynamic queue is the Resource occupied by the currently running task that has exhausted its rotation time slice, then the priority of the currently running task that has exhausted its rotation time slice needs to be appropriately increased before being inserted into the end of the ready queue of the multi-level dynamic queue, because only when the currently running task that has exhausted its rotation time slice is rescheduled to run as soon as possible can the ready task requesting the same Resource minimize the response time; if the Event that the high-priority task in the waiting queue is waiting for is the Event set by the currently running task that has exhausted its rotation time slice, then the priority of the currently running task that has exhausted its rotation time slice needs to be appropriately increased before being inserted into the ready queue of the multi-level dynamic queue. On the contrary, if the on-time execution of tasks in the ready queue of the multi-level dynamic queue has nothing to do with the resource they request, or the on-time execution of tasks in the waiting queue has nothing to do with the event they are waiting for, the currently running task that has exhausted the rotation time slice needs to be appropriately lowered in priority and then inserted into the end of the ready queue of the multi-level dynamic queue.

[0097] The first part of formula (1) is w1*(Op-1), which represents the impact of the old priority on the new priority. Op-1 means that the old priority is reduced by one level, that is, the traditional multi-level dynamic queue simply reduces the currently running task that has exhausted the rotation time slice by one level. w1 is usually 1.

[0098] The second part of formula (1) is Represents the impact of all tasks newly inserted into the ready queue of the multi-level dynamic queue on the new priority of the currently running task that has exhausted the rotation time slice due to requesting the same Resource, Rl j and Tp i The multiplication is because the importance of the resource and the priority of the task requesting the resource will add up to each other and positively affect the new priority of the currently running task that has exhausted the rotation time slice. That is, the higher the priority of the ready task requesting the more important resource, the more it is necessary to increase the priority of the currently running task that has exhausted the rotation time slice, so as to ensure that it can be rescheduled as soon as possible to reduce the response time of the ready task requesting the same resource. i Used to determine whether to consider the impact of the Resource factor on the new priority of the currently running task that has exhausted the rotation time slice. If the relationship between the timely response of the ready task and Resource is not considered, Rs i Set to 0; if the relationship between the timely response of the ready task and Resource is considered, Rs i Set to 1. 2i It is used to indicate the influence of Resource on the timely response of ready tasks, which can be between 0 and 1. 2i The smaller the value of, the less the timely response of the ready task is affected by Resource; 2i The larger the value is, the more the timely response of the ready task is affected by Resource.

[0099] The third part of formula (1) is Represents the impact of all tasks in the waiting queue on the new priority of the currently running task that has exhausted its rotation time slice due to the occurrence of the Event set by the currently running task that has exhausted its rotation time slice. If the priority of the task in the waiting queue is Tp i The higher the value, the more it is necessary to reschedule the currently running task that has exhausted the rotation time slice as soon as possible so that the task can end the waiting state. Therefore, Tp i Positively affects the new priority of currently running tasks that have used up their round-robin time slices. 3iIt is used to indicate the degree of influence of the event on the timely response of the waiting task, which can be between 0 and 1. 3i The smaller the value, the less the timely response of the waiting task is affected by the Event; 3i The larger the value, the more the timely response of the waiting task is affected by the Event. i Used to consider whether to consider the impact of Event on the new priority of the currently running task that has exhausted the rotation time slice. If the timely response of the waiting task is not affected by Event, Es can be used. i Set to 0; if you consider that the timely response of the waiting task is affected by Event, you can set Es i Set to 1.

[0100] Delta=Np-Op+1

[0101] if(lowerbound1≤Delta≤upperbound1)

[0102] {Np=Op-1} (2)

[0103] Delta=Np-Op+1

[0104] if(Delta≤lowerbound2)

[0105] {Np=Op+loewrbound2}

[0106] if(Delta≥upperbound2)

[0107] {Np=Op+upperbound2} (3)

[0108] Formula (2) and Formula (3) adjust the new priority according to whether the change amount of the new priority compared with the old priority is within a preset range. Formula (2) and Formula (3) are explained below.

[0109] The Delta in formula (2) is the change of the new priority compared to the old priority. If the size of Delta is within the preset lower limit - lowerbound1 and upper limit - upperbound1, it means that the change of the new priority compared to the old priority is too small, that is, the two factors Event and Resource have too little influence on the new priority. In this case, the traditional multi-level dynamic queue approach is still followed and the new priority is directly set to the old priority minus 1.

[0110] The Delta in formula (3) is the change of the new priority compared to the old priority. If the size of Delta is lower than the preset lower limit lowerbound2, then in order to control the change of the new priority Np, the change of Np compared to the old priority Op is controlled to lowerbound2; if the size of Delta is higher than the preset upper limit upperbound2, then in order to control the change of the new priority Np, the change of Np compared to the old priority Op is controlled to upperbound2.

[0111] S311: The currently running task changes from the running state to the ready state, is inserted into the end of the ready queue of the corresponding priority of the multi-level dynamic queue, releases the occupied processor, and returns to step S2.

[0112] Step S4: All queues of the multi-level dynamic queues are empty, indicating that all tasks have been completed, and the idle task of the system is selected to occupy the processor and run.

[0113] See also Figure 4 The present invention also provides a multi-factor optimized multi-level dynamic queue task scheduling system, including:

[0114] The multi-level dynamic queue and task initialization module is used to initialize the multi-level dynamic queue, set the corresponding rotation time slice size and corresponding priority of each level of the multi-level dynamic queue; initialize all tasks in the multi-level dynamic queue, set the priority size of each task and the time required for each task to run; initialize the parameters involved in multi-factor optimization; according to the priority of each task, insert the ready queue of the corresponding priority size of the multi-level dynamic queue;

[0115] The first task scheduling and running module is used to sequentially traverse the ready queues of levels 0 to N-1 of the multi-level dynamic queue, select the first task in the non-empty queue for scheduling and running, so that the task occupies the processor, the task state changes from the ready state to the running state, and at the same time delete the task from the ready queue of the multi-level dynamic queue;

[0116] The multi-level dynamic queue and task scheduling module is used to check whether the rotation time slice of the current running task is exhausted every time the system timer interrupt occurs. If not, the current running task continues to run; if the rotation time slice is exhausted, it will check whether there is a new task added to the ready queue and waiting queue of the multi-level dynamic queue. If a new task is added, the priority of the current running task will be updated. Otherwise, the task scheduling will be performed directly, which will cause the current running task to give up the processor and change from the running state to the ready state. According to the new priority of the task, the task will be reinserted into the queue corresponding to the multi-level dynamic queue;

[0117] The multi-level dynamic queue detection module is used to select the idle task of the system to occupy the processor and run when all queues of the multi-level dynamic queues are empty, indicating that all tasks have been completed.

[0118] The multi-level dynamic queue and task initialization module includes a multi-level dynamic queue initialization unit, a task initialization unit, a multi-factor optimization parameter initialization unit, a system waiting Event matrix initialization unit, and a system waiting Resource matrix initialization unit.

[0119] The task scheduling system of a multi-level dynamic queue with multi-factor optimization in this example can execute a task scheduling method of a multi-level dynamic queue with multi-factor optimization provided by the present invention, and can execute any combination of implementation steps of the method example, and has the corresponding functions and beneficial effects of the method.

[0120] An embodiment of the present invention further provides a task scheduling device for a multi-level dynamic queue with multi-factor optimization, comprising a memory and a processor, wherein the memory is used to store at least one program, and the processor is used to load the at least one program to execute the method described above.

[0121] An embodiment of the present invention further provides a computer-readable storage medium, in which processor-executable instructions are stored. When the processor-executable instructions are executed by the processor, they are used to execute the method described above.

[0122] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0123] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0124] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0125] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0126] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, ordinary technicians in the relevant field should understand that the specific implementation methods of the present invention can still be modified or replaced by equivalents. Any modification or equivalent replacement that does not depart from the spirit and scope of the present invention should be covered within the scope of protection of the claims of the present invention.

Claims

1. A multi-factor optimized multi-level dynamic queue task scheduling method, characterized in that: The following steps are involved: Step S1: Initialize the multi-level dynamic queue and set the corresponding rotation time slice size and corresponding priority of each level of the multi-level dynamic queue; Initialize all tasks in the multi-level dynamic queue, set the priority of each task and the time required for each task to run; initialize the parameters involved in multi-factor optimization; insert the ready queue of the multi-level dynamic queue with the corresponding priority according to the priority of each task; Step S2: sequentially traverse the ready queues of levels 0 to N-1 of the multi-level dynamic queue, select the first task in the non-empty queue for scheduling, make the task occupy the processor, change the task state from the ready state to the running state, and delete the task from the ready queue of the multi-level dynamic queue; Step S3: Every time a system timer interrupt occurs in the system, the system will check whether the rotation time slice of the currently running task is exhausted. If not, the currently running task continues to run; if the rotation time slice is exhausted, the ready queue and the waiting queue of the multi-level dynamic queue will be checked to see whether a new task has been added. If a new task has been added, the priority of the currently running task will be updated. Otherwise, the task scheduling will be performed directly, which will cause the currently running task to give up occupying the processor and change from the running state to the ready state. According to the new priority of the task, the task will be reinserted into the queue corresponding to the multi-level dynamic queue, and the process returns to step S2; Step S4: All queues of the multi-level dynamic queues are empty, indicating that all tasks have been completed, and the idle task of the system is selected to occupy the processor and run.

2. The task scheduling method of multi-level dynamic queue with multi-factor optimization according to claim 1 is characterized in that: In step S1, the parameters involved in the multi-factor optimization are initialized, including: a first lower limit lowerbound1, a first upper limit upperbound1, a second lower limit lowerbound2, and a second upper limit upperbound2.

3. The task scheduling method of multi-level dynamic queue with multi-factor optimization according to claim 1 is characterized in that: Step S1 also includes the following initialization steps: Initialize the system waiting event matrix: All values ​​of the system waiting event matrix are initialized to 0, indicating that the task does not wait for the occurrence of the event; when the operating system is running, a new task is inserted into the ready queue of the multi-level dynamic queue. If the task requests the occurrence of an event, the task number is used as the row index and the number of the event requested by the task is used as the column index, and the value of the corresponding position in the event matrix is ​​set to 1; Initialize the system waiting Resource matrix: The values ​​of the system waiting Resource matrix are all initialized to 0, indicating that the task does not request the Resource; when the operating system is running, a new task is inserted into the ready queue of the multi-level dynamic queue. If the task requests a Resource, the task number is used as the row index and the number of the resource requested by the task is used as the column index, and the value of the corresponding position in the matrix is ​​set to 1; the importance of each Resource is saved by the Resource_Level_Array array.

4. The task scheduling method of multi-level dynamic queue with multi-factor optimization according to claim 3 is characterized in that: The specific steps of step S3 include: S301: Initialize a running task list table, which is used to record the resources that are occupied but not released by the currently running task, and the events that are about to be set by the currently running task but have not been set yet; S302: triggering system counter interrupt; S303: Enter the system counter interrupt processing function to determine whether the rotation time slice of the currently running task is exhausted. If the rotation time slice is not exhausted, enter the next step S304; if the rotation time slice is exhausted, enter step S306; S304: The system counter interrupt processing function ends and exits the system counter interrupt processing function; S305: The current running task continues to run, and the process goes to step S302; S306: Determine whether a new task is inserted into the ready queues of each level of the multi-level dynamic queue. If a new task is inserted, proceed to step S307; if no new task is inserted, proceed to step S308; S307: registering the inserted new task, and updating the system waiting resource matrix according to the resource requested by the inserted new task; S308: Determine whether a new task is inserted into the ready queue of the multi-level dynamic queue. If a new task is inserted, proceed to step S309; ​​if no new task is inserted, proceed to step S310; S309: registering the inserted new task, and updating the system waiting event matrix according to the event that the inserted new task is waiting to occur; S310: Calculate a new priority according to the running task list table, the system waiting Resource matrix, the system waiting Event matrix, and the Resource_Level_Array array, round the new priority, and update the priority of the current running task to the calculated new priority; S311: The currently running task changes from the running state to the ready state, is inserted into the end of the ready queue of the corresponding priority of the multi-level dynamic queue, releases the occupied processor, and returns to step S2.

5. The task scheduling method of multi-level dynamic queue with multi-factor optimization according to claim 3 is characterized in that: In step S310, the method for calculating the new priority includes: Among them, Np is the new priority, Op is the old priority; Rs i Resource influence switch, Es i Event affects the switch; the first Tp i Rl is the priority of the task newly inserted into the ready queue of each level of the multi-level dynamic queue. j The importance of the Resource requested by the task newly inserted into the ready queue of each level of the multi-level dynamic queue. The second Tp i is the priority of the task waiting in the queue; w1 is the weight of the impact of the old priority, w 2i is the weight of the impact of the Resource on whether the task can be completed in time, w 3i The weight of the impact of the event on whether the task can be completed in time; Delta=Np-Op+1 if(lowerbound1≤Delta≤upperbound1) {Np=Op-1} (2) Delta=Np-Op+1 if(Delta≤lowerbound2) {Np=Op+loewrbound2} if(Delta≥upperbound2) {Np=Op+upperbound2} (3) The Delta in formula (2) is the change of the new priority compared to the old priority. If the size of Delta is within the preset lower limit - lowerbound1 and upper limit - upperbound1, it means that the change of the new priority compared to the old priority is too small, that is, the two factors Event and Resource have too little influence on the new priority. In this case, the traditional multi-level dynamic queue approach is still followed and the new priority is directly set to the old priority minus 1. The Delta in formula (3) is the change of the new priority compared to the old priority. If the size of Delta is lower than the preset lower limit lowerbound2, then in order to control the change of the new priority Np, the change of Np compared to the old priority Op is controlled to lowerbound2; if the size of Delta is higher than the preset upper limit upperbound2, then in order to control the change of the new priority Np, the change of Np compared to the old priority Op is controlled to upperbound2.

6. A multi-factor optimized multi-level dynamic queue task scheduling system, characterized in that: include: The multi-level dynamic queue and task initialization module is used to initialize the multi-level dynamic queue and set the corresponding rotation time slice size and corresponding priority of each level of the multi-level dynamic queue; Initialize all tasks in the multi-level dynamic queue, set the priority of each task and the time required for each task to run; initialize the parameters involved in multi-factor optimization; insert the ready queue of the multi-level dynamic queue with the corresponding priority according to the priority of each task; The first task scheduling and running module is used to sequentially traverse the ready queues of levels 0 to N-1 of the multi-level dynamic queue, select the first task in the non-empty queue for scheduling and running, so that the task occupies the processor, the task state changes from the ready state to the running state, and at the same time delete the task from the ready queue of the multi-level dynamic queue; The multi-level dynamic queue and task scheduling module is used to check whether the rotation time slice of the current running task is exhausted every time the system timer interrupt occurs. If not, the current running task continues to run; if the rotation time slice is exhausted, it will check whether there is a new task added to the ready queue and waiting queue of the multi-level dynamic queue. If a new task is added, the priority of the current running task will be updated. Otherwise, the task scheduling will be performed directly, which will cause the current running task to give up the processor and change from the running state to the ready state. According to the new priority of the task, the task will be reinserted into the queue corresponding to the multi-level dynamic queue; The multi-level dynamic queue detection module is used to select the idle task of the system to occupy the processor and run when all queues of the multi-level dynamic queues are empty, indicating that all tasks have been completed.

7. The task scheduling system of multi-level dynamic queues with multi-factor optimization according to claim 6 is characterized in that: The multi-level dynamic queue and task initialization module includes a multi-level dynamic queue initialization unit, a task initialization unit, a multi-factor optimization parameter initialization unit, a system waiting Event matrix initialization unit, and a system waiting Resource matrix initialization unit.

8. An electronic device comprising at least one processor and a memory connected to the at least one processor in communication; characterized in that: The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the task scheduling method of the multi-stage dynamic queue with multi-factor optimization according to any one of claims 1-5.

9. A non-transitory computer-readable storage medium storing computer instructions, characterized in that: The computer instructions are used to enable the computer to execute the task scheduling method of a multi-stage dynamic queue with multi-factor optimization according to any one of claims 1 to 5.

10. A computer program product, comprising a computer program; characterized in that When the computer program is executed by a processor, the computer program implements the task scheduling method of a multi-stage dynamic queue with multi-factor optimization according to any one of claims 1 to 5.

Citation Information

Cited By

  • Air conditioner energy consumption calculation task scheduling method and device and server

    CN121169028A