24
Virtual Machines What Why How Powerpoint?

Virtual Machines

  • Upload
    haruki

  • View
    62

  • Download
    1

Embed Size (px)

DESCRIPTION

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. - PowerPoint PPT Presentation

Citation preview

Page 1: Virtual Machines

Virtual Machines

What

Why

How

Powerpoint?

Page 2: 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

Page 3: Virtual Machines

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.

Page 4: Virtual Machines

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)

Page 5: Virtual Machines

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

Page 6: Virtual Machines

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.

Page 7: Virtual Machines

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

Page 8: Virtual Machines

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

Page 9: Virtual Machines

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.

Page 10: Virtual Machines

Serial Port (Continued)

Efficiency

Stinks

Virtualizability

Can have more serial ports than exist

Can redirect serial ports to anything else (USB?)

Page 11: Virtual Machines

Virtualizing Video Framebuffer

Frame Buffer

Mark every page is r/o

When OS writes, VM gets an interrupt and writes

HUGE slowdown

Page 12: Virtual Machines

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.

Page 13: Virtual Machines

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!!!!

Page 14: Virtual Machines

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.

Page 15: Virtual Machines

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.

Page 16: Virtual Machines

CPU in a Virtual Machine

Each guest OS gets the CPU a fixed amount

If a guest OS is idle ... CPU is wasted

Page 17: Virtual Machines

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.

Page 18: Virtual Machines

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

Page 19: Virtual Machines

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

Page 20: Virtual Machines

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

Page 21: Virtual Machines

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.

Page 23: Virtual Machines

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

Page 24: Virtual Machines

Other Uses of VMs

Since any guest can be a file ...

Ship it across country

Pause and restart

Clone thousands

Debug