Announcements: If you haven't picked up midterm 2, Professor Smith still has them, so there's no rush. Material for today: Virtual Machines (smith.10.txt pp. 38-42) and a bit on performance (smith.10.txt p. 29) VIRTUAL MACHINES read Robert Goldberg's "Survey of Virtual Machine Research" in the reader. virtual machine := software-supported copy of hardware. * usually: most user-level instructions are actually executed on hardware, and privileged instructions are simulated. Uses of virtual machines * run several different OSs at same time * debug OS safely | Joke: lameness 5 * debug network software | that's the kind of cloning * run multiple versions of the <| they haven't decided to ban same OS | yet. * have students do system programming * run things with high reliability and security due to isolation Examples of virtual machines * Smith gave some examples from his day e.g. IBM's VM/370. See his notes. * VMware (now a subsidiary of EMC) makes virtual machines for x86. * note: the founder of VMware, Mendel Rosenblum, was a Berkeley master student with Prof. Smith and could buy us a building (if he wanted to) * whole digression about how EMC started as a cement company and hired Israeli tank makers to make cheap disks in the 1980s * VMs are big. There's a whole conference on them. NOT a virtual machine but with similar effect * emulators (SNES emulators, Java Virtual Machine): these simulate every single instruction using software. Very slow. * User-Mode Linux: a port of the Linux kernel specifically to run as a user process. This allows you to try viruses in a "honeypot" or across a "honeynet." Or you can try rm -rf / and see how Linux would die, without harming your system. Implementation * Smith showed transparencies from | Note: the recommended reading. see <| (to that other note-taking dude) reader. | there's nothing worse than going to * the virtual machine monitor is | a 300 foot arena and having someone the actual program on the base | pull out a pocket camera and use a machine that creates virtual | flash machines, which each can run an OS * in normal operation (user state), instructions just run on underlying hardware * sensitive instructions (those that can affect the VMM or VM) are trapped to the VMM and simulated by the VMM * if you cannot trap all sensitive commands, it may be impossible to make a virtual machine on that architecture (VMware uses dynamic recompilation on the x86) Smith drew this: |----| |----||----| |----| | Joke: |user| |user||user| |user| | In Smith's parents' generation, people |----| |----||----| |----| | were taught to have good handwriting. \ / \ / | Obviously, Smith never learned it. |----------| |----------| <| But, he graded our papers so he won't | OS | | OS | | comment on whose is worse |----------| |----------| | VM | | VM | |----------| |----------| | Joke: \ / | Guy and Keith are in an equivalence \ / | class: they both sit at the front and \ / | talk a lot |----------| | | VMM | | Smith has problems |----------| | hardware | |----------| Virtual Machine Memory Management |----| Problem: There is only 1 TLB, and the VMM |user| handles it with its own page table. The OS thinks |----|---- that it is handling it. How do we get user \->|---| virtual page numbers into the hardware's TLB |----------| |PT1| to make things fast? | OS |...|---| <- |----------| / \ OS's page table maps user page # to VM's page # | VM |<-/ - we want the TLB to cache values from this |----------|- there is one per process \ |---| |----------| >|PT2| <- VMM's page table maps VM's page # to machine page # | VMM |...|---| the TLB is naturally a cache of this |----------| / there is one per virtual machine | hardware |<-/ |----------| |----| Solution: have the VMM handle another page |user|------------- table. make the hardware TLB cache this |----|---- \ instead of PT3. PT3 is a composition of \->|---| \ PT1 and PT2. |----------| |PT1| \ | OS |...|---| \ If there is a TLB miss, the VMM checks PT3 |----------| / |---| for the entry. If the page # is not in PT3, | VM |<-/ |PT3| the VMM checks PT2 to see whether it needs to |----------|- |---| load from there. If the entry is not found \ |---| / there, it throws a TLB miss to the operating |----------| >|PT2| / system, which should look in PT1 to give what | VMM |...|---| / the OS thinks is the physical page number. |----------| / / Then the VMM looks up this page # in PT2 and | hardware |<-/ / provides the true physical page number. Then |----------|<-------/ it fixes PT3. Actually I'm not sure about this, but it's something like that. Q (Ravi): How can PT3 be allowed to exist? A: It's created. | Q (Smith): Does everyone get it? | (front row says yes) Q (Andrew): How fast? | If the front row is not OK they tell A: If the OS's paging is inefficient, | me. (flirting) it may even be faster to make it think the machine has 4 GiB of RAM, | note: must have fast memory access so that the OS does no paging. | because if it is slow then VMs would | be discussed only in theory classes. | (bashing theory) Virtual Machine I/O I/O is usually trapped and simulated. Q (Keith): How fast? A: performance is still not an issue becuase I/O is usually very slow. I/O code (e.g. channel programs) must | Joke: writing self-modifying code is be interpreted or translated. Self- | like throwing knives in the air with modifying channel programs are | no handles. usually prohibited. Q (Smith) Has anyone ever written self-modifying code? A: Keith has. I/O devices are usually completely simulated (e.g. give OS "mini-disks" that are pieces of the true big disk) Virtual Machine state The VMM keeps a bit for each VM to tell whether that machine is in user or supervisor mode. | Joke (I think): * if code tries to do a privileged | Anyone who has ever come within 3 in. instruction while in user mode, | of hexadecimal printouts knows about it results in an abend. | abends. Hardware Virtualizers * If the machine supports mapping virtual machines to parts of hardware, most software simulation could be eliminated. * I don't get it. He just read what was written in the notes. VM Performance * It will run slower, naturally, than running natively. Specific performance issues * support for privileged instructions * maintaining virtual processor status (user/supervisor bits) * paging (a big performance hit) * console functions (different VMs must share consoles) * I/O interrupts must be delivered to correct VM * translation of channel programs * maintaining clocks might be hard: * if we want to make the OS think | joke it is running on a really fast | clocks should advance monotonically, machine, just run the clock | not like a pogo stick. more slowly than real time * trying to run the clock at real | joke (I think) time might be an issue because | something about time jumping & the ticks might jump | H.G. Wells How to make VMs faster * have hardware resources dedicated to a VM so they don't have to be mapped (maybe OS memory) * give certain VMs priority over others * run virtual = real (same as #1) (I don't know what that means) * let VM do paging instead of OS if | anecdote (or something): OS is inefficient | DB2 had a page fault double paging * modify OS to avoid slow features | anomaly because of conflict between * performance enhancements in | VM and database microcode (e.g. VM assist for 370) * extend hardware to support VMs Special performance problem * optimizations in VMM may conflict with optimizations in OS * e.g. double paging in DB2. * buffer paging (?) * OS might try to optimize disk spooling but it already has virtual disk addresses Q (Andrew): Are there any examples? | digression: keynote speaker for A: Yes. (see above). VM is big. | something must talk during lunch | because it's the only time he's free | in August. So definition of success: | when you lose control of your life | completely | Jokes (really lame) | Yakov: Round robin his time. | Smith: use preemptive: be able to say | I don't want you to go More digression into Dilbert: it's not as strange as you think. Don't read it. No, do. It might help for career planning. People with pointy hair should not have managerial positions. PERFORMANCE EVALUATION See Heidelberger, P; Lavenberg, S. "Computer performance evaluation methodology". IEEE Transactions on Computers. Vol. C-33, pp. 1195-1220. Dec. 1984 Performance is not as important as it | bashing Berkeley: You can go to Fry's used to be, but even so... | and get a machine with more than what Performance is still important for | Berkeley had when I first got here, real-time operating systems | which isn't hard. It helps to have performance in mind from the beginning (design, debug, install, etc.) * e.g. IBM's DB2 had no performance guys and their first release was really slow and some things could not be optimized because they were design flaws Evaluating Performance covers * measurement * analytic methods (equations), stochastic modeling. See Stat 134. * simulation modeling (e.g. hw1) * tuning * design improvement Making performance good requires good understanding of system; you can't just be a "performance expert" with a bag of tricks (e.g. queueing theory) Measurement * it is good to do to get "real" data * disadvantage: measurement is the hardest aspect of every academic field * measurement studies are few and oft cited Hardware monitoring * they use a hardware monitor (e.g. logic analyzers) * data can sometimes be collected by logic probes * difficult since many important transistors are deep withiin the chip * these days pins are installed to read from * these days programmable counters may be used to count memory accesses, etc. * note: sampling should be done randomly, not periodically, so that you don't keep measuring the same part of a periodic action Software measurements: modify the software to store information * e.g. to get number of page faults * requires you to be able to edit OS source or to attach binary patches * problem: it might degrade performance to add code for measurements * some compilers insert profiling information Hardware counters * on modern CPUs a counter can measure 2-4 things. See next lecture. He repeated this stuff. But watch out. It's much more boring than VMs.