Processor scheduling for physical machine

By creating virtual processors in virtualization mode and scheduling them to run on physical processors, the problem of inflexible resource utilization in traditional cgroup strategies is solved, thereby improving processor utilization and system stability.

WO2026040757A1PCT designated stage Publication Date: 2026-02-26CLOUD INTELLIGENCE ASSETS HOLDING (SINGAPORE) PTE LTD +1
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2025/110842
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2024-08-21
Filing Date
2025-07-28
Publication Date
2026-02-26

AI Technical Summary

Technical Problem

In traditional operating systems, cgroup processor scheduling strategies are relatively fixed, resulting in some groups having idle or busy processor resources, making fine-grained management impossible and affecting system stability and resource utilization.

Method used

By switching the host operating system to virtualization mode, creating virtual processors, and scheduling them to run on physical processors, processor resources can be dynamically managed, improving flexibility and utilization.

Benefits of technology

It enables flexible management of processor resources, improves the utilization of physical processors and system stability, and can dynamically adjust resource allocation according to demand.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2025110842_26022026_PF_FP_ABST
    Figure CN2025110842_26022026_PF_FP_ABST
Patent Text Reader

Abstract

Embodiments of the present disclosure provide a processor scheduling method for a physical machine, a device, a system, a product, and a storage medium. The physical machine comprises a physical processor, and the physical processor has a corresponding scheduling queue. The method comprises: switching a running host operating system from a root mode to a virtualization mode, and creating at least one virtual processor in the virtualization mode; generating a scheduling object and adding same to the scheduling queue of the physical processor; and in the process of selecting a running task for the physical processor on the basis of the scheduling queue of the physical processor, if the scheduling object is selected, selecting a target virtual processor from the at least one virtual processor, and scheduling the physical processor to run the target virtual processor.
Need to check novelty before this filing date? Find Prior Art

Description

Processor scheduling of physical machine TECHNICAL FIELD

[0001] The present disclosure relates to the technical field of virtualization, and in particular, to processor scheduling of physical machine. BACKGROUND

[0002] A control group (cgroup) function is provided in a traditional operating system such as Linux, different function groups can be set, each function group includes at least one process, and the processor range used by different function groups can be set through the cgroup function, so as to divide different processor use ranges and use quotas for each function group. Although such cgroup configuration can be changed online, the stability of the system needs to be considered in a production environment, and the quotas of different cgroup groups are not frequently changed, and the CPU scheduling strategy is relatively fixed, which may result in idle or partially busy processor resources corresponding to part of the cgroup groups. Therefore, the processor scheduling scheme using the cgroup in the related art is not flexible enough and cannot finely manage the processors. SUMMARY

[0003] To overcome the problems in the related art, the present disclosure provides a processor scheduling method, device, system, product and storage medium of physical machine.

[0004] According to a first aspect of an embodiment of the present disclosure, a processor scheduling method of physical machine is provided, the physical machine includes a physical processor, the physical processor corresponds to a scheduling queue, and the method includes: switching a running host operating system from a root mode to a virtualization mode, creating at least one virtual processor in the virtualization mode; generating a scheduling object and adding it to the scheduling queue of the physical processor; in the process of selecting a running task for the physical processor based on the scheduling queue of the physical processor, if the scheduling object is selected, a target virtual processor is selected from the at least one virtual processor, and the physical processor is scheduled to run the target virtual processor.

[0005] According to a second aspect of an embodiment of the present disclosure, a computer device is provided, including a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor implements the steps of the method embodiment of the first aspect when executing the computer program.

[0006] According to a third aspect of the embodiments of the present disclosure, a processor scheduling system of a physical machine is provided, the physical machine comprising a physical processor and a host operating system running on the physical processor, a virtualization layer is implemented between the physical processor and the host operating system, the virtualization layer comprising the processor scheduling system, the processor scheduling system being configured to perform the steps of the method according to the first aspect.

[0007] According to a fourth aspect of the embodiments of the present disclosure, a computer readable storage medium is provided, the computer readable storage medium storing a computer program, the computer program being configured to perform the steps of the method according to the first aspect when executed by a processor.

[0008] According to a fifth aspect of the embodiments of the present disclosure, a computer program product is provided, the computer program product comprising a computer program, the computer program being configured to perform the steps of the method according to the first aspect when executed by a processor.

[0009] The technical solutions provided by the embodiments of the present disclosure can have the following beneficial effects: in the embodiments of the present disclosure, the physical machine comprises a physical processor, the physical processor corresponds to a scheduling queue, the embodiments can switch a running host operating system from a root mode to a virtualization mode, in the virtualization mode, at least one virtual processor is created, a scheduling object is generated and added to the scheduling queue of the physical processor, in the process of selecting a running task for the physical processor based on the scheduling queue of the physical processor, if the scheduling object is selected, a target virtual processor is selected from the at least one virtual processor, and the physical processor is scheduled to run the target virtual processor. Based on this, the embodiments of the present disclosure can directly create a new virtual processor in the running host operating system, by adding a scheduling object in the scheduling queue of the physical processor, when the scheduling object is selected, a target virtual processor can be selected to run on the physical processor, so that the physical processor can be used to execute the target virtual processor, the utilization rate of the physical processor is improved, and the number of virtual processors created can be arbitrary, and the computing power of the physical processor can be flexibly provided to the upper layer through the virtual processor.

[0010] It should be understood that the foregoing general description and the following detailed description are only exemplary and explanatory, and cannot limit the present disclosure. BRIEF DESCRIPTION OF DRAWINGS

[0011] FIG. 1 is a flowchart of a processor scheduling method of a physical machine according to an exemplary embodiment of the present disclosure.

[0012] FIG. 2A is a schematic diagram of a physical machine according to an exemplary embodiment of the present disclosure.

[0013] FIG. 2B is a schematic diagram of a processor scheduling method of a physical machine according to an example embodiment of the present disclosure.

[0014] FIG. 3 is a hardware structure diagram of a computer device in which a processor scheduling apparatus of a physical machine is located according to an example embodiment of the present disclosure.

[0015] FIG. 4 is a structure diagram of a processor scheduling apparatus of a physical machine according to an example embodiment of the present disclosure. DETAILED DESCRIPTION

[0016] The example embodiments will be described in detail herein with reference to the attached drawings. In the following description, the same or similar components are designated by the same or similar reference numerals, and a repeated description thereof will be omitted. The embodiments described in the following example embodiments do not represent all embodiments consistent with the present disclosure. Rather, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.

[0017] The terminology used in the present disclosure is for the purpose of describing particular embodiments only and is not intended to be limiting of the present disclosure. As used in the present disclosure and the appended claims, the singular forms "a," "an" and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It will be further understood that the terms "comprises" and / or "comprising," when used in this specification, specify the presence of stated features, integers, steps, operations, elements, and / or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof.

[0018] It should be understood that although the terms first, second, third, etc. can be used herein to describe various information, these terms are not intended to denote a particular order or hierarchy. These terms are used only to distinguish one from another. For example, a first information can be termed a second information, and similarly, a second information can also be termed a first information, without departing from the scope of the present disclosure. Depending on the context, the word "if' as used herein can be interpreted as meaning "when" or "in response to determining."

[0019] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the present disclosure are all information and data authorized by the user or authorized by all parties, and the collection, use and processing of relevant data need to comply with relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation portal for user to choose authorization or refusal.

[0020] As in an operating system such as Linux, cgroup is a kernel feature that can be used to limit, record and isolate the usage of hardware resources of a control group, where the hardware resources include but are not limited to CPU, memory, disk I / O (input / output) and the like. With cgroup, a system administrator can control hardware resources, for example, limit the proportion of processors such as CPU (Central Processing Unit) and / or memory used by a specific process, or count their resource usage, and the like. Taking CPU resource allocation as an example, the functions provided by cgroup include limiting the total CPU usage time of all processes in the control group, and binding the processes in the control group to specific CPU cores and / or memory nodes.

[0021] However, the processor scheduling strategy based on cgroup is relatively fixed, which may result in the situation that the processor resources corresponding to some cgroup groups are idle or some are busy. Therefore, the processor scheduling scheme using cgroup is not flexible enough and cannot finely manage the processors. In a production environment, although cgroup can be dynamically adjusted, the configuration of these cgroups is often an experienced value verified by practice and large-scale deployment, and it is not likely to be frequently changed.

[0022] Therefore, hardware resource control through some virtualization technology can also be considered, for example, virtualization technology allows physical CPUs on a physical machine to be abstracted and divided into multiple virtual CPUs (vCPUs). As an example, the virtualization management tool KVM (Kernel-based Virtual Machine) in the Linux kernel can implement virtualization using Linux kernel modules and some user space tools, allowing multiple virtual machines (VMs) to run on a Linux system, each of which can independently run different operating systems and applications. KVM can allocate vCPUs to virtual machines running on the host, and the vCPUs are mapped and scheduled to physical CPUs. In KVM, the scheduling of vCPUs can be based on various strategies, including round robin, fair scheduling and real-time scheduling, depending on the implementation of the virtualization management software. The ultimate goal is to ensure the performance of the VM while maximizing the performance of the physical hardware. KVM uses the scheduler of the Linux kernel to mount vCPUs on physical CPUs, and KVM also supports advanced functions such as CPU-intensive task priority and memory page migration.

[0023] A vCPU can be dynamically migrated to different physical cores in order to more efficiently utilize physical resources. This is referred to as vCPU migration. For example, if the vCPUs on one physical core are lightly loaded while the vCPUs on another physical core are heavily loaded, then some of the load can be migrated to the lightly loaded core in order to achieve load balancing. Dynamic scheduling also allows for dynamic modification of the number of vCPUs. For example, when the vCPUs are running under high load, the number of vCPUs can be increased in order to meet the resource demands of the VM. Administrators can use various monitoring tools to track resource usage and make optimization adjustments based on this data.

[0024] Based on this, the scheduling of physical processors can be implemented through the idea of virtualization. The processor scheduling scheme provided by the embodiments of the present disclosure can switch a running operating system to a virtualization mode, create a new virtual processor for it, and then schedule the new virtual processor to run on a physical processor, so as to more efficiently utilize the resources of the physical processor, improve the utilization of the processor, and the number of virtual processors created can be arbitrary, and the computing power of the physical processor can be flexibly provided to the upper layer through the virtual processor.

[0025] As shown in FIG. 1, it is a processor scheduling method of a physical machine according to an exemplary embodiment of the present disclosure, the physical machine includes a physical processor, the physical processor corresponds to a scheduling queue, and the method can include the following steps.

[0026] In step 102, the running host operating system is switched from the root mode to the virtualization mode, and at least one virtual processor is created in the virtualization mode.

[0027] In step 104, a scheduling object is generated and added to the scheduling queue of the physical processor.

[0028] In step 106, in the process of selecting a running task for the physical processor based on the scheduling queue of the physical processor, if the scheduling shell is selected, a target virtual processor is selected, and the physical processor is scheduled to run the target virtual processor.

[0029] As an example, the hardware resources of the physical machine include, but are not limited to, one or more combinations of processors such as a CPU, a Graphics Processing Unit (GPU), a Data Processing Unit (DPU), a Tensor Processing Unit (TPU), a Cloud Infrastructure Processing Unit (CIPU), an Application Specific Integrated Circuit (ASIC), and the like. The hardware resources of the physical machine can also include any type of storage medium, and other components such as I / O devices, communication components, displays, power components, audio components, and the like, without limitation.

[0030] The host operating system is system software running on the physical machine, responsible for managing hardware resources and providing a platform so that application programs can run on the operating system and access and utilize hardware resources to perform specific tasks. As an example, the host operating system can be a Linux operating system or the like, without limitation.

[0031] The processor in the embodiments of the present disclosure includes, but is not limited to, a CPU, a GPU, a DPU, or a TPU, and the like. In subsequent embodiments, most of the descriptions take the CPU as an example for convenience.

[0032] In order to provide elastic computing power, the embodiments of the present disclosure can directly create a new virtual processor for the running host operating system, and then realize elastic computing power by scheduling the new virtual processor to run on the physical processor.

[0033] As an example, in actual application, the timing of triggering the execution of the embodiments of the present disclosure can have multiple cases, for example, it can be necessary to adjust the cgroup, such as receiving a cgroup adjustment request, or any other arbitrary situation can trigger the execution of the embodiments of the present disclosure.

[0034] The virtualization mode of KVM needs to start a virtual machine, which is different from the virtualization mode of KVM. The embodiments of the present disclosure switch the running host operating system from root mode to virtualization mode, that is, switch the running physical CPU to virtualization mode, which is more lightweight than the virtualization mode of KVM. Based on this, the embodiments of the present disclosure create one or more virtual processors in the virtualization mode.

[0035] In some examples, as shown in FIG. 2A, is a physical machine architecture diagram according to an exemplary embodiment of the present disclosure. The physical machine architecture of the present embodiment provides two running modes for a host operating system in a running state, i.e., a root mode and a virtualization mode, and a virtualization layer can be inserted between the hardware resources and the host operating system, the virtualization layer can be located between the hardware resources and the host operating system of the physical machine, and the running host operating system is switched from the root mode to the virtualization mode by the virtualization layer, so that various functions can be flexibly implemented for the running host operating system without reinstalling the operating system.

[0036] As an example, the host operating system corresponds to a root mode and a virtualization mode. The root mode is a working mode in which the host operating system has direct access to the hardware resources, and the virtualization mode is a working mode in which the virtualization layer virtualizes the hardware resources and replaces the host operating system to schedule and access the virtualized resources. The access of the virtualization layer to the hardware resources is limited in the virtualization mode. Compared with the root mode, the virtualization mode can also be referred to as a non-root mode, and accordingly, the host operating system in the virtualization mode can also be referred to as a guest operating system.

[0037] In the present embodiment, a lightweight, powerful and efficient virtualization layer is inserted between the hardware resources and the host operating system. The virtualization layer can be developed in advance and inserted between the hardware resources and the host operating system. The way of inserting the virtualization layer is not limited. For example, the virtualization layer can be inserted when the host operating system is in a normal running state after the host operating system is installed on the physical machine.

[0038] As an example, the virtualization layer can be a software module in the host operating system, and the software module can switch the host operating system from the root mode to the virtualization mode when the host operating system is in the root mode. After the switching, the host operating system becomes a guest operating system, and the virtualization layer takes over the management of the hardware resources of the physical machine, i.e., the meaning of inserting the virtualization layer between the hardware resources and the host operating system, so that the host operating system uses the hardware resources through the virtualization layer.

[0039] After the host operating system is switched from the root mode to the virtualization mode, the existing physical machine CPU can be switched to a corresponding virtual CPU, for example, a CPU. In the virtualization mode of the present embodiment, new virtual CPUs are further created. The newly created virtual CPUs can be one or more, which can be flexibly configured according to actual needs, and the present embodiment does not limit this.

[0040] As an example, assuming that the physical machine includes 4 physical CPUs, after the host operating system switches from the root mode to the virtualization mode, the 4 physical CPUs can be switched to corresponding virtual CPUs respectively; the embodiment can also newly create n virtual CPUs based on the 4 switched virtual CPUs; in order to distinguish the virtual CPUs switched from the physical CPUs, the embodiment refers to the newly created virtual CPUs as newly created virtual CPUs. In this way, the total number of virtual CPUs is the 4 switched virtual CPUs plus the n newly created virtual CPUs.

[0041] As an example, during the process of switching the host operating system from the root mode to the virtualization mode, after the physical CPUs are switched to corresponding virtual CPUs, the virtualization layer can create a corresponding physical description structure for each physical CPU, and create a corresponding virtualization description structure for the virtual CPU, and the physical description structure of each physical CPU corresponds to the virtualization description structure. The physical description structure is used to save the context information of the physical CPU running in the root mode during mode switching, and the virtualization description structure is used to synchronize the context information in the physical description structure during mode switching. The virtualization layer manages the virtual CPUs switched from the physical CPUs through the virtualization description structure.

[0042] As an example, there can be various ways to create a new virtual processor; for example, the virtual processor switched from the physical processor above corresponds to a virtualization description structure, in order to create a new virtual processor, a virtualization description structure can be newly created, and optionally, a series of registers and the like can also be configured, and the specific implementation is realized by the virtual processor creation function of the virtualization layer, and the embodiment does not limit this. For example, the virtualization description structure of the new virtual processor here is similar to the virtualization description structure corresponding to the physical CPU above, for example, the fields of the two are the same, but the specific field values are different. Each newly created virtualization description structure represents a newly created virtual processor, and the corresponding newly created virtual processor can be managed through the virtualization description structure. The specific management manner is not limited by the embodiment.

[0043] As an example, for the virtualization layer of the physical machine bottom layer in the embodiment, the virtual processor is a running task that can be scheduled to run on the physical CPU, and on the newly created virtual processor, the virtual processor can be used to run any task, similar to the virtual machine of KVM, but the creation method of the virtual processor in the embodiment is different from KVM, and the virtual processor is managed by the virtualization layer. As an example, various user tasks such as common user processes can run on the virtual processor of the embodiment, and user processes can be bound to the newly created virtual processor as needed, and the like, which are not limited by the embodiment. Therefore, by scheduling the newly created virtual processor to run on the physical CPU, the embodiment can provide elastic computing power for the upper layer, and how the virtualization layer of the bottom layer schedules the newly created virtual processor according to the busy state of the physical CPU is transparent to the upper layer task, which can maintain the transparency to the original running mode.

[0044] As an example, a scheduler can be implemented in the virtualization layer for scheduling these virtual CPUs (the virtual CPU switched over by the physical CPU + the n newly created virtual CPUs). The embodiment method can be applied to the scheduler of the virtualization layer, and optionally, the scheduler can run on each physical CPU, that is, the embodiment method can be applied to each physical CPU.

[0045] In the embodiment, in the virtualization mode, each physical processor in the virtualization layer corresponds to a scheduling queue, and the scheduling queue contains one or more to-be-run tasks of the physical processor; the to-be-run tasks of the physical processor can be upper-layer processes bound to the physical processor, and the like. The to-be-run tasks can be taken out from the scheduling queue of the physical processor by the virtualization layer and executed by the physical processor by setting some scheduling strategies, and the specific scheduling strategies and scheduling methods can be flexibly configured according to actual needs, which are not limited by the embodiment.

[0046] In order to enable the newly created virtual processor to be scheduled to run on the physical processor, the embodiment can generate a scheduling object and add it to the scheduling queue. As an example, a scheduling object can be newly created in the scheduling queue of each physical processor, or a scheduling object can be newly created in part of the scheduling queues, which are not limited by the embodiment.

[0047] Thus, as the scheduling object is added to the scheduling queue of the physical processor, the scheduling object has a chance to be selected when the physical processor selects a task to run from the scheduling queue. In this embodiment, the scheduling object is not a task to run on the physical processor, but triggers the selection of a virtual processor when the scheduling object is selected. That is, the scheduling object is a data object in the scheduling queue of the physical processor, and can be considered as a shell for the newly created virtual processors. Thus, if the scheduling object is selected from the scheduling queue of the physical processor, one of the newly created virtual processors can be selected, and the selected virtual processor is referred to as a target virtual processor. Further, the physical processor can be scheduled to run the target virtual processor.

[0048] As an example, as shown in FIG. 2B, assume that the physical machine includes four physical CPUs (physical CPU_1 to physical CPU_4) and has six vCPUs as follows: ① vCPU_1, vCPU_2, vCPU_3, and vCPU_4, which are switched from the physical CPUs; and ② vCPU_5 and vCPU_6, which are newly created. The scheduling object can be inserted into the scheduling queue of each of the four physical CPUs. The virtualization layer can manage each physical CPU to select a task to run for the physical CPU based on the scheduling queue corresponding to the physical CPU. As the scheduling object is inserted into the scheduling queue, assume that the scheduling object is selected from the scheduling queue of physical CPU_1, and one of the newly created vCPUs vCPU_5 and vCPU_6 is selected. Assume that vCPU_5 is selected, and the running task of vCPU_5 can be executed by physical CPU_1.

[0049] The scheduling queue of the physical CPU contains the original running task of the physical CPU. The newly inserted scheduling object is used to trigger the selection of the newly created virtual CPU for running. As an example, the priority of the scheduling object in the scheduling queue can be set. For example, the priority of the original running task of the physical CPU can be higher than the priority of the newly created virtual CPU. In other examples, other tasks of the virtualization layer, such as memory exchange and other background tasks, can also be included in the scheduling queue. The priority of the background task can be lower than the priority of the newly created virtual CPU. Of course, other priority strategies can also be used in actual applications, and the present embodiment does not limit this. In this way, when the physical CPU is idle, for example, when the original running task of the physical CPU does not need to run, the vCPU of the present embodiment can be timely scheduled, so that the vCPU can use the computing power of the physical CPU when it is idle. For example, the physical CPU itself is bound to run certain control groups. Through the scheme of the present embodiment, the physical CPU can run the newly created virtual CPU when it is idle. The newly created virtual CPU can carry any running task.

[0050] As an example, the newly created virtual CPU can have multiple ones. When a scheduling object is selected from a certain scheduling queue, one of the multiple newly created virtual CPUs can be randomly selected to be run by the physical CPU. The selection method can be arbitrary, such as random selection, priority-based selection, and the like. Considering that in actual applications, there can be multiple physical CPUs and multiple newly created virtual CPUs, in order to better schedule the newly created virtual CPUs, as an example, the virtual CPU corresponds to a scheduling entity. The method can further include: creating a virtual processor scheduling queue, the virtual processor scheduling queue being used to store the scheduling entity corresponding to the virtual processor; and selecting a target virtual processor from the at least one virtual processor, including: selecting a target scheduling entity from the virtual processor scheduling queue, and determining the target virtual processor corresponding to the target scheduling entity.

[0051] As an example, taking a CPU as an example, each virtual CPU can correspond to a scheduling entity. The scheduling entity can contain relevant information of the virtual CPU, including but not limited to the identifier of the virtual CPU, the execution function of the virtual CPU, the time slice of the virtual CPU, and the like. The scheduling entity can be stored in the virtual CPU scheduling queue. When a scheduling object is selected from the scheduling queue of the physical CPU, a scheduling entity can be selected from the virtual CPU scheduling queue. The virtual CPU corresponding to the selected scheduling entity can run on the physical CPU, and the selected scheduling entity is removed from the virtual CPU scheduling queue. It can be understood that the same applies to other processors, such as GPUs, and the like.

[0052] For example, as shown in FIG. 2B, a virtual CPU scheduling queue is included, and the scheduling entity se5 of the newly created vCPU_5 and the scheduling entity se6 of the newly created vCPU_6 can be added to the virtual CPU scheduling queue. Assuming that the virtualization layer selects a scheduling object from the scheduling queue of the physical CPU_1, a scheduling entity can be selected from the virtual CPU scheduling queue, and assuming that the scheduling entity se5 is selected, which corresponds to the vCPU_5, the vCPU_5 can be executed by the physical CPU_1.

[0053] In another example, assuming that there are 4 physical CPUs and 5 newly created virtual CPUs, the scheduling entities corresponding to the 5 virtual CPUs are first stored in a virtual CPU scheduling queue. At a certain time, the scheduler_A corresponding to the physical CPU_A selects a scheduling object from the scheduling queue of the physical CPU_A, and the scheduler_A selects a scheduling entity from the virtual CPU scheduling queue, which corresponds to the newly created virtual CPU_1. Then, the newly created virtual CPU_1 runs on the physical CPU_A. Since the scheduling entity of the newly created virtual CPU_1 is taken out, the scheduler_B corresponding to the physical CPU_B selects a scheduling object from the scheduling queue of the physical CPU_B, and the scheduler_B selects a scheduling entity from the virtual CPU scheduling queue. At this time, the scheduling entity of the newly created virtual CPU_1 is not in the virtual CPU scheduling queue, and the scheduler_B selects other scheduling entities so that other newly created virtual CPUs can run on the physical CPU_B.

[0054] As can be seen from the above examples, through the cooperation of the scheduling entity and the virtual CPU scheduling queue, multiple virtual CPUs can be flexibly scheduled in multiple physical CPUs, and each virtual CPU has the opportunity to be scheduled.

[0055] In actual applications, one or more virtual CPU scheduling queues can be created as needed, and the number of virtual CPU scheduling queues is not limited in the embodiment, and the priorities of different virtual CPU scheduling queues can be set as needed.

[0056] As an example, the virtual processor scheduling queue can be a global scheduling queue, a scheduling entity se can be created for each newly created virtual processor, and the scheduling entities corresponding to the various newly created virtual processors can be added to the global scheduling queue. Each time a scheduling object in the scheduling queue of a certain physical processor is selected, a scheduling entity can be selected from the global scheduling queue, and the newly created virtual processor corresponding to the selected scheduling entity can be scheduled to run on the physical processor.

[0057] As an example, the scheduling entities corresponding to vCPU_5 and vCPU_6 in the foregoing embodiment can be added to the global queue; assuming that the scheduling shell is selected from the scheduling queue of physical CPU_1, the scheduling entity is selected from the global scheduling queue; assuming that the selected scheduling entity corresponds to vCPU_5, the scheduling entity is dequeued from the scheduling queue, and then the running task of vCPU_5 can be executed by physical CPU_1.

[0058] As an example, the strategy for selecting the scheduling entity of each newly created virtual CPU can be a first-in first-out strategy, or the priority of the scheduling entity of different vCPUs can be set according to actual needs, and the embodiment is not limited in this regard.

[0059] As an example, the virtual processor scheduling queue includes a global scheduling queue and an emergency scheduling queue, the priority of the virtual processor corresponding to the scheduling entity in the global scheduling queue is lower than the priority of the virtual processor corresponding to the scheduling entity in the emergency scheduling queue; the selecting of the target scheduling entity from the virtual processor scheduling queue includes: determining whether there is a scheduling entity in the emergency scheduling queue; if yes, selecting the target scheduling entity from the emergency scheduling queue; if no, selecting the target scheduling entity from the global scheduling queue.

[0060] As an example, two types of queues with different levels are set for the virtual processor scheduling queue, the emergency scheduling queue can be used to store the scheduling entities of virtual processors that need to be executed in priority, and in actual applications, some virtual processors can be given a higher priority and some virtual processors can be given a lower priority based on some emergency tasks or conditions.

[0061] In the selection process of the scheduling entity, the emergency scheduling queue can be preferentially checked, if there is a scheduling entity in the emergency scheduling queue, the scheduling entity can be preferentially selected from this queue, and if there is no scheduling entity in the emergency scheduling queue, the scheduler will select the scheduling entity from the global scheduling queue. This ensures that non-emergency tasks can also be reasonably scheduled. Based on this, the embodiment can more effectively run virtual CPUs with different priorities by distinguishing between global and emergency scheduling queues, and ensures that emergency tasks can be responded in time.

[0062] In actual applications, how to determine the priority of different virtual processors, that is, which scheduling entities of virtual processors are stored in the emergency scheduling queue and the global scheduling queue, can be configured as needed, and the embodiment is not limited in this regard.

[0063] After the step of creating the at least one virtual processor, the method further comprises: creating a scheduling entity corresponding to the virtual processor and adding the scheduling entity to the global scheduling queue; detecting whether a preset emergency event occurs to the virtual processor corresponding to each scheduling entity in the global scheduling queue; and after removing the scheduling entity corresponding to the virtual processor in which the preset emergency event occurs from the global scheduling queue, adding the scheduling entity to the emergency scheduling queue.

[0064] That is, the scheduling entities in the global scheduling queue can be added by the following way: when the virtual processor is created, the scheduling entity corresponding to the virtual processor is created and added to the global scheduling queue.

[0065] The scheduling entities in the emergency scheduling queue can be added by the following way: detecting whether a preset emergency event occurs to the virtual processor corresponding to each scheduling entity in the global scheduling queue; and after removing the scheduling entity corresponding to the virtual processor in which the preset emergency event occurs from the global scheduling queue, adding the scheduling entity to the emergency scheduling queue.

[0066] In the embodiment, the global scheduling queue and the emergency scheduling queue can be created; when the virtual processor is created, the scheduling entity of the virtual processor can be created and stored in the global scheduling queue. The virtual processor can carry various tasks, which can be tasks submitted by a virtualization layer, upper-layer applications, and the like. At a certain moment, the scheduling entity of the virtual processor is in the global scheduling queue, which indicates that the virtual processor is not scheduled to run on a physical processor at the moment. However, because the virtual processor can carry various tasks, some emergency events can occur, which require the virtual processor to run to process, for example, an emergency event of a process bound to the virtual processor or an interrupt event that needs to be responded by the virtual processor.

[0067] Based on this, in the embodiment, whether a preset emergency event occurs to the virtual processor corresponding to each scheduling entity in the global scheduling queue can be detected. If a preset emergency event occurs to a virtual processor, the scheduling entity corresponding to the virtual processor can be removed from the global scheduling queue and added to the emergency scheduling queue.

[0068] Because the scheduler selects the scheduling entity from the emergency scheduling queue preferentially, the scheduling entities in which the emergency events occur can be scheduled to run on the virtual processor more quickly.

[0069] The processor needs to respond quickly to some events such as interrupts during runtime. If the processor does not respond in time to such events, it may cause serious problems or even crash of the system. However, the conventional virtual processor scheduling is limited by priority and time slice, and cannot guarantee the real-time performance. Therefore, the events need to be responded quickly. Based on this, in some embodiments, an emergency scheduling queue can be created to mount the scheduling entities of the virtual processors that need to be processed urgently.

[0070] As an example, the emergency scheduling queue can be one or more, for example, there can be multiple, and multiple emergency scheduling queues of different priorities can also be set according to needs, and the like. The embodiments are not limited in this regard.

[0071] As an example, the physical machine includes a plurality of physical processors, each of the physical processors is configured to run a scheduler, and the method is applied to the scheduler running in each physical processor. The emergency scheduling queue includes a local emergency scheduling sub-queue corresponding to each physical CPU respectively, and a global emergency scheduling sub-queue. The priority of the virtual CPU corresponding to the scheduling entity in the local emergency scheduling sub-queue is higher than the priority of the virtual CPU corresponding to the scheduling entity in the global emergency scheduling sub-queue. Alternatively, the virtual CPU corresponding to the scheduling entity in the local emergency scheduling sub-queue is bound to the physical CPU corresponding to the local emergency scheduling sub-queue. The method of determining whether there is a scheduling entity in the emergency scheduling queue includes determining whether there is a scheduling entity in the target local emergency scheduling sub-queue corresponding to the physical processor. If there is, the scheduling entity is selected from the target local emergency scheduling sub-queue. If not, the scheduling entity is selected from the global emergency scheduling sub-queue.

[0072] In the embodiments, different levels of emergency events and other different situations that may occur in actual applications are considered, and the physical machine can include a plurality of physical processors. A scheduler corresponding to each physical processor is designed to be responsible for the runtime scheduling of the virtual processors on the physical processor. A local emergency scheduling sub-queue corresponding to each physical processor can be designed to be exclusively occupied by the physical processor, and a global emergency scheduling sub-queue corresponding to each physical processor can also be designed. The scheduling entity in the local emergency scheduling sub-queue has a higher priority, or is the scheduling entity of the virtual processor bound to the physical processor, for example, the virtual processor has local physical processor affinity and runs more efficiently on the local physical processor.

[0073] The process of selecting a scheduling entity in the emergency scheduling queue can be checking whether there is a scheduling entity in the local emergency scheduling sub-queue. If there is, the scheduling entity is selected from the local emergency scheduling sub-queue in priority to ensure the fastest response time. If the local emergency scheduling sub-queue is empty, the global emergency scheduling sub-queue is checked and a scheduling entity is selected therefrom.

[0074] In this embodiment, by introducing local and global emergency scheduling sub-queues, and considering priority and binding relationship, the efficiency and response speed of processor scheduling in a virtualized environment are improved, and it is ensured that when an emergency event is discovered, a virtual processor can be quickly and effectively scheduled to run.

[0075] In some examples, the scheduling the physical processor to run the target virtual processor includes: allocating a current running duration of the current scheduling period to the target virtual processor, and scheduling the physical processor to run the target virtual processor based on the current running duration; the method further includes: if the target virtual processor completes running on the physical processor, re-adding a scheduling entity corresponding to the target virtual processor to the global scheduling queue.

[0076] In actual application, the running duration is a time slice, and the time slice allocated to the target virtual processor can be flexibly set as needed, for example, it can be a fixed time slice set for each scheduling period, it can be different time slices set for different scheduling periods, it can be set according to the running situation of the physical processor, and so on. This embodiment does not limit this.

[0077] Taking a CPU as an example, after the selected scheduling entity corresponding to a target virtual CPU (vCPU) is taken out, the physical CPU can run the vCPU based on the time slice allocated to the vCPU. The target vCPU can normally complete execution on the physical CPU according to the allocated time slice, and then the scheduling entity of the target vCPU can be re-added to the global scheduling queue after completing the running of the time slice, so that the target vCPU can be scheduled again in the future.

[0078] In some examples, the allocating a current running duration of the current scheduling period to the target virtual processor includes: obtaining a difference between an actual running duration of the target virtual processor in a historical scheduling period and a historical running duration allocated to the target virtual processor in the historical scheduling period, and determining a current running duration of the target virtual processor in the current scheduling period based on the difference.

[0079] As an example, when a vCPU runs on a physical CPU, it can be trapped early due to various reasons. Trapping refers to a situation where a vCPU running on a physical CPU encounters a situation that requires the vCPU to exit execution on the physical CPU and the virtualization layer takes over the physical CPU. Therefore, trapping can cause the actual runtime of a vCPU to be less than the allocated time slice, and there can also be a situation where a vCPU runs overtime. Based on this, the embodiment uses historical execution conditions to implement a dynamic and fair time slice allocation strategy.

[0080] As an example, the actual runtime of a virtual processor in each scheduling period can be implemented in various ways. For example, the scheduler can start timing after scheduling the virtual processor to run on a physical processor. Alternatively, the actual runtime of a virtual processor can be implemented by using a timer. The timer can be a preemption timer in existing hardware virtualization, or a software timer running in the virtual processor, etc. When the virtual processor is scheduled to run on a physical processor, the software timer also starts. When the virtual processor is trapped, the actual runtime of the virtual processor can be obtained by the timing duration of the timer, thereby checking whether the virtual processor runs overtime.

[0081] If there is a difference between the actual runtime in the historical scheduling period (which can be the last scheduling period, or multiple previous scheduling periods, etc.) and the historical time slice allocated in the historical scheduling period, the local time slice can be determined based on the difference. The specific way can be flexibly configured as needed. For example, if the difference is positive, the time slice can be reduced this time; if the difference is negative, the time slice can be increased, etc.

[0082] Alternatively, the time slice can also be allocated by using integration or other methods. As an example, if the time slice of the historical scheduling period is exceeded, the time slice of the next scheduling period can be appropriately reduced; if there is a surplus, the corresponding integration can be set to offset the time used before, etc.

[0083] As can be seen from the above embodiment, by using historical execution conditions, the time slice can be dynamically allocated for the target virtual processor in each scheduling period, thereby achieving fair time slice allocation.

[0084] In some examples, the method can further include starting a timer when the physical processor is scheduled to run the target virtual processor based on the actual runtime, and stopping the running of the target virtual processor when the timing duration of the timer is reached.

[0085] In this embodiment, a timer can be used to ensure that the virtual processor runs within the allocated time slice and automatically stops running when the time slice expires. When the timer reaches the set time length, an event is triggered, which indicates that the physical processor stops executing the current virtual processor. After the physical processor receives the timer event, it will stop running the target virtual processor and return control to the scheduler, so that the scheduler can continue to schedule the running of the physical processor.

[0086] The timer can be implemented in various ways. As an example, a preemption timer in existing hardware virtualization can be used. As another example, a software timer can be run in the virtual processor, which starts when the virtual processor is scheduled to run on the physical processor. If the virtual processor continues to run until the timer reaches the set time length, the running of the target virtual processor can be stopped, i.e. the target virtual processor is trapped. The trapping method can be various. As an example, the timer can be pre-set with a corresponding interrupt event. When the timer reaches the set time length, the timer pre-set interrupt event is injected into the virtual processor, so that when the virtualization layer detects the interrupt event of the timer, the running of the virtual processor is stopped.

[0087] As an example, the timer time length can be configured as needed, for example, based on the length of the scheduling period of the scheduler. For example, assuming that the scheduling period of the scheduler is 5ms, the timer time length can be lower than the scheduling period to ensure the scheduling accuracy of the scheduler. Alternatively, the timer time length can be determined according to the time slice of the virtual processor to ensure that the virtual processor can exit in time when the time slice arrives.

[0088] The timer can ensure that the target virtual processor runs within the allocated time slice, prevent the target virtual processor from using the physical processor overtime, and reduce the computational burden of the scheduler, without the need for the scheduler to check the running time of the target virtual processor.

[0089] In some examples, the method further includes: creating a global suspension queue; during the running of the target virtual processor by the physical processor, if a suspension event corresponding to the target virtual processor is detected, suspending the running of the target virtual processor and adding the scheduling entity of the target virtual processor to the global suspension queue; and if it is detected that the target virtual processor satisfies a pre-set wake-up condition, removing the scheduling entity of the target virtual processor from the global suspension queue and adding it to the virtual processor scheduling queue.

[0090] As an example, normally, the vCPU keeps running on the physical CPU until the time slice allocated to the target vCPU ends; however, during the running process, the target vCPU can be paused due to some reasons, for example, some instructions such as halt or mwait are executed, which pause the execution of the target vCPU and return to the scheduler, and wait for some events (such as an interrupt) to reawaken the target vCPU. If the instructions need to be executed, the target vCPU can be trapped into the root mode to run, and the specific way of executing the instructions can be implemented by the existing virtualization layer, and thus the embodiment will not be described again. After the target vCPU is paused, the scheduling entity of the target vCPU can be added to the global pause queue. Subsequently, if it is detected that the target virtual CPU meets the preset wake-up condition, the scheduling entity of the target virtual CPU can be taken out from the global pause queue and added to the global scheduling queue, and after the target virtual CPU is reawakened, the target virtual CPU is run by the physical CPU again.

[0091] In actual applications, the preset wake-up condition can be set according to actual needs, for example, it can be an IPI (Inter-Processor Interrupts, processor interrupt) event sent to the target vCPU, or a software LAPIC (Local Advanced Programmable Interrupt Controller, local programmable interrupt controller) timer expires or receives some active synchronization instructions sent to the target vCPU. The virtualization layer can detect that the target virtual CPU meets the preset wake-up condition.

[0092] Through the above embodiment, since the scheduling entity of the target virtual CPU is added to the global pause queue when the target virtual CPU is paused, the target virtual CPU will not appear in the global scheduling queue, and thus the target virtual CPU will not be scheduled. By setting the corresponding wake-up condition, when the target virtual CPU needs to be woken up, the scheduling entity of the target virtual CPU is removed from the global pause queue and added to the virtual CPU scheduling queue, so that the target virtual CPU can participate in subsequent scheduling and execution.

[0093] As an example, in the example in which the virtual CPU scheduling queue includes the global scheduling queue or the emergency scheduling queue, the scheduling entity of the target virtual CPU can be added to the global scheduling queue or the emergency scheduling queue according to the emergency degree of the event sent to the target vCPU after the target virtual CPU is reawakened.

[0094] In some examples, the method further includes: during the running of the physical processor on the target virtual processor, if it is detected that the target virtual processor corresponds to a yield event, stopping the running of the target virtual processor, and adding the scheduling entity of the target virtual processor to the global scheduling queue.

[0095] As an example, the yield event can be various, such as a pause instruction used in a multi-core processor to prompt the processor to be in a waiting state to optimize resource use, which does not perform a specific function, but prompts the processor that it is a yieldable state. Based on this, in the embodiment, when the yield event corresponding to the target virtual processor is detected, such as the execution of the pause instruction in the target vCPU, the target vCPU can be directly yielded, that is, the running of the target virtual CPU is stopped, and the scheduling entity of the target virtual CPU can rejoin the global scheduling queue, so that the target virtual CPU can participate in subsequent scheduling and execution.

[0096] Next, the following embodiments are used for illustration. The following embodiments take the processor as an example of CPU. It can be understood that in actual application, the CPU in the embodiment can be replaced by other types of processors, such as GPU, and the like, and the embodiment does not limit this. Embodiment 1 Normal running scheduling of virtual CPU in light virtualization architecture

[0097] The embodiment can be applied to a virtualization layer to switch a running host operating system from a root mode to a virtualization mode, and create at least one virtual CPU in the virtualization mode. Since the newly created virtual CPU can not have a fixed physical CPU corresponding to it, the range of physical CPUs that the virtual CPU can run on can be set.

[0098] As an example, the scheduling priority of the newly created virtual CPU can be set, and the priority can be set to be not higher than the priority of other directly switched physical CPUs, but higher than the priority of background tasks.

[0099] As an example, the time slice of the newly created virtual CPU that can run on the physical CPU can be set, so that the scheduler of the virtualization layer allocates a certain time slice to the virtual CPU for use in each scheduling period.

[0100] As an example, a scheduling running function can be established for the scheduling class of the virtual CPU, including running functions, dequeuing, and enqueuing functions; the running process of the virtual CPU is not different from the physical CPU after actual switching, so the running function can directly reuse the running function of the vCPU switched by the physical CPU.

[0101] Each physical CPU has a corresponding scheduling queue, and a scheduling object for scheduling a virtual CPU can be added in the scheduling queue of each physical CPU. The scheduling object can be added in the scheduling queue of all physical CPUs, or can be added in the scheduling queue of part of the physical CPUs.

[0102] Each newly created virtual CPU corresponds to a vCPU structure, which contains a scheduling entity corresponding to the aforementioned scheduling class. The scheduling entity can include the aforementioned running function, dequeuing, enqueuing, and other functions, and can also include the time slice and other information. The scheduling entity of each newly created virtual CPU can be mounted in the global scheduling queue, which can be a linked list or other data structure.

[0103] Each physical CPU can run a scheduler in the virtualization layer. The scheduler in each physical CPU can select a running task from the scheduling queue of the physical CPU for running. Based on the priority set for the virtual CPU, when a scheduling shell is selected from the scheduling queue, it means that it is the turn of the newly created virtual CPU to run, and a scheduling entity se can be selected from the global scheduling queue. If a vCPU scheduling entity is selected, it is dequeued from the global scheduling queue. If the global scheduling queue is empty, the scheduler will select other running tasks in the scheduling queue of the physical CPU.

[0104] The selected target virtual CPU scheduling entity se can be called to execute its specific running function set. As an example, the running function set includes functions for dequeuing, executing, and enqueuing the scheduling entity se; optionally, the specific execution process can be to set a running timeout time based on the time slice and historical execution information, and then execute the specific task function, which can be executed in the process of executing the specific task function. The actual running time can be counted at the end of the specific task function, which can be used for subsequent scheduler adjustment of the time slice of the vCPU.

[0105] To avoid long execution of the target virtual CPU, a time slice check can be set. Considering that the execution of the vCPU can be trapped due to various events, a timeout check can be performed at the trapping place.

[0106] At the same time, if the target vCPU does not trap for a long time during execution, this check will not be performed consistently, causing the running of other CPUs to hang; therefore, a certain timer can be set, which can be implemented using the preemption timer in existing hardware virtualization, or a software timer can be run in the vCPU. When the vCPU is scheduled to run on the physical CPU, the software timer also starts. The timer has a timing duration, and the timer starts counting when the virtual CPU runs. The setting of the timing duration realizes the setting of the exit time of the vCPU. As an example, the timer can be pre-set with a corresponding interrupt event, and when the timing duration of the timer reaches, the timer pre-set interrupt event is injected to the vCPU, so that when the virtualization layer detects the interrupt event of the timer, the running of the vCPU is stopped.

[0107] Therefore, the longest runtime of the target vCPU without trapping will not be longer than the timing duration of the timer. Of course, too frequent trapping can also cause performance loss, and the duration can be set to be longer than the time slice corresponding to the newly created vCPU.

[0108] After the virtual CPU completes the current time slice, the scheduling se of the virtual CPU will be re-queued into the global scheduling queue. In this way, the virtual CPU can continue to be selected for running if there is an idle time slice on another physical CPU.

[0109] In each scheduling round, the time slice that can be run can be calculated at the beginning, and the actual time slice used can be calculated at the end; for example, the timing duration of the timer can be read at the end, and if it is exceeded, the next scheduling period will be appropriately reduced. Of course, if there is a surplus, appropriate points can be used to offset the previous overtime, but it cannot be too long, otherwise it will affect the fairness of scheduling.

[0110] The scheduling process of the normal running of the virtual CPU described in Embodiment 1; in other examples, emergency running scheduling can also be implemented considering some special cases.

[0111] As an example, the CPU runs in time for some interrupts or exceptions and the like, and needs to respond quickly; for such events, if the virtual CPU does not get running in time, it can cause serious problems in the system, or even cause the system to be stuck. However, the regular virtual CPU scheduling is limited by priority and time slice, and cannot guarantee real-time performance; therefore, fast response is required for such events, and based on this, the embodiment can also create an emergency scheduling queue for mounting the scheduling entities se of the virtual CPUs that need to be handled urgently.

[0112] In actual application, if the vCPU receives an interrupt or exception event of the vCPU during running on the physical CPU, such as an external interrupt and the like, the vCPU can be trapped to the root mode of the virtualization layer to handle the interrupt event.

[0113] If there are some vCPUs that are not running on the physical CPU, the virtualization layer can detect events sent to these vCPUs, such as interrupt events between vCPUs and the like, and if it is an emergency event, the se of the virtual CPU can be mounted to the emergency scheduling queue, so that the vCPU can be scheduled to run on the physical CPU as soon as possible.

[0114] Since the emergency scheduling will disrupt the original scheduler time allocation rhythm, and even the priority inversion situation can occur, the time length of the emergency scheduling required can be limited, for example, different priority emergency scheduling queues can be established. For example, each physical CPU can correspond to a local emergency scheduling sub-queue, which needs to be responded first, and the local CPU will consider whether it has an event to run when scheduling, even if the current running priority is higher than the priority of the virtual CPU. Secondly, a global emergency scheduling sub-queue can also be set, which is used for some events that need to be processed quickly but have slightly lower priority. The virtual CPU in it will be given priority over the virtual CPU in the global scheduling queue mentioned above, and all physical CPUs will give priority to this scheduling queue when scheduling. In addition, in order to relatively guarantee the full running of the virtual CPU in the emergency scheduling situation, some virtual CPUs can also be bound to a certain physical CPU and fixed to a certain physical CPU for execution.

[0115] As an example, when the scheduler selects a scheduling entity, it first determines whether there is a local CPU emergency scheduling sub-queue that needs to be executed immediately. If there is a virtual CPU that needs to be selected first, the virtual CPU can be executed immediately. Of course, at this time, due to the emergency execution, it is possible that the virtual CPU has already been executed previously and there is no free time slice for execution at present. At this time, it is necessary to allocate a minimum running time slice to it to ensure that it can run normally.

[0116] If the local emergency scheduling sub-queue is empty, further selection is made from the global emergency scheduling sub-queue. If the global emergency scheduling sub-queue is not empty, a scheduling entity is selected from it to enable the corresponding virtual CPU to run; otherwise, a scheduling entity is selected from the global scheduling queue. That is, when selecting a scheduling entity, the order is: local emergency scheduling queue, global emergency scheduling queue, global scheduling queue.

[0117] In this embodiment, considering that the virtual CPU can be suspended for running due to some reasons, the following suspension scheduling embodiment based thereon can also be included: as an example, when the virtual CPU is running on the physical CPU, a halt or mwait suspension instruction occurs, the virtual CPU can be trapped into the virtualization root mode, so that the virtualization layer can execute a function related to the suspension instruction; at the same time, the scheduling entity of the virtual CPU can be mounted into the global suspension queue. Optionally, the scheduling entity of the virtual CPU can include a processing function, and the processing function can include a halt field. The halt field of the scheduling entity can be set to 1, indicating that the vCPU corresponding to the scheduling entity is in a suspended state. Through the setting, it can be represented that the vCPU is in a suspended state.

[0118] Subsequently, the virtualization layer can detect whether the preset wake-up condition is met for the vCPU in the pause state. The wake-up condition can be set as needed, for example, the virtualization layer intercepts an interrupt event sent by another vCPU to the vCPU in the pause state, such as an ipi interrupt event, and the like. The vCPU sending the ipi interrupt event can trap into the root mode, and the vCPU in the pause state can be woken up to execute the interrupt event. Alternatively, the processing flow can be to clear the halt field of the processing function in the scheduling entity, to represent that the vCPU clears the pause state, and the scheduling entity can also be removed from the global pause queue and moved into the global scheduling queue.

[0119] In actual applications, the preset wake-up condition can also be other, for example, the software lapic timer expires, or the virtual CPU receives an active synchronization instruction, and also wakes up from the pause queue and performs the same operation.

[0120] For the trap-out of the vCPU in the running process caused by the pause instruction, the yield field of the scheduling entity can be set to the yield flag, and the execution of the virtual CPU this time is yielded. The scheduling entity of the virtual CPU does not enter the pause queue, but is moved into the global scheduling queue, and the next time the virtual CPU is scheduled, the virtual CPU can also be selected to run.

[0121] As can be seen from the above embodiments, the CPU scheduling method of the physical machine is applied to the virtualization layer in the physical machine. The physical machine includes a physical CPU, and the physical CPU corresponds to a scheduling queue. The virtualization layer can switch the running host operating system from the root mode to the virtualization mode. In the virtualization mode, at least one virtual CPU is created. A scheduling object is generated and added to the scheduling queue of the physical CPU. In the process of selecting a running task for the physical CPU based on the scheduling queue of the physical CPU, if the scheduling object is selected, a target virtual CPU is selected from the at least one virtual CPU, and the physical CPU is scheduled to run the target virtual CPU. Based on this, the embodiments of the present disclosure can directly create a new virtual CPU in the running host operating system. When the scheduling object is selected, the target virtual CPU can be selected to run on the physical CPU by adding the scheduling object to the scheduling queue of the physical CPU. Therefore, the resources of the physical CPU can be more efficiently utilized, the utilization rate of the CPU is improved, and the number of virtual CPUs created can be arbitrary, and the physical CPU computing power can be flexibly provided to the upper layer through the virtual CPU.

[0122] Correspondingly, the disclosure also provides a processor scheduling system of a physical machine, as described in the foregoing embodiments, please see Fig. 2A, the physical machine includes a physical processor and a host operating system running on the physical processor, a virtualization layer is implemented between the physical processor and the host operating system, the processor scheduling system can be implemented in the virtualization layer, and the steps of the method described in any one of the foregoing embodiments are executed by the processor scheduling system.

[0123] As an example, the virtualization layer can switch the running host operating system from the root mode to the virtualization mode when needed. For example, the physical machine can include hardware resources, the hardware resources including at least one physical computing resource object and a physical address space, the physical address space having a host physical address, the host operating system running on the physical computing resource object; switching the running host operating system from the root mode to the virtualization mode includes: creating a memory page table for storing a mapping relationship between a guest physical address in the virtualization mode and a host physical address in the root mode; creating an information carrying object required during mode switching, the information carrying object being used for synchronizing context information between the root mode and the virtualization mode; switching the running host operating system from the root mode to the virtualization mode based on the information carrying object and the memory page table.

[0124] The physical address space has a host physical address in the root mode, the host physical address can be denoted by HPA (Physical Address), and the host physical address is the address of physical memory in a physical memory resource; in the virtualization mode, the physical address space corresponds to a virtual address space, the virtual address space has a guest physical address, the guest physical address can be denoted by GPA (Guest Physical Address), and the guest physical address is the address of virtual memory in a virtual memory resource.

[0125] In this embodiment, the virtualization layer can create a memory page table, the memory page table being used for storing a mapping relationship between a guest physical address in the virtualization mode and a host physical address in the root mode. The memory page table can be denoted by EPT (Extended Page Tables).

[0126] Optionally, creating the memory page table includes: establishing a page table structure body corresponding to the memory page table, and applying a root page of the memory page table from the physical address space; generating an entry address of the memory page table according to the host physical address of the root page, and adding the entry address to the page table structure body; and creating a multi-level memory page table according to the address range of the physical address space and a page granularity used for mapping the guest physical address and the host physical address.

[0127] Optionally, the information carrying object required for mode switching can be created, including: creating a physical descriptor structure for any physical computing resource object, the physical descriptor structure being used to save the context information of any physical computing resource in the root mode during mode switching; creating a virtualization descriptor structure for any physical computing resource object and initializing, the virtualization descriptor structure being used to synchronize the context information in the physical descriptor structure during mode switching; creating a virtualization control structure for any physical computing resource object and initializing, the virtualization control structure being used to save the running state information and running control information of any physical computing resource object in the virtualization mode.

[0128] Optionally, the running host operating system can be switched from the root mode to the virtualization mode based on the information carrying object and the memory page table, including: in the case of mode switching of a target physical computing resource object, saving the context information of the target physical computing resource object in the root mode into the physical descriptor structure corresponding to the target physical computing resource object; synchronizing the values of each register and the configuration information of the segment register in the context information in the physical descriptor structure into the virtualization descriptor structure and the virtualization control structure corresponding to the target physical computing resource object, respectively; controlling the target physical computing resource object to run according to the virtualization descriptor structure, the virtualization control structure and the memory page table, so as to switch the running host operating system from the root mode to the virtualization mode.

[0129] Further optionally, saving the context information of the target physical computing resource object in the root mode into the physical descriptor structure corresponding to the target physical computing resource object includes: saving the values of each register and the top and bottom addresses of the second stack in the context information into the physical descriptor structure, the second stack being the stack used by the target physical computing resource object in the root mode; switching the second stack used by the target physical computing resource object in the root mode to the first stack corresponding to the target physical computing resource object in the virtualization mode.

[0130] Further optionally, controlling the target physical computing resource object to run according to the virtualization descriptor structure, the virtualization control structure and the memory page table includes: loading the values of the special registers in the virtualization control structure and the virtualization descriptor structure; injecting the running control information in the virtualization control structure into the target physical computing resource object, and loading the values of the general registers in the virtualization descriptor structure; executing the mode switching instruction to control the target physical computing resource object to enter the virtualization mode and start running from the first instruction, and in the running process, performing memory management and access based on the memory page table.

[0131] Corresponding to the foregoing embodiments of the processor scheduling method of the physical machine, the present disclosure also provides embodiments of a processor scheduling apparatus of a physical machine and a computer device to which the processor scheduling apparatus is applied.

[0132] The embodiments of the processor scheduling apparatus of the physical machine of the present disclosure can be applied on a computer device, such as a server or a terminal device. The apparatus embodiments can be implemented by software, or by hardware or a combination of software and hardware. Taking the software implementation as an example, as a logically meaningful apparatus, the processor scheduling apparatus of the present disclosure is formed by reading the corresponding computer program instructions in the non-volatile memory into the memory for running by the processor. From the hardware perspective, as shown in FIG. 3, FIG. 3 is a hardware structure diagram of a computer device to which the processor scheduling apparatus of the physical machine of the present disclosure is applied. In addition to the processor 310, the network interface 320, the memory 330, and the non-volatile memory 340 shown in FIG. 3, the computer device to which the processor scheduling apparatus 331 of the physical machine in the embodiments is applied usually includes other hardware according to the actual functions of the computer device, and thus will not be described here.

[0133] As shown in FIG. 4, FIG. 4 is a structure diagram of a processor scheduling apparatus of a physical machine according to an exemplary embodiment of the present disclosure, the physical machine including a physical processor corresponding to a scheduling queue, the apparatus including: a creating module 41 configured to switch a running host operating system from a root mode to a virtualization mode, and create at least one virtual processor in the virtualization mode; an adding module 42 configured to generate a scheduling object and add the scheduling object to the scheduling queue of the physical processor; and a scheduling module 43 configured to, in the process of selecting a running task for the physical processor based on the scheduling queue of the physical processor, if the scheduling object is selected, select a target virtual processor, and schedule the physical processor to run a running task of the target virtual processor.

[0134] In some other examples, the virtual processor corresponds to a scheduling entity, and the creating module is further configured to create a virtual processor scheduling queue for storing the scheduling entity corresponding to the virtual processor, and the selecting module is configured to select a target scheduling entity from the virtual processor scheduling queue, and determine a target virtual processor corresponding to the target scheduling entity.

[0135] In some examples, the virtual processor scheduling queue includes a global scheduling queue and an emergency scheduling queue, a priority of a virtual processor corresponding to a scheduling entity in the global scheduling queue is lower than a priority of a virtual processor corresponding to a scheduling entity in the emergency scheduling queue; and the selecting module is further configured to: determine whether the target scheduling entity exists in the emergency scheduling queue; if yes, select the target scheduling entity from the emergency scheduling queue; and if no, select the target scheduling entity from the global scheduling queue.

[0136] In some examples, the creating module is further configured to: create a scheduling entity corresponding to the virtual processor and add the scheduling entity to the global scheduling queue; detect whether a preset emergency event occurs to a virtual processor corresponding to each scheduling entity in the global scheduling queue; and after removing a scheduling entity corresponding to a virtual processor on which the preset emergency event occurs from the global scheduling queue, add the scheduling entity to the emergency scheduling queue.

[0137] In some examples, the physical machine includes a plurality of physical processors, each of the physical processors is configured to run a scheduler, and the apparatus is applied to the scheduler running in each physical processor; the emergency scheduling queue includes a local emergency scheduling subqueue corresponding to each of the physical CPUs respectively and a global emergency scheduling subqueue; a priority of a virtual CPU corresponding to a scheduling entity in the local emergency scheduling subqueue is higher than a priority of a virtual CPU corresponding to a scheduling entity in the global emergency scheduling subqueue; or a virtual CPU corresponding to a scheduling entity in the local emergency scheduling subqueue is bound to a physical CPU corresponding to the local emergency scheduling subqueue; and the determining whether the target scheduling entity exists in the emergency scheduling queue includes: determining whether a target local emergency scheduling subqueue corresponding to the physical processor has a scheduling entity; if yes, selecting the scheduling entity from the target local emergency scheduling subqueue; and if no, selecting the scheduling entity from the global emergency scheduling subqueue.

[0138] In some examples, the scheduling module is further configured to: allocate a current runtime length of a current scheduling period to the target virtual processor, and schedule the physical processor to run the target virtual processor based on the current runtime length; and if the target virtual processor completes running on the physical processor, re-add a scheduling entity corresponding to the target virtual processor to the global scheduling queue.

[0139] In some examples, the scheduling module is further configured to: obtain a difference between an actual runtime length of the target virtual processor in a historical scheduling period and a historical runtime length allocated to the target virtual processor in the historical scheduling period, and determine a current runtime length of the target virtual processor in a current scheduling period based on the difference.

[0140] In some other examples, the scheduling module is further configured to: start a timer when scheduling the physical processor to run the target virtual processor based on the current running duration; and stop running of the target virtual processor when the duration of the timer is reached.

[0141] In some other examples, the apparatus further includes a suspension module configured to: create a global suspension queue; suspend running of the target virtual CPU and add a scheduling entity of the target virtual CPU to the global suspension queue if a suspension event corresponding to the target virtual CPU is detected during running of the target virtual CPU by the physical CPU; and add the scheduling entity of the target virtual CPU to the virtual CPU scheduling queue after removing the scheduling entity of the target virtual CPU from the global suspension queue if the target virtual CPU satisfies a preset wake-up condition.

[0142] In some other examples, the apparatus further includes a yield module configured to: stop running of the target virtual CPU and add a scheduling entity of the target virtual CPU to the global scheduling queue if a yield event corresponding to the target virtual CPU is detected during running of the target virtual CPU by the physical CPU.

[0143] The functions and effects of the modules in the processor scheduling apparatus of the physical machine are specifically described in the implementation process of the corresponding steps in the processor scheduling method of the physical machine, and thus will not be repeated here.

[0144] Correspondingly, the embodiments of the present disclosure further provide a computer program product, including a computer program, which, when executed by a processor, implements the steps of the processor scheduling method embodiments of the physical machine.

[0145] Correspondingly, the embodiments of the present disclosure further provide a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the processor scheduling method embodiments of the physical machine when executing the program.

[0146] Correspondingly, the embodiments of the present disclosure further provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the processor scheduling method embodiments of the physical machine.

[0147] For the apparatus embodiment, since it basically corresponds to the method embodiment, the relevant part can be seen from the part of the method embodiment. The apparatus embodiment described above is only illustrative, wherein the modules described as separate components can or can not be physically separated, and the components displayed as modules can or can not be physical modules, i.e., can be located in one place or distributed on multiple network modules. Part or all of the modules can be selected to achieve the purpose of the present disclosure according to actual needs. Those skilled in the art can understand and implement it without creative labor.

[0148] The above embodiments can be applied to one or more computer devices, which are devices capable of automatically performing numerical calculation and / or information processing according to pre-set or stored instructions. The hardware of the computer device includes but is not limited to microprocessors, application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), digital signal processors (DSPs), embedded devices, etc.

[0149] The computer device can be any electronic product capable of human-computer interaction with the user, such as a personal computer, a tablet computer, a smart phone, a personal digital assistant (PDA), a game console, an interactive Internet Protocol Television (IPTV), a smart wearable device, etc.

[0150] The computer device can also include a network device and / or a user device. The network device includes but is not limited to a single network server, a server group composed of multiple network servers, or a cloud composed of a large number of hosts or network servers based on cloud computing.

[0151] The network in which the computer device is located includes but is not limited to the Internet, a wide area network, a metropolitan area network, a local area network, a virtual private network (VPN), etc.

[0152] The above describes particular embodiments of the present disclosure. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims can be performed in a different order and still accomplish the desired result. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve the desired results. In certain implementations, multitasking and parallel processing can be advantageous or necessary.

[0153] The division of steps in the above methods is only for the sake of clarity, and in implementation, one step can be combined or some steps can be split and decomposed into multiple steps, as long as the same logical relationship is included, which is within the protection scope of the patent; adding insignificant modifications or introducing insignificant designs in the algorithm or process, but not changing the core design of the algorithm and process, are within the protection scope of the application.

[0154] While the present disclosure contains many specific embodiments, these should not be construed as limiting any of the claims hereto in scope or requirement except to the specific embodiments described. Certain features that are, for clarity, described above and illustrated in the drawings can be combined or eliminated, and other features can be added. Further, while the application has been described here with reference to particular embodiments, it is not intended to be limited to the details described, since additional embodiments and / or variations can be possible according to the detailed description and the annexed drawings. In other instances, well-known structures and functions have not been described in detail so as not to unnecessarily obscure aspects of the application. It will be understood by those within the art that, in general, terms used herein, and especially

[0155] Where a term is introduced as "specific example" or "some examples" or the like, this is intended to mean that the specific feature, structure, material, or characteristic being described is included in at least one embodiment or example of the present disclosure. The illustrative appearance of the above-mentioned terms in the detailed description is not necessarily intended to identify the same embodiment or example. Moreover, the description of particular features, structures, materials, or characteristics is intended to bring about a better understanding for at least one embodiment or example, and it is not intended to mean that all or even some embodiments or examples necessarily include the particular feature, structure, material, or characteristic.

[0156] Other embodiments of the present disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the application disclosed herein. The present disclosure is intended to cover any and all variations of the present disclosure comprising features of the disclosure that are within the spirit and scope of the claims. It is submitted that the true scope of the present disclosure is not limited to the specific embodiments disclosed, but is in accordance with the appended claims.

[0157] It is to be understood that the present disclosure is not limited to the precise construction herein described and as shown in the drawings, and that various modifications and changes can be made by those skilled in the art without departing from the scope thereof. The scope of the present disclosure is limited only by the claims appended hereto.

[0158] The above description is merely the preferred embodiment of this disclosure, and is not used to limit this disclosure. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of this disclosure should be included in the scope of this disclosure.

Claims

1. A processor scheduling method of a physical machine, the physical machine comprising a physical processor, the physical processor corresponding to a scheduling queue, the method comprising: switching a running host operating system from a root mode to a virtualization mode, in the virtualization mode, creating at least one virtual processor; generating a scheduling object and adding the scheduling object to the scheduling queue of the physical processor; in a process of selecting a running task for the physical processor based on the scheduling queue of the physical processor, if the scheduling object is selected, selecting a target virtual processor from the at least one virtual processor, and scheduling the physical processor to run the target virtual processor. 2.The method of claim 1, the virtual processor corresponding to a scheduling entity, the method further comprising: creating a virtual processor scheduling queue, the virtual processor scheduling queue being used to store the scheduling entity corresponding to the virtual processor; the selecting the target virtual processor from the at least one virtual processor comprising: selecting a target scheduling entity from the virtual processor scheduling queue, and determining the target virtual processor corresponding to the target scheduling entity. 3.The method of claim 2, the virtual processor scheduling queue comprising a global scheduling queue and an emergency scheduling queue, a priority of a virtual processor corresponding to a scheduling entity in the global scheduling queue being lower than a priority of a virtual processor corresponding to a scheduling entity in the emergency scheduling queue; the selecting the target scheduling entity from the virtual processor scheduling queue comprising: determining whether there is a scheduling entity in the emergency scheduling queue; if yes, selecting the target scheduling entity from the emergency scheduling queue; if no, selecting the target scheduling entity from the global scheduling queue. 4.The method of claim 3, after the step of creating the at least one virtual processor, the method further comprising: creating the scheduling entity corresponding to the virtual processor and adding the scheduling entity to the global scheduling queue; detecting whether a preset emergency event occurs to a virtual processor corresponding to each scheduling entity in the global scheduling queue; after removing the scheduling entity corresponding to the virtual processor in which the preset emergency event occurs from the global scheduling queue, adding the scheduling entity to the emergency scheduling queue. 5.The method of claim 3, the physical machine comprising a plurality of physical processors, each of the physical processors being used to run a scheduler, the method being applied to the scheduler running in each physical processor; the emergency scheduling queue comprising: a local emergency scheduling subqueue corresponding to each of the physical processors respectively, and a global emergency scheduling subqueue; wherein a priority of a virtual processor corresponding to a scheduling entity in the local emergency scheduling subqueue is higher than a priority of a virtual processor corresponding to a scheduling entity in the global emergency scheduling subqueue; or a virtual processor corresponding to a scheduling entity in the local emergency scheduling subqueue is bound to the physical processor corresponding to the local emergency scheduling subqueue; the determining whether there is a scheduling entity in the emergency scheduling queue comprising: determining whether there is a scheduling entity in a target local emergency scheduling sub-queue corresponding to the physical processor; if so, selecting a scheduling entity from the target local emergency scheduling sub-queue; if not, selecting a scheduling entity from the global emergency scheduling sub-queue.

6. The method of claim 3, wherein the scheduling the physical processor to run the target virtual processor comprises: allocating a current running duration of a current scheduling period to the target virtual processor, and scheduling the physical processor to run the target virtual processor based on the current running duration; the method further comprises: if the target virtual processor completes running on the physical processor, re-adding the scheduling entity corresponding to the target virtual processor to the global scheduling queue.

7. The method of claim 6, wherein the allocating a current running duration of a current scheduling period to the target virtual processor comprises: obtaining a difference between an actual running duration of the target virtual processor in a historical scheduling period and a historical running duration allocated to the target virtual processor in the historical scheduling period, and determining the current running duration of the target virtual processor in the current scheduling period based on the difference.

8. The method of claim 7, the method further comprises: starting a timer when scheduling the physical processor to run the target virtual processor based on the current running duration, and stopping the running of the target virtual processor when a timing duration of the timer arrives.

9. The method of claim 2, the method further comprises: creating a global pause queue; during the running of the target virtual processor on the physical processor, if a pause event corresponding to the target virtual processor is detected, pausing the running of the target virtual processor, and adding the scheduling entity of the target virtual processor to the global pause queue; if the target virtual processor is detected to satisfy a preset wake-up condition, removing the scheduling entity of the target virtual processor from the global pause queue and adding it to the virtual processor scheduling queue.

10. The method of claim 3, the method further comprises: during the running of the target virtual processor on the physical processor, if a yield event corresponding to the target virtual processor is detected, stopping the running of the target virtual processor, and adding the scheduling entity of the target virtual processor to the global scheduling queue.

11. A computer device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein, the processor executes the computer program to implement the steps of the method of any one of claims 1 to 10.

12. A processor scheduling system of a physical machine, the physical machine comprising a physical processor and a host operating system running on the physical processor, a virtualization layer being implemented between the physical processor and the host operating system, the virtualization layer comprising the processor scheduling system, the processor scheduling system being configured to perform the steps of the method of any one of claims 1 to 10.

13. A computer program product comprising a computer program, the computer program being configured to perform the steps of the method of any one of claims 1 to 10 when executed by a processor.

14. A computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of the method of any one of claims 1 to 10.

Citation Information

Patent Citations

  • Multi-virtual processor synchronous scheduling method and multi-virtual processor synchronous scheduling system

    CN106250217A

  • Virtual CPU scheduling method and device, computer equipment and storage medium

    CN111459622A

  • Dynamic frequency modulation method for CPU (Central Processing Unit) under virtualization

    CN117076137A

  • Virtual machine control method and virtual machine system

    US20100115513A1