CN114327814A - Task scheduling method, virtual machine, physical host and storage medium - Google Patents

Task scheduling method, virtual machine, physical host and storage medium Download PDF

Info

Publication number
CN114327814A
CN114327814A CN202111498968.8A CN202111498968A CN114327814A CN 114327814 A CN114327814 A CN 114327814A CN 202111498968 A CN202111498968 A CN 202111498968A CN 114327814 A CN114327814 A CN 114327814A
Authority
CN
China
Prior art keywords
virtual machine
physical host
task
physical
vcpu thread
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111498968.8A
Other languages
Chinese (zh)
Inventor
潘雪松
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Alibaba China Co Ltd
Original Assignee
Alibaba China Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Alibaba China Co Ltd filed Critical Alibaba China Co Ltd
Priority to CN202111498968.8A priority Critical patent/CN114327814A/en
Publication of CN114327814A publication Critical patent/CN114327814A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The embodiment of the invention provides a task scheduling method, a virtual machine, a physical host and a storage medium, wherein the method comprises the following steps: when the central processing unit VCPU thread of the virtual machine is in an idle state, a termination instruction can be called, so that the virtual machine does not release the physical resources corresponding to the VCPU thread to the physical host. Meanwhile, the virtual machine can record and synchronize the first time period of the VCPU thread in the idle state to the physical host, so that the physical host can know the working state of the VCPU thread under the condition of not recycling physical resources, and further carry out task scheduling according to the working state, thereby improving the accuracy of task scheduling and ensuring the normal execution of tasks. Meanwhile, after a new task is allocated to the virtual machine, the VCPU thread can directly utilize the physical resources which are not released to the physical host machine to execute the task, so that the response speed of the task is improved.

Description

Task scheduling method, virtual machine, physical host and storage medium
Technical Field
The present invention relates to the field of virtualization technologies, and in particular, to a task scheduling method, a virtual machine, a physical host, and a storage medium.
Background
Virtualization technology is a logical representation of physical resources on a physical host. With the development of virtualization technology, the cost of physical hardware equipment can be greatly reduced, and the waste of physical resources is reduced.
In a virtualized scenario, after a Virtual machine executes a specific instruction, such as a termination instruction, that is, a hash instruction, the Virtual machine may be in an un-trapped state, that is, when a Virtual Central Processing Unit (VCPU) thread of the Virtual machine is in an idle state, a physical resource corresponding to the VCPU thread is not released and released back to a physical host. At this time, the physical host may think that the VCPU thread of the virtual machine is still executing the task, and the task is not allocated to the virtual machine where the physical resource monopolization occurs, but actually, the VCPU thread of the virtual machine is in an idle state, so that the task scheduling is inaccurate.
Therefore, how to ensure the accuracy of task scheduling becomes an urgent problem to be solved.
Disclosure of Invention
In view of this, embodiments of the present invention provide a task scheduling method, a virtual machine, a physical host, and a storage medium, so as to ensure accuracy of task scheduling.
In a first aspect, an embodiment of the present invention provides a task scheduling method, including:
executing a termination instruction called when a Virtual Central Processing Unit (VCPU) thread is in an idle state, so that a virtual machine containing the VCPU thread does not release physical resources corresponding to the VCPU thread to a physical host;
recording a first time period when the VCPU thread is in an idle state;
sharing the first time interval with the physical host to enable the physical host to schedule the tasks to be executed in the physical host according to the first time interval.
In a second aspect, an embodiment of the present invention provides a virtual machine, including: the virtual central processing VCPU thread, the virtual memory and the kernel module;
the virtual machine is used for executing a termination instruction called when the VCPU thread is in an idle state, so that the virtual machine containing the VCPU thread does not release the physical resource corresponding to the VCPU thread to a physical host; sharing the first time interval that the VCPU thread is in an idle state with the physical host, so that the physical host schedules the tasks to be executed in the physical host according to the first time interval;
the kernel module is used for determining a shared memory space in the virtual memory; and recording the first time period to the shared memory space.
In a third aspect, an embodiment of the present invention provides another task scheduling method, including:
acquiring a first time period recorded by a virtual machine when a Virtual Central Processing Unit (VCPU) thread in the virtual machine is in an idle state, wherein after the VCPU thread is in the idle state and a termination instruction is called, physical resources corresponding to the VCPU thread are not released to a physical host;
and scheduling the tasks to be executed in the physical host according to the first time interval.
In a fourth aspect, an embodiment of the present invention provides a physical host, including: a memory and a processor, and a virtual machine running in an isolated environment constructed by the memory and the processor;
the memory for storing a computer program;
the processor is configured to execute the computer program to implement the task scheduling method according to the first aspect or the third aspect.
In a fifth aspect, an embodiment of the present invention provides a non-transitory machine-readable storage medium having stored thereon executable code, which when executed by a processor of an electronic device, causes the processor to implement at least the task scheduling method according to the first aspect or the third aspect.
According to the task scheduling method provided by the embodiment of the invention, the termination instruction can be called when the central processing unit (VCPU) thread of the virtual machine is in an idle state, and after the instruction is called, the virtual machine does not release the physical resource corresponding to the VCPU thread back to the physical host, but continues to monopolize the physical resource corresponding to the VCPU thread. Meanwhile, the virtual machine can record a first time period when the VCPU thread is in an idle state, and share the first time period to the physical host, so that the physical host can accurately know the working state of the VCPU thread under the condition that physical resources are not recycled, and know the use condition of the physical resources, particularly CPU resources, so as to further carry out task scheduling according to the use condition of the resources.
Therefore, in the method, the virtual machine can accurately know the working condition of the VCPU thread, namely the use condition of the CPU resource of the virtual machine per se, through the sharing in the first time period, without releasing the physical resource corresponding to the VCPU thread, so that the accuracy of task scheduling is further improved, and the normal execution of the task is ensured. Meanwhile, after any new task is allocated to the virtual machine, the task can be directly allocated to the VCPU thread which has the physical resource of the physical host computer in an idle state, and the VCPU thread can directly utilize the physical resource which is not released to the physical host computer to execute the task, so that the response speed of the task is improved.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and those skilled in the art can also obtain other drawings according to the drawings without creative efforts.
Fig. 1 is a schematic flowchart of a task scheduling method according to an embodiment of the present invention;
fig. 2 is a schematic flowchart of another task scheduling method according to an embodiment of the present invention;
fig. 3 is a schematic structural diagram of a virtual machine corresponding to the task scheduling method provided in the embodiment shown in fig. 1 or fig. 2;
fig. 4 is a flowchart illustrating a task scheduling method according to another embodiment of the present invention;
fig. 5 is a flowchart illustrating a task scheduling method according to another embodiment of the present invention;
fig. 6 is a schematic structural diagram of a physical host corresponding to the task scheduling method provided in the embodiment shown in fig. 3 or fig. 4;
fig. 7 is a schematic structural diagram of a physical host according to an embodiment of the present invention;
fig. 8 is a schematic structural diagram of another physical host according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The terminology used in the embodiments of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used in the examples of the present invention and the appended claims, the singular forms "a", "an", and "the" are intended to include the plural forms as well, and "a" and "an" generally include at least two, but do not exclude at least one, unless the context clearly dictates otherwise.
It should be understood that the term "and/or" as used herein is merely one type of association that describes an associated object, meaning that three relationships may exist, e.g., a and/or B may mean: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the character "/" herein generally indicates that the former and latter related objects are in an "or" relationship.
The words "if," "if," as used herein may be interpreted as "at … …" or "at … …" or "in response to a determination" or "in response to a recognition," depending on the context. Similarly, the phrases "if determined" or "if identified (a stated condition or event)" may be interpreted as "when determined" or "in response to a determination" or "when identified (a stated condition or event)" or "in response to an identification (a stated condition or event)", depending on the context.
It is also noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a good or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such good or system. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a commodity or system that includes the element.
Some embodiments of the invention are described in detail below with reference to the accompanying drawings. The features of the embodiments and examples described below may be combined with each other without conflict between the embodiments. In addition, the sequence of steps in each method embodiment described below is only an example and is not strictly limited.
Fig. 1 is a flowchart illustrating a task scheduling method according to an embodiment of the present invention, where the task scheduling method according to the embodiment of the present invention may be executed by a virtual machine running in an isolation environment constructed by a physical host. As shown in fig. 1, the method comprises the steps of:
s101, executing a termination instruction called when a Virtual Central Processing Unit (VCPU) thread is in an idle state, so that a virtual machine containing the VCPU thread does not release physical resources corresponding to the VCPU thread to a physical host.
When a VCPU thread in a virtual machine processes a task, the thread is obviously in a working state. Then when the VCPU thread is not executing the task, i.e. the CPU is in an idle state, a termination instruction is called, and the virtual machine can be in a non-stuck-out state through the call of the termination instruction. This no-collapse state can be considered as: when the VCPU thread is in the idle state, the virtual machine including the VCPU thread does not release the physical resource corresponding to the VCPU thread back to the physical host, and the virtual machine has exclusive rights to the physical resource corresponding to the VCPU thread.
Optionally, the manager of the physical host may modify a code of a Virtual Machine Monitor (VMM) in the physical host, so that the Virtual Machine running in the physical host does not release the physical resource after the termination instruction is called. More specifically, the non-trapping after the call termination instruction can be realized by modifying the content in a Virtual Machine Control Structure (VMCS) register in a Kernel-Based Virtual Machine (KVM). The KVM is also included in the VMM.
Alternatively, for a virtual machine deployed with a Linux operating system, the termination instruction mentioned in the above description may be a hash instruction.
S102, recording a first time period when the VCPU thread is in an idle state.
After the termination instruction is called, the virtual machine can record the starting time of the VCPU thread in an idle state; meanwhile, when the VCPU thread resumes executing the task, the virtual machine also records the stop time when the VCPU thread is in the idle state, and the start time and the stop time may form a first period when the virtual machine is in the idle state.
Optionally, the first period of time may be recorded in a virtual memory space of the virtual machine. Specifically, the first period of time may be recorded in a shared memory space in the virtual memory space, and the physical host and the virtual machine share the shared memory space. For the acquisition of the shared memory space, optionally, when the virtual machine is started, the virtual machine may apply for a part of the virtual memory space allocated by the physical host as the shared memory space, where the shared memory space is shared by the virtual machine and the physical host, and both of them may read and write data. Optionally, the virtual machine may have a kernel module configured therein, and the kernel module may be used to apply for the shared memory space from the virtual memory space in response to the startup of the kernel module. And optionally, the kernel module may also be used to record the first period.
S103, sharing a first time interval with the physical host, so that the physical host schedules the tasks to be executed in the physical host according to the first time interval.
By executing step 101, the virtual machine is in an idle state, so that the virtual machine does not trap to cause monopolization of physical resources, but the physical host does not know that the VCPU thread of the virtual machine is currently in an idle state, so that the physical host cannot accurately know the use condition of its own physical resources, especially CPU resources. In order to improve the above situation, the virtual machine may share the first time period recorded in step 102 to the physical host, so that the physical host can accurately know the usage of its own CPU resource, and may also schedule the task to be executed according to the accurate usage of the CPU resource.
For the sharing in the first period, optionally, the virtual machine sends a memory address of the shared memory space to the physical host, and the physical host can obtain the first period according to the memory address.
In this embodiment, the termination instruction may be called when the VCPU thread of the virtual machine is in the idle state, and after the termination instruction is called, the virtual machine does not release the physical resource corresponding to the VCPU thread back to the physical host, but continues to monopolize the physical resource corresponding to the VCPU thread. Meanwhile, the virtual machine can record a first time period when the VCPU thread is in an idle state, and synchronize the first time period to the physical host, so that the physical host can accurately know the working state of the VCPU thread under the condition that physical resources are not recycled, know the use condition of the physical resources of the physical host, particularly CPU resources, and further carry out task scheduling according to the use condition of the resources.
Therefore, in the method, the virtual machine can accurately know the working condition of the VCPU thread, that is, the use condition of the CPU resource of the virtual machine can be accurately known, by sharing the virtual machine in the first time period, without releasing the physical resource corresponding to the VCPU thread, so as to further improve the accuracy of task scheduling and ensure the normal execution of the task.
In addition, by executing the above scheme, after any new task is allocated to the virtual machine, the VCPU thread in the idle state monopolizes the physical resource allocated by the physical host, so that the VCPU thread can directly utilize the monopolized physical resource to execute the task, thereby improving the response speed to the task. For the reason of improving the response speed of the task, more specifically:
in step 101 of the above embodiment, the virtual machine is in the non-trapped state after the termination instruction is called, but different from this manner, optionally, when the VCPU thread is in the idle state and after the termination instruction is called, the virtual machine may also be in the trapped state, that is, the virtual machine may release the physical resource to the physical host. After the virtual machine is trapped out, when a new task occurs, the physical host reallocates the physical resources to the virtual machine, so that the VCPU thread of the virtual machine responds to the new task by using the reallocated physical resources.
In the above process, due to the trapping caused after the virtual machine calls the instruction, a process of releasing and reallocating the physical resource occurs, so that the virtual machine can respond to the new task only after passing through the long link, thereby affecting the response speed of the task. However, according to the mode of the embodiment shown in fig. 1, since the virtual machine does not get out after the termination instruction is called, the process that the virtual machine releases the physical resource and the physical host reallocates the physical resource can be omitted, so that the link through which the task is executed is shortened, and the response speed of the virtual machine to the task can be improved.
Alternatively, since multiple virtual machines can typically run in a physical host, when a new task occurs, the new task can be assigned to virtually any virtual machine that contains an idle VCPU thread. If the VCPU threads included in each of the plurality of virtual machines are in a working state and there are also physical resources in the physical host that are not allocated to the virtual machine, the new task may also be allocated to the physical host.
However, because of the virtualization of the virtual machine itself, the time required for the virtual machine to execute the task is longer than the time required for the physical host to execute the task for the same task, and therefore, the response speed of the physical host to the task is higher than that of the virtual machine by using the VCPU thread of the virtual machine. In practice, a low-priority task with low requirement on the task response speed is generally allocated to the virtual machine, and a high-priority task with high requirement on the task response speed is allocated to the physical host. Corresponding to the following description, a high priority task may be considered an online task and a low priority task may be considered an offline task.
In practice, the virtual machine calls the termination instruction when the VCPU thread is in the idle state, and may also execute other control instructions generated by the physical device, and fig. 2 is a flowchart of another task scheduling method provided in the embodiment of the present invention.
As shown in fig. 2, the method may include the steps of:
s201, executing a termination instruction called when the Virtual Central Processing Unit (VCPU) thread is in an idle state, so that the virtual machine containing the VCPU thread does not release the physical resource corresponding to the VCPU thread to the physical host.
S202, recording a first period of time when the VCPU thread is in an idle state.
The execution process of the above steps S201 to S202 is similar to the corresponding steps of the foregoing embodiment, and reference may be made to the relevant description in the embodiment shown in fig. 1, which is not repeated herein.
S203, executing a target control instruction generated by the physical host, enabling the virtual machine to release the physical resources corresponding to the VCPU thread to the physical host, enabling the physical host to acquire a second time period for releasing the physical resources corresponding to the VCPU thread, and scheduling the task to be executed according to the first time period and the second time period.
When the virtual machine executes the target control instruction generated by the physical host, the physical resources corresponding to the VCPU thread are released to the physical host, that is, the virtual machine is in a trapped state. At this time, the physical host may autonomously know the second time period when the virtual machine releases the physical resource corresponding to the VCPU thread, that is, the physical host may know the release condition of its own physical resource, especially the CPU resource.
Alternatively, the target control instruction may be an interrupt instruction or a Write data Register (WRMSR) instruction. When there is a write data task for the physical host, then a WRMSR instruction may be generated. This write data task is actually a high priority task with a high requirement on the task response speed, and the high priority task may be regarded as an online task, corresponding to the following description. Wherein the content of the first and second substances,
when other types of high priority tasks are present in the physical host, then an interrupt instruction may be generated. For example, the high-priority task may also include an interaction triggered by a user to an application such as a social application, a shopping application, an information application, etc. installed in the terminal device. The physical host needs to quickly respond to the interactive operation triggered by the user so as to feed back the interactive result to the user in time, thereby ensuring the human-computer interactive experience of the user.
Optionally, the second time period when the VCPU thread releases the physical resource is a time period when the high-priority target task to be executed is executed.
It can be seen that, when the virtual machine executes the steps S201 to S202, the physical host can know the first time period that the VCPU thread of the virtual machine is in the idle state, that is, know the exclusive condition of the CPU resource of the physical host. Executing steps S203 to S204 makes it possible for the physical host to know the release of its CPU resources.
Finally, the physical host can schedule the task to be executed according to the accurate use condition of the CPU resource so as to further ensure the accuracy of task scheduling.
It should be noted that, in practice, the target control instruction is generated according to the generation of the high-priority task, and the reason for terminating the instruction call is that the VCPU thread is in an idle state. Because there is no strict sequence between the generation of the task and the idle state of the VCPU thread, the termination instruction and the target control instruction executed by the virtual machine also have no strict sequence, that is, there is no strict sequence between the above steps S201 to S202 and steps S203 to S204.
It should be noted that, since the target control instruction is generated due to the generation of the high-priority task, if the VCPU thread in the virtual machine is in a working state, that is, there is a task currently being processed, and at this time, the physical host generates the target control instruction, the virtual machine will respond to the target control instruction preferentially, stop executing the current task and trap out, that is, release the physical resources corresponding to the VCPU thread, and the physical host executes the high-priority task by using the released physical resources.
And after the high-priority task is executed, the physical host can continue to execute the unfinished task generated by the virtual machine due to the response of the target control instruction by using the physical resource released by the virtual machine. After the virtual machine executes the target control instruction and releases the physical resources, the physical host can directly utilize the released physical resources to continue to execute the unfinished task without reallocating the physical resources to the virtual machine and then continuously executing the unfinished task by the virtual machine, so that the response speed of the task can be improved.
Optionally, after the high-priority task is executed, if a virtual machine including an idle VCPU thread runs in the physical host, the virtual machine may also be allowed to execute an unfinished task. And in practice, the uncompleted tasks may be executed by different virtual machines before and after the generation of the target control instruction.
In this embodiment, the virtual machine can enable the physical host to obtain the first time period when the VCPU thread is in the idle state in a data sharing manner, that is, know the exclusive situation of the CPU resource of the physical host, and can also obtain the second time period when the virtual machine releases the physical resource corresponding to the VCPU thread autonomously, that is, know the release situation of the CPU resource of the physical host, and finally, the physical host can perform more accurate scheduling on the task to be executed according to the accurate usage situation of the CPU resource.
The above embodiments describe the implementation process of the task scheduling method from the perspective of the virtual machine. Based on the foregoing embodiments, fig. 3 is a schematic structural diagram of a virtual machine according to an embodiment of the present invention. As shown in fig. 3, the virtual machine may include: VCPU thread, virtual memory and kernel module.
The virtual machine may call the termination instruction when the VCPU thread is in the idle state, so that the virtual machine does not release the physical resource corresponding to the VCPU thread included in the virtual machine to the physical host, that is, the virtual machine monopolizes the physical resource corresponding to the VCPU thread.
When the virtual machine is started, the kernel module in the virtual machine is also started, and at this time, optionally, the kernel module may determine a part of the virtual memory space from the virtual memory of the virtual machine as a shared memory space, so that both the virtual machine and the physical host perform data reading and writing. The virtual machine records the first period of time that the VCPU thread is in the idle state in the shared memory space, and shares the first period of time in the shared memory space to the physical host. Optionally, the recording of the first time period may also be performed by a kernel module in the virtual machine. In an alternative sharing manner, the virtual machine may send the memory address of the shared memory space to the physical host, so that the physical host reads the first time period recorded therein according to the memory address.
Finally, the physical host can schedule the task to be executed according to the exclusive condition of the CPU resource.
In practice, optionally, the virtual machine may further execute a target control instruction generated by the physical host, and in response to the execution of the target control instruction, the virtual machine may be in a trapped state, that is, the physical resource corresponding to the VCPU thread is sent to the physical host, so that the physical host autonomously obtains a second time period when the virtual machine releases the physical resource, so that the physical host knows the release condition of the CPU resource of the physical host.
At this time, the physical host can simultaneously schedule the tasks to be executed according to the exclusive condition and the release condition of the CPU resources, so that the accuracy of task scheduling is improved.
In addition, for the parts of the embodiment not described in detail, reference may be made to the related description of the embodiment shown in fig. 1 to 2. The implementation process and technical effect of the technical solution refer to the descriptions in the embodiments shown in fig. 1 to fig. 2, and are not described herein again.
In the above embodiments, the physical host may perform task scheduling according to the usage of its CPU resource, and fig. 4 is a flowchart of another task scheduling method provided in the embodiments of the present invention. The task scheduling method provided by the embodiment of the invention can be executed by a physical host with a virtual machine. As shown in fig. 4, the method may include the steps of:
s301, a first time period recorded by the virtual machine when the VCPU thread is in an idle state is obtained, wherein after the VCPU thread is in the idle state and a termination instruction is called, physical resources corresponding to the VCPU thread are not released to the physical host.
S302, scheduling the tasks to be executed in the physical host according to the first time interval.
The virtual machine may record a first period of time that the VCPU thread is in an idle state in the manner in the embodiment shown in fig. 1 or fig. 2, that is, during this first period of time, the virtual machine may monopolize part of the physical resources of the physical host, especially CPU resources. Then, the virtual machine can share the first time period of the exclusive CPU resource to the physical host by setting a shared virtual memory, so that the physical host knows the exclusive condition of the CPU resource. The physical host can further schedule the task to be executed according to the resource exclusive condition.
Alternatively, the administrator of the physical host may modify the code of the VMM in the physical host in such a way that the virtual machine running in the physical host does not release the physical resources after the termination instruction is invoked. More specifically, it may be implemented by modifying the VMCS register running in KVM to not trap after the virtual machine call termination instruction. The KVM is included in the VMM.
In this embodiment, the virtual machine in the non-trapped state may share the exclusive condition of the physical resource to the physical host, so that the physical host may accurately obtain the use condition of the physical resource, especially the CPU resource, without releasing the physical resource by the virtual machine, thereby scheduling the task according to the accurate use condition of the resource and ensuring the response speed of the task.
In addition, for the parts of the embodiment not described in detail, reference may be made to the related description of the embodiment shown in fig. 1. The implementation process and technical effect of the technical solution refer to the description in the embodiment shown in fig. 1, and are not described herein again.
Based on the embodiment shown in fig. 4, fig. 5 is a flowchart illustrating a task scheduling method according to another embodiment of the present invention. As shown in fig. 5, the method may include the steps of:
s401, acquiring a first time period recorded by the virtual machine when the VCPU thread is in an idle state, wherein after the VCPU thread is in the idle state and a termination instruction is called, physical resources corresponding to the VCPU thread are not released to the physical host.
The execution process of step S401 is similar to the corresponding steps in the foregoing embodiment, and reference may be made to the relevant description in the embodiment shown in fig. 3, which is not repeated herein.
S402, sending a target control instruction to the virtual machine, so that the VCPU thread in the virtual machine responds to the target control instruction, and releasing the physical resources corresponding to the VCPU thread to the physical host.
And S403, acquiring a second time period for releasing the physical resources corresponding to the VCPU thread.
The physical host may also send a target control instruction after obtaining the task to be executed, so that the virtual machine responds to the target control instruction, and the virtual machine is in a trapped state, that is, the virtual machine releases the physical resource corresponding to the VCPU thread to the physical host. As in the embodiment shown in fig. 2, the target control instruction may be an interrupt instruction or a WRMSR instruction generated by the physical host when a high-priority task occurs. And in response to the virtual machine releasing the corresponding physical resource for the VCPU thread, the physical host may also autonomously record a second period of time during which the virtual machine releases the physical resource.
As can be seen, by executing step S401, the physical host can know the exclusive condition of the CPU resource of the physical host when the virtual machine is in the non-trapped state; by executing steps S402 to S403, the physical host can know the release condition of the CPU resource of the physical host when the virtual machine is in the trapped state, that is, the use condition of the CPU resource of the physical host in different time periods can be accurately obtained.
S404, scheduling the tasks to be executed in the physical host according to the first time interval and the second time interval.
Finally, the physical host can schedule the task to be executed according to different use conditions of the CPU resource of the physical host in different time periods.
It should be noted that, because there is no strict sequence between the generation of the task to be executed and the idle state of the VCPU thread, the termination instruction and the target control instruction executed by the virtual machine also have no strict sequence, and therefore, there is no strict sequence between step S401 and steps S402 to S403.
In this embodiment, the exclusive condition of the physical resource when the virtual machine is in the non-trapped state may be shared with the physical host, and the physical host may also autonomously obtain the release condition of the physical resource after the virtual machine executes the target control instruction. The physical host can know the physical resources of the physical host, mainly different using conditions of the CPU resources at different time intervals, so that task scheduling is carried out according to the accurate using conditions of the resources, and the response speed of the tasks is guaranteed.
In addition, for the parts of the embodiment not described in detail, reference may be made to the related description of the embodiment shown in fig. 2. The implementation process and technical effect of the technical solution refer to the description in the embodiment shown in fig. 2, and are not described herein again.
Through the embodiments, the physical host can accurately obtain the use condition of the physical resource of the physical host, especially the CPU resource, and then can perform task scheduling based on the use condition. Before describing the scheduling process in detail, the tasks to be executed may also be explained: in practice, the tasks to be executed, which need to be scheduled by the physical host, can be divided into online tasks and offline tasks according to the requirement on the task response speed.
For example, different types of applications may be installed in the terminal device used by the user. The user can trigger interactive operation on different types of application programs, and meanwhile, an interactive result corresponding to the interactive operation also needs to be obtained in real time. More specifically, the interactive operation triggered by the user may be a start operation, a search operation, and the like triggered by an application such as a social application, a shopping application, an information application, and the like, and the user needs to see an operation result corresponding to different operations in real time. A task that requires a real-time response like the one described above can be considered an online task.
For some tasks that do not need real-time response, for example, a manager of a physical host used with a shopping application needs to count the access condition of the shopping application, the selling condition of goods, and the like in the past month by means of the physical host, and the physical host needs to obtain the statistical result after 24 hours. It can be seen that, like this, where a longer task processing time is specified, a task that has low requirements for response speed may be an offline task.
The online task and the offline task obtained based on the division can be scheduled in different modes according to different conditions.
When the VCPU thread of the virtual machine is in an idle state and does not trap at the first time period, the physical host may directly allocate the task to be executed to the idle VCPU thread for the task to be executed obtained at any time in the first time period. That is, when the physical host acquires the task to be executed in the first period, the task can be directly executed by the virtual machine containing the idle VCPU thread. Alternatively, the task to be executed assigned to the VCPU thread may be an offline task or an online task. However, considering that the virtual machine is a virtualization device, the time required for the virtual machine to execute the task is generally longer than the time required for the physical host to execute the task for the same task, and therefore, the task to be executed directly by the idle VCPU thread is generally an offline task with low response speed requirement.
The above scheduling manner can be understood as follows: when a virtual machine containing an idle VCPU thread exists and a physical resource corresponding to the VCPU thread is not released, the task to be executed can be directly allocated to the virtual machine. And the scheduling mode is more suitable for offline tasks.
For the task to be executed obtained in the first time period, optionally, if the physical host includes the remaining physical resources that are not allocated to any virtual machine, the task to be executed may also be executed directly by using the remaining physical resources in the physical host. Compared with the method that the virtual machine containing the idle VCPU thread executes the task, the method that the residual physical resources in the physical host are directly used for executing the task to be executed can better ensure the response speed of the task. For this scheduling manner, the task to be executed obtained in the first time period may be an offline task or an online task.
When the obtained task to be executed is an online task, the task to be executed has a higher requirement on the task response speed, and in one case, if the remaining physical resources which are not allocated to the virtual machine exist in the physical host, the remaining physical resources can be directly used for executing the online task. In another case, if all the physical resources of the physical host are allocated to at least one virtual machine running inside, the physical host sends a target control instruction to the target virtual machine in response to the acquisition of the online task, so that the target virtual machine releases the physical resources corresponding to the VCPU thread in response to the target control instruction, and the physical host executes the online task by using the physical resources released by the target virtual machine.
In practice, the target control instruction is usually an interrupt instruction or a WRMSR instruction. Optionally, the target virtual machine may be any one of the at least one virtual machine, and optionally, the target virtual machine may be selected according to a current load condition, a historical operating state, and the like of each virtual machine in the at least one virtual machine. The historical running state may include historical task execution of the virtual machine and/or a third period of time during which a VCPU thread of the virtual machine is in an idle state within a preset time period.
The above scheduling manner can be understood as follows: when the physical host acquires the online task with high priority, if the physical host has the residual physical resources which are not allocated to the virtual machine, the physical host can directly utilize the residual physical resources to execute the task so as to ensure the response speed of the task. If all the physical resources in the physical host are allocated to the virtual machine, the virtual machine can release the physical resources corresponding to the VCPU thread of the virtual machine by means of the target control instruction, so that the physical host executes the online task by using the released physical resources, and the response speed of the task can also be ensured.
In the above scheduling manner for the online task, it is not limited whether the VCPU thread of the virtual machine is in an idle state when the target control instruction is received, and in one case, the virtual machine responds to the target control instruction after the virtual machine call termination instruction, that is, when the VCPU thread in the virtual machine is in an idle state. At this time, the process of responding to the target control instruction and releasing the physical resources corresponding to the VCPU thread does not affect the execution progress of the task of the virtual machine itself.
In another case, the virtual machine responds to the target control instruction before the virtual machine calls the termination instruction, i.e. when the VCPU thread in the virtual machine is in the working state. At this time, the response target control instruction forcibly causes the virtual machine to release the physical resource, so that the task being executed by the virtual machine becomes an incomplete task, and the execution progress of the task of the virtual machine itself is affected.
For this situation, after the physical host completes the online task using the physical resource released by the virtual machine, optionally, if there is a virtual machine in the physical host whose VCPU is in an idle state, the physical host may allocate the uncompleted task to the virtual machine having the VCPU thread in the idle state. Optionally, if there are multiple virtual machines in which the VCPUs are in the idle state, the target virtual machine may be selected from the current load condition and the historical operating state of each virtual machine, and the uncompleted task is allocated to the target virtual machine.
Alternatively, if there is no virtual machine in the physical host with the VCPU in an idle state, the physical host may reallocate the physical resources to the virtual machine, so that the virtual machine continues to perform the unfinished task.
Alternatively, since the virtual machine has released the physical resources, the physical host can directly utilize the physical resources released back to the physical host to execute the uncompleted tasks of the virtual machine resulting from responding to the target control instruction. And compared with the physical host, the physical resources are allocated to the virtual machine again, the virtual machine continues to execute the unfinished tasks, and the unfinished tasks before the virtual machine are finished by directly using the physical resources in the physical host, so that the response speed of the tasks can be improved.
The above scheduling manner can be understood as follows: after the physical host completes the online task, the unfinished task generated by the virtual machine due to the response to the target control instruction can be further scheduled according to the use condition that the physical resource of the physical host is mainly the CPU resource.
The above embodiments describe the process of task scheduling from the perspective of a physical host. Based on the foregoing embodiments, fig. 6 is a schematic structural diagram of a physical host according to an embodiment of the present invention. As shown in fig. 6, the physical host may include: a processor, a memory, and a virtual machine running in an isolated environment constructed by the memory and the processor.
A memory for storing a computer program;
and a processor, configured to execute the computer program to implement the task scheduling method provided in the embodiments shown in fig. 1 to fig. 2 or fig. 4 to fig. 5.
For convenience of understanding, a specific implementation process of the task scheduling method provided by the above embodiments is exemplarily described by taking an online shopping scenario as an example.
The shopping application is installed in the terminal device of the user, and the manager of the application also maintains a server, i.e. the physical host 1, for ensuring the normal operation of the application, so the manager of the application is also the manager of the physical device in the above embodiment. And a virtual machine 2 and a virtual machine 3 are also running in the physical host 1.
During online shopping using the shopping application, from the perspective of the user, the user can trigger a start operation on the application to enable the terminal device to display a main interface of the shopping application. And then, the user can trigger a search operation on the main interface so that the terminal equipment can display the search interface. Further, the user can trigger a click operation on the commodity A in the search result, so that the terminal device displays a commodity detail page of the commodity A. For various interactive operations triggered by the user, the physical host needs to quickly respond to the interactive operations, so that a response result is fed back to the terminal equipment, and finally the terminal equipment is displayed. Thus, the response of the physical host to the interaction may be considered an online task with a high demand for response speed.
From the perspective of an application manager, in order to better provide shopping services for users, the manager often needs to collect and count the use condition of the shopping application periodically by using a physical host, and the count result often needs to be fed back to the manager after a period of time, for example, several hours. The use cases may include access times of the application programs, transaction times, selling cases of various types of commodities, and the like. For tasks such as statistical tasks and the like which do not need to feed back results in real time, the tasks can be considered to be offline tasks with low requirements on response speed.
Based on the above description, it can be known that a physical host with multiple virtual machines needs to schedule an online task or an offline task, so as to ensure that a shopping application program can normally provide an online shopping function for a user.
Specifically, when the VCPU thread included in the virtual machine 2 in the physical host is in the idle state, the termination instruction is called, so that the virtual machine is in the non-trapped state, that is, the virtual machine 2 does not release the physical resource corresponding to the VCPU thread back to the physical host, that is, the virtual machine 2 monopolizes the physical resource allocated by the physical host. Meanwhile, the virtual machine 2 records a first time period when the VCPU thread of the virtual machine 2 is in an idle state, and records the first time period in the shared memory set in the virtual machine 2, so that the physical host can obtain the time period when the VCPU thread of the virtual machine 2 is in the idle state by means of the shared memory, that is, the exclusive situation of the CPU resource of the physical host can be known.
Similarly, when the VCPU thread included in the virtual machine 3 is in an idle state, the physical host is notified in the above manner.
When the physical host obtains an offline task generated by the manager of the application program, if the virtual machine 2 or the virtual machine 3 includes an idle VCPU thread, the offline task may be directly allocated to the virtual machine including the idle VCPU thread.
If the VCPU threads of the virtual machines 2 and 3 are both in a working state and the physical resources of the physical host that are not allocated to the virtual machines are in an idle state, the offline task may be allocated to the physical host.
If the VCPU threads of the virtual machines 2 and 3 are both in a working state, and the physical resources in the physical host that are not allocated to the virtual machines are also in a working state, the offline tasks may be allocated according to the current load conditions and the historical operating states of the virtual machines and the physical host.
It should be noted that, because the virtual machine including the VCPU thread in the idle state does not release the physical resource to the physical host, when the offline task occurs, the virtual machine may directly execute the offline task by using the unreleased physical resource, so as to omit a process in which the virtual machine releases the physical resource and the physical host re-allocates the physical resource to the virtual machine, thereby improving the response speed of the virtual machine to the task.
When the physical host obtains the offline task, if the physical host has physical resources which are not allocated to the virtual machine, the physical host can directly execute the offline task.
And in practice, the task of the virtual machine is usually an offline task generated by the physical host manager, considering that the response speed of the virtual machine to the task is slower than that of the physical host.
When the physical host obtains the online task generated by the user, in one case, if there are physical resources not allocated to the virtual machine in the physical host, the online task may be directly allocated to the physical host.
In another case, if there is no physical resource allocated to the virtual machine in the physical host, in response to the acquisition of the online task, the physical host may generate an interrupt instruction, so that the virtual machine 2 and/or the virtual machine 3 stops executing the currently executing task, and release the physical resource corresponding to the VCPU thread of the physical host back to the physical host, that is, the virtual machine is in a sunken state, and the physical host may record a second time period in which different virtual machines release the physical resource, so as to know the release condition of the CPU resource of the physical host. At this time, the physical host may perform the online task using the physical resources released by the virtual machine. And the task that was previously executing in virtual machine 2 and/or virtual machine 3 becomes an incomplete task due to the release of the physical resources.
And after the execution of the online task is completed, the physical resources released back to the physical host can continue to execute the unfinished tasks corresponding to the virtual machine 2 and the virtual machine 3, and the unfinished tasks do not need to be continuously executed by the virtual machine, so that the response speed of the tasks is improved.
The task scheduling method provided by the embodiments of the present invention can also be understood by combining the physical host shown in fig. 7.
It should be noted that the virtual machine mentioned in the task scheduling method provided in each of the above embodiments may also be replaced with another virtual device obtained after implementing resource isolation from the operating system level, such as a secure container (i.e., a sandbox container). And in practice, the offline task may be typically performed by the physical host or a secure container running in the physical host; the online task may be typically performed by a physical host or by a generic container running in a physical host. The common container and the physical host share physical resources which are not allocated to virtual devices such as a virtual machine or a secure container in the physical host. The process of physical host task scheduling in the scenario illustrated in fig. 7 can also be understood in conjunction with fig. 8.
In addition, an embodiment of the present invention provides a computer storage medium for storing computer software instructions for the electronic device, which includes a program for executing the user program running method in the method embodiments shown in fig. 1 to 2 or fig. 4 to 5.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.

Claims (14)

1. A task scheduling method is applied to a virtual machine and comprises the following steps:
executing a termination instruction called when a Virtual Central Processing Unit (VCPU) thread is in an idle state, so that a virtual machine containing the VCPU thread does not release physical resources corresponding to the VCPU thread to a physical host;
recording a first time period when the VCPU thread is in an idle state;
sharing the first time interval with the physical host to enable the physical host to schedule the tasks to be executed in the physical host according to the first time interval.
2. The method of claim 1, further comprising:
and executing a target control instruction generated by the physical host, so that the virtual machine releases the physical resources corresponding to the VCPU thread to the physical host, so that the physical host acquires a second time period for releasing the physical resources corresponding to the VCPU thread and schedules the task to be executed according to the first time period and the second time period.
3. The method of claim 1, further comprising:
responding to the starting of the virtual machine, and determining a shared memory space in a virtual memory space of the virtual machine;
storing the first period of time in the shared memory space;
the sharing of the first time period with the physical host comprises:
and sending the memory address of the shared memory space to the physical host, so that the physical host acquires the first time interval according to the memory address.
4. The method of claim 3, wherein determining a target memory space in the memory space of the virtual machine in response to the virtual machine booting comprises:
and responding to the starting of a kernel module in the virtual machine, and determining the target memory space.
5. A task scheduling method is applied to a physical host, and comprises the following steps:
acquiring a first time period recorded by a virtual machine when a Virtual Central Processing Unit (VCPU) thread in the virtual machine is in an idle state, wherein after the VCPU thread is in the idle state and a termination instruction is called, physical resources corresponding to the VCPU thread are not released to a physical host;
and scheduling the tasks to be executed in the physical host according to the first time interval.
6. The method of claim 5, further comprising:
and modifying a virtual machine monitoring program in the physical host machine so that the virtual machine does not release the physical resources corresponding to the VCPU thread after calling the termination instruction.
7. The method of claim 5, wherein scheduling the tasks to be executed in the physical host according to the first time period comprises:
and if the physical host acquires the task to be executed in the first time period, executing the task to be executed by the VCPU thread.
8. The method of claim 5, further comprising:
sending a target control instruction to the virtual machine, so that the VCPU thread in the virtual machine responds to the target control instruction, and releases a physical resource corresponding to the VCPU thread to the physical host;
acquiring a second time period for releasing the physical resources corresponding to the VCPU thread;
the scheduling the task to be executed in the physical host according to the first time period includes:
and scheduling the task to be executed according to the first time interval and the second time interval.
9. The method of claim 8, wherein the task to be performed comprises an online task in the physical host; the sending the target control instruction to the virtual machine includes:
responding to the acquisition of the online task, and if all physical resources in the physical host are allocated to the virtual machine, sending the target control instruction to the virtual machine;
the scheduling the task to be executed according to the first time period and the second time period comprises:
and executing the online task according to the physical resources released to the physical host by the VCPU thread in the second time period.
10. The method of claim 9, wherein the target control instruction is generated prior to invoking the termination instruction, and wherein the tasks to be executed further comprise outstanding tasks being executed by the VCPU thread when the virtual machine responds to the target control instruction;
the method further comprises the following steps:
and after the online task is executed, releasing physical resources to execute the unfinished task in the second time period by utilizing the VCPU thread.
11. The method of claim 6, further comprising:
acquiring a historical running state of the VCPU thread, wherein the historical running state comprises a third time period and/or a historical task execution condition which are in an idle state within a preset time length;
the scheduling the task to be executed in the physical host according to the first time period includes:
and scheduling the task to be executed according to the first time period and the historical running state.
12. A virtual machine, comprising: the virtual central processing VCPU thread, the virtual memory and the kernel module;
the virtual machine is used for executing a termination instruction called when the VCPU thread is in an idle state, so that the virtual machine containing the VCPU thread does not release the physical resource corresponding to the VCPU thread to a physical host; sharing the first time interval that the VCPU thread is in an idle state with the physical host, so that the physical host schedules the tasks to be executed in the physical host according to the first time interval;
the kernel module is used for determining a shared memory space in the virtual memory; and recording the first time period to the shared memory space.
13. A physical host, comprising: a memory and a processor, and a virtual machine running in an isolated environment constructed by the memory and the processor;
the memory for storing a computer program;
the processor for executing the computer program to implement the task scheduling method according to any one of claims 1 to 11.
14. A non-transitory machine-readable storage medium having stored thereon executable code, which when executed by a processor of an electronic device, causes the processor to perform the task scheduling method of any one of claims 1 to 11.
CN202111498968.8A 2021-12-09 2021-12-09 Task scheduling method, virtual machine, physical host and storage medium Pending CN114327814A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111498968.8A CN114327814A (en) 2021-12-09 2021-12-09 Task scheduling method, virtual machine, physical host and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111498968.8A CN114327814A (en) 2021-12-09 2021-12-09 Task scheduling method, virtual machine, physical host and storage medium

Publications (1)

Publication Number Publication Date
CN114327814A true CN114327814A (en) 2022-04-12

Family

ID=81049965

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111498968.8A Pending CN114327814A (en) 2021-12-09 2021-12-09 Task scheduling method, virtual machine, physical host and storage medium

Country Status (1)

Country Link
CN (1) CN114327814A (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20160259664A1 (en) * 2014-01-15 2016-09-08 Shanghai Jiao Tong University Method for dynamic interrupt balanced mapping based on current scheduling states of vcpus
CN105975327A (en) * 2015-03-10 2016-09-28 国际商业机器公司 Method for reducing virtual machine pre-emption in virtualized environment and computer system
US20170249186A1 (en) * 2013-08-26 2017-08-31 Vmware, Inc. Cpu scheduler configured to support latency sensitive virtual machines
CN109144679A (en) * 2017-06-27 2019-01-04 华为技术有限公司 Processing method, device and the virtual equipment of interrupt requests
CN111324432A (en) * 2020-01-21 2020-06-23 腾讯科技(深圳)有限公司 Processor scheduling method, device, server and storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170249186A1 (en) * 2013-08-26 2017-08-31 Vmware, Inc. Cpu scheduler configured to support latency sensitive virtual machines
US20160259664A1 (en) * 2014-01-15 2016-09-08 Shanghai Jiao Tong University Method for dynamic interrupt balanced mapping based on current scheduling states of vcpus
CN105975327A (en) * 2015-03-10 2016-09-28 国际商业机器公司 Method for reducing virtual machine pre-emption in virtualized environment and computer system
CN109144679A (en) * 2017-06-27 2019-01-04 华为技术有限公司 Processing method, device and the virtual equipment of interrupt requests
CN111324432A (en) * 2020-01-21 2020-06-23 腾讯科技(深圳)有限公司 Processor scheduling method, device, server and storage medium

Similar Documents

Publication Publication Date Title
US10073711B2 (en) Virtual machine monitor configured to support latency sensitive virtual machines
US7945908B1 (en) Method and system for improving the accuracy of timing and process accounting within virtual machines
US9304794B2 (en) Virtual machine control method and virtual machine system using prefetch information
US8635612B2 (en) Systems and methods for hypervisor discovery and utilization
JP5458998B2 (en) Virtual machine system and virtual machine management method
WO2011104824A1 (en) Multi-core processor system, control program, and control method
US20180088979A1 (en) Virtual machine liveliness detection
US20090241112A1 (en) Recording medium recording virtual machine control program and virtual machine system
CN111831434A (en) Resource allocation method, device, storage medium and electronic equipment
CN115480931A (en) Inter-core communication processing method and device and computer system
CN111831432B (en) IO request scheduling method and device, storage medium and electronic equipment
CN111831436A (en) Scheduling method and device of IO (input/output) request, storage medium and electronic equipment
CN114327814A (en) Task scheduling method, virtual machine, physical host and storage medium
US11429424B2 (en) Fine-grained application-aware latency optimization for virtual machines at runtime
EP3502887B1 (en) Interrupt handling for multiple virtual machines
Joe et al. Effects of dynamic isolation for full virtualized RTOS and GPOS guests
US20230236901A1 (en) Safe critical section operations for virtual machines with virtual central processing unit overcommit
US20240134669A1 (en) Paravirtual pause loops in guest user space
CN116880962A (en) Method, device, equipment and vehicle for determining virtual machine manager delay information
Wang et al. Unleashing the Power of Preemptive Priority-based Scheduling for Real-Time GPU Tasks
CN117632516A (en) Resource allocation method and device and computer equipment
CN117056014A (en) Intelligent management and control method and device for virtualized equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination