Scheduling method and computer system
By configuring multiple queues on the physical CPU and dynamically adjusting the scheduling priority of the virtual CPU, the processing performance problem caused by the lack of distinction between task types in the virtualization scenario is solved, and the real-time execution of tasks and efficient allocation of resources are achieved.
Patent Information
- Application Number
- CN202210210979.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-04
- Publication Date
- 2026-02-06
- Estimated Expiration
- 2042-03-04
AI Technical Summary
In virtualization scenarios, existing technologies fail to effectively differentiate task types due to the scheduling methods for virtual CPUs, resulting in long queues for I/O-intensive tasks that consume relatively few resources, thus affecting processing performance.
By configuring multiple queues on the physical CPU with different scheduling priorities, virtual CPUs are scheduled sequentially, and their scheduling priorities are dynamically adjusted according to the cumulative running time of the virtual CPUs. High scheduling priority is used for tasks that consume fewer resources, and low scheduling priority is used for tasks that consume more resources, so as to ensure the real-time execution of tasks and the reasonable allocation of resources.
It improves the processing performance of the virtual CPU, ensures the processing efficiency of different types of tasks, guarantees the real-time performance of I/O-intensive tasks, and meets the resource requirements of computationally intensive tasks.
Smart Images

Figure CN114661415B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present application relate to the technical field of computer, and particularly, to a scheduling method and a computer system. BACKGROUND
[0002] In a virtualization scenario, the CPU (Central Processing Unit) allocated to a virtual machine is not a real or physical CPU (Physical Central Processing Unit, PCPU), but a virtual CPU (Virtual Central Processing Unit, VCPU). When the virtual CPU allocated to the virtual machine is scheduled to run on a physical CPU, it can execute tasks. Therefore, it involves scheduling the virtual CPU to the physical CPU.
[0003] In the related art, a physical CPU can have multiple virtual CPUs simultaneously preempt resources, and multiple virtual CPUs can wait to be scheduled to run in the running queue of the physical CPU. After each virtual CPU runs for a time slice, if the corresponding computing task has not been executed, the virtual CPU will continue to join the tail of the running queue and continue to wait to be scheduled to run. In order to ensure fairness, the time slice of the physical CPU is usually evenly allocated to multiple virtual CPUs in the running queue. However, for a virtual machine CPU that executes a task consuming less resources, such as a virtual CPU that executes an I / O intensive task, it may be in a queuing state for a long time, thereby affecting the processing performance. SUMMARY
[0004] Embodiments of the present application provide a scheduling method and a computer system to solve the technical problem of affecting the processing performance in the prior art.
[0005] In a first aspect, a scheduling method is provided in embodiments of the present application, comprising:
[0006] scheduling virtual CPUs in a plurality of queues configured by a physical CPU to run in turn according to scheduling priorities corresponding to the plurality of queues respectively;
[0007] in a case where the accumulated running time of a virtual CPU of any virtual machine reaches the set running time of the virtual machine corresponding to the current scheduling priority of the virtual machine, reducing the scheduling priority of the virtual machine, and adding at least one virtual CPU in a start state in the virtual machine to the queue corresponding to the current scheduling priority of the virtual machine; wherein the set running time of the virtual machine corresponding to a plurality of scheduling priorities increases in turn according to the order of scheduling priority from high to low.
[0008] In a second aspect, the embodiments of the present application provide a scheduling method, comprising:
[0009] According to the scheduling priorities of the multiple queues configured by the CPU, execution units in the multiple queues are sequentially scheduled to run;
[0010] When the cumulative running time of the execution unit of any execution entity reaches the device running time of the execution entity corresponding to the current scheduling priority, the scheduling priority of the execution entity is lowered, and at least one execution unit in the execution entity in the starting state is added to the queue corresponding to the current scheduling priority of the execution entity; wherein the set running time of the execution entity corresponding to the multiple scheduling priorities increases in turn according to the order of the scheduling priorities from high to low.
[0011] In a third aspect, the embodiments of the present application provide a computer system, comprising a storage component and a processing component; the processing component comprises at least one physical CPU; the storage component stores one or more computer instructions; the one or more computer instructions are used to be called and executed by the processing component to implement the scheduling method of the first aspect or the scheduling method of the second aspect.
[0012] In the embodiments of the present application, the physical CPU is configured with multiple queues corresponding to different scheduling priorities, each virtual machine is respectively provided with a set running time corresponding to multiple scheduling priorities, and the set running time corresponding to the multiple scheduling priorities increases in turn according to the order of the scheduling priorities from high to low; when the virtual CPU is scheduled to run on the physical CPU, the virtual CPU in the multiple queues is sequentially scheduled to run according to the order of the scheduling priorities of the multiple queues from high to low, and when the cumulative running time of the virtual CPU of any virtual machine reaches the set running time of the virtual machine corresponding to the current scheduling priority, the scheduling priority of the virtual machine is lowered and at least one virtual CPU in the virtual machine in the starting state is added to the queue corresponding to the scheduling priority of the virtual machine; through the embodiments of the present application, the set running time corresponding to the high scheduling priority is the shortest, the virtual CPU executing the task consuming less CPU resource mainly runs in the queue corresponding to the high scheduling priority, the virtual CPU executing the task consuming more CPU resource is degraded to run in the queue of low priority, and the queue of high scheduling priority is preferentially scheduled, so that the virtual CPU executing the task consuming less CPU resource can timely interrupt and preempt the virtual CPU of low scheduling priority, thereby reducing the impact of the high-load virtual machine on the low-load virtual machine, ensuring the real-time performance of the task execution of the virtual CPU executing the task consuming less CPU resource, providing better processing performance for different types of tasks, and ensuring the processing performance of the virtual CPU.
[0013] These and other aspects of the present application will become more apparent from the following description. BRIEF DESCRIPTION OF DRAWINGS
[0014] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, hereinafter, a brief introduction will be given to the drawings needed to be used in the description of the embodiments or the prior art. Obviously, the drawings described below are some embodiments of the present application, and for those skilled in the art, other drawings can also be obtained without creative labor on the basis of these drawings.
[0015] Figure 1 A flow chart of an embodiment of the scheduling method provided by the present application is shown;
[0016] Figure 2 A flow chart of another embodiment of the scheduling method provided by the present application is shown;
[0017] Figure 3 A scheduling interaction schematic diagram in an actual application of an embodiment of the present application is shown;
[0018] Figure 4 A flow chart of the scheduling method in an actual application of an embodiment of the present application is shown;
[0019] Figure 5 A structural schematic diagram of an embodiment of the scheduling device provided by the present application is shown;
[0020] Figure 6 A structural schematic diagram of an embodiment of the computer system provided by the present application is shown. DETAILED DESCRIPTION
[0021] In order to enable those skilled in the art to better understand the technical solutions of the present application, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application.
[0022] In some of the processes described in the specification and the claims of the present application and the above-described drawings, a plurality of operations appear in a specific order, but it should be clearly understood that these operations can be executed or performed in parallel or in a sequence different from that in which they appear in the present text. The serial numbers of the operations, such as 101, 102, etc., are only used to distinguish different operations, and the serial numbers themselves do not represent any execution sequence. In addition, these processes can include more or fewer operations, and the operations can be executed or performed in sequence or in parallel. It should be noted that the descriptions of "first", "second", etc. in the present text are used to distinguish different messages, devices, modules, etc., and do not represent the sequence, nor do "first" and "second" represent different types.
[0023] The technical scheme of the embodiment of the present application is applied to a physical CPU (Central Processing Unit) scheduling scene, and relates to how execution units such as virtual CPUs, processes or threads are scheduled and run in a physical CPU.
[0024] In order to facilitate understanding of the technical scheme of the present application, the following explains technical terms that may be involved in the embodiment of the present application:
[0025] Virtual Machine: a complete computer system running in a completely isolated environment through software simulation, which has complete hardware system functions.
[0026] Virtual Central Processing Unit (VCPU for short): a CPU simulated by virtual machine technology, which is not a physical CPU, and multiple virtual CPUs in virtualization technology may share the resources of a same physical CPU.
[0027] Queue: a structure instance corresponding to a physical CPU, which can be understood as a linear table with limited operations, and is used to organize execution units in a ready state together and schedule them in a physical CPU in turn according to a queue order, such as a first-in first-out order.
[0028] Scheduler: a kernel module used to schedule execution units in a queue to run in a physical CPU.
[0029] Computing-intensive task: computing-intensive refers to the fact that the hard disk and memory performance of a system are much better than that of a CPU; and a computing-intensive task refers to a task that needs to perform a large amount of computation and consumes a large amount of CPU resources, and the I / O (Input / Output) operation of the computing-intensive task can be completed in a very short time, while the CPU has many operations to process, and the CPU load is very high.
[0030] I / O-intensive task: I / O-intensive refers to the fact that the CPU performance of a system is much better than that of a hard disk and memory; and an I / O-intensive task refers to a task that consumes less CPU resources and spends most of the time waiting for I / O operations, and the CPU load is low.
[0031] Execution unit: The execution unit herein refers to a unit scheduled to run in a CPU to perform a specific task, which can refer to a process, a thread, or a virtual CPU, etc. The execution unit corresponds to an execution entity, and one execution entity can include one or more execution units. For example, the execution entity is a virtual machine, and the execution unit can refer to a virtual CPU. The execution entity is a process, and the execution unit can refer to a thread, etc. Wherein, after the virtual CPU is scheduled to the physical CPU to obtain the use right, the virtual operating system running based on the virtual CPU can schedule the processes / threads in the virtual machine to run in the virtual CPU. In addition, the processes / threads in the physical environment are also scheduled to run in the physical CPU.
[0032] Taking a virtualization scenario as an example, as described in the background, there are multiple virtual machine CPUs competing for resources in one physical CPU. In order to ensure fairness, in the related art, the physical CPU is time-shared in a multiplexing manner, and the time of the CPU is divided into multiple time slices, which are uniformly allocated to the waiting virtual CPUs in the queue. However, this method will affect the real-time performance of the execution of the task consuming less resources.
[0033] The inventors find in the process of implementing the present application that for a task consuming more resources, what is needed is the absolute resource of the CPU, and the delay is not concerned, for example, for a computing-intensive task requiring 40% CPU resource, it does not matter whether all the CPU resources are obtained within the first 400 milliseconds of 1 second or whether the 40% CPU resource is obtained after waiting for 600 milliseconds; for a task consuming less resource, the CPU resource requirement is not high, but the delay is very sensitive, for example, for an I / O-intensive task requiring 5% CPU resource, if all the requests delivered to the CPU for processing can be completed within the first 50 milliseconds of 1 second, then the I / O operation can continue efficiently, if the I / O operation starts in the last 50 milliseconds of 1 second, then the I / O operation is in a stagnant state for the first 950 milliseconds, causing serious bandwidth damage and affecting the real-time performance of the task. Since different tasks have different loads, assuming that there are computing-intensive virtual CPUs and I / O-intensive virtual CPUs that simultaneously compete for physical CPU resources, the computing-intensive virtual CPUs are often well satisfied, while the performance of the I / O-intensive virtual CPUs is severely damaged. In particular, in the cloud computing scenario, the number of virtual CPUs is much larger than the number of physical CPUs provided by the cloud computing platform, so the competition for physical CPU resources is more serious, resulting in queuing delay of the I / O-intensive CPU and affecting the real-time performance of the task. Accordingly, the inventors have found that after a series of researches, the technical scheme of the present application is proposed, which on the one hand guarantees the real-time performance of the task consuming less resource, and on the other hand guarantees the absolute resource required by the task consuming more resource, so as to improve the processing performance of the virtual CPU.
[0034] 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 part of the embodiments of the present application, not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor fall within the scope of protection of the present application.
[0035] Figure 1 A flowchart of one embodiment of a scheduling method provided by the embodiments of the present application can include the following steps:
[0036] 101: According to the scheduling priority of the plurality of queues configured by the CPU, the execution units in the plurality of queues are sequentially scheduled and run.
[0037] In the embodiment, each CPU can be configured to correspond to a plurality of queues having different scheduling priorities. The CPU can be a physical CPU or a virtual CPU, the execution unit can be an actual operation unit of an execution subject, one execution subject can correspond to one or more execution units, and one CPU can correspond to one or more execution subjects. When the CPU is a virtual CPU, the execution unit can be a thread that needs to be scheduled to run in the virtual CPU, and the corresponding execution subject can be a process; when the CPU is a physical CPU, the execution unit can be a virtual CPU, and the corresponding execution subject can be a virtual machine; or the execution unit can be a thread, and the corresponding execution subject can be a process.
[0038] The execution unit that needs to consume CPU resources to run also corresponds to a scheduling priority, and the scheduling priority of each execution unit can be the scheduling priority of the execution subject to which the execution unit belongs, that is, the scheduling priorities of the execution units included in one execution subject are the same. Alternatively, the initial scheduling priority of each execution subject can be the highest scheduling priority.
[0039] In addition, in order to further ensure the real-time performance of the task, the scheduling priority of at least one execution subject corresponding to the CPU can be periodically adjusted to the highest scheduling priority, and the execution unit of the at least one execution subject in the start state is added to the queue corresponding to the highest scheduling priority.
[0040] The technical scheme of the embodiment of the application can be executed by a scheduler, which can specifically schedule the execution units in the plurality of queues in order of scheduling priority, that is, from high to low.
[0041] 102: Accumulate the running time of the execution unit of any execution entity, and if the accumulated running time reaches the set running time of the execution entity corresponding to the current scheduling priority, adjust the scheduling priority of the execution entity and add at least one execution unit in the start state of the execution entity to the corresponding queue.
[0042] The execution unit is used to execute a task consuming CPU resources, and the execution unit receiving the task is woken up to switch from the sleep state to the start state to wait to be scheduled to run in the CPU. Each execution unit receives a task and is woken up, and then is added to the corresponding queue according to the scheduling priority corresponding to the execution unit.
[0043] The CPU can be divided into multiple time slices, and each execution unit is scheduled to run in a time slice in the CPU. The CPU can uniformly divide the multiple time slices and allocate them to each execution unit. The running time of each execution unit in the CPU can be integrated to obtain the cumulative running time of the execution unit corresponding to the CPU for each execution subject. The cumulative running time of the execution unit can refer to the sum of the total running time of each execution unit in the execution subject.
[0044] The set running time of each execution entity corresponding to the multiple scheduling priorities increases in turn from high to low according to the scheduling priority. Optionally, the set running time of each execution entity corresponding to the lowest scheduling priority can be infinite time, that is, no time limit is set for the lowest scheduling priority. For other scheduling priorities that are not the lowest scheduling priority, the set running time can be configured in advance according to the specifications of each execution subject. Optionally, the set running time of the highest scheduling priority corresponding to the execution subject can be determined first according to the specifications of the execution subject, such as the number of execution units started, and then the set running time of other scheduling priorities can be determined based on the set running time of the highest scheduling priority. According to the specifications of the execution subject, the proportion of CPU resources that the execution subject can consume when executing a task can be determined, and the set running time is configured accordingly. The higher the scheduling priority, the smaller the set running time.
[0045] In this embodiment, according to the cumulative running time of the execution unit of any execution subject, if the cumulative running time of the execution unit reaches the set running time corresponding to the current scheduling priority of the execution subject, that is, the cumulative running time of the execution unit is greater than or equal to the set running time, which means that the set running time cannot meet the CPU running time required by the execution subject, and the execution subject can execute a task that consumes more resources. At this time, the scheduling priority of the execution subject can be lowered, and at least one execution unit of the execution subject in the start state can be added to the queue corresponding to the current scheduling priority of the execution subject, so as to lower the scheduling priority of the execution unit of the execution subject, reduce the impact on the execution unit that executes a task that consumes less resources, ensure the real-time performance of task execution, and add the execution unit that executes a task that consumes more resources to the queue of a low scheduling priority. The low scheduling priority corresponds to a larger set running time, which can also ensure that the execution unit that executes a task that consumes more resources can fully obtain resources, thereby improving the processing performance of the virtual CPU.
[0046] Optionally, lowering the scheduling priority of the execution subject can be lowering the execution subject by one scheduling priority, so that the execution unit in the execution subject that executes a task that consumes more resources can be gradually added to the queue of the lowest scheduling priority in a step-by-step manner.
[0047] In the case that the accumulated running time of the execution unit of each execution subject is less than the set running time of the execution subject corresponding to the current scheduling priority, the current scheduling priority of the execution subject can be kept unchanged, and after the execution unit of the execution subject runs for a time slice in the CPU, the execution unit will enter the tail of the queue where it is currently located to continue waiting for scheduling.
[0048] In an actual application, the technical solution of the embodiment of the present application can be applied to a virtualization scenario, the execution subject can be a virtual machine, the execution unit can be a virtual CPU of the virtual machine, and the virtual CPU is scheduled to a physical CPU to run to execute a corresponding task. In one or more embodiments below, the technical solution of the present application is introduced mainly by taking scheduling of the physical CPU as an example. Figure 2 The scheduling method provided in the embodiment of the present application is shown in a flowchart, and the technical solution of the embodiment can be executed by a scheduler. The method can include the following steps:
[0049] 201: The virtual CPUs in the multiple queues are scheduled in turn according to the scheduling priorities corresponding to the multiple queues configured by the physical CPU.
[0050] In the embodiment of the present application, one virtual machine can correspond to one or more virtual CPUs, and the multiple virtual CPUs of one or more virtual machines can be scheduled to run in one physical CPU. After a virtual CPU accepts a task, the virtual CPU is woken up, thereby switching from a dormant state to an activated state to wait for being scheduled to run in the corresponding physical CPU.
[0051] The physical CPU can be configured with multiple queues, and the multiple queues correspond to different scheduling priorities respectively. Each virtual CPU woken up to wait for being scheduled to run in the physical CPU also corresponds to a scheduling priority, and each virtual CPU can first join the corresponding queue to wait for being called to run according to the corresponding scheduling priority. The calling priority of each virtual CPU can be the scheduling priority of the virtual machine to which the virtual CPU belongs, that is, the scheduling priorities of the execution units of the virtual CPUs in activated state in one virtual machine are the same. Alternatively, the initial scheduling priority of each virtual machine can be the highest scheduling priority.
[0052] In addition, in order to further ensure the real-time performance of task execution, the scheduling priority of at least one virtual machine corresponding to the physical CPU can be periodically adjusted to the highest priority, and multiple virtual CPUs in activated state in the at least one virtual machine are added to the queue corresponding to the highest scheduling priority, that is, at the beginning of each scheduling period, the scheduling priorities of all virtual CPUs waiting for scheduling in the physical CPU can be adjusted to the highest priority. In this implementation manner, the initial scheduling priority of each virtual machine can also be any one of the scheduling priorities.
[0053] 202: accumulating running time of virtual CPUs in any virtual machine, and in case that the running time reaches the set running time of the virtual machine corresponding to the current scheduling priority of the virtual machine, lowering the scheduling priority of the virtual machine and adding at least one virtual CPU in the start state in the virtual machine to the queue corresponding to the current scheduling priority of the virtual machine; wherein the set running time of the virtual machine corresponding to the multiple scheduling priorities increases in turn according to the order of scheduling priority from high to low.
[0054] Wherein the virtual CPU is used to execute tasks, and the virtual CPU receiving the task will be woken up to switch to the start state and added to the corresponding queue to wait to be scheduled to run in the physical CPU. Each virtual CPU receives a task and wakes up, and then specifically adds to the corresponding queue according to the corresponding scheduling priority. After each virtual CPU task is completed, it is removed from the queue and enters the sleep state until it is woken up again.
[0055] Wherein multiple time slices can be divided, and each virtual CPU is scheduled to run in the physical CPU for an allocated time slice. The CPU can evenly divide multiple time slices and allocate to each virtual CPU in the queue, etc. The total running time of each virtual CPU in the physical CPU can be integrated to obtain the cumulative running time of the virtual CPU in the physical CPU of each virtual machine, that is, the cumulative running time of the virtual CPU refers to the sum of the total running time of each virtual CPU in the virtual machine. Alternatively, in case of periodically adjusting the scheduling priority of at least one virtual machine corresponding to the physical CPU, the cumulative running time of the virtual CPU can specifically refer to the cumulative running time of the virtual machine in the current adjustment period, that is, the sum of the total running time of each virtual CPU in the virtual machine in the current adjustment period. The cumulative running time is recalculated in each adjustment period.
[0056] Wherein the set running time of each virtual machine corresponding to the multiple queues increases in turn according to the order of scheduling priority from high to low. Alternatively, the set running time of each virtual machine corresponding to the lowest scheduling priority can be infinite time, that is, no time limit is set for the lowest scheduling priority. For other scheduling priorities that are not the lowest scheduling priority, the set running time can be pre-configured according to the specifications of each virtual machine. Wherein the specifications of the virtual machine define the basic attributes of the virtual machine in terms of computing performance, storage performance, network performance, etc., such as including the number of virtual CPUs, memory size, etc.
[0057] Optionally, according to the specification of the virtual machine, the set running time corresponding to the highest scheduling priority of the virtual machine can be determined first, and then the set running time of other scheduling priorities can be determined based on the set running time of the highest scheduling priority, for example, the set running time of other scheduling priorities can be set to twice the set running time of the previous scheduling priority, etc. Of course, the present application does not make specific limitations thereon, and it can be set in combination with the actual situation, etc. Wherein, the higher the scheduling priority, the smaller the corresponding set running time.
[0058] In the embodiment, when the accumulated running time of the virtual CPU of the virtual machine reaches the set running time of the current scheduling priority of the virtual machine, it means that the set running time cannot meet the CPU time required by the virtual machine, and it is possible to execute a task consuming more resources. At this time, the scheduling priority of the virtual machine can be lowered, and at least one virtual CPU in the starting state for executing a task in the virtual machine can be added to the queue corresponding to the current scheduling priority of the virtual machine, so as to lower the virtual CPU scheduling priority of the virtual machine, reduce the impact on the virtual CPU in the virtual machine executing a task consuming less resources, ensure the real-time performance of task execution, and add the virtual CPU executing a task consuming more resources to the queue of low scheduling priority, which corresponds to a larger set running time, and can also ensure that the virtual CPU executing a task consuming more resources can obtain sufficient CPU resources.
[0059] Optionally, lowering the scheduling priority of the virtual machine can be lowering the virtual machine by one scheduling priority, so as to gradually add the virtual CPU in the virtual machine executing a task consuming more resources to the queue of the lowest scheduling priority in a step-by-step manner, so as to ensure the effective execution of the task. Therefore, in some embodiments, the lowering of the scheduling priority of the virtual machine and the addition of at least one virtual CPU in the starting state to the corresponding queue can include:
[0060] lowering the virtual machine by one scheduling priority;
[0061] adding at least one virtual CPU of the virtual machine in the starting state to the queue corresponding to the current scheduling priority of the virtual machine.
[0062] Wherein, if the accumulated running time of the virtual CPU of any virtual machine is less than the set running time corresponding to the current scheduling priority of the virtual machine, the current scheduling priority of the virtual machine can be kept unchanged, and the virtual CPU of the virtual machine will enter the tail of the current queue to continue waiting for scheduling after running a time slice in the physical CPU, etc.
[0063] The embodiments of the present application dynamically adjust the scheduling priority of the virtual CPU according to the CPU time consumed by the virtual CPU, ensure that the virtual CPU consuming more resources, such as the compute-intensive virtual CPU, is in a lower scheduling priority to consume the remaining CPU resources, and the virtual CPU consuming less resources, such as the I / O-intensive virtual CPU, is in the highest scheduling priority, so as to interrupt and preempt the low-scheduling-priority virtual CPU in time, improve the real-time performance of task execution, on the one hand, ensure the response time of the virtual CPU such as the I / O-intensive virtual CPU, and on the other hand, try to use the remaining CPU resources to serve more compute-intensive virtual machine CPUs.
[0064] In some embodiments, in a case where the cumulative running time of the virtual CPU of any virtual machine reaches the set running time corresponding to the current scheduling priority of the virtual machine, the scheduling priority of the virtual machine is lowered, and the joining of the at least one virtual CPU in the start state into the corresponding queue can include:
[0065] In a case where the current time slice running of any virtual CPU of any virtual machine ends or any virtual CPU is woken up, it is determined whether the cumulative running time of the virtual CPU of the virtual machine reaches the set running time corresponding to the current scheduling priority of the virtual machine.
[0066] If yes, the scheduling priority of the virtual machine is lowered, and the scheduling priority of the at least one virtual CPU in the start state is joined into the corresponding queue.
[0067] Otherwise, the scheduling priority of the virtual machine can be kept unchanged.
[0068] In the case where the current time slice running of any virtual CPU ends, the virtual CPU needs to be re-joined into the queue to continue waiting for scheduling, and in the case where any virtual CPU is woken up due to accepting a task, the virtual CPU also needs to be joined into the queue to wait for scheduling. Therefore, in the case where the current time slice running of any virtual CPU of any virtual machine ends or any virtual CPU is woken up, the cumulative running time of the virtual CPU of the virtual machine can be determined to decide whether the scheduling priority of the virtual machine needs to be adjusted or not.
[0069] In the case where the current time slice running of any virtual CPU ends, the virtual CPU needs to be re-joined into the queue to continue waiting for scheduling, and in the case where any virtual CPU is woken up due to accepting a task, the virtual CPU also needs to be joined into the queue to wait for scheduling. Therefore, in the case where the current time slice running of any virtual CPU of any virtual machine ends or any virtual CPU is woken up, the cumulative running time of the virtual CPU of the virtual machine can be determined to decide whether the scheduling priority of the virtual machine needs to be adjusted or not.
[0070] The at least one virtual CPU in the start state in the virtual machine can include a virtual CPU that has joined any queue and a virtual CPU that has been woken up but has not joined any queue.
[0071] The scheduling priority of the virtual machine can be kept unchanged in a case where the cumulative running time of the virtual CPU is less than the set running time corresponding to the current scheduling priority of the virtual machine.
[0072] In some embodiments, in a case where the cumulative running time of the virtual CPU of any virtual machine reaches the set running time corresponding to the current scheduling priority of the virtual machine, the scheduling priority of the virtual machine can be lowered and the at least one virtual CPU in the start state can be joined into the corresponding queue.
[0073] In a case where any virtual machine is not the lowest scheduling priority, in a case where the cumulative running time of the virtual CPU of the virtual machine reaches the set running time corresponding to the current scheduling priority of the virtual machine, the scheduling priority of the virtual machine can be lowered and the at least one virtual CPU in the start state can be joined into the corresponding queue.
[0074] If any virtual machine is the lowest scheduling priority, the scheduling priority of the virtual machine can be kept unchanged.
[0075] In addition, as described above, the scheduling priority of the at least one virtual machine corresponding to the physical CPU can be periodically adjusted to the highest priority and the multiple virtual CPUs in the start state in the at least one virtual machine can be joined into the queue corresponding to the highest scheduling priority. In some embodiments, in a case where the cumulative running time of the virtual CPU of any virtual machine reaches the set running time corresponding to the current scheduling priority of the virtual machine, the scheduling priority of the virtual machine can be lowered and the at least one virtual CPU in the start state can be joined into the corresponding queue.
[0076] In a case where the cumulative running time of the virtual CPU of any virtual machine reaches the set running time corresponding to the current scheduling priority of the virtual machine and the current adjustment period has not ended, the scheduling priority of the virtual machine can be lowered and the at least one virtual CPU in the start state can be joined into the corresponding queue.
[0077] If any virtual machine is the lowest scheduling priority, the scheduling priority of the virtual machine can be kept unchanged until the current adjustment period ends.
[0078] In some embodiments, if the task execution of any virtual CPU ends, the virtual CPU can be dequeued from the queue in which it is located and deleted from the virtual CPU. The dequeued virtual CPU enters the sleep state until it is woken up by receiving a task again and switched to the start state.
[0079] In some embodiments, since both the awakened virtual CPU and the virtual CPU whose current time slice has ended but whose task has not yet finished are added to the corresponding queue, thus causing an enqueue event, the method may further include the following to further ensure the real-time performance of task execution:
[0080] For any enqueue event in a queue, the scheduling priority of the currently enqueued virtual CPU is higher than that of the currently running virtual CPU, and the currently enqueued virtual CPU is scheduled to preemptively run in the physical CPU.
[0081] In addition, the preempted virtual CPU can be inserted into the head of the corresponding queue according to its current scheduling priority.
[0082] To make it easier to understand, the following will be combined with... Figure 3 The interactive diagram shown illustrates the technical solution of this application. For example... Figure 3 As described above, a computer system may include multiple physical CPUs 100. Taking one physical CPU as an example, it is assumed that one physical CPU 100 can support multiple virtual machines 300. Multiple virtual machines 300 store multiple virtual CPUs 301 that preempt the resources of physical CPU 302 to run on physical CPU 302 to perform tasks.
[0083] Scheduler 200 loads and maintains three queues for physical CPU 302: queue 1, queue 2, and queue 3, which correspond to scheduling priorities High, Normal, and Low, respectively. High scheduling priority is the highest scheduling priority, Low scheduling priority is the lowest scheduling priority, and Normal scheduling priority is the middle scheduling priority.
[0084] Each virtual machine 300 can be pre-configured with a set runtime corresponding to the three scheduling priorities. Optionally, the set runtime Htime for the High scheduling priority and the set runtime Ntime for the Normal scheduling priority can be configured. Since the Low scheduling priority is the lowest scheduling priority, its corresponding set runtime can be empty, representing infinity.
[0085] Each virtual machine can initially be scheduled with a High scheduling priority, and the scheduling priority of each virtual machine can be periodically adjusted to a High scheduling priority.
[0086] The virtual CPU 301 in each virtual machine 300 will be added to the corresponding queue according to the scheduling priority of the virtual machine 300.
[0087] The scheduler 200 can traverse the three queues in turn according to the order of the scheduling priorities from high to low to schedule the virtual CPUs to run a time slice in the physical CPUs.
[0088] In the method, the scheduler 200 can count the cumulative running time of the virtual CPUs of each virtual machine in the current adjustment period, and in the case that the current time slice of any virtual CPU in the virtual machine ends or any virtual CPU is woken up, determine whether the cumulative running time of the virtual CPUs of the virtual machine reaches the set running time of the virtual machine corresponding to the current scheduling priority of the virtual machine. If yes, the scheduling priority of the virtual machine is lowered by one, and the virtual CPU currently in the wake-up state of the virtual machine is added to the queue of the scheduling priority lowered by one. If no, the current scheduling priority is kept unchanged, and the virtual CPU whose current time slice ends or the CPU that is woken up is added to the queue corresponding to the current scheduling priority.
[0089] For example, the current time slice of a virtual CPU of a virtual machine with the High scheduling priority ends or the virtual CPU is woken up, the cumulative running time of the virtual CPUs of the virtual machine in the current adjustment period is counted, and Htime corresponding to the High scheduling priority of the virtual machine is determined. If the cumulative running time of the virtual CPUs is greater than or equal to Htime and the current adjustment period has not ended, the scheduling priority of the virtual machine is lowered to the Normal scheduling priority, and all the virtual CPUs of the virtual machine in the start state are added to the queue of the Normal scheduling priority to wait for scheduling. If the cumulative running time of the virtual CPUs is less than Htime, the High scheduling priority is kept unchanged, and the virtual CPU whose current time slice ends or the virtual CPU that is woken up is added to the queue of the High scheduling priority to wait for scheduling.
[0090] For example, the current time slice of a virtual CPU of a virtual machine with the High scheduling priority ends or the virtual CPU is woken up, the cumulative running time of the virtual CPUs of the virtual machine in the current adjustment period is counted, and Htime corresponding to the High scheduling priority of the virtual machine is determined. If the cumulative running time of the virtual CPUs is greater than or equal to Htime and the current adjustment period has not ended, the scheduling priority of the virtual machine is lowered to the Normal scheduling priority, and all the virtual CPUs of the virtual machine in the start state are added to the queue of the Normal scheduling priority to wait for scheduling. If the cumulative running time of the virtual CPUs is less than Htime, the High scheduling priority is kept unchanged, and the virtual CPU whose current time slice ends or the virtual CPU that is woken up is added to the queue of the High scheduling priority to wait for scheduling.
[0091] If a virtual machine is lowered to the Low scheduling priority, the Low scheduling priority remains unchanged until the end of the current adjustment period. The virtual CPU in the virtual machine enters the queue of the Low scheduling priority after each time slice runs out or is woken up.
[0092] Taking the above three scheduling priorities as an example, the detailed scheduling flow as shown in Figure 4 may include:
[0093] The scheduler loads and maintains three queues for the physical CPU, which correspond to the High, Normal and Low scheduling priorities 401 in turn;
[0094] In each adjustment period, the virtual machine is adjusted to the High scheduling priority 402;
[0095] The virtual CPU enters the corresponding queue according to the scheduling priority of the virtual machine corresponding thereto 403;
[0096] It is detected whether the scheduling priority of the currently queued virtual CPU is greater than the currently running virtual CPU 404; if not, the virtual CPU is queued at the tail of the queue 405, and if yes, the running is preempted 406;
[0097] The virtual CPU is scheduled to run 407;
[0098] The virtual CPU runs in the queue of the High scheduling priority, and the adjustment period has not ended, after the current time slice runs out, it is judged whether the cumulative running time of the virtual CPU of the virtual machine corresponding thereto reaches Htime 408, if yes, step 403 is executed, and if no, the scheduling priority is adjusted to the Normal scheduling priority 409, and then step 403 is executed.
[0099] The virtual CPU runs in the queue of the Normal scheduling priority, and the adjustment period has not ended, after the current time slice runs out, it is judged whether the cumulative running time of the virtual CPU of the virtual machine corresponding thereto reaches Ntime 410, if yes, step 403 is executed, and if no, the scheduling priority is adjusted to the Low scheduling priority 411, and then step 403 is executed.
[0100] The virtual CPU runs in the queue of the Low scheduling priority, and the adjustment period has not ended, after the current time slice runs out, step 403 is executed.
[0101] If the adjustment period ends, the scheduling priority of the virtual machine is adjusted to the High scheduling priority.
[0102] In this embodiment, the High priority ensures the real-time performance of the task execution of the virtual machine which has certain demand for CPU delay and consumes less resources, the Normal priority is used for the virtual machine which has low demand for real-time performance and consumes more resources, and the Low priority is used for limiting the virtual machine which consumes too much resources and reducing the impact of these high-load virtual machines on low-load virtual machines. Each virtual machine can define different Htime and Ntime according to the specifications. The scheduling priority is dynamically adjusted through the virtual CPU cumulative running time consumed by the virtual CPU of the virtual machine, the task type of the virtual machine is intelligently identified, and better processing performance can be provided for different types of tasks.
[0103] It should be noted that the above only takes three scheduling priorities as an example to illustrate the specific scheduling process, and it can be understood that multiple scheduling priorities can be set in actual application, and the present application does not specifically limit this.
[0104] Figure 5 An embodiment structure schematic diagram of a scheduling device provided by the present application is shown in the figure, and the device can include:
[0105] The scheduling module 501 is configured to sequentially schedule the execution units in the multiple queues according to the scheduling priorities of the multiple queues configured by the CPU and run.
[0106] The processing module 502 is configured to adjust the scheduling priority of the execution entity and add at least one execution unit in a start state of the execution entity to the corresponding queue when the cumulative running time of any execution entity reaches the device running time of the execution entity corresponding to the current scheduling priority; wherein the set running time of the execution entity corresponding to the multiple queues increases in turn according to the order of the scheduling priority from high to low.
[0107] In an actual application, the scheduling module can be specifically configured to sequentially schedule the virtual CPUs in the multiple queues according to the scheduling priorities corresponding to the multiple queues respectively configured by the physical CPU and run;
[0108] The processing module can be specifically configured to reduce the scheduling priority of the virtual machine and add at least one virtual CPU in a start state to the corresponding queue when the cumulative running time of any virtual CPU of the virtual machine reaches the set running time of the virtual machine corresponding to the current scheduling priority; wherein the set running time of the virtual machine corresponding to the multiple scheduling priorities increases in turn according to the order of the scheduling priority from high to low.
[0109] In some embodiments, the processing module can be specifically configured to determine whether the accumulated running time of the virtual CPU of the virtual machine reaches the set running time of the current scheduling priority corresponding to the virtual machine in the case that the current time slice of any virtual CPU of any virtual machine ends or any virtual CPU is woken up, and if so, lower the scheduling priority of the virtual machine and add the scheduling priority of at least one virtual CPU in the start state to the corresponding queue; and if not, keep the scheduling priority of the virtual machine unchanged.
[0110] In some embodiments, the processing module lowering the scheduling priority of the virtual machine and adding at least one virtual CPU in the start state to the corresponding queue comprises: lowering the virtual machine by one scheduling priority; and adding at least one virtual CPU of the virtual machine in the start state to the queue corresponding to the current scheduling priority of the virtual machine.
[0111] In some embodiments, the processing module is further configured to keep the current scheduling priority of the virtual machine unchanged in the case that the accumulated running time of the virtual CPU is less than the set running time of the current scheduling priority corresponding to the virtual machine.
[0112] In some embodiments, the processing module is further configured to periodically adjust the scheduling priority of at least one virtual machine corresponding to the physical CPU to the highest priority, and add a plurality of virtual CPUs in the start state in the at least one virtual machine to the queue corresponding to the highest scheduling priority.
[0113] In some embodiments, the scheduling module can be specifically configured to lower the scheduling priority of the virtual machine and add at least one virtual CPU in the start state to the corresponding queue in the case that the accumulated running time of the virtual CPU of any virtual machine reaches the set running time of the current scheduling priority corresponding to the virtual machine and the current adjustment period has not ended.
[0114] In some embodiments, the scheduling module is further configured to, for the enqueue event of any queue, schedule the currently enqueued virtual CPU to preempt the running in the physical CPU in the case that the scheduling priority of the currently enqueued virtual CPU is higher than the scheduling priority of the currently running virtual CPU; and insert the preempted virtual CPU to the head position of the corresponding queue according to the current scheduling priority thereof.
[0115] In some embodiments, the scheduling module can be specifically configured to lower the scheduling priority of the virtual machine and add at least one virtual CPU in the start state to the corresponding queue in the case that the accumulated running time of the virtual CPU of the virtual machine reaches the set running time of the current scheduling priority corresponding to the virtual machine, if the virtual machine is not of the lowest scheduling priority.
[0116] In some embodiments, the processing module is further configured to keep the scheduling priority of the virtual machine unchanged until the end of the current adjustment period if any of the virtual machines has the lowest scheduling priority.
[0117] Figure 5 The scheduling device can perform Figure 1 or Figure 2 The implementation principle and technical effects of the scheduling method of the embodiments are not described again. The specific manner in which each module and unit of the scheduling device in the above embodiments performs operations has been described in detail in the embodiments related to the method, and will not be described in detail here.
[0118] In addition, the embodiments of the present application further provide a computer system, which can include a storage component 601 and a processing component 602, as described in the above embodiments. Figure 6 The processing component 602 can include at least one physical CPU 603.
[0119] The storage component 601 stores one or more computer instructions, wherein the one or more computer instructions are called and executed by the processing component 602 to implement the scheduling method of the embodiments described in the above Figure 1 or Figure 2 The scheduling method of the embodiments.
[0120] The computer system can be a physical device or be implemented as a distributed cluster composed of multiple physical devices.
[0121] The computer system can be an elastic computing host providing ECS (Elastic Compute Service) provided by a cloud computing platform, and the virtual machine created in the computer system can be an ECS instance.
[0122] The storage component 601 is configured to store various types of data to support the operation of the terminal. The storage component can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0123] Of course, the computer system can also include other components, such as an input / output interface, a communication component, etc. The input / output interface provides an interface between the processing component and the peripheral interface module, which can be an output device, an input device, etc. The communication component is configured to facilitate wired or wireless communication between the computing device and other devices.
[0124] The embodiment of the present application further provides a computer readable storage medium, which stores a computer program. The computer program is executed by a computer to realize the scheduling method of the above-mentioned Figure 1 or Figure 2 embodiment. The computer readable medium can be included in the computer system described in the above-mentioned embodiment, or can exist separately and is not assembled into the electronic device.
[0125] The embodiment of the present application further provides a computer program product, which comprises a computer program carried on a computer readable storage medium. The computer program is executed by a computer to realize the scheduling method of the above-mentioned Figure 1 or Figure 2 embodiment. In such an embodiment, the computer program can be downloaded and installed from a network, and / or installed from a detachable medium. When the computer program is executed by a processor, various functions defined in the system of the present application are executed.
[0126] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-mentioned system, device and unit can refer to the corresponding processes in the above-mentioned method embodiments, which will not be described here.
[0127] The device embodiments described above are only schematic, wherein the units described as separate components can or can not be physically separate, and the components displayed as units can or can not be physical units, that is, can be located in one place, or can be distributed on multiple network units. Part or all of the modules can be selected according to actual needs to achieve the purpose of the embodiment scheme. Those skilled in the art can understand and implement without creative labor.
[0128] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be realized by means of software and necessary general hardware platform, and of course can also be realized by hardware. Based on such understanding, the above technical solutions or the essential part of the prior art can be embodied in the form of software product, which can be stored in a computer readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes a plurality of instructions to make a computer device (which can be a personal computer, server, or network device, etc.) execute the method described in each embodiment or some part of the embodiment.
[0129] Finally, it should be noted that the above examples are only used to illustrate the technical solutions of the present application, and are not intended to limit the same; although the present application has been described in detail with reference to the foregoing examples, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing examples, or make equivalent replacements for some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A scheduling method, characterized in that, include: According to the scheduling priority corresponding to the multiple queues configured by the physical CPU, the virtual CPUs in the multiple queues are scheduled to run in sequence; If the cumulative runtime of the virtual CPUs of any virtual machine reaches the set runtime corresponding to the current scheduling priority of the virtual machine, the scheduling priority of the virtual machine is reduced, and at least one virtual CPU in the virtual machine that is in the startup state is added to the queue corresponding to the current scheduling priority of the virtual machine; wherein, according to the order of scheduling priority from high to low, the set runtime corresponding to multiple scheduling priorities of the virtual machine increases sequentially, and the cumulative runtime of the virtual CPUs refers to the sum of the total runtime of all virtual CPUs in the virtual machine.
2. The method according to claim 1, characterized in that, The step of reducing the scheduling priority of a virtual machine and adding at least one virtual CPU that is currently running to the queue corresponding to the current scheduling priority of the virtual machine when the cumulative running time of any virtual CPU of the virtual machine reaches the set running time for the virtual machine's current scheduling priority includes: When the current time slice of any virtual CPU of any virtual machine ends or any virtual CPU is woken up and started, determine whether the cumulative running time of the virtual CPU of the virtual machine has reached the set running time corresponding to the current scheduling priority of the virtual machine. If so, reduce the scheduling priority of the virtual machine and add at least one virtual CPU in the virtual machine that is in the startup state to the queue corresponding to the current scheduling priority of the virtual machine; If not, the scheduling priority of the virtual machine remains unchanged.
3. The method according to claim 2, characterized in that, The step of reducing the scheduling priority of the virtual machine and adding at least one virtual CPU in the startup state to the corresponding queue includes: Reduce the scheduling priority of the virtual machine by one; Add at least one virtual CPU that is in the startup state in the virtual machine to the queue corresponding to the current scheduling priority of the virtual machine.
4. The method according to claim 1, characterized in that, Also includes: The scheduling priority of at least one virtual machine corresponding to the physical CPU is periodically adjusted to the highest priority, and multiple virtual CPUs in the at least one virtual machine that are in the startup state are added to the queue corresponding to the highest scheduling priority.
5. The method according to claim 4, characterized in that, The step of reducing the scheduling priority of a virtual machine and adding at least one virtual CPU that is currently running to the queue corresponding to the current scheduling priority of the virtual machine when the cumulative running time of any virtual CPU of the virtual machine reaches the set running time for the virtual machine's current scheduling priority includes: If the cumulative running time of the virtual CPU of any virtual machine reaches the set running time corresponding to the current scheduling priority of the virtual machine and the current adjustment period has not ended, the scheduling priority of the virtual machine is reduced, and at least one virtual CPU in the virtual machine that is in the startup state is added to the queue corresponding to the current scheduling priority of the virtual machine.
6. The method according to claim 1, characterized in that, Also includes: For any enqueue event in a queue, the scheduling priority of the currently enqueued virtual CPU is higher than the scheduling priority of the currently running virtual CPU, and the currently enqueued virtual CPU is scheduled to preemptively run in the physical CPU. The virtual CPU that is to be preempted is inserted into the head of the corresponding queue according to its current scheduling priority.
7. The method according to claim 1, characterized in that, The step of reducing the scheduling priority of a virtual machine and adding at least one virtual CPU that is currently running to the queue corresponding to the current scheduling priority of the virtual machine when the cumulative running time of any virtual CPU of the virtual machine reaches the set running time for the virtual machine's current scheduling priority includes: If any virtual machine is not at the lowest scheduling priority, and the accumulated running time of the virtual CPUs of the virtual machine reaches the set running time corresponding to the current scheduling priority of the virtual machine, the scheduling priority of the virtual machine is reduced, and at least one virtual CPU in the virtual machine that is in the startup state is added to the queue corresponding to the current scheduling priority of the virtual machine.
8. The method according to claim 4, characterized in that, Also includes: If any virtual machine has the lowest scheduling priority, its scheduling priority remains unchanged until the current adjustment period ends.
9. A scheduling method, characterized in that, include: The execution units in the multiple queues configured by the CPU are scheduled and run sequentially according to their scheduling priorities. Based on the cumulative running time of the execution units of any execution entity, if the running time of the device corresponding to the current scheduling priority of the execution entity is reached, the scheduling priority of the execution entity is reduced, and at least one execution unit in the execution entity that is in the start state is added to the queue corresponding to the current scheduling priority of the execution entity; wherein, in order of scheduling priority from high to low, the set running time of the execution entity corresponding to the multiple scheduling priorities increases sequentially, and the cumulative running time of the execution units refers to the sum of the total running time of all execution units in the execution entity.
10. A computer system, characterized in that, It includes a storage component and a processing component; the processing component includes at least one physical CPU; The storage component stores one or more computer instructions; the one or more computer instructions are to be invoked and executed by the processing component to implement the scheduling method as described in any one of claims 1 to 8 or the scheduling method as described in claim 9.
Citation Information
Patent Citations
Virtual CPU scheduling method
CN103049332A
Virtual machine dispatching algorithm based on task load and current work property of virtual machine
CN104598298A
Multi-virtual processor synchronous scheduling method and multi-virtual processor synchronous scheduling system
CN106250217A