Task round-robin scheduling method and device, electronic equipment and storage medium

By using round-robin scheduling to divide processes into scheduling queues based on process runtime and kernel scope in a multi-core processor, the problem of excessive process waiting time in embedded operating systems is solved, improving the real-time performance of task execution and system performance.

CN114968527BActive Publication Date: 2026-02-13NINGBO SANXING INTELLIGENT ELECTRIC
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210594067.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-27
Publication Date
2026-02-13
Estimated Expiration
2042-05-27

AI Technical Summary

Technical Problem

In embedded operating systems, when using the time-slice round-robin scheduling algorithm, processes with short runtimes may wait for too long, resulting in poor real-time performance of tasks. Furthermore, issues such as unreasonable time slice length settings and frequent process switching can affect system throughput and processor utilization.

Method used

In a multi-core processor, processes are added to the corresponding scheduling queue based on their runtime and the runtime range of the processor core. They are then scheduled in a round-robin fashion according to their time slice length. Process scheduling is optimized by calculating the remaining runtime and historical scheduling information, thus avoiding the mixed execution of short and long processes.

Benefits of technology

It shortens the waiting time of short-running processes, improves the real-time execution of task processes, reduces processor resource consumption and switching time, and enhances the overall performance of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114968527B_ABST
    Figure CN114968527B_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a task round-robin scheduling method and device, electronic equipment and storage medium, and relate to the field of operating system task scheduling. According to the received task round-robin scheduling instruction, a plurality of processes of a target task are obtained; according to the running time length of each process and the running time length range corresponding to each processor core, each process is added to the scheduling queue of the corresponding processor core; for each processor core, all processes in the scheduling queue are round-robin scheduled according to the time slice length corresponding to the processor core. The method avoids mixing the execution of processes with shorter running time length and processes with longer running time length, thereby shortening the waiting time and overall execution time of processes with shorter running time length, and improving the real-time performance of task process execution.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of operating system task scheduling, in particular to a task round-robin scheduling method and device, an electronic device and a storage medium. BACKGROUND

[0002] At present, in an embedded operating system, the scheduling of processes plays a crucial role in the utilization of processors, the real-time performance of task execution and the user experience. In the prior art, a time slice round-robin algorithm can be used to schedule processes.

[0003] However, when the time slice round-robin scheduling algorithm is used to schedule processes, there is often a problem that the waiting time of some processes with a short running time is too long, resulting in a long overall execution time of the processes and poor real-time performance of process execution. SUMMARY

[0004] Therefore, the present application aims to provide a task round-robin scheduling method and device, an electronic device and a storage medium to shorten the waiting time and overall execution time of processes with a short running time and improve the real-time performance of task execution.

[0005] To achieve the above-mentioned purpose, the technical solutions adopted by the embodiments of the present application are as follows:

[0006] In a first aspect, the present application provides a task round-robin scheduling method applied to an electronic device with a multi-core processor, and the method comprises the following steps:

[0007] According to the received task round-robin scheduling instruction, a plurality of processes of a target task are obtained;

[0008] According to the running time of each process and the running time range corresponding to each processor core, each process is added to the scheduling queue of the corresponding processor core;

[0009] For each processor core, all processes in the scheduling queue are round-robin scheduled according to the time slice length corresponding to the processor core.

[0010] In an optional implementation, the round-robin scheduling of all processes in the scheduling queue according to the time slice length corresponding to the processor core comprises:

[0011] According to the time slice length corresponding to the processor core, a target process in a ready state in the scheduling queue is scheduled;

[0012] After scheduling the target process according to the time slice length, if the target process is not executed completely, the target process is added to the tail of the scheduling queue, and the next process in the ready state in the scheduling queue is scheduled as a new target process until all processes in the scheduling queue are executed completely.

[0013] In an optional embodiment, the method further comprises:

[0014] calculating a remaining running time length of the target process;

[0015] judging whether the remaining running time length meets a preset running time length;

[0016] if the remaining running time length does not meet the preset running time length, scheduling the target process according to the remaining running time length;

[0017] if the remaining running time length meets the preset running time length, scheduling the target process in the ready state in the scheduling queue according to a time slice length corresponding to the processor core.

[0018] In an optional embodiment, the calculating the remaining running time length of the target process comprises:

[0019] obtaining a historical scheduling number of the target process and a historical running time length corresponding to each historical scheduling;

[0020] calculating the remaining running time length of the target process according to the historical scheduling number and the historical running time length.

[0021] In an optional embodiment, the calculating the remaining running time length of the target process according to the historical scheduling number and the historical running time length comprises:

[0022] calculating the remaining running time length according to the following formula:

[0023] T=aT n +a(1-a)T n-1 +…+a(1-a) n-1 T1

[0024] wherein, T represents the remaining running time length, a is a preset constant, n represents the historical scheduling number of the target process, T n represents the historical running time length corresponding to the nth scheduling of the target process, T n-1 represents the historical running time length corresponding to the (n-1)th scheduling of the target process, and T1 represents the historical running time length corresponding to the 1st scheduling of the target process.

[0025] In an optional embodiment, the method further comprises:

[0026] set a corresponding running time range for each processor core according to a running time of each process;

[0027] adding each process to a scheduling queue of a corresponding processor core according to a running time of each process and a corresponding running time range of each processor core, includes:

[0028] determining a target running time range to which the running time of each process belongs;

[0029] determining a corresponding processor core of each process according to the target running time range;

[0030] adding each process to a scheduling queue of a corresponding processor core.

[0031] In a second aspect, the present application provides a task round-robin scheduling device applied to an electronic device with a multi-core processor, the device includes:

[0032] an obtaining module, configured to obtain a plurality of processes of a target task according to a received task round-robin scheduling instruction;

[0033] an adding module, configured to add each process to a scheduling queue of a corresponding processor core according to a running time of each process and a corresponding running time range of each processor core;

[0034] a scheduling module, configured to perform round-robin scheduling on all processes in the scheduling queue according to a time slice length corresponding to each processor core.

[0035] In an optional implementation, the scheduling module is further configured to perform scheduling on a target process in a ready state in the scheduling queue according to the time slice length corresponding to the processor core; after performing scheduling on the target process according to the time slice length, if the target process is not executed completely, the target process is added to a tail of the scheduling queue, and a next process in a ready state in the scheduling queue is taken as a new target process for scheduling, until all processes in the scheduling queue are executed completely.

[0036] In a third aspect, the present application provides an electronic device including a multi-core processor and a memory, the memory stores a computer program capable of being executed by the processor, and the multi-core processor can execute the computer program to implement the method in any one of the preceding embodiments.

[0037] In a fourth aspect, the present application provides a computer readable storage medium, having stored thereon a computer program, which, when executed by a processor, implements the method according to any one of the preceding embodiments.

[0038] The task round-robin scheduling method, device, electronic device and storage medium provided by the embodiments of the present application, in the case of obtaining multiple processes of a target task, add each process to the scheduling queue of the corresponding processor core according to the running time of each process and the running time range corresponding to each processor core, thereby dividing the processes according to the running time, and dividing the processes belonging to different running time ranges to different processor cores for scheduling, so that the processes with shorter running time and the processes with longer running time can be avoided to be mixed for execution, thereby shortening the waiting time of the processes with shorter running time and the overall execution time, and improving the real-time performance of the task process execution.

[0039] In order to make the above objectives, characteristics and advantages of the present application more apparent and easy to understand, the following preferred embodiments are specifically described below, and the accompanying drawings are referred to, and the detailed description is as follows. BRIEF DESCRIPTION OF DRAWINGS

[0040] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiments. It should be understood that the following drawings only show some embodiments of the present application, and therefore should not be regarded as a limitation to the scope, and for those skilled in the art, other related drawings can also be obtained without creative labor on the basis of these drawings.

[0041] Figure 1 A block schematic diagram of an electronic device provided by the embodiments of the present application is shown;

[0042] Figure 2 A flowchart of a task round-robin scheduling method provided by the embodiments of the present application is shown;

[0043] Figure 3 Another flowchart of a task round-robin scheduling method provided by the embodiments of the present application is shown;

[0044] Figure 4 Another flowchart of a task round-robin scheduling method provided by the embodiments of the present application is shown;

[0045] Figure 5 Another flowchart of a task round-robin scheduling method provided by the embodiments of the present application is shown;

[0046] Figure 6 Another flowchart of a task round-robin scheduling method provided by the embodiments of the present application is shown;

[0047] Figure 7 A functional module diagram of the task round-robin scheduling apparatus provided by the embodiments of the present application is shown.

[0048] Icon: 100-electronic device; 110-memory; 120-multicore processor; 130-communication module; 200-obtaining module; 210-adding module; 220-scheduling module. DETAILED DESCRIPTION

[0049] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, but not all the embodiments of the present application. The components of the embodiments of the present application described and shown in the drawings can be arranged and designed in various different configurations.

[0050] Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the claimed present application, but only represents selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of the present application.

[0051] It should be noted that the relational terms such as "first" and "second" and the like are used only to distinguish one entity or operation from another, and do not necessarily require or imply that these entities or operations exist in any such actual relationship or order. Moreover, the terms "comprising", "including" or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, article or apparatus that includes a list of elements not only includes those elements, but also includes other elements not explicitly listed, or other elements inherent in such a process, method, article or apparatus. Without more limitations, the element defined by the statement "comprising a" does not exclude the presence of additional identical elements in the process, method, article or apparatus that includes the element.

[0052] At present, in an embedded operating system, the scheduling of a process plays a crucial role in the utilization of a processor, the real-time performance of a task and the experience of a user, and among numerous scheduling methods, the time slice round-robin scheduling algorithm is a relatively simple, most fair and most widely used algorithm.

[0053] In the prior art, when the time slice round-robin scheduling algorithm is used for process scheduling in an electronic device with a multicore processor, all processes are often mixed and randomly allocated to different processor cores, the processes are scheduled according to the allocated time slices, or the processes are sorted in combination with a task priority strategy, and then the processes are scheduled according to the time slices.

[0054] However, the method has the following problems:

[0055] 1. Whether all processes are mixed and then allocated, or the processes are sorted in combination with task priority measurement, the length of the execution time of the processes is not considered. That is, in the method, long processes with long execution times and short processes with short execution times are allocated together. In the case of too many processes, when the processes are scheduled by time slice rotation, if the long process is executed first, the waiting time of the short process will inevitably be increased, resulting in the problem of long execution time of many short processes and poor real-time performance of task processes.

[0056] 2. Because long processes with long execution times and short processes with short execution times are allocated together, and when setting the time slice length for the processes allocated in the processor core, the execution time of the processes needs to be considered, therefore, in this case, there is a problem of unreasonable time slice length setting: if the time slice length is set too long, the waiting time of each task will be increased, and in the extreme case, it will degenerate into a first-come-first-served situation; if the time slice length is set too short, frequent rotation switching between processes will affect the system throughput and the utilization of the processor.

[0057] 3. Because when scheduling processes by time slice rotation scheduling algorithm, sometimes multiple rotations are needed to complete the execution of a process, and currently the rotation switching of the process is often realized by the switching in and out of the process control block, in this case, additional processor resources are consumed, and additional switching time is needed, therefore, a process scheduled once cannot run a complete time slice.

[0058] On this basis, the application provides a task rotation scheduling method to solve the above problems.

[0059] Please refer to Figure 1 is a block diagram of an electronic device 100. The electronic device 100 can be a terminal device, such as a PC, etc., and the electronic device is provided with an open source operating system and a built-in task scheduler, such as FreeRTOS, uccos, linux, etc.

[0060] The electronic device 100 includes a memory 110, a multi-core processor 120, and a communication module 130. The memory 110, the multi-core processor 120, and the communication module 130 are directly or indirectly electrically connected to each other to realize the transmission or interaction of data. For example, these elements can be electrically connected to each other through one or more communication buses or signal lines.

[0061] The memory 110 is configured to store programs or data. The memory can be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), etc.

[0062] The multi-core processor 120 is configured to read / write data or programs stored in the memory and run corresponding functions. It can be understood that the multi-core processor 120 includes a plurality of processor cores.

[0063] The communication module 130 is configured to establish a communication connection between the electronic device 100 and other communication terminals through the network, and to receive / transmit data through the network.

[0064] It should be understood that, Figure 1 The structure shown is only a structural schematic diagram of the electronic device 100. The electronic device 100 can further include more or less components than those shown in the figure, or have a different configuration from that shown in the figure. Figure 1 The components shown in the figure can be implemented in hardware, software or a combination thereof. Figure 1 The components shown in the figure can be implemented in hardware, software or a combination thereof. Figure 1 The components shown in the figure can be implemented in hardware, software or a combination thereof.

[0065] The embodiment of the present application further provides a computer readable storage medium, which stores a computer program. When the computer program is run by the multi-core processor, the task rotation scheduling method provided by the embodiment of the present application can be implemented.

[0066] The task rotation scheduling method provided by the embodiment of the present application will be described below with the electronic device 100 as an execution subject. Specifically, Figure 2 For a flowchart of the task rotation scheduling method provided by the embodiment of the present application, please refer to Figure 2 The method comprises the following steps.

[0067] In step S20, according to the received task rotation scheduling instruction, a plurality of processes of a target task are acquired.

[0068] Optionally, the task rotation scheduling instruction is input by a user, and is a scheduling instruction for a target task, used to instruct to rotate schedule a plurality of processes of the target task. The target task is a task selected by the user and needed to be rotated and scheduled. It can be understood that the target task can be a plurality of tasks or one task, and for any target task, it can include a plurality of processes.

[0069] Optionally, after receiving the task rotation scheduling instruction, the electronic device needs to acquire the plurality of processes of the target task and related data of each process, and select a corresponding task scheduler according to a system type of the electronic device, and select a task rotation scheduling strategy for the plurality of processes.

[0070] In step S22, each process is added to a scheduling queue of a corresponding processor core according to a running time length of each process and a running time length range corresponding to each processor core.

[0071] Optionally, while acquiring the plurality of processes of the target task, the electronic device can estimate an execution time length of each process of the target task according to a task characteristic. It can be understood that the running time length of each process is a time length needed for each process to run completely, and the time length is an estimated time length.

[0072] Optionally, each processor core includes a scheduling queue, used to temporarily store a process needed to be scheduled in the processor core.

[0073] In this embodiment, the electronic device can add each process to a scheduling queue of a processor core corresponding to a running time length range according to the running time length of each process. In a possible implementation manner, the plurality of processes can be added to the scheduling queue according to a principle of first come first served, that is, a process coming first is arranged at a head of the scheduling queue, a process coming last is arranged at a tail of the scheduling queue, and the processes are scheduled in an order from the head to the tail.

[0074] In step S24, for each processor core, all processes in the scheduling queue are rotated and scheduled according to a time slice length corresponding to the processor core.

[0075] Optionally, the electronic device can set a corresponding time slice length for each processor core according to a running time length range of each processor core. The time slice length is a time length of execution of a process each time the process is scheduled in the processor core.

[0076] Optionally, the electronic device can rotate and schedule all processes in the scheduling queue in each processor core according to the time slice length of the processor core. That is, for a process, the process is only executed for a time slice length each time the process is scheduled, and then the next process is switched to be scheduled.

[0077] The task round-robin scheduling method provided in the embodiments of the present application can obtain a plurality of processes of a target task after receiving a task round-robin scheduling instruction, add each process to a scheduling queue of a corresponding processor core according to a running time length of each process and a running time length range corresponding to each processor core, thereby dividing the processes according to the running time length, dividing the processes belonging to different running time length ranges into different processor cores, and then scheduling the processes according to a time slice length, so that the processes with a relatively short running time length and the processes with a relatively long running time length can be prevented from being mixed for execution, thereby shortening the waiting time of the processes with a relatively short running time length and the overall execution time, and improving the real-time performance of the task process execution.

[0078] In addition, since the method avoids mixing the short processes with a relatively short running time length and the long processes with a relatively long running time length in the same processor core for scheduling, the corresponding time slice length can be reasonably set according to the running time length range corresponding to each processor core, the problem of a relatively long waiting time of the short processes caused by a too long time slice, and the problem of affecting the system throughput and the processor utilization caused by a too short time slice can be avoided.

[0079] Optionally, considering that the running time lengths of the processes included in the target task with different scheduling times and different task types can be quite different, when task round-robin scheduling is needed, the running time length range of the processor core can be divided according to the plurality of processes of the target task obtained, and each process can be added to the scheduling queue of the corresponding processor core according to the running time length.

[0080] Specifically, on the basis of Figure 2 , Figure 3 For a flowchart of the task round-robin scheduling method provided in the embodiments of the present application, please refer to Figure 3 , the method further includes:

[0081] In step S21, a running time length range corresponding to each processor core is set according to the running time length of each process.

[0082] Optionally, the electronic device can set the running time length range corresponding to each processor core according to the number of processor cores and the characteristic value of the running time length of each process. For example, the running time lengths of the processes are arranged in ascending order, and a characteristic value such as a median value or an average value is selected as a critical value of the running time length range, and the running time length range corresponding to each processor core is randomly set.

[0083] In one example, if the electronic device includes four processor cores, three runtime length critical values T1, T2, and T3 need to be determined according to the runtime lengths of the respective processes, and T1 < T2 < T3. On this basis, the runtime length ranges corresponding to the respective processor cores can be less than or equal to T1, greater than T1 and less than or equal to T2, greater than T2 and less than or equal to T3, and greater than T3, respectively.

[0084] On this basis, the above step S22 can also be implemented by the following steps:

[0085] Step S22-1, for each process, determining a target runtime length range to which the runtime length of the process belongs;

[0086] Optionally, for any process, the target runtime length range is the runtime length range to which the runtime length of the process belongs. It can be understood that the target runtime length range is one of the runtime length ranges corresponding to the plurality of processor cores.

[0087] Step S22-2, determining the processor core corresponding to the process according to the target runtime length range;

[0088] Step S22-3, adding the process to the scheduling queue of the corresponding processor core.

[0089] Optionally, since each processor core corresponds to a corresponding runtime length range, the processor core to which the process should be allocated can be determined according to the target runtime length range, and then the process is added to the scheduling queue of the corresponding processor core.

[0090] Optionally, considering that in the round-robin scheduling process, the same process may need to be rotated multiple times according to the time slice length before it is executed completely, the process that has not been executed completely can be re-added to the scheduling queue for scheduling.

[0091] Specifically, on the basis of Figure 2 , Figure 4 A flowchart of the task round-robin scheduling method provided by the embodiments of the present application is shown in Figure 4 The above step S24 of performing round-robin scheduling on all processes in the scheduling queue according to the time slice length corresponding to the processor core can also be implemented by the following steps:

[0092] Step S24-1, scheduling the target process in the ready state in the scheduling queue according to the time slice length corresponding to the processor core;

[0093] Optionally, at the current time, the plurality of processes in any processor core can be in different states, such as scheduling state, ready state, waiting state, and completion state.

[0094] The process in the scheduling state can be a process currently being scheduled; the process in the ready state can be a process at the head of the scheduling queue and next to be scheduled; the process in the waiting state can be a process in the scheduling queue and not at the head of the scheduling queue; and the process in the completion state can be a process that has been completely executed.

[0095] In step S24-2, after scheduling the target process according to the time slice length, if the target process has not been executed completely, the target process is added to the tail of the scheduling queue, and the next process in the ready state in the scheduling queue is scheduled as a new target process until all processes in the scheduling queue are scheduled and executed completely. Alternatively, the target process is scheduled according to the time slice length, i.e., the target process is scheduled and run for the time slice length. It can be understood that after the time slice length, the target process can not have been executed completely, but at this time, the processes need to be rotated and switched. Therefore, the process that has not been executed completely can be added to the tail of the scheduling queue again to wait for the next scheduling.

[0096] Alternatively, the scheduling queue is the scheduling queue in the processor core to which the target process is added at the beginning, i.e., when the target process is added to the scheduling queue again, the processor core is not switched, and the target process is added to the tail of the scheduling queue in the processor core.

[0097] Alternatively, when the target process is scheduled, the target process is removed from the head of the scheduling queue, and the process originally at the second position in the scheduling queue is at the head of the scheduling queue at this time, i.e., enters the ready state. Therefore, after the target process is scheduled according to the time slice length, the process in the ready state in the scheduling queue can be scheduled as a new target process according to the time slice length, and the processes are cycled in this way until all processes in the scheduling queue are executed completely.

[0098] It can be understood that when all processes in the scheduling queue are executed completely, the scheduling queue is an empty queue.

[0099] The task rotation scheduling method provided in the embodiments of the present application can add the target process to the scheduling queue in the processor core after the target process is scheduled according to the time slice length, without switching the processor core. Therefore, the process control block can be adjusted in and out frequently during task switching, the resource consumption of the processor and the additional switching time are reduced, and the running time of a process when the process is scheduled is close to the time slice length set maximally.

[0100] Optionally, when the processes are rotated according to the time slice length, there is sometimes a process that is about to be executed, but is hard switched due to meeting the time slice length. In order to avoid the hard switching problem, further reduce the switching times, and improve the resource utilization of the processor, the scheduling time of the process that is about to be executed can be adjusted by estimating the remaining running time of the process.

[0101] Specifically, based on the above, Figure 4 Figure 5 A flowchart of a task rotation scheduling method provided by the embodiment of the application is shown in Figure 5 The method further includes:

[0102] Step S10, calculating the remaining running time of the target process;

[0103] Step S11, judging whether the remaining running time meets the preset running time;

[0104] If yes, step S24-1 is executed; if no, step S12 is executed.

[0105] Optionally, the preset running time can be set according to the time slice length. In a possible implementation, the preset running time can be twice the time slice length.

[0106] Optionally, the remaining running time is the running time required for the target process to be executed, which is an estimated value in the embodiment.

[0107] Optionally, if the remaining running time meets the preset running time, that is, the remaining running time is greater than or equal to the preset running time, step S24-1 is executed, and the target process in the ready state in the scheduling queue is scheduled according to the time slice length corresponding to the processor core.

[0108] Optionally, if the remaining running time does not meet the preset running time, that is, the remaining running time is less than the preset running time, step S12 is executed.

[0109] Step S12, scheduling the target process according to the remaining running time;

[0110] Optionally, if the remaining running time of the target process in the ready state is less than the preset running time, it indicates that the target process is about to be executed, and the target process does not need to be scheduled according to the time slice length, but can be scheduled according to the preset running time.

[0111] It can be understood that after the target process is scheduled according to the remaining running time, the target process is executed. ​

[0112] Optionally, since the remaining running time length is an estimated value, there can be a case that the target process is not executed completely after being scheduled according to the remaining running time length, in which case the target process can be re-joined to the tail of the scheduling queue and wait for scheduling again.

[0113] The task round-robin scheduling method provided by the embodiments of the present application can calculate the remaining running time length of the target process in the ready state, and directly schedule the target process according to the remaining running time length in the case that the remaining running time length does not meet the preset running time length, thereby avoiding the hard switching problem of the process and further reducing the switching times and improving the resource utilization rate of the processor.

[0114] Optionally, the remaining running time length of the target process can be calculated according to the historical running time length and the historical running times of the target process, specifically, in the case that the target process is in the ready state, Figure 5 on the basis of Figure 6 For the flowchart of the task round-robin scheduling method provided by the embodiments of the present application, please refer to Figure 6 The calculation of the remaining running time length of the target process in the step S10 can also be realized by the following steps:

[0115] In step S10-1, the historical scheduling times of the target process and the historical running time length corresponding to each historical scheduling are obtained.

[0116] Optionally, since switching the process in the process scheduling process will produce additional switching time and the reaction time of the operating system, each process may not run the complete time slice length when being scheduled, that is, the actual running time of each process will fluctuate around the time slice length, on the basis of which, in order to improve the accuracy of the estimation, the historical running time length corresponding to each historical scheduling needs to be obtained.

[0117] Optionally, the historical scheduling times are the times that the target process in the ready state has been scheduled, and the historical running time length corresponding to each historical scheduling is the specific running time length of the target process when being scheduled each time. For example, if it is obtained that the target process has been scheduled twice, the obtained historical running time length is the historical running time length corresponding to the first time of being scheduled and the historical running time length obtained when being scheduled the second time.

[0118] Optionally, the historical scheduling times of the target process and the historical running time length corresponding to each historical scheduling can be obtained according to the process name of the target process or the identification information of the target process.

[0119] In step S10-2, the remaining running time length of the target process is calculated according to the historical scheduling times and the historical running time length.

[0120] Optionally, the remaining running time length of the target process can be calculated by the following formula:

[0121] T = aT n +a(1-a)T n-1 +…+a(1-a) n-1 T1

[0122] Wherein, T represents the remaining running time length, a is a preset constant, n represents the historical scheduling times of the target process, T n represents the historical running time length corresponding to the nth scheduling of the target process, T n-1 represents the historical running time length corresponding to the (n-1)th scheduling of the target process, and T1 represents the historical running time length corresponding to the 1st scheduling of the target process.

[0123] In one example, if the historical running times of a process are three times, then the remaining running time length of the target process in the ready state is:

[0124] T = aT3+a(1-a)T2+a(1-a)(1-a)T1

[0125] Optionally, a can be set in the electronic device in advance by the user according to specific circumstances.

[0126] In order to run the corresponding steps in the above embodiments and various possible manners, an implementation manner of a task round-robin scheduling device is given as follows. Please refer to Figure 7 , Figure 7 A functional module diagram of a task round-robin scheduling device provided by the embodiments of the present application. It should be noted that the basic principle and technical effects of the task round-robin scheduling device provided by the embodiments are the same as those of the above embodiments. For brief description, the part not mentioned in the embodiments can be referred to the corresponding content in the above embodiments. The task round-robin scheduling device comprises an acquisition module 200, an adding module 210, and a scheduling module 220.

[0127] The acquisition module 200 is configured to acquire a plurality of processes of a target task according to a received task round-robin scheduling instruction.

[0128] It can be understood that the acquisition module 200 can also perform the above step S20.

[0129] The adding module 210 is configured to add each process to a scheduling queue of a corresponding processor core according to the running time length of each process and the running time length range corresponding to each processor core.

[0130] It can be understood that the adding module 210 can also perform the above step S22.

[0131] The scheduling module 220 is configured to perform round-robin scheduling on all processes in the scheduling queue according to the time slice length corresponding to each processor core.

[0132] It can be understood that the scheduling module 220 can also perform the step S24.

[0133] Optionally, the scheduling module 220 is further configured to schedule the target process in the ready state in the scheduling queue according to the time slice length corresponding to the processor core; after scheduling the target process according to the time slice length, if the target process is not executed completely, the target process is added to the tail of the scheduling queue, and the next process in the ready state in the scheduling queue is scheduled as a new target process until all processes in the scheduling queue are executed completely.

[0134] It can be understood that the scheduling module 220 can also perform the steps S24-1 to S24-2.

[0135] Optionally, the scheduling module 220 is further configured to calculate the remaining running time length of the target process; determine whether the remaining running time length meets the preset running time length; if the remaining running time length does not meet the preset running time length, schedule the target process according to the remaining running time length; and if the remaining running time length meets the preset running time length, schedule the target process in the ready state in the scheduling queue according to the time slice length corresponding to the processor core.

[0136] It can be understood that the scheduling module 220 can also perform the steps S10 to S12.

[0137] Optionally, the scheduling module 220 is further configured to obtain the historical scheduling times of the target process and the historical running time length corresponding to each historical scheduling time; and calculate the remaining running time length of the target process according to the historical scheduling times and the historical running time length.

[0138] It can be understood that the scheduling module 220 can also perform the steps S10-1 to S10-2.

[0139] Optionally, the scheduling module 220 is further configured to calculate the remaining running time length according to the following formula:

[0140] T=aT n +a(1-a)T n-1 +…+a(1-a) n-1 T1

[0141] wherein T represents the remaining running time length, a is a preset constant, n represents the historical scheduling times of the target process, T n represents the historical running time length corresponding to the nth scheduling of the target process, T n-1T1 represents the historical running time length corresponding to the first time the target process is scheduled.

[0142] Optionally, the adding module 210 is further configured to set a corresponding running time length range for each processor core according to the running time length of each process; determine, for each process, a target running time length range to which the running time length of the process belongs; determine, according to the target running time length range, a processor core corresponding to the process; and add the process to a scheduling queue of the corresponding processor core.

[0143] It can be understood that the adding module 210 can also perform the above steps S21, S22-1 to S22-3.

[0144] The task round-robin scheduling device provided by the embodiments of the present application acquires, by the acquiring module, a plurality of processes of a target task according to a received task round-robin scheduling instruction; adds, by the adding module, each process to a scheduling queue of a corresponding processor core according to the running time length of each process and a running time length range corresponding to each processor core; and performs, by the scheduling module, round-robin scheduling on all processes in the scheduling queue according to the time slice length corresponding to each processor core, which avoids mixing execution of a task with a shorter running time length and a task with a longer running time length, thereby shortening the waiting time of the task with the shorter running time length and improving the real-time performance of task execution.

[0145] Optionally, the above modules can be stored in the memory shown in the form of software or firmware (Firmware) or solidified in the operating system (Operating System, OS) of the electronic device, and can be run by the processor in the electronic device. Figure 1 The data, program code, and the like required for running the above modules can be stored in the memory. Figure 1

[0146] ​In several embodiments provided in the present application, it should be understood that the disclosed apparatus and method can also be implemented by other manners. The apparatus embodiments described above are merely illustrative, for example, the flowcharts and block diagrams in the drawings show the possible implementation architecture, function and operation of the apparatus, method and computer program product according to the embodiments of the present application. In this regard, each block in the flowcharts or block diagrams can represent a module, a program segment or a part of code, which contains one or more executable instructions for implementing the specified logic function. It should also be noted that in some alternative implementations, the functions noted in the blocks can occur in different orders from those noted in the drawings. For example, two consecutive blocks can actually run substantially in parallel, and sometimes they can run in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and the combination of blocks in the block diagrams and / or flowcharts, can be implemented by a dedicated hardware-based system that runs the specified functions or actions, or can be implemented by a combination of dedicated hardware and computer instructions.

[0147] In addition, the function modules in the embodiments of the present application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.

[0148] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for causing 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 methods described in the embodiments of the present application. The aforementioned storage medium includes various media that can store program codes, such as a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.

[0149] The above only describes the preferred embodiments of the present application and is not intended to limit the present application. For those skilled in the art, the present application can have various modifications and changes. Any modification, equivalent replacement, improvement, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application.

Claims

1. A method of round-robin scheduling of tasks, characterized by, The method is applied to an electronic device with a multi-core processor, and the method comprises the following steps: According to the received task round-robin scheduling instruction, a plurality of processes of a target task are obtained; According to the running time length of each process and the running time length range corresponding to each processor core, each process is added to the scheduling queue of the corresponding processor core; the running time length is a pre-estimated time length obtained according to the task characteristics of the target task; For each processor core, the round-robin scheduling is performed on all processes in the scheduling queue according to the time slice length corresponding to the processor core; The method further comprises the following steps: According to the running time length of each process, a corresponding running time length range is set for each processor core; The step of adding each process to the scheduling queue of the corresponding processor core according to the running time length of each process and the running time length range corresponding to each processor core comprises the following steps: For each process, a target running time length range to which the running time length of the process belongs is determined; According to the target running time length range, the processor core corresponding to the process is determined; 2. The method of claim 1, wherein, The process is added to the scheduling queue of the corresponding processor core. The step of performing the round-robin scheduling on all processes in the scheduling queue according to the time slice length corresponding to the processor core comprises the following steps: According to the time slice length corresponding to the processor core, a target process in a ready state in the scheduling queue is scheduled; 3. The method of claim 2, wherein, After the target process is scheduled according to the time slice length, if the target process is not executed completely, the target process is added to the tail of the scheduling queue, and the next process in a ready state in the scheduling queue is scheduled as a new target process until all processes in the scheduling queue are executed completely. The method further comprises the following steps: The remaining running time length of the target process is calculated; It is judged whether the remaining running time length meets a preset running time length; If the remaining running time length does not meet the preset running time length, the target process is scheduled according to the remaining running time length; 4. The method of claim 3, wherein, If the remaining running time length meets the preset running time length, a target process in a ready state in the scheduling queue is scheduled according to the time slice length corresponding to the processor core. The step of calculating the remaining running time length of the target process comprises the following steps: The historical scheduling times of the target process and the historical running time length corresponding to each historical scheduling are obtained; 5. The method of claim 4, wherein, According to the historical scheduling times and the historical running time length, the remaining running time length of the target process is calculated. The step of calculating the remaining running time length of the target process according to the historical scheduling times and the historical running time length comprises the following steps: wherein, characterizes the remaining running time length, is a preset constant, n characterizes the historical scheduling times of the target process, characterizes the historical running time length corresponding to the nth time of scheduling the target process, characterizes the historical running time length corresponding to the n-1th time of scheduling the target process, characterizes the historical running time length corresponding to the 1st time of scheduling the target process.

6. A task round-robin scheduling apparatus characterized by comprising: The remaining running time length is calculated according to the following formula: The device is applied to an electronic device with a multi-core processor, and the device comprises the following modules: An obtaining module is configured to obtain a plurality of processes of a target task according to a received task round-robin scheduling instruction; The adding module is configured to add each process to a scheduling queue of a corresponding processor core according to a running time of each process and a running time range corresponding to each processor core, wherein the running time is an estimated time obtained according to a task characteristic of the target task; The scheduling module is configured to perform round-robin scheduling on all processes in the scheduling queue according to a time slice length corresponding to each processor core. The adding module is further configured to set a corresponding running time range for each processor core according to a running time of each process, determine a target running time range to which the running time of each process belongs, determine a processor core corresponding to each process according to the target running time range, and add each process to a scheduling queue of the corresponding processor core.

7. The apparatus of claim 6, wherein, The scheduling module is further configured to perform scheduling on a target process in a ready state in the scheduling queue according to a time slice length corresponding to each processor core, and after performing scheduling on the target process according to the time slice length, if the target process is not executed completely, add the target process to a tail of the scheduling queue, perform scheduling on a next process in a ready state in the scheduling queue as a new target process, and repeat the above operations until all processes in the scheduling queue are executed completely.

8. An electronic device, comprising: A computer program product comprising a multi-core processor and a memory, the memory storing a computer program capable of being executed by the multi-core processor, the multi-core processor being capable of executing the computer program to implement the method of any one of claims 1-5.

9. A computer readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the multi-core processor to implement the method of any one of claims 1-5.

Citation Information

Patent Citations

  • Job scheduling method and device, host and storage medium

    CN111897637A

  • Method and apparatus for efficient scheduling of multithreaded programs

    US20140208330A1