The present invention relates to the field of virtualization, and, more particularly to a method, apparatus and system for optimizing context switching between virtual machines.
Virtualization technology enables a single host running a virtual machine monitor (“VMM”) to present multiple abstractions of the host, such that the underlying hardware of the host appears as one or more independently operating virtual machines (“VMs”). Each VM may therefore function as a self-contained platform, running its own operating system (“OS”), or a copy of the OS, and/or a software application. The operating system and application software executing within a VM is collectively referred to as “guest software.” The VMM performs “context switching” as necessary to multiplex between various virtual machines according to a “round-robin” or some other predetermined scheme. To perform a context switch, the VMM may suspend execution of a first VM, optionally save the current state of the first VM, extract state information for a second VM and then execute the second VM.
The present invention is illustrated by way of example and not limitation in the figures of the accompanying drawings in which like references indicate similar elements, and in which:
Embodiments of the present invention provide a method, apparatus and system for optimizing context switching between VMs. Reference in the specification to “one embodiment” or “an embodiment” of the present invention means that a particular feature, structure or characteristic described in connection with the embodiment is included in at least one embodiment of the present invention. Thus, the appearances of the phrases “in one embodiment,” “according to one embodiment” or the like appearing in various places throughout the specification are not necessarily all referring to the same embodiment.
The VMM on a virtual machine host has ultimate control over the host's physical resources and, as previously described, the VMM allocates these resources to guest software according to a round-robin or some other scheduling scheme. Current VMM's rely on the same execution thread (e.g., a hardware thread, a processor core and/or a central processing unit) to perform context switching (i.e., to save/restore the state of virtual machines) and to run the virtual machines. Currently, when the VMM schedules another VM for execution, it suspends execution of the active VM, and restores the state of a previously suspended VM from memory and/or disk into the processor cache, then resumes execution of the newly restored VM. It may also save the execution state of the suspended VM from the processor cache into memory and/or disk. The VMM typically uses the same execution thread to save the execution state (i.e., the internal state of the processor cache when the current VM was context switched out, including the paging data structure, device state, program counters, stack pointers, etc.) of the current VM from the host's processor cache to a main storage location, such as memory and/or disk. The previously suspended state of a second virtual machine from main memory and/or disk is brought into the host's processor cache and the second virtual machine is allowed to execute. Storing and retrieving state information to and from memory and/or disk, and use of the same execution thread to perform all such tasks is a virtualization overhead that may result in delays that significantly degrade the host's overall performance and the performance of the virtual machines.
Embodiments of the present invention include an optimized method, apparatus and system for context switching between VMs. More specifically, embodiments of the present invention optimize the context switching between virtual machines by using a separate execution thread to restore the state of a new VM in parallel while the VMM is running the previous VM (i.e., using a different execution thread). As used herein, an execution thread may include a separate process on a host, a separate thread and/or a separate processor core on a multi-core processor. “Multi-core processors” are well known to those of ordinary skill in the art and include a chip that contains more than one processor core. Embodiments of the present invention may be implemented as software, hardware, firmware and/or as a combination thereof. For example, the VMM may be implemented as a software application, or device driver, or as part of the operating system, or as part of or embedded in a chipset or microprocessor, or as a combination thereof.
In yet another embodiment, a hyperthreaded processor may be used to optimize context switching between virtual machines. Hyperthreaded processors (e.g., (Intel Corporation's Pentium® 4 Processor with Hyper-Threading Technology) are well known to those of ordinary skill in the art and include a single physical processor with multiple logical processors, each sharing the physical resources of the host.
According to one embodiment, each thread on Host 200 may be assigned to a virtual machine. Thus, for example, Thread 205 may execute VM 250 while Thread 210 may execute VM 255. In this embodiment, when Enhanced VMM 275 determines that it needs to perform a context switch from VM 250 to VM 255, it may activate Thread 210 to begin retrieving state information for VM 255 into Main Cache 225. Upon the context switch, Thread 205 may save the state information for VM 250 while Thread 210 begins execution of VM 255 using the state information already loaded into Main Cache 225.
Although specific embodiments have been described in detail above, any of the above-described embodiments may be practiced separately or in combination, to achieve the same result. It will be readily apparent to those of ordinary skill in the art that these combinations of features may be practiced in various embodiments to further optimize context switching between VMs.
The hosts according to embodiments of the present invention may be implemented on a variety of computing devices. According to an embodiment of the present invention, computing devices may include various components capable of executing instructions to accomplish an embodiment of the present invention. For example, the computing devices may include and/or be coupled to at least one machine-accessible medium. As used in this specification, a “machine” includes, but is not limited to, any computing device with one or more processors. As used in this specification, a machine-accessible medium includes any mechanism that stores and/or transmits information in any form accessible by a computing device, the machine-accessible medium including but not limited to, recordable/non-recordable media (such as read only memory (ROM), random access memory (RAM), magnetic disk storage media, optical storage media and flash memory devices), as well as electrical, optical, acoustical or other form of propagated signals (such as carrier waves, infrared signals and digital signals).
According to an embodiment, a computing device may include various other well-known components such as one or more processors. As previously described, these computing devices may include multi-core processors and/or hyperthreaded processors. The processor(s) and machine-accessible media may be communicatively coupled using a bridge/memory controller, and the processor may be capable of executing instructions stored in the machine-accessible media. The bridge/memory controller may be coupled to a graphics controller, and the graphics controller may control the output of display data on a display device. The bridge/memory controller may be coupled to one or more buses. A host bus controller such as a Universal Serial Bus (“USB”) host controller may be coupled to the bus(es) and a plurality of devices may be coupled to the USB. For example, user input devices such as a keyboard and mouse may be included in the computing device for providing input data.
In the foregoing specification, the invention has been described with reference to specific exemplary embodiments thereof. It will, however, be appreciated that various modifications and changes may be made thereto without departing from the broader spirit and scope of the invention as set forth in the appended claims. The specification and drawings are, accordingly, to be regarded in an illustrative rather than a restrictive sense.
The present application is related to co-pending U.S. patent application Ser. No. ______, entitled “Method, Apparatus and System for Optimizing Context Switching Between Virtual Machines,” Attorney Docket Number P18449, assigned to the assignee of the present invention (and filed concurrently herewith).