250 likes | 343 Views
What Why How Powerpoint?. Virtual Machines. What is a Virtual Machine?. A Piece of software that emulates hardware. Might emulate the I/O devices Might emulate the CPU Might be very high fidelity emulation Might cheat. Different from an O.S. An OS has system calls.
E N D
What Why How Powerpoint? Virtual Machines
What is a Virtual Machine? • A Piece of software that emulates hardware. • Might emulate the I/O devices • Might emulate the CPU • Might be very high fidelity emulation • Might cheat
Different from an O.S. • An OS has system calls. • To write to the serial port, you call write(...) • A VM fakes hardware. • To write to the serial port, you copy bytes and trigger interrupts.
Operating Systems and Virtual Machines • Operating Systems can run on real hardware. • Operating Systems can run on fake hardware (virtual hardware). • Lots of Oss can run on the same real machine. • If the VM is good, the OS cannot tell. • Timing issues • Performance (good or bad)
Uses of a Virtual Machine • Pretend to be a non-existent machine (prototyping) • Multitask lots of virtual machines on one physical machine (web servers). • Emulate any machine or network • Atari • Parallels • Vmware's Teams
Examples of Virtual Machines • VMware • Has many Linux/Windows boxes running on one. • Parallels • Has a Windows OS running under MacOS • VM • Has many applications running on a mainframe.
How to Make a Virtual Machine • Take over the CPU into supervisor mode. • Mark a bunch of memory regions protected • Interrupt table, devices, page tables • Start running the OS code • On the real CPU in non-supervisor mode • On a fake CPU if need be • CPU is different • CPU is non-virtualizeable
What if it's the Wrong CPU • You can always fake the CPU • Read the instruction • Do what it would do • Repeat • Suffer a 5x to 20x performance hit
Reading/Writing to the Serial Port • Writing • OS writes to a device register • VM gets an interrupt, fakes the write • Reading • VM gets an interrupt. • VM fakes an interrupt to the OS.
Serial Port (Continued) • Efficiency • Stinks • Virtualizability • Can have more serial ports than exist • Can redirect serial ports to anything else (USB?)
Virtualizing Video Framebuffer • Frame Buffer • Mark every page is r/o • When OS writes, VM gets an interrupt and writes • HUGE slowdown
Virtualizing a Modern Video Card • OS makes a command list • OS writes to a register on the video card to trigger the graphics processor unit. • VM gets an interrupt • VM rewrites the command list if needed • VM sends the (new) commands to the video card.
Virtualizing Graphics With a Fake Device Driver • Make a device driver that does not actually drive a device, but instead communicates with the VM. • Have the VM receive these messages and execute the instructions. • SPEED!!!!
Virtualizing RAM • OS has a page table stored in ram it thinks it owns. • VM has really marked that as read-only. • When the OS makes a change, the VM gets an interrupt and reflects the change to the real page table.
RAM in a Virtual Machine • No sharing between guess OSs. • No way for an OS to make RAM as unneeded. • NO way to change the allocation of RAM between Vms on the fly.
CPU in a Virtual Machine • Each guest OS gets the CPU a fixed amount • If a guest OS is idle ... CPU is wasted
File Systems in a Virtual Machine • Each guest OS has it's own fake disk drive. • Each fake disk drive is typically a file on the host. • Yes, this is lots of disk space.
Cheating in a VM • It's called a performance enhancement :-) • Since Window's data structures are well known, and it's possible to write a windows device driver... • Vmware can share identical RAM pages • Vmware can harvest free RAM • Vmware can harvest idle CPU • Vmware has a vmware file system
Xen • Basic Idea: • Don't emulate a real machine, that's too hard and slow. • Edit each guest OS to communicate with the host (paravirtualization). • Implications • better performance, easier implementation • Can no longer run unmodified Oss
Xen (again) • Xen has code inside Windows (non-published) and Linux. • Xen (starting at 3.0) can also do straight virtualization for a few Oss (like Windows). • Best??? of both worlds. • Also supports live migration • Only a 300 ms delay
Performance • If you need to fake the CPU • performance is like 5-10% of real time. • If your application is I/O intensive • performance can suffer • If you application is CPU intensive • performance is better • If you are emulating an Atari 2600(tm) • Your performance is better than real time.
Performance (again) • Dr. Dobbs says • CPU performance hit is < 10% • Ram hit is “costs ~200M” • http://www.ddj.com/hpc-high-performance-computing/199000664;jsessionid=BSCMYJRQRF5VSQSNDLRSKHSCJUNN2JVN?pgno=3
Crazy Nested VM-itude • Can you run a VM inside a VM? • depends • Should you run a VM inside a VM • maybe not • How deep can you go • typically, either zero or infinity
Other Uses of VMs • Since any guest can be a file ... • Ship it across country • Pause and restart • Clone thousands • Debug