High-performance virtual machine networking

09804904 · 2017-10-31

Assignee

Inventors

Cpc classification

International classification

Abstract

A virtual machine (VM) runs on system hardware, which includes a physical network interface device that enables transfer of packets between the VM and a destination over a network. A virtual machine monitor (VMM) exports a hardware interface to the VM and runs on a kernel, which forms a system software layer between the VMM and the system hardware. Pending packets (both transmit and receive) issued by the VM are stored in a memory region that is shared by, that is, addressable by, the VM, the VMM, and the kernel. Rather than always transferring each packet as it is issued, packets are clustered in the shared memory region until a trigger event occurs, whereupon the cluster of packets is passed as a group to the physical network interface device. Optional mechanisms are included to prevent packets from waiting too long in the shared memory space before being transferred to the network. An interrupt offloading mechanism is also disclosed for use in multiprocessor systems such that it is in most cases unnecessary to interrupt the VM in order to request a VMM action, and the need for VMM-to-kernel context transitions is reduced.

Claims

1. A method for transmitting a cluster of packets, the method comprising: deferring, by a software component of a virtual machine, sending a request to transfer one or more pending packets until a triggering event is identified, the one or more pending packets being stored at respective guest packet addresses in a memory space that is shared by the software component and a virtual machine monitor; identifying, by the software component, the triggering event, wherein the triggering event is a time since a most recent receipt of an acknowledgement signal acknowledging transfer of at least one earlier transferred packet exceeds a predetermined maximum time; based on the identified triggering event, sending, by the software component to the virtual machine monitor, a request to transfer the one or more pending packets; and transferring, by a physical network interface device, the one or more pending packets from the shared memory space over a network, wherein transferring the one or more pending packets from the shared memory space over the network comprises enabling a clustering mode that causes delivering the one or more pending packets in groups.

2. The method of claim 1, wherein packet data of pending packets are stored at respective guest packet addresses in the shared memory.

3. The method of claim 2, wherein guest address pointers to the pending packet's packet data are stored in the shared memory.

4. The method of claim 2, wherein the shared memory is also shared by a kernel.

5. The method of claim 4, wherein the virtual machine is prevented from modifying the guest address pointers and the packet data for the pending packets.

6. The method of claim 5, further comprising: upon detecting the transfer request, guest addresses to which each guest address pointer points is translated into a corresponding physical address; and upon completing the transfer of the pending packets pointed to by the guest address pointers, restoring the virtual machine's ability to modify the guest address pointers and the packet data.

7. The method of claim 4, wherein the transfer request is generated by the virtual machine.

8. A system comprising: a host having virtualization software executing thereon; a virtual machine instantiated on the host; a share memory that is shared by a software component of the virtual machine, the software component configured to: defer sending a request to transfer one or more pending packets until a triggering event is identified, the one or more pending packets being stored at respective guest packet addresses in the shared memory; identify the triggering event, wherein the triggering event is a time since a most recent receipt of an acknowledgement signal acknowledging transfer of at least one earlier transferred pack exceeds a predetermined maximum time; and based on the identified triggering event, send, to the virtual machine monitor, a request to transfer the one or more pending packets; and a physical network interface device configured to transfer the one or more pending packets from the shared memory over a network, wherein transferring the one or more pending packets from the shared memory over the network comprises enabling a clustering mode that causes delivering the one or more pending packets in groups.

9. The system of claim 8, wherein packet data of pending packets are stored at respective guest packet addresses in the shared memory.

10. The system of claim 9, wherein guest address pointers to the pending packet's packet data are stored in the shared memory.

11. The system of claim 9, wherein the shared memory is also shared by a kernel.

12. The system of claim 11, wherein the virtual machine is prevented from modifying the guest address pointers and the packet data for the pending packets.

13. The system of claim 12, wherein the virtualization software including the kernel component causes the one or more processors to implement the method further comprising: upon detecting the transfer request, guest addresses to which each guest address pointer points is translated into a corresponding physical address; and upon completing the transfer of the pending packets pointed to by the guest address pointers, restoring the virtual machine's ability to modify the guest address pointers and the packet data.

14. A non-transitory computer-readable storage medium having computer-executable instructions that cause a processor to perform operations comprising: receiving, from a software component of a virtual machine, a request to defer sending a request to transfer one or more pending packets until a triggering event is identified, the one or more pending packets being stored at respective guest packet addresses in a shared memory space that is shared by the software component and a virtual machine monitor; receiving an indication that the software component has identified the triggering event, wherein the triggering event is a time since a most recent receipt of an acknowledgement signal acknowledging transfer of at least one earlier transferred pack exceeds a predetermined maximum time; and based on the identified triggering event, receiving, from the software component, a request to transfer the one or more pending packets; and receiving, from a physical network interface device, a request to transfer the one or more pending packets from the shared memory space over a network, wherein transferring the one or more pending packets from the shared memory space over the network comprises enabling a clustering mode that causes delivering the one or more pending packets in groups.

15. The non-transitory computer-readable storage medium of claim 14, wherein packet data of pending packets are stored at respective guest packet addresses in the shared memory.

16. The non-transitory computer-readable storage medium of claim 15, wherein the shared memory is also shared by a kernel.

17. The non-transitory computer-readable storage medium of claim 16, wherein the virtual machine is prevented from modifying the guest address pointers and the packet data for the pending packets.

18. The non-transitory computer-readable storage medium of claim 17, wherein the computer-executable instructions further cause the processor to perform operations comprising upon detecting the transfer request, guest addresses to which each guest address pointer points is translated into a corresponding physical address.

19. The non-transitory computer-readable storage medium of claim 18, wherein the computer-executable instructions further cause the processor to perform operations comprising upon completing the transfer of the pending packets pointed to by the guest address pointers, restoring the virtual machine's ability to modify the guest address pointers and the packet data.

20. The non-transitory computer-readable storage medium of claim 15, wherein guest address pointers to the pending packet's packet data are stored in the shared memory.

Description

BRIEF DESCRIPTION OF THE DRAWINGS

(1) FIG. 1 illustrates the main components of kernel-based, virtualized computer system.

(2) FIG. 2 illustrates the components and control flow in the VM networking system according to the invention.

(3) FIG. 3 illustrates various memory data structures used in the invention.

(4) FIG. 4 illustrates interrupt offloading according to the invention.

DETAILED DESCRIPTION

(5) In broadest terms, two features of the invention enable it to overcome the delay-causing disadvantages of the prior art. First, to eliminate the need for host transitions. NIC drivers (one or more, depending on the number of NICs included) are installed and run within the kernel 600. This allows all networking to be done by direct kernel interactions. Second, a novel virtual networking interface is provided that minimizes and, in some cases eliminates, the need for VM-to-VMM and VMM-to-kernel transitions, as well as the need to copy data. The interface according to the invention has the added advantage of simplicity and thus avoids the complexity of emulating a standard interface. These features of the invention are described below in greater detail.

(6) In the description of the invention below, it is assumed that the system hardware 100 has the Intel x86 architecture only because this is the platform on which the ESX Server product of VMware, Inc., currently runs and it is the ESX Server in which a prototype of the invention has been implemented and tested. The mechanisms provided by the invention are not specific to the x86 architecture, however. Those skilled in the art of operating systems-level programming will know how to adapt the embodiment of the invention described below for use with other architectures.

(7) The invention involves a system and method for transferring a data set over the network according to any protocol in which the data set is converted into a sequence of data sub-sets that are transferred as units. According to the common USB protocol, these sub-sets are referred to as “packets.” For the sake of simplicity, the term “packet” is used below to refer to any data sub-set transferred as a unit over the network, regardless of the protocol.

(8) The unique components of the VM networking system according to the preferred embodiment of the invention are illustrated in FIG. 1. Various hardware and software components shown in FIG. 1 are omitted in FIG. 2 merely for the sake of simplicity and clarity; those skilled in the art of networking software will realize which of these standard components will be used by the invention. Also for the sake of simplicity, the device(s) are labeled collectively with the number 400. Moreover, the memory 130 is shown separated from the other system hardware 100 merely to make it easier to describe certain structures used by the invention.

(9) The unique features of the invention are the following: a driver (“vmxnet driver”) 225 that runs in the guest (VM 200) and an emulation component (“vmxnet emulation”) 360 that runs in the VMM 300; As will become clearer below, the driver 225 and the emulation component 360 form, in cooperation, a virtual networking interface that the VMM emulates for the guest (VM 200); an implementation component (“vmxnet implementation”) 611 that runs in the kernel 600; a shared memory region 132 (both FIG. 2 and FIG. 3) that is mapped as shared between the vmxnet driver, the VMM 300 (and thus available to the emulation component 360), and the kernel 600 (and thus available to the implementation component 611); and the physical NIC driver 614, which, according to the invention, is loaded in and runs in the kernel 600.

(10) Other than the memory 130, all of these features are software and as such are instructions that are either stored on the disk 140 or are loaded into the system memory 130 for execution by the processor(s) 110. The VM 200 also includes (or the VMM exports) a virtual NIC 272, which any source within the VM “believes” is the device handling network transmission. In reality, of course, the physical NIC 172 performs this function. The design and operation of virtual components such as the virtual NIC 272 are well understood in the art.

(11) FIG. 3 illustrates various structures that are stored in the memory 130 for use by the invention. These structures include: a guest transmit pointer queue 1320 and a guest receive pointer queue 1322; a guest transmit packet data buffer 1321 and a guest receive pointer queue 1322; a physical transmit pointer queue 1310 and a physical receive pointer queue 1312; a physical transmit packet data buffer 1311 and a physical receive pointer queue 1313; an optional overflow queue 1370; and optional parameters T.sub.max, T.sub.def, R.sub.max, and R.sub.def, whose purpose is explained below.

(12) The shared memory portion 132, as well as the guest packet data buffers 1321, 1323, lie within the guest physical address space, that is, in the space allocated for the virtual memory 230. In FIG. 3, this space is shown within the dashed line 231. As is discussed above, whenever an entity in the VM needs to access memory within this space, it uses either a guest PPN directly, or a guest VPN, which the guest OS maps to a guest PPN. Of course, the guest physical address space 231 resides in the actual machine memory 130 and, as such, is ultimately always accessed using actual (machine) physical addresses.

(13) Some map of guest virtual addresses (page numbers) to guest physical addresses (page numbers) will also be needed in most embodiments of the invention.

(14) Both Linux and Windows operating systems provide functions to accomplish this mapping within the guest VM. For efficiency when the guest OS is a version of Windows, however, the vmxnet driver 225 preferably precomputes the GVPN-to-GPPN mapping, which is illustrated in FIG. 2 as map 217.

(15) The vmxnet driver 225 then calls the VMM 600 with the GPPNs for the structure 132. The driver 225 also preferably fills in receive buffer pointers inside of the shared data structure 132 and, in the case of non-zero-copy transmits in Windows (see below) also fills in the transmit buffer pointers. The kernel 600 then creates corresponding a GPPN-to-PPN map; this map will typically be a part of the general memory map 617 the kernel keeps for the VM, although this is not necessary.

(16) The entries in the guest pointer queues 1320, 1322 are GPPNs that point to respective entries in the buffers 1321 and 1323. What this means is that the vmxnet driver 225 can access all of the structures within the guest memory space 231 using GPPNs alone. In order for the kernel 600 to access the shared memory structures or the guest transmit/receive packet data buffers, it must have the corresponding PPNs (machine). The kernel 600 gets these required PPNs by consulting the GPPN-to-PPN memory map it has earlier established for these structures.

(17) The remaining memory structures shown in FIG. 3—the physical pointer queues 1310, 1312, the physical packet data buffers 1311, 1313, and the overflow queue 1370, lie outside the guest address space 231 of the VM, but can be accessed by the VMM and kernel using actual physical (machine) addresses.

(18) The uses of these various memory structures are explained below.

(19) As with any other networking system, the invention must provide for two main operations, namely, transmits and receives between some source entity or component and some destination entity or component. In this invention, the source entity or component is anything within the VM 200 that needs to communicate over the network 700. The designation “source” does not imply that it is this component that is sending data blocks to some remote device such as a printer (although this is of course the case for transmits), but rather that it is the source or initiator of the network transaction, regardless of whether this is an IN or an OUT. Similarly, “destination” does not necessarily mean that the entity or component referred to is the recipient of a data set sent by the source, but rather merely that it is the entity or component with which the source wants to communicate via the network; in other words, the destination is simply the source's counterpart in a network transaction. The two principle network operations—transmit and receive—will now be described separately.

(20) Consider now the way in which the kernel 600—or any standard operating system—handles packet transmission and reception, even in systems with no virtual machine. For each packet to be transmitted, the packet data is stored beginning at an address in the physical transmit packet data buffer 1311. The physical transmit pointer queue 1310 then contains an entry that points to (gives the address of) the packet data; in other words, the physical transmit pointer queue 1310 is a queue of address pointers that direct the NIC controller 175 to the data of the packets to be transmitted. For each packet to be received, an entry in the physical receive pointer queue 1312 contains the address of an available space in the physical receive packet data buffer 1313 in which incoming packet data can be stored.

(21) The pointer queues 1310 and 1312 are commonly implemented as first-in-first-out (FIFO) linked list, with the “last” element linked to the “first,” so that each queue forms a “ring” buffer. Any other known data structure may of course be used instead to perform the same function.

(22) Trapping

(23) For both packet transmits and receives, the vmxnet driver 255 needs to cause the VMM to perform certain tasks. On the other hand, the VMM is preferably transparent to the VM. The question is then how the driver (a VM component) is to call into the VMM, that is, how to generate some form of transfer request that the VMM can sense and act on, but without the VM needing to “know” about the underlying VMM. In this invention, this is preferably done using the well-known technique of “trapping”: The driver 225 does something that causes an exception, which will be detected and handled by the VMM's interrupt/exception handler 355; here, handling the exception means executing the instructions that are needed to perform the transmit and receive operations explained below.

(24) In the preferred embodiment of the invention, the driver causes an exception by issuing protected instructions, that is, instructions that require a higher privilege level than the driver 225 (a user-level guest component) is at. IN or OUT operations are suitable for this purpose: an IN or OUT will cause a protection violation that will cause the CPU 110 to raise an exception, which will in turn be taken and handled by VMM's interrupt/exception handler 355. Using IN and OUT operations to enable the VM to trap (in this case, to “call”) into the VMM is preferred because this is a common operation performed by conventional device drivers. Any other known mechanism may be used, however, to allow the vmxnet driver 225 to cause an exception that the VMM can trap and act on.

(25) Transmits

(26) Basic Transmit Path

(27) Assume that an entity within the VM 200 (either an application 260 or the guest OS 225 itself) wishes to send or receive information over the network 700 and that the information is transferred in units such as packets. The simple transmit path used in the preferred embodiment of the invention is the following:

(28) 1. The guest OS 220 calls the vmxnet driver 225 with a network packet in the conventional manner.

(29) 2. The vmxnet driver 225 puts the guest physical address(es) of the packet data into the next free entry(-ies) in the guest transmit pointer queue 1320. If there is no room in the queue 1320, then the driver 225 tells the guest OS 220 to stop sending data, using standard signals.

(30) 3. The vmxnet driver 225 does an IN operation, which is trapped using known mechanisms by the vmxnet emulation module 360 in the VMM 300.

(31) 4. The VMM 300 calls into the vmxnet implementation module 611 in the kernel 600 to transmit the packet located at the address in the guest transmit data buffer 1321 to which the pointer queue 1320 entry points. The VMM returns the result of the kernel 600 call to the driver 225 as the result of the IN operation. Note that the result of the transmit returned to the virtual NIC 272 by the VMM will be consistent with the result returned to the physical NIC 172 by the destination device, except in rare cases such as hardware failure of the physical NIC. Even in such a case, however, the consequence would simply be that the guest OS would interpret any such packets as having been dropped; all standard networking code is written to deal with such packet drops.

(32) 5. Using known mechanisms, the kernel then 600 takes ownership of the pointer queue 1320 entry that contains the packet address so that it cannot be reused until the physical NIC 172 has transmitted the packet. Here, “ownership” means the exclusive right to modify the entry. Note that this is an instance of both the guest (VM) and the host (kernel) accessing the shared memory region 132.

(33) 6. Recall that the guest transmit pointer queue 1320 entries are the GPPNs of the corresponding entries in the packet data buffer 1321. For the kernel 600 to locate a packet in the machine address space, as it must, it takes the entry (GPPN) in the pointer queue 1320, which the kernel gets from the VMM, and then consults its GPPN-to-PPN map to find the actual (machine) physical address (PA) of the packet data in the data buffer 1321. The kernel 600 then gives the physical address of the packet data to the physical NIC 172, that is, to its controller 175. Note that it is not necessary for the kernel to copy the packet information into its own physical transmit packet data buffer 1311—the controller 175 will have the physical (machine) address of the packet data in the guest transmit packet data buffer 1321 and can read the data directly from that guest buffer 1321.

(34) 7. When the physical NIC 172 is done with the packet, the kernel 600 gives ownership of the corresponding pointer queue 1320 entry back to the driver 225.

(35) 8. The kernel 600 tells the VMM 300 to interrupt the VM 200 if the VM has stopped sending packets because there is no free space in the pointer queue 1320 (see step 2 above) or if it has been too long since the VM has been given a chance to process transmitted packets.

(36) Note that this arrangement according to the invention needs only one trap to the VMM, via the IN operation, to send a packet.

(37) One advantage of virtualization systems such as those made by VMware, Inc., is that the guest OS 220 may be a conventional, commodity OS such as the different versions of Microsoft Windows and Linux. Of relevance to this invention, in particular, to step 2 above, is that both Windows and Linux provide drivers that support zero-copy transmits and that may be used as the guest driver 225.

(38) In Linux, the driver is given a single virtual address for the packet data and a simple masking operation is used to translate from a virtual address to a physical address; this feature may be used for packet address translation. Note, however, that the GPPN-to-PPN translation is also a fast operation in the kernel 600 because only a single physical address is involved (offsets are invariant). Nonetheless, when the guest OS 220 is Linux, it will typically be slightly faster to allow the driver 225 to handle translation through mapping, thereby avoiding altogether the need to copy the untranslated (guest physical) packet address into the buffer 133.

(39) In contrast, in systems where the guest OS 220 is a version of Windows, it will usually be more efficient to copy the whole packet: In Windows, packets are fragmented into several pieces. In order to do a zero-copy transmit, the vmxnet driver 225 must ask Windows to give it the guest physical addresses (GPPNs) for each piece of the packet and then pass this list of GPPNs to the kernel 600. In order to copy the packet, the driver 225 must ask Windows to give it the virtual address of each piece of the packet. It can then take these virtual addresses and copy the packet into a single contiguous packet and then send down to the kernel 600 a single guest physical address for the packet. Throughput benchmarks show that, at least at present, copying is faster than not copying in Windows-based systems.

(40) Additionally, in Windows-based systems, copying can be made faster than not copying because of certain optimizations provided by this invention. When copying, the driver 225 preferably pre-allocates enough memory to hold the maximum number of outstanding, pending transmit packets. Each pointer queue 1320 entry is then a (guest physical address pointer) into this pre-allocated memory. For an Ethernet network, for example, the MTU (“Maximum Transmission Unit”—the limit on the size of data sent over a network; the MTU is typically a property of the physical network interface) is 1514 bytes, so that one page is allocated for every two packets; packets are thus guaranteed not to cross a page boundary. Each entry in the guest transmit pointer queue 1320 is then preferably initialized to point into the pre-allocated memory space. After the memory is allocated, the VMM 300 is called by the vmxnet driver 225 via an OUT operation to pin all of these pages, using conventional mechanisms. The kernel 600 is then called to pre-compute the GPPN-to-PPN mapping for each packet. The result is that the kernel 600 has to do very little work during a packet transmit since no further guest-to-physical (machine) memory translations will be required.

(41) Whether zero-copy transmit is provided by the operating system will also affect when the guest transmit and receive packet data buffers are created, and how: If zero-copy transmit is not provided, then the vmxnet driver 225 preferably creates the structures 132, 1321 and 1323, for example, when the vmxnet driver 225 is loaded into the guest OS 220. Where the guest OS does provide for zero-copy transmits, however, the transmit buffer 1321 will normally be given to the driver 225 by the guest OS 220; the driver 225 then gives the buffer back after the transmit completes to the physical NIC 172.

(42) Where the guest OS is Linux, the receive buffer 1323 is created when needed by the driver 225 calling a Linux buffer allocator. After the driver receives the needed buffer, it passes it to the guest OS 220. In systems where the guest OS is a version of Windows, the driver 225 preallocates any needed receive buffer, such as buffer 1323.

(43) Transmit Clustering

(44) Streaming is generally done using TCP/IP (Transmission Control Protocol/Internet Protocol). With this protocol, an acknowledgement packet is sent to the data sender after a number of packets is sent. The result is that there are receive interrupts that are processed very frequently by the kernel 600 while the VM is streaming data out at relatively high data rates. The invention takes advantage of these receive interrupts to implement “transmit clustering.”

(45) The idea behind transmit clustering is that the guest (VM 200), in particular, the vmxnet driver 225, puts packet address information in the pointer queue 1320, but does not immediately call the VMM to transmit the packets. Rather, packets are transmitted in groups—clusters—upon the occurrence of a triggering condition. A preferred triggering condition is such that queued packets are transmitted for the virtual NIC 270 when the next packet is received on the virtual NIC. Because packets are typically received very frequently, transmits can generally be done without any driver-to-VMM traps and without any VMM-to-kernel 600 calls.

(46) The invention provides alternative mechanisms for implementing transmit packet clustering. One other way, for example, is for the guest (in particular, the vmxnet driver 225) to determine that it has too many packets in its transmit pointer queue 1320 that the kernel 600 has not taken ownership of yet. Recall that packets are returned to the sender to acknowledge transmission of packets sent. One way to determine that too many packets are “waiting” or “queued” is therefore for the VMM to detect that it has been too long since receive interrupts have occurred.

(47) What is “too long” can be determined as a function of the number of queued packets, for example, when the number of transmitted packets that have not been sent exceeds a predetermined maximum. When this threshold is crossed, the VMM calls the kernel 600 to transmit all pending packets in the transmit pointer queue 1320. In one prototype of the invention, for example, the threshold value for triggering the kernel to transmit pending packets was ten pending packets.

(48) In the preferred embodiment of the invention, the number of currently queued packets is tracked as follows, which also further clarifies that is meant by “too long”:

(49) When the kernel 600 turns clustering ON (see below), it sets a maximum number T.sub.max of queued transmit packets in the shared memory data structure. The number T.sub.max is a configuration parameter that can be determined using conventional design criteria, and may be made adjustable by a system administrator using known techniques. In a prototype of the invention, for example, the parameter had a default value of ten queued packets (T.sub.max=10).

(50) The vmxnet driver 225 inspects this value T.sub.max to decide if it should send packets by trapping to the VMM 300 (see above) or if it should simply put the packet address (pointer) in the transmit pointer queue 1320 and continue with other tasks. Each time the vmxnet driver 225 puts a packet in the transmit pointer queue 1320 without trapping to the VMM to send the packet, it increments a count T.sub.def of deferred transmits. The vmxnet driver 225 preferably includes a comparison routine such that, when this count exceeds the transmit cluster max count (T.sub.def>T.sub.max), the vmxnet driver 225 calls the VMM. Whenever the kernel 600 transmits packets out of the transmit pointer queue 1320 it resets T.sub.def=0. Note that, because T.sub.def is in the shared memory region 132, the vmxnet driver 225 can increment T.sub.def with no need for any call to the kernel 600.

(51) In the TCP/IP case, having too many pending packets should not happen very often. However, it will probably happen more often where the UDP (User Datagram Protocol) is used because there may then not be many packets that the VM receives.

(52) An alternative way to cluster packets to be transmitted is as a function of time, which may be measured using a known timing routine 615, preferably in the kernel 600. If more than a predetermined threshold time (for example, 10 milliseconds) has elapsed since the last packet was received on the virtual NIC 272 and there are pending packets to transmit, then the timer 615 will expire. Note that the kernel 600 will know when the virtual NIC 272 last got a packet because the kernel is the component that put it there. The kernel then interprets expiration of the timer as a signal to transmit the packets. This case should also happen only rarely.

(53) Transmit clustering is turned ON by the kernel 600 (preferably, as a routine 613 in the implementation module 612) when it determines that the rate of packets being transmitted during a predetermined period is high enough and is turned OFF when the rate of packets being transmitted is too low. Transmit clustering cannot be ON all of the time because it will have a negative impact on network performance. For example, if clustering is ON all of the time, and there is no network traffic (no incoming packets) then even a single ping (transmission of a single packet) by the VM will sit in the transmit queue 1320 until the maximum permitted (threshold or “time-out”) time has run out because there will be no received packet to trigger the transmit. In a prototype of the invention, this threshold was ten milliseconds, which is far too long to wait to transmit a single packet.

(54) Whether clustering should be activated may also be determined using different types of predetermined thresholds, either packet-based or time-based or both: In one prototype of the invention, for example, transmit clustering was activated (turned ON) when at least 4000 packets were transmitted on average per second, measured over a 30 millisecond interval (thus, 120 packets must be transmitted in the interval); clustering was turned OFF when fewer than 3000 packets were transmitted on average per second, measured over a 30 millisecond interval (90 packets transmitted in the interval). These numbers—representing “high enough” and “too low”—are of course examples, and may be adjusted and optimized using conventional techniques of performance analysis.

(55) Hardware Transmit Overflow

(56) When the kernel 600 tries to transmit packets that are stored in the vmxnet driver's 225 guest transmit pointer queue 1320, it tries to transfer the packets' addresses to the physical transmit pointer queue 1310 of the physical NIC 172. There is no guarantee, however, that there will be room in the physical transmit pointer queue 1310. Whenever the kernel's 600 transmit code (in the implementation module 612) runs, it takes ownership of all of the packets in the vmxnet driver's 272 transmit pointer queue 1320 and then calls the physical NIC 172 in the conventional manner in order to send the packets. For each packet that the physical NIC 172 cannot handle, the kernel 600 puts the packet into a separate overflow queue 1370 for the device so that the packet can be sent when the physical NIC signals the kernel 600 in any conventional manner that space is available in its physical transmit pointer queue 1310. These queued packets (in the overflow queue 1370) will be sent before any other packets are sent.

(57) Receives

(58) The receive path also utilizes the data structures that are shared between the kernel 600 and the vmxnet driver 225 to minimize VMM-to-kernel transitions. Because the kernel 600 can access the guest receive pointer queue 1322, received packets can be put into the memory space accessible to the VM 200 without any VMM intervention.

(59) Basic Receive Path

(60) The basic path followed when a packet is received is the following:

(61) 1) The kernel 600 determines the virtual NIC(s) 272 for which the packet is intended. (Only one virtual NIC 172 is shown, for the sake of simplicity, but any number may be included in a system that includes the invention, in particular, in a broadcast or multi-cast system.)

(62) 2) For each virtual NIC, the kernel 600: a) Inspects the guest receive pointer queue 1322 in the memory portion 132 shared with the vmxnet driver 225 to find an empty packet. If there is no empty packet, then the packet is dropped: b) The kernel 600 copies the data from the received packet into the guest receive packet data buffer 1323 at the location pointed to by the corresponding entry on the guest receive pointer queue 1322; and c) The kernel 600 posts an action to the VMM to tell it to raise a standard receive interrupt to the VM (in particular, to the vmxnet driver 225).

(63) 3) On each receive interrupt the guest vmxnet driver 225: a) Dismisses the interrupt and, in the case of Windows, blocks future interrupts; b) Processes all incoming packets and gives them to the guest OS 220; the receive entries are then made ready again to receive more packets; and c) In the case of Windows, enables future interrupts.

(64) Receive Clustering

(65) In the simplest case, an interrupt is raised to the VM 200 for each packet received. The guest driver 225 then needs to do one or two conventional IN/OUT operations to trap to the VMM 300 to deal with the interrupt. The raising of the interrupt is a fairly expensive operation, however, as are the IN/OUT operations themselves. Receive clustering according to the invention reduces this overhead by a factor at least approximately equal to the receive cluster size—only one interrupt is raised per cluster of packets. For example, with a cluster size of ten packets, there will only be one interrupt raised for each group of ten packets.

(66) The idea behind receive clustering according to the invention is that if the VM is receiving enough packets, then they can be delivered in groups—again, clusters—instead of individually. Clustering is turned ON, for example using the routine 613, when the kernel 600 determines that the VM is receiving a sufficient number of packets per second and it is turned OFF when the receive rate gets too low.

(67) Receive clustering according to the invention has a straightforward implementation: When a packet is inserted into the vmxnet driver's 225 receive pointer queue 1322, a count R.sub.def is incremented by any conventional routine in the emulation module 360 in the VMM 300. If the count R.sub.def exceeds a maximum predetermined number R.sub.max of unprocessed received packets, then an interrupt is raised to the VM.

(68) The maximum number R.sub.max of unprocessed received packets is a configuration parameter that can be determined using conventional design criteria, and may be made adjustable by a system administrator using known techniques. Note that if the threshold number R.sub.max is made too big, then throughput will suffer because the VM will not be able to process the packets fast enough and the sender (in most cases, a remote device communicating via the network 700) will slow down. Lowering the threshold number, however, reduces the benefit of clustering by increasing interrupts to the guest. In a prototype of the invention, for example, the parameter had a default value of ten unprocessed packets (R.sub.max=10).

(69) Moreover, in the prototype, receive clustering was turned ON if at least 4000 packets were received on average per second, measured over a 30 millisecond interval (120 packets must be received in the interval) and turned OFF if fewer than 3000 packets were received on average per second, measured over a 30 millisecond interval (90 packets must be received in the interval). These numbers were tuned for a 100 Mbit network with relatively slow system hardware but should be adjusted using normal design techniques as new generations of hardware and networking become available.

(70) As in transmit clustering, a timer may be used to handle the case when a receive packet is pending too long: If a packet remains pending in the guest receive pointer queue 1322 for more than a predetermined threshold time, for example, ten milliseconds, without the guest VM being interrupted, then the timer forces the VMM to raise an interrupt to the VM. If the queue size is not too large, then the timer will not have to raise interrupts to the guest very often.

(71) Interrupt Off-Loading

(72) In general, a VM suffers performance degradation relative to a native machine running benchmarks because of emulation overheads, that is, the CPU cycles required to run the emulations. Consequently, the availability of CPU cycles generally is a limiting factor when running benchmarks. In multi-processor systems, transmit and receive clustering according to the invention provides a way to off-load the networking burden to a different CPU.

(73) As mentioned above, in the preferred embodiment of the invention, with transmit clustering, most of the transmits are initiated as a result of a receive interrupt. Similarly, the work of handling a received packet, including copying the data into the guest's receive packet data buffer 1323 is done as a result of a receive interrupt. Using interrupt off-loading according to the invention, the interrupts from the (or one of the) physical NIC(s) 172 are directed to an idle CPU if one is available so that the idle CPU can do all other transmit and receive work. This relieves the CPU currently used to process the instructions relating to the execution of the VM (that is, the CPU on which the VM is running) from the burden of handling networking tasks. This off-loading arrangement will typically give the VM more CPU cycles in which to do other work besides handling these networking tasks.

(74) Both receive and transmit clustering can cause interrupts to be generated for the VM. Interrupts are generated by the kernel 600 for a guest VM by posting an action to the VMM, whose interrupt/exception handler 355 then takes over processing of the interrupt, including forwarding it, if appropriate, to the VM. If the VM is running, then it must be interrupted so that the VMM may check actions. If the interrupt for the physical NIC 172 happens on the same CPU where the VM is running, then processing may proceed as normal. However, if the interrupts are sent to a different CPU, then an IPI (inter-processor interrupt) must be sent to the CPU on which the VM is running.

(75) The general procedure for implementing an IPI is well known: In most existing multi-processor systems some device and/or mechanism is implemented specifically for delivering IPIs. In Intel-based systems, for example, each CPU has an APIC (Advanced Programmable Interrupt Controller), which has a unique ID; the APICs are all connected via a bus. In such systems, the following procedure is followed when a thread on one CPU (the “local” CPU) wants to send an IPI to another CPU (the “destination” CPU”); a similar procedure is followed in systems that have architectures not based on Intel processors.

(76) 1) The thread programs the APIC on its local CPU with the APIC ID of the destination and the “vector” to deliver the IPI on. Note that the designation “destination” here does not mean the destination device of the network transfer, but rather the APIC/CPU on which the VMM 300 is executing. In this invention, the thread that programs the local APIC is the kernel 600 and the destination is the APIC/CPU on which the VMM 300 is executing.

(77) 2) The local APIC puts a message on the shared APIC bus. This message typically takes the following form: <type=IPI, destination=APIC id, vector=V>.

(78) 3) The destination APIC receives the message. It sees from the “type” parameter that the message involves an IPI, so it raises the interrupt line to the destination CPU.

(79) 4) The destination CPU senses the interrupt and asks its APIC what the vector is.

(80) 5) The destination APIC replies that the vector is V.

(81) 6) The destination CPU then calls the interrupt handler stored in the IDT: IDT[V].handler( )

(82) In the IPI context, in systems based on the Intel x86 architecture, the “vector” V is usually only a single byte and must have a value that lies in the range [32, 255]. Each vector V represents an index into the IDT. The IDT has 256 entries. Entries 0-31 are reserved for exceptions. Analogous structures are found in other architectures.

(83) Typically, all interrupts are fielded by the VMM's interrupt/exception handler 355, whereupon the VMM calls the kernel 600 to actually deal with the device or the IPI. It would be preferable, however, to eliminate as many VMM-to-kernel 600 crossings as possible because they are expensive in terms of CPU cycles. To make this as efficient as possible, the invention preferably takes advantage of the IPI procedure outlined above and of the fact that when the kernel sends an IPI it can decide which CPU to send the IPI to and which IPI vector to use. According to this aspect of the invention, the kernel uses the IPI vector V as a “check-action” IPI. The procedure is also illustrated in FIG. 4.

(84) In FIG. 4, merely by way of example, four CPUs (CPU0-CPU3) are shown, each having its own APIC (APIC0-APIC3, respectively). The APICs are connected to a bus 710.

(85) Further in FIG. 4, the VMM 300 is shown separated from the kernel 600 and running directly on a hardware processor. This is done just for the sake of clarity in describing the different steps involved in interrupt offloading according to the invention. The actual relationship between the VMM and the kernel is shown in the preferred embodiment of the invention is shown in FIG. 2. In this example, the VMM 300 is running on CPU1, which forms the destination CPU.

(86) Typically, each CPU will have a separate IDT. It would also be possible, however, for CPUs to have separate pointers but share a single IDT. The invention may be used in either case. In FIG. 4, separate IDTs—IDT1, IDT3—are shown for CPU1 and CPU3, respectively, other IDTs having been omitted for the sake of simplicity.

(87) As a preliminary step, the kernel 600 configures the hardware interrupt sub-system to send device interrupts (that is, interrupts from some source entity) to a currently idle CPU; in the illustrated example, CPUs CPU0, CPU2, and CPU3 are currently idle (or at least not operating at full capacity), and the kernel selects CPU3 as being the “most idle, using any known criterion. CPU3 therefore becomes the “local” CPU.

(88) In Intel-based systems, the interrupt sub-system comprises at least one IOAPIC (I/O APIC) 1400, which is on the same bus 710 as the APICs APIC0-APIC3. The interrupt lines of all devices are routed to pins of the IOAPIC. In FIG. 4, two devices are shown connected to the IOAPIC 1400—the physical NIC 172, and, by way of another example, a physical SCSI adapter 1410; in general, any number N of devices may be connected to the IOAPIC via a respective pin Pin 0. Pin 1, Pin 2, . . . , Pin N.

(89) For each pin, or at least each pin in use, the kernel programs the IOAPIC using conventional commands to tell it which APIC to send each interrupt to and which vector to use. The IOAPIC therefore includes a table 1420, which is indexed by pin number and whose entries indicate what to do when a given interrupt arises. When a device raises an interrupt, it is fielded by the IOAPIC. The IOAPIC, which knows which pin the interrupt came in on, looks up the information for the interrupt in the table 1420 using the pin number as an index. It then sends a message on the bus 710 to the appropriate APIC telling it that an interrupt has occurred.

(90) In FIG. 4, for example, an interrupt on pin 0 causes the IOAPIC to deliver the interrupt to CPU3 (more specifically, to CPU3's APIC3) at vector 85. CPU3 then takes the vector (shown as V85) provided by the IOAPIC 1400 and with it as an index enters its IDT-IDT3—to get the address addr.sub.k, which is the location of the kernel's interrupt/exception handler 655 routine for handling Pin 0 interrupts. The result of this preliminary step is that an interrupt that arrives from the physical NIC 172, for example to acknowledge packet transmission, leads to the kernel's interrupt/exception handler 655 being called at the routine whose entry point is addr.sub.k.

(91) As another preliminary step, the VMM 300 and the kernel 600 agree on which vector V.sub.ca (the designation “ca” indicating “check action”) to use for the check-action IPI. The VMM 300 then puts the address addr.sub.ca of its check-action IPI routine 356 in its CPU's IDT-IDT1—indexed by V.sub.ca.

(92) Assume now that as part of executing the kernel's interrupt/exception handler 655, the kernel determines that it needs the VMM, which is executing on CPU 1, to check actions. This could happen, for example, if the VM receives a new packet that needs to be processed. The kernel then sends an IPI via the local APIC (here, APIC3), which puts the IPI on the APIC bus 710. This IPI will have the form <type=IPI,

(93) destination=APIC1, vector=Vca>. APIC1 will then receive the IPI and pass to CPU1 the vector Vca. CPU1 will then enter IDT1 at index Vca, which will direct it to the address addr.sub.ca of the VMM's check action routine 356.

(94) Two advantages of this aspect of the invention should now be clear: First, device interrupts, in particular from the physical NIC 172, may be handled by an idle CPU, even though the interrupt may ultimately require VMM action; the CPU on which the VMM is running does not itself need to handle the device interrupts. Second, the interrupt is passed to the VMM solely using existing hardware structures, with no need for a VMM-to-kernel or kernel-to-VMM state transition. Moreover, if this interrupt off-loading aspect of the invention is included in the system, packets can be received and transmitted without a single VMM-to-kernel crossing.

(95) The interrupt offloading mechanism described above is useful regardless of the need for network operations on behalf of the VM: Regardless of the task that the VM needs done, this aspect of the invention reduces the need to interrupt the VM in order for the VMM to take and handle interrupts, and it also reduces and, in most cases, eliminates the need for a VMM-to-kernel or kernel-to-VMM crossing (world switch) in order to pass an interrupt to the VMM for handling. Note that interrupt offloading according to the invention will work even where the destination CPU is not supporting a VMM/VM, but rather some other software or even hardware entity—regardless of the nature of the entity that ultimately is to receive the interrupt, offloading may be used to relieve the CPU it is running on from the task of handling device interrupts and to enable the kernel to forward interrupts to the entity using hardware mechanisms, with no need for direct calls between the kernel and the entity.