730 likes | 1.42k Views
Virtualization Technology. Prof. Dan Connors. Virtualization. Real vs. Virtual Similar essence, effect ”Formally” different A framework that combines or divides [computing] resources to present a transparent view of one or more environments Hardware/software partitioning (or aggregation)
E N D
Virtualization Technology Prof. Dan Connors
Virtualization • Real vs. Virtual • Similar essence, effect • ”Formally” different • A framework that combines or divides [computing] resources to present a transparent view of one or more environments • Hardware/software partitioning (or aggregation) • Partial or complete machine simulation • Emulation (partial or complete) • Time-sharing (in fact, sharing in general) • In general, can be M-to-N mapping (M “real” resources, N “virtual” resources) • Examples: VM (M-N), Grid Computing (M-1) , Multitasking (1-N)
Virtualization: Motivation Areas • Server consolidation • Application Consolidation • Sandboxing • Multiple execution environments • Virtual hardware • Debugging • Software migration (Mobility) • Appliance (software) • Testing/Quality Assurance
Types of Virtualization Process & application virtualization Process executes on CPU with modification of native instructions Created binary instrumentation and translation systems CPU/Machine virtualization Each process feels like it has its own CPU Created by OS preemption and scheduler Memory virtualization Process feels like it has its own address space Created by MMU, configured by OS Storage virtualization (Input/Output) Logical view of disks “connected” to a machine External pool of storage
Application Level Virtualization • Java Virtual Machine (JVM) • Executes Java byte code (virtual instructions) • Provides the implementation for the instruction set interpreter (or JIT compiler) • Provides code verification, SEH, garbage collection • Hardware access through underlying OS • JVM Architecture • Stack-based architecture • No MMU • Virtual hardware: PC, register-set, heap, method (code) areas • Rich instruction set • Direct object manipulation, type conversion, exception throws • Provides a runtime environment through JRE • Other Examples: .NET CLI, Parrot (PERL 6)
Virtual CPUs • Each process feels like it has its own CPU • But cannot execute privileged instructions (e.g., modify the MMU or the interval timer, halt the processor, access I/O) • Created by OS preemption and scheduler • Pseudo-machine with interpreted instructions • 1966: O-code for BCPL • 1973: P-code for Pascal • 1995: Java Virtual Machine • Run anywhere
Virtual Machines Machine virtualization Partition a physical computer to act like several real machines Migrate an entire OS + applications from one machine to another Early examples 1972: IBM System 370
Machines: Stacked Architecture APPLICATIONS API Calls USER LEVEL LIBRARIES User Space System Calls Kernel Space KERNEL Instructions HARDWARE
Possible Virtual Abstraction Levels • Instruction Set Architecture • Emulate the ISA in software • Interprets, translates to host ISA (if required) • Device abstractions implemented in software • Inefficient • Optimizations: Caching? Code reorganization? • Applications: Debugging, Teaching, multiple OS • Hardware Abstraction Layer (HAL) • Between “real machine” and “emulator” (maps to real hardware) • Handling non-virtualizable architectures (scan, insert code?) • Applications: Fast and usable, virtual hardware (in above too), consolidation, migration
Possible Abstraction Levels • Operating System Level • Virtualized SysCall Interface (may be same) • May or may not provide all the device abstractions • Easy to manipulate (create, configure, destroy) • Library (user-level API) Level • Presents a different subsystem API to application • Complex implementation, if kernel API is limited • User-level device drivers • Application (Programming Language) Level • Virtual architecture (ISA, registers, memory, …) • Platform-independence ( highly portable) • Less control on the system (extremely high-level)
Machine Virtualization Privileged vs. unprivileged instructions Regular applications use unprivileged instructions Easy to virtualize If regular applications execute privileged instructions, they trap VM catches the trap and emulates the instruction
Virtual Machine Monitor (VMM) Hypervisor- Program in charge of virtualization Arbitrates access to physical resources Presents a set of virtual device interfaces to each host Guest OS runs until: Privileged instruction traps System interrupts Exceptions (page faults) Explicit call: VMCALL (Intel) or VMMCALL (AMD)
Approaches • Intel x86 arch doesn’t support trapping privileged instructions • Two approaches to modifying OS to run on virtual machine: • Binary translation (BT) • Scan instruction stream and replace instructions • Replace privileged instructions with something the VM can intercept. (VMWare approach) • Paravirtualization • Don’t use non-virtualizable instructions (Xen approach) • Static design approach, paravirtualization support is designed before dynamic adaptation
Translation Approaches • Source instrumentation: • Instrument source programs • Binary instrumentation: • Instrument executables directly Advantages for binary instrumentation • Language independent • Machine-level view • Instrument legacy/proprietary software
Instrumentation Approaches When to instrument: • Instrument statically • Instrument dynamically Advantages for dynamic instrumentation • No need to recompile or relink • Discover code at runtime • Handle dynamically-generated code • Attach to running processes
www.pintool.org - Support for Binary Translation • Easy-to-use Instrumentation: • Uses dynamic instrumentation • Do not need source code, recompilation, post-linking • Programmable Instrumentation: • Provides rich APIs to write in C/C++ your own instrumentation tools (called Pintools) • Multiplatform: • Supports x86, x86-64, Itanium, Xscale • Supports Linux, Windows, MacOS • Robust: • Instruments real-life applications: Database, web browsers, … • Instruments multithreaded applications • Supports signals • Efficient: • Applies compiler optimizations on instrumentation code
Application Operating System Hardware Pin (VM) Software Architecture of Binary Translation Address space Pintool Pin Instrumentation APIs Virtual Machine (VM) Code Cache JIT Compiler Emulation Unit
BT: Instrumentation Approaches • JIT Mode • Pin creates a modified copy of the application on-the-fly • Original code never executes • More flexible, more common approach • Probe Mode • Pin modifies the original application instructions • Inserts jumps to instrumentation code (trampolines) • Lower overhead (less flexible) approach
1’ 1 3 2 2’ 4 5 7’ 6 7 JIT-Mode Instrumentation Original code Code cache Exits point back to Pin Pin Pin fetches trace starting block 1 and start instrumentation
1’ 2’ 7’ JIT-Mode Instrumentation Original code Code cache 1 3 2 4 5 6 7 Pin Pin transfers control into code cache (block 1)
1’ 3’ 1 3 2 5’ 2’ 4 5 6’ 7’ 6 7 JIT-Mode Instrumentation Original code Code cache trace linking Pin Pin fetches and instrument a new trace
A Original Code C B D F E JIT Code Model A’ A B C C’ D D’ Hot Path, Found with Hardware E F F’ Code Cache Original Code
Light-weight application Significant demands on the run-time system Transformation cost: Start-up (initialization) overhead time A black line represents a service request from the virtual machine. Space between adjacent black lines indicates time being spent in already compiled code paths.
JIT A’ JIT B’ JIT C’ JIT D’ C’ A’ 1) JIT A’ JIT B’ JIT C’ JIT D’ C’ A’ 2) JIT A’ JIT B’ JIT C’ JIT D’ C’ A’ 1) A’ B’ C’ D’ C’ A’ 2) Persistence Original dynamic instruction stream A B C D C A Traditional JIT Persistent JIT
Instrumentation Approaches • JIT Mode • Pin creates a modified copy of the application on-the-fly • Original code never executes • More flexible, more common approach • Probe Mode • Pin modifies the original application instructions • Inserts jumps to instrumentation code (trampolines) • Lower overhead (less flexible) approach
A Sample Probe • A probe is a jump instruction that overwrites original instruction(s) in the application • Instrumentation invoked with probes • Pin copies/translates original bytes so probed functions can be called • Entry point overwritten with probe: • 0x400113d4:jmp 0x41481064 • 0x400113d9: push %ebx • Original function entry point: • 0x400113d4: push %ebp • 0x400113d5: mov %esp,%ebp • 0x400113d7: push %edi • 0x400113d8: push %esi • 0x400113d9: push %ebx • Copy of entry point with original bytes: • 0x50000004: push %ebp • 0x50000005: mov %esp,%ebp • 0x50000007: push %edi • 0x50000008: push %esi • 0x50000009: jmp 0x400113d9
Popular VM Platforms Xen Runs under an OS and provides virtual containers for running other operating systems. Runs a subset of x86. Routes all hardware accesses to the host OS. Altris Software Virtualization Services Windows registry & directory tweaking Allows multiple instances of applications to be installed Microsoft Virtual Server Parallels VMWare
Overall Picture (More stars are better)
Instruction Set Architecture Level Virtualization • Technologies • Emulation: Translates guest ISA to native ISA • Emulates hardware specific IN/OUT instructions to mimic a device • Translation Cache: Optimizes emulation by making use of similar recent instructions • Code rearrangement • Speculative scheduling (alias hardware) • Issues • Efficient Exception handling • Self-modifying code
ISA Level Virtualization: Examples • Bochs: Open source x86 emulator • Emulates whole PC environment • x86 processor and most of the hardware (VGA, disk, keyboard, mouse, …) • Custom BIOS, emulation of power-up, reboot • Host ISAs: x86, PowerPC, Alpha, Sun, and MIPS • Crusoe (Transmeta) • “Code morphing engine” – dynamic x86 emulator on VLIW processor • 16 MB “translation cache” • Shadow registers: Enables easy exception handling • QEMU: • Full Implementation • Multiple target ISAs: x86, ARM, PowerPC, Sparc • Supports self-modifying code • Full-software and simulated (using mmap()) MMU • User-space only: Useful for Cross-compilation and cross-debugging
HAL Virtualization Techniques • Standalone vs. Hosted • Drivers • Host and VMM worlds • I/O • Protection Rings • Multilevel privilege domains • Handling “silent” fails • Scan code and insert/replace artificial traps • Cache results to optimize
Paravirtualization • Traditional architectures do not scale • Interrupt handling • Memory management • World switching • Virtualized architecture interface • Much simpler architectural interface • Virtual I/O and CPU instructions, registers, … • Portability is lost
Examples • Denali • Simpler customized OS with no VM for network applications • Xen • Simpler port to commercial OS • Exposes some “real” hardware, e.g. clock, physical memory address