Example: confidence

Mechanism: Limited Direct Execution

6 Mechanism: Limited Direct ExecutionIn order to virtualize the CPU, the operating system needs to somehowshare the physical CPU among many jobs running seemingly at thesametime. The basic idea is simple: run one process for a little while, thenrun another one, and so forth. Bytime sharingthe CPU in this manner,virtualization is are a few challenges, however, in building such virtualizationmachinery. The first isperformance: how can we implement virtualiza-tion without adding excessive overhead to the system? The secondiscontrol: how can we run processes efficiently while retaining control overthe CPU?

4 MECHANISM: LIMITED DIRECT EXECUTION TIP: USE PROTECTED CONTROL TRANSFER The hardware assists the OS by providing different modes of execution. In user mode, applications do not have full access to hardware resources. In kernel mode, the OS has access to the full resources of the machine. Special instructions to trap into the kernel and return-from …

Tags:

  Limited, Execution, Direct, Limited direct execution

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of Mechanism: Limited Direct Execution

1 6 Mechanism: Limited Direct ExecutionIn order to virtualize the CPU, the operating system needs to somehowshare the physical CPU among many jobs running seemingly at thesametime. The basic idea is simple: run one process for a little while, thenrun another one, and so forth. Bytime sharingthe CPU in this manner,virtualization is are a few challenges, however, in building such virtualizationmachinery. The first isperformance: how can we implement virtualiza-tion without adding excessive overhead to the system? The secondiscontrol: how can we run processes efficiently while retaining control overthe CPU?

2 Control is particularly important to the OS, as it is in charge ofresources; without control, a process could simply run forever and takeover the machine, or access information that it should not be allowedtoaccess. Obtaining high performance while maintaining controlis thusone of the central challenges in building an operating :HOWTOEFFICIENTLYVIRTUALIZETHECPU WITHCONTROLThe OS must virtualize the CPU in an efficient manner while retainingcontrol over the system. To do so, both hardware and operating-systemsupport will be required. The OS will often use a judicious bit of hard-ware support in order to accomplish its work Basic Technique: Limited Direct ExecutionTo make a program run as fast as one might expect, not surprisinglyOS developers came up with a technique, which we calllimited directexecution.

3 The Direct Execution part of the idea is simple: just run theprogram directly on the CPU. Thus, when the OS wishes to start a pro-gram running, it creates a process entry for it in a process list,allocatessome memory for it, loads the program code into memory (from disk), lo-cates its entry point ( , themain()routine or something similar), jumps12 MECHANISM: LIMITEDDIRECTEXECUTIONOSP rogramCreate entry for process listAllocate memory for programLoad program into memorySet up stack with argc/argvClear registersExecutecallmain()Run main()Executereturnfrom mainFree memory of processRemove from process listFigure.

4 Direct Execution Protocol (Without Limits)to it, and starts running the user s code. Figure shows this basic di-rect Execution protocol (without any limits, yet), using a normal call andreturn to jump to the program smain()and later back into the simple, no? But this approach gives rise to a few problemsin our quest to virtualize the CPU. The first is simple: if we just run aprogram, how can the OS make sure the program doesn t do anythingthat we don t want it to do, while still running it efficiently? The second:when we are running a process, how does the operating system stop itfrom running and switch to another process, thus implementing thetimesharingwe require to virtualize the CPU?

5 In answering these questions below, we ll get a much better sense ofwhat is needed to virtualize the CPU. In developing these techniques,we ll also see where the Limited part of the name arises from; withoutlimits on running programs, the OS wouldn t be in control of anythingand thus would be just a library a very sad state of affairs foranaspiring operating system! Problem #1: Restricted OperationsDirect Execution has the obvious advantage of being fast; the programruns natively on the hardware CPU and thus executes as quicklyas onewould expect. But running on the CPU introduces a problem: what ifthe process wishes to perform some kind of restricted operation, suchas issuing an I/O request to a disk, or gaining access to more systemresources such as CPU or memory?

6 THECRUX: HOWTOPERFORMRESTRICTEDOPERATIONSA process must be able to perform I/O and some other restricted oper-ations, but without giving the process complete control over the can the OS and hardware work together to do so?OPERATINGSYSTEMS[ ] : LIMITEDDIRECTEXECUTION3 ASIDE: WHYSYSTEMCALLSLOOKLIKEPROCEDURECALLSYou may wonder why a call to a system call, such asopen()orread(),looks exactly like a typical procedure call in C; that is, if it looks just likea procedure call, how does the system know it s a system call, and doallthe right stuff? The simple reason: itisa procedure call, but hidden in-side that procedure call is the famous trap instruction.

7 More specifically,when you callopen()(for example), you are executing a procedure callinto the C library. Therein, whether foropen()or any of the other sys-tem calls provided, the library uses an agreed-upon calling conventionwith the kernel to put the arguments toopen()in well-known locations( , on the stack, or in specific registers), puts the system-call numberinto a well-known location as well (again, onto the stack or a register),and then executes the aforementioned trap instruction. The codein thelibrary after the trap unpacks return values and returns control to theprogram that issued the system call.

8 Thus, the parts of the C library thatmake system calls are hand-coded in assembly, as they need to carefullyfollow convention in order to process arguments and return values cor-rectly, as well as execute the hardware-specific trap instruction. And nowyou know why you personally don t have to write assembly code to trapinto an OS; somebody has already written that assembly for approach would simply be to let any process do whatever it wantsin terms of I/O and other related operations. However, doing so wouldprevent the construction of many kinds of systems that are desirable.

9 Forexample, if we wish to build a file system that checks permissions beforegranting access to a file, we can t simply let any user process issue I/Osto the disk; if we did, a process could simply read or write the entire diskand thus all protections would be , the approach we take is to introduce a new processor mode,known asuser mode; code that runs in user mode is restricted in what itcan do. For example, when running in user mode, a process can t issueI/O requests; doing so would result in the processor raising an exception;the OS would then likely kill the contrast to user mode iskernel mode, which the operating system(or kernel) runs in.

10 In this mode, code that runs can do what it likes, in-cluding privileged operations such as issuing I/O requests and executingall types of restricted are still left with a challenge, however: what should a user pro-cess do when it wishes to perform some kind of privileged operation,such as reading from disk? To enable this, virtually all modernhard-ware provides the ability for user programs to perform asystem on ancient machines such as the Atlas [K+61,L78], system callsallow the kernel to carefully expose certain key pieces of functionality touser programs, such as accessing the file system, creating anddestroy-ing processes, communicating with other processes, and allocating morec 2008 19, ARPACI-DUSSEAUTHREEEASYPIECES4 MECHANISM: LIMITEDDIRECTEXECUTIONTIP.


Related search queries