text stringlengths 1 7.76k | source stringlengths 17 81 |
|---|---|
384 INPUT/OUTPUT CHAP. 5 system must do the same thing in software. This means that it must first acquire a list of bad sectors, either by reading them from the disk, or simply testing the entire disk itself. Once it knows which sectors are bad, it can build remapping tables. If the operating system wants to use the ap... | clipped_os_Page_384_Chunk6601 |
SEC. 5.4 DISKS 385 recalibrations insert gaps into the bit stream and are unacceptable. Special drives, called AV disks (Audio Visual disks), which never recalibrate are available for such applications. Anecdotally, a highly convincing demonstration of how advanced disk con- trollers have become was given by the Dutch ... | clipped_os_Page_385_Chunk6602 |
386 INPUT/OUTPUT CHAP. 5 rare that having the same sector go bad on a second (independent) drive during a reasonable time interval (e.g., 1 day) is small enough to ignore. The model also assumes the CPU can fail, in which case it just stops. Any disk write in progress at the moment of failure also stops, leading to inc... | clipped_os_Page_386_Chunk6603 |
SEC. 5.4 DISKS 387 in the presence of CPU crashes during stable writes? It depends on precisely when the crash occurs. There are fiv e possibilities, as depicted in Fig. 5-27. Old 1 Old 2 Disk 1 Old 2 Disk New 1 Old 2 Disk New 1 2 Disk New 1 New 2 Disk Crash Crash Crash Crash Crash (a) (b) (c) (d) (e) ECC error Figure ... | clipped_os_Page_387_Chunk6604 |
388 INPUT/OUTPUT CHAP. 5 block number, for example, −1. Under these conditions, after a crash the recovery program can check the nonvolatile RAM to see if a stable write happened to be in progress during the crash, and if so, which block was being written when the crashed happened. The two copies of the block can then ... | clipped_os_Page_388_Chunk6605 |
SEC. 5.5 CLOCKS 389 this base signal can be multiplied by a small integer to get frequencies up to several gigahertz or even more. At least one such circuit is usually found in any computer, providing a synchronizing signal to the computer’s various circuits. This signal is fed into the counter to make it count down to... | clipped_os_Page_389_Chunk6606 |
390 INPUT/OUTPUT CHAP. 5 5.5.2 Clock Software All the clock hardware does is generate interrupts at known intervals. Every- thing else involving time must be done by the software, the clock driver. The exact duties of the clock driver vary among operating systems, but usually include most of the following: 1. Maintaini... | clipped_os_Page_390_Chunk6607 |
SEC. 5.5 CLOCKS 391 (a) (b) (c) Time of day in ticks Time of day in seconds Counter in ticks System boot time in seconds Number of ticks in current second 64 bits 32 bits 32 bits Figure 5-29. Three ways to maintain the time of day. how long the process has run. To do things right, the second timer should be saved when ... | clipped_os_Page_391_Chunk6608 |
392 INPUT/OUTPUT CHAP. 5 Current time Next signal Clock header 3 4 6 2 1 X 4200 3 Figure 5-30. Simulating multiple timers with a single clock. Note that during a clock interrupt, the clock driver has several things to do— increment the real time, decrement the quantum and check for 0, do CPU ac- counting, and decrement... | clipped_os_Page_392_Chunk6609 |
SEC. 5.5 CLOCKS 393 timer is very high. Below we will briefly describe a software-based timer scheme that works well under many circumstances, even at fairly high frequencies. The idea is due to Aron and Druschel (1999). For more details, please see their paper. Generally, there are two ways to manage I/O: interrupts a... | clipped_os_Page_393_Chunk6610 |
394 INPUT/OUTPUT CHAP. 5 an occasional missed deadline. Being 10 μsec late from time to time is often better than having interrupts eat up 35% of the CPU. Of course, there will be periods when there are no system calls, TLB misses, or page faults, in which case no soft timers will go off. To put an upper bound on these... | clipped_os_Page_394_Chunk6611 |
SEC. 5.6 USER INTERFACES: KEYBOARD, MOUSE, MONITOR 395 a key release. It is up to the driver to keep track of the status of each key (up or down). So all the hardware does is give press and release interrupts. Software does the rest. When the A key is struck, for example, the scan code (30) is put in an I/O reg- ister.... | clipped_os_Page_395_Chunk6612 |
396 INPUT/OUTPUT CHAP. 5 requested input, so the characters must be buffered to allow type ahead. Either a dedicated buffer can be used or buffers can be allocated from a pool. The former puts a fixed limit on type ahead; the latter does not. This issue arises most acutely when the user is typing to a shell window (com... | clipped_os_Page_396_Chunk6613 |
SEC. 5.6 USER INTERFACES: KEYBOARD, MOUSE, MONITOR 397 standard. The defaults are all control characters that should not conflict with text input or codes used by programs; all except the last two can be changed under pro- gram control. Character POSIX name Comment CTRL-H ERASE Backspace one character CTRL-U KILL Erase... | clipped_os_Page_397_Chunk6614 |
398 INPUT/OUTPUT CHAP. 5 twice consecutively. After seeing a CTRL-V, the driver sets a flag saying that the next character is exempt from special processing. The LNEXT character itself is not entered in the character queue. To allow users to stop a screen image from scrolling out of view, control codes are provided to ... | clipped_os_Page_398_Chunk6615 |
SEC. 5.6 USER INTERFACES: KEYBOARD, MOUSE, MONITOR 399 and make continuous low-resolution photos of the surface under them, looking for changes from image to image. Whenever a mouse has moved a certain minimum distance in either direction or a button is depressed or released, a message is sent to the computer. The mini... | clipped_os_Page_399_Chunk6616 |
400 INPUT/OUTPUT CHAP. 5 own escape sequences. As a consequence, it was difficult to write software that worked on more than one terminal type. One solution, which was introduced in Berkeley UNIX, was a terminal data- base called termcap. This software package defined a number of basic actions, such as moving the curso... | clipped_os_Page_400_Chunk6617 |
SEC. 5.6 USER INTERFACES: KEYBOARD, MOUSE, MONITOR 401 The X Window System Nearly all UNIX systems base their user interface on the X Window System (often just called X), developed at M.I.T. as part of project Athena in the 1980s. It is very portable and runs entirely in user space. It was originally intended for con- ... | clipped_os_Page_401_Chunk6618 |
402 INPUT/OUTPUT CHAP. 5 Remote host Window manager Application program Motif Intrinsics Xlib X client UNIX Hardware X server UNIX Hardware Window User space Kernel space X protocol Network Figure 5-33. Clients and servers in the M.I.T. X Window System. elements, called widgets. To make a true GUI interface, with a uni... | clipped_os_Page_402_Chunk6619 |
SEC. 5.6 USER INTERFACES: KEYBOARD, MOUSE, MONITOR 403 program itself. X considers this connection to be reliable in the sense that lost and duplicate messages are handled by the networking software and it does not have to worry about communication errors. Usually, TCP/IP is used between the client and server. Four kin... | clipped_os_Page_403_Chunk6620 |
404 INPUT/OUTPUT CHAP. 5 #include <X11/Xlib.h> #include <X11/Xutil.h> main(int argc, char *argv[]) { Display disp; /* ser ver identifier */ Window win; /* window identifier */ GC gc; /* graphic context identifier */ XEvent event; /* storage for one event */ int running = 1; disp = XOpenDisplay("display name"); /* conne... | clipped_os_Page_404_Chunk6621 |
SEC. 5.6 USER INTERFACES: KEYBOARD, MOUSE, MONITOR 405 It is worth mentioning that not everyone likes a GUI. Many programmers pre- fer a traditional command-line oriented interface of the type discussed in Sec. 5.6.1 above. X handles this via a client program called xterm. This program emulates a venerable VT102 intell... | clipped_os_Page_405_Chunk6622 |
406 INPUT/OUTPUT CHAP. 5 appear on the screen. Graphics adapters often have powerful 32- or 64-bit CPUs and up to 4 GB of their own RAM, separate from the computer’s main memory. Each graphics adapter supports some number of screen sizes. Common sizes (horizontal × vertical in pixels) are 1280 × 960, 1600 × 1200, 1920 ... | clipped_os_Page_406_Chunk6623 |
SEC. 5.6 USER INTERFACES: KEYBOARD, MOUSE, MONITOR 407 Thumb Title bar File Edit View Tools Options Help Client area (200, 100) (0, 0) (0, 767) Menu bar Tool bar Window Scroll bar (1023, 767) (1023, 0) 12 6 9 3 4 8 5 7 1 11 2 10 Figure 5-35. A sample window located at (200, 100) on an XGA display. To make this programm... | clipped_os_Page_407_Chunk6624 |
408 INPUT/OUTPUT CHAP. 5 #include <windows.h> int WINAPI WinMain(HINSTANCE h, HINSTANCE, hprev, char *szCmd, int iCmdShow) { WNDCLASS wndclass; /* class object for this window */ MSG msg; /* incoming messages are stored here */ HWND hwnd; /* handle (pointer) to the window object */ /* Initialize wndclass */ wndclass.lp... | clipped_os_Page_408_Chunk6625 |
SEC. 5.6 USER INTERFACES: KEYBOARD, MOUSE, MONITOR 409 also a 32-bit signed integer), s (string), sz (string terminated by a zero byte), p (pointer), fn (function), and h (handle). Thus szCmd is a zero-terminated string and iCmdShow is an integer, for example. Many programmers believe that en- coding the type in variab... | clipped_os_Page_409_Chunk6626 |
410 INPUT/OUTPUT CHAP. 5 There are two ways Windows can get a program to do something. One way is to post a message to its message queue. This method is used for keyboard input, mouse input, and timers that have expired. The other way, sending a message to the window, inv olves having Windows directly call WndProc itse... | clipped_os_Page_410_Chunk6627 |
SEC. 5.6 USER INTERFACES: KEYBOARD, MOUSE, MONITOR 411 A complete treatment of the GDI is out of the question here. For the interested reader, the references cited above provide additional information. Nevertheless, given how important it is, a few words about the GDI are probably worthwhile. GDI has various procedure ... | clipped_os_Page_411_Chunk6628 |
412 INPUT/OUTPUT CHAP. 5 Windows metafile and is widely used to transmit drawings from one Windows pro- gram to another. Such files have extension .wmf. Many Windows programs allow the user to copy (part of) a drawing and put it on the Windows clipboard. The user can then go to another program and paste the contents of... | clipped_os_Page_412_Chunk6629 |
SEC. 5.6 USER INTERFACES: KEYBOARD, MOUSE, MONITOR 413 0 2 4 6 8 0 2 4 6 8 0 2 4 6 8 0 2 4 6 8 Window 1 Window 2 0 2 4 6 8 0 2 4 6 8 0 2 4 6 8 0 2 4 6 8 Window 1 Window 2 (a) (b) Figure 5-38. Copying bitmaps using BitBlt. (a) Before. (b) After. have file and information headers and a color table before the pixels. This... | clipped_os_Page_413_Chunk6630 |
414 INPUT/OUTPUT CHAP. 5 20 pt: 53 pt: 81 pt: Figure 5-39. Some examples of character outlines at different point sizes. error. To improve the quality still more, it is possible to embed hints in each char- acter telling how to do the rasterization. For example, both serifs on the top of the letter T should be identica... | clipped_os_Page_414_Chunk6631 |
SEC. 5.6 USER INTERFACES: KEYBOARD, MOUSE, MONITOR 415 plastic. However, a thin film of ITO (Indium Tin Oxide) or some similar con- ducive material) is printed in thin lines onto the surface’s underside. Beneath it, but not quite touching it, is a second surface also coated with a layer of ITO. On the top surface, the ... | clipped_os_Page_415_Chunk6632 |
416 INPUT/OUTPUT CHAP. 5 Manipulating a touch screen with just a single finger is still fairly WIMPy— you just replace the mouse pointer with your stylus or index finger. Multitouch is a bit more complicated. Touching the screen with fiv e fingers is like pushing fiv e mouse pointers across the screen at the same time ... | clipped_os_Page_416_Chunk6633 |
SEC. 5.7 THIN CLIENTS 417 and other things that used to require PC software. It is even possible that eventually the only software people run on their PC is a Web browser, and maybe not even that. It is probably a fair conclusion to say that most users want high-performance interactive computing but do not really want ... | clipped_os_Page_417_Chunk6634 |
418 INPUT/OUTPUT CHAP. 5 an industry used to a doubling of performance every 18 months (Moore’s law), having no progress at all seems like a violation of the laws of physics, but that is the current situation. As a consequence, making computers use less energy so existing batteries last longer is high on everyone’s age... | clipped_os_Page_418_Chunk6635 |
SEC. 5.8 POWER MANAGEMENT 419 nothing except send a signal to the operating system, which does the rest in soft- ware. In some countries, electrical devices must, by law, hav e a mechanical power switch that breaks a circuit and removes power from the device, for safety reasons. To comply with this law, another switch ... | clipped_os_Page_419_Chunk6636 |
420 INPUT/OUTPUT CHAP. 5 annoying delay while it is restarted. On the other hand, if it waits too long to shut down a device, energy is wasted for nothing. The trick is to find algorithms and heuristics that let the operating system make good decisions about what to shut down and when. The trouble is that ‘‘good’’ is h... | clipped_os_Page_420_Chunk6637 |
SEC. 5.8 POWER MANAGEMENT 421 Window 1 Window 2 Window 1 Window 2 Zone (a) (b) Figure 5-41. The use of zones for backlighting the display. (a) When window 2 is selected, it is not moved. (b) When window 1 is selected, it moves to reduce the number of zones illuminated. When it is next needed, it is spun up again. Unfor... | clipped_os_Page_421_Chunk6638 |
422 INPUT/OUTPUT CHAP. 5 On many computers, there is a relationship between CPU voltage, clock cycle, and power usage. The CPU voltage can often be reduced in software, which saves energy but also reduces the clock cycle (approximately linearly). Since power con- sumed is proportional to the square of the voltage, cutt... | clipped_os_Page_422_Chunk6639 |
SEC. 5.8 POWER MANAGEMENT 423 more data to transmit. Finally, it will give up and go to sleep, because continuous polling is very bad for power consumption. Shortly after, the producer provides more data, but now the network stack is fast sleep. Waking up the stack takes time and slows down the throughput. One possible... | clipped_os_Page_423_Chunk6640 |
424 INPUT/OUTPUT CHAP. 5 when it switches on the radio again. At that point any accumulated messages can be sent to it. Outgoing messages that are generated while the radio is off are buffered on the mobile computer. If the buffer threatens to fill up, the radio is turned on and the queue transmitted to the base statio... | clipped_os_Page_424_Chunk6641 |
SEC. 5.8 POWER MANAGEMENT 425 more. Most mobile devices have programs that can be run to query and display all these parameters. Smart batteries can also be instructed to change various opera- tional parameters under control of the operating system. Some notebooks have multiple batteries. When the operating system dete... | clipped_os_Page_425_Chunk6642 |
426 INPUT/OUTPUT CHAP. 5 In order to measure the energy usage, Flinn and Satyanarayanan devised a soft- ware tool called PowerScope. What it does is provide a power-usage profile of a program. To use it, a computer must be hooked up to an external power supply through a software-controlled digital multimeter. Using the... | clipped_os_Page_426_Chunk6643 |
SEC. 5.9 RESEARCH ON INPUT/OUTPUT 427 existing buffering systems (DeBruijn and Bos, 2008). Streamline is especially use- ful for demanding network applications. Megapipe (Han et al., 2012) is another network I/O architecture for message-oriented workloads. It creates per-core bidi- rectional channels between the kernel... | clipped_os_Page_427_Chunk6644 |
428 INPUT/OUTPUT CHAP. 5 leads to substantial overhead. Getting rid of this overhead is where the research comes in (Tsafir et al., 2005). Similarly, interrupt latency is still a concern for research groups, especially in the area of real-time operating systems. Since these are often found embedded in critical systems ... | clipped_os_Page_428_Chunk6645 |
SEC. 5.10 SUMMARY 429 Character-oriented terminals have a variety of issues concerning special char- acters that can be input and special escape sequences that can be output. Input can be in raw mode or cooked mode, depending on how much control the program wants over the input. Escape sequences on output control curso... | clipped_os_Page_429_Chunk6646 |
430 INPUT/OUTPUT CHAP. 5 controller, how long will it take to transfer 1000 words from the disk controller to main memory, if (a) word-at-a-time mode is used, (b) burst mode is used? Assume that com- manding the disk controller requires acquiring the bus to send one word and acknowl- edging a transfer also requires acq... | clipped_os_Page_430_Chunk6647 |
CHAP. 5 PROBLEMS 431 Then it copies the data to the network controller board. When all the bytes are safely inside the controller, they are sent over the network at a rate of 10 megabits/sec. The receiving network controller stores each bit a microsecond after it is sent. When the last bit arrives, the destination CPU ... | clipped_os_Page_431_Chunk6648 |
432 INPUT/OUTPUT CHAP. 5 29. A disk manufacturer has two 5.25-inch disks that each have 10,000 cylinders. The newer one has double the linear recording density of the older one. Which disk proper- ties are better on the newer drive and which are the same? Are any worse on the newer one? 30. A computer manufacturer deci... | clipped_os_Page_432_Chunk6649 |
CHAP. 5 PROBLEMS 433 39. A system simulates multiple clocks by chaining all pending clock requests together as shown in Fig. 5-30. Suppose the current time is 5000 and there are pending clock re- quests for time 5008, 5012, 5015, 5029, and 5037. Show the values of Clock header, Current time, and Next signal at times 50... | clipped_os_Page_433_Chunk6650 |
434 INPUT/OUTPUT CHAP. 5 Rectangle(hdc, xleft, ytop, xright, ybottom); Is there any real need for the first parameter (hdc), and if so, what? After all, the coor- dinates of the rectangle are explicitly specified as parameters. 50. A thin-client terminal is used to display a Web page containing an animated cartoon of s... | clipped_os_Page_434_Chunk6651 |
6 DEADLOCKS Computer systems are full of resources that can be used only by one process at a time. Common examples include printers, tape drives for backing up company data, and slots in the system’s internal tables. Having two processes simultan- eously writing to the printer leads to gibberish. Having two processes u... | clipped_os_Page_435_Chunk6652 |
436 DEADLOCKS CHAP. 6 Deadlocks can also occur in a variety of other situations.. In a database sys- tem, for example, a program may have to lock several records it is using, to avoid race conditions. If process A locks record R1 and process B locks record R2, and then each process tries to lock the other one’s record,... | clipped_os_Page_436_Chunk6653 |
SEC. 6.1 RESOURCES 437 swapping it out and swapping A in. Now A can run, do its printing, and then re- lease the printer. No deadlock occurs. A nonpreemptable resource, in contrast, is one that cannot be taken away from its current owner without potentially causing failure. If a process has begun to burn a Blu-ray, sud... | clipped_os_Page_437_Chunk6654 |
438 DEADLOCKS CHAP. 6 semaphores are all initialized to 1. Mutexes can be used equally well. The three steps listed above are then implemented as a down on the semaphore to acquire the resource, the use of the resource, and finally an up on the resource to release it. These steps are shown in Fig. 6-1(a). typedef int s... | clipped_os_Page_438_Chunk6655 |
SEC. 6.2 INTRODUCTION TO DEADLOCKS 439 typedef int semaphore; semaphore resource 1; semaphore resource 1; semaphore resource 2; semaphore resource 2; void process A(void) { void process A(void) { down(&resource 1); down(&resource 1); down(&resource 2); down(&resource 2); use both resources( ); use both resources( ); up... | clipped_os_Page_439_Chunk6656 |
440 DEADLOCKS CHAP. 6 6.2.1 Conditions for Resource Deadlocks Coffman et al. (1971) showed that four conditions must hold for there to be a (resource) deadlock: 1. Mutual exclusion condition. Each resource is either currently assign- ed to exactly one process or is available. 2. Hold-and-wait condition. Processes curre... | clipped_os_Page_440_Chunk6657 |
SEC. 6.2 INTRODUCTION TO DEADLOCKS 441 (a) (b) (c) T U D C S B A R Figure 6-3. Resource allocation graphs. (a) Holding a resource. (b) Requesting a resource. (c) Deadlock. requests and releases of the three processes are given in Fig. 6-4(a)–(c). The oper- ating system is free to run any unblocked process at any instan... | clipped_os_Page_441_Chunk6658 |
442 DEADLOCKS CHAP. 6 (j) A Request R Request S Release R Release S B Request S Request T Release S Release T C Request T Request R Release T Release R 1. A requests R 2. B requests S 3. C requests T 4. A requests S 5. B requests T 6. C requests R deadlock 1. A requests R 2. C requests T 3. A requests S 4. C requests R... | clipped_os_Page_442_Chunk6659 |
SEC. 6.2 INTRODUCTION TO DEADLOCKS 443 leads to deadlock. We just carry out the requests and releases step by step, and after every step we check the graph to see if it contains any cycles. If so, we have a deadlock; if not, there is no deadlock. Although our treatment of resource graphs has been for the case of a sing... | clipped_os_Page_443_Chunk6660 |
444 DEADLOCKS CHAP. 6 recover after the fact. In this section we will look at some of the ways deadlocks can be detected and some of the ways recovery from them can be handled. 6.4.1 Deadlock Detection with One Resource of Each Type Let us begin with the simplest case: there is only one resource of each type. Such a sy... | clipped_os_Page_444_Chunk6661 |
SEC. 6.4 DEADLOCK DETECTION AND RECOVERY 445 R S T T U V U V W C D E D E G G A F B (a) (b) Figure 6-5. (a) A resource graph. (b) A cycle extracted from (a). uses one dynamic data structure, L, a list of nodes, as well as a list of arcs. During the algorithm, to prevent repeated inspections, arcs will be marked to indic... | clipped_os_Page_445_Chunk6662 |
446 DEADLOCKS CHAP. 6 any cycles. If this property holds for all nodes, the entire graph is cycle free, so the system is not deadlocked. To see how the algorithm works in practice, let us use it on the graph of Fig. 6-5(a). The order of processing the nodes is arbitrary, so let us just inspect them from left to right, ... | clipped_os_Page_446_Chunk6663 |
SEC. 6.4 DEADLOCK DETECTION AND RECOVERY 447 Resources in existence (E1, E2, E3, …, Em) Current allocation matrix C11 C21 Cn1 C12 C22 Cn2 C13 C23 Cn3 C1m C2m Cnm Row n is current allocation to process n Resources available (A1, A2, A3, …, Am) Request matrix R11 R21 Rn1 R12 R22 Rn2 R13 R23 Rn3 R1m R2m Rnm Row 2 is what ... | clipped_os_Page_447_Chunk6664 |
448 DEADLOCKS CHAP. 6 finish, they are deadlocked. Although the algorithm is nondeterministic (because it may run the processes in any feasible order), the result is always the same. As an example of how the deadlock detection algorithm works, see Fig. 6-7. Here we have three processes and four resource classes, which ... | clipped_os_Page_448_Chunk6665 |
SEC. 6.4 DEADLOCK DETECTION AND RECOVERY 449 6.4.3 Recovery from Deadlock Suppose that our deadlock detection algorithm has succeeded and detected a deadlock. What next? Some way is needed to recover and get the system going again. In this section we will discuss various ways of recovering from deadlock. None of them a... | clipped_os_Page_449_Chunk6666 |
450 DEADLOCKS CHAP. 6 Recovery through Killing Processes The crudest but simplest way to break a deadlock is to kill one or more proc- esses. One possibility is to kill a process in the cycle. With a little luck, the other processes will be able to continue. If this does not help, it can be repeated until the cycle is ... | clipped_os_Page_450_Chunk6667 |
SEC. 6.5 DEADLOCK AVOIDANCE 451 In Fig. 6-8 we see a model for dealing with two processes and two resources, for example, a printer and a plotter. The horizontal axis represents the number of instructions executed by process A. The vertical axis represents the number of in- structions executed by process B. At I1 A req... | clipped_os_Page_451_Chunk6668 |
452 DEADLOCKS CHAP. 6 point t the only safe thing to do is run process A until it gets to I4. Beyond that, any trajectory to u will do. The important thing to see here is that at point t, B is requesting a resource. The system must decide whether to grant it or not. If the grant is made, the system will enter an unsafe... | clipped_os_Page_452_Chunk6669 |
SEC. 6.5 DEADLOCK AVOIDANCE 453 A B C 3 2 2 9 4 7 Free: 3 (a) A B C 4 2 2 9 4 7 Free: 2 (b) A B C 4 4 — 4 2 9 7 Free: 0 (c) A B C 4 — 2 9 7 Free: 4 (d) Has Max Has Max Has Max Has Max Figure 6-10. Demonstration that the state in (b) is not safe. processes needs fiv e. There is no sequence that guarantees completion. Th... | clipped_os_Page_453_Chunk6670 |
454 DEADLOCKS CHAP. 6 A B C D 0 0 0 0 6 Has Max 5 4 7 Free: 10 A B C D 1 1 2 4 6 Has Max 5 4 7 Free: 2 A B C D 1 2 2 4 6 Has Max 5 4 7 Free: 1 (a) (b) (c) Figure 6-11. Three resource allocation states: (a) Safe. (b) Safe. (c) Unsafe. the customers suddenly asked for their maximum loans, the banker could not sat- isfy a... | clipped_os_Page_454_Chunk6671 |
SEC. 6.5 DEADLOCK AVOIDANCE 455 These matrices are just C and R from Fig. 6-6. As in the single-resource case, processes must state their total resource needs before executing, so that the system can compute the right-hand matrix at each instant. The three vectors at the right of the figure show the existing resources,... | clipped_os_Page_455_Chunk6672 |
456 DEADLOCKS CHAP. 6 those of the banker’s algorithm to prevent deadlock. For instance, networks may throttle traffic when buffer utilization reaches higher than, say, 70%—estimating that the remaining 30% will be sufficient for current users to complete their service and return their resources. 6.6 DEADLOCK PREVENTIO... | clipped_os_Page_456_Chunk6673 |
SEC. 6.6 DEADLOCK PREVENTION 457 all processes to request all their resources before starting execution. If ev erything is available, the process will be allocated whatever it needs and can run to comple- tion. If one or more resources are busy, nothing will be allocated and the process will just wait. An immediate pro... | clipped_os_Page_457_Chunk6674 |
458 DEADLOCKS CHAP. 6 resources whenever they want to, but all requests must be made in numerical order. A process may request first a printer and then a tape drive, but it may not request first a plotter and then a printer. (a) (b) 1. Imagesetter 2. Printer 3. Plotter 4. Tape drive 5. Blu-ray drive A i B j Figure 6-13... | clipped_os_Page_458_Chunk6675 |
SEC. 6.7 OTHER ISSUES 459 Condition Approach Mutual exclusion Spool ev erything Hold and wait Request all resources initially No preemption Take resources away Circular wait Order resources numer ically Figure 6-14. Summary of approaches to deadlock prevention. 6.7.1 Two-Phase Locking Although both avoidance and preven... | clipped_os_Page_459_Chunk6676 |
460 DEADLOCKS CHAP. 6 complete service if their execution were not interleaved with competing processes. A process locks resources in order to prevent inconsistent resource states caused by interleaved access to resources. Interleaved access to locked resources, however, enables resource deadlock. In Fig. 6-2 we saw a ... | clipped_os_Page_460_Chunk6677 |
SEC. 6.7 OTHER ISSUES 461 Readers interested in network protocols might be interested in another book by one of the authors, Computer Networks (Tanenbaum and Wetherall, 2010). Not all deadlocks occurring in communication systems or networks are com- munication deadlocks. Resource deadlocks can also occur there. Conside... | clipped_os_Page_461_Chunk6678 |
462 DEADLOCKS CHAP. 6 Consider an atomic primitive try lock in which the calling process tests a mutex and either grabs it or returns failure. In other words, it never blocks. Pro- grammers can use it together with acquire lock which also tries to grab the lock, but blocks if the lock is not available. Now imagine a pa... | clipped_os_Page_462_Chunk6679 |
SEC. 6.7 OTHER ISSUES 463 Now suppose that a UNIX system has 100 process slots. Ten programs are running, each of which needs to create 12 children. After each process has created 9 processes, the 10 original processes and the 90 new processes have exhausted the table. Each of the 10 original processes now sits in an e... | clipped_os_Page_463_Chunk6680 |
464 DEADLOCKS CHAP. 6 It is worth mentioning that some people do not make a distinction between starvation and deadlock because in both cases there is no forward progress. Others feel that they are fundamentally different because a process could easily be pro- grammed to try to do something n times and, if all of them ... | clipped_os_Page_464_Chunk6681 |
SEC. 6.9 SUMMARY 465 forever. Commonly the event that the processes are waiting for is the release of some resource held by another member of the set. Another situation in which deadlock is possible is when a set of communicating processes are all waiting for a message and the communication channel is empty and no time... | clipped_os_Page_465_Chunk6682 |
466 DEADLOCKS CHAP. 6 Gridlock is a resource deadlock and a problem in competition synchronization. New York City’s prevention algorithm, called "don’t block the box," prohibits cars from entering an intersection unless the space following the intersection is also available. Which prevention algorithm is this? Can you ... | clipped_os_Page_466_Chunk6683 |
CHAP. 6 PROBLEMS 467 15. Explain how the system can recover from the deadlock in previous problem using (a) recovery through preemption. (b) recovery through rollback. (c) recovery through killing processes. 16. Suppose that in Fig. 6-6 Cij + Rij > E j for some i. What implications does this have for the system? 17. Al... | clipped_os_Page_467_Chunk6684 |
468 DEADLOCKS CHAP. 6 28. Tw o processes, A and B, each need three records, 1, 2, and 3, in a database. If A asks for them in the order 1, 2, 3, and B asks for them in the same order, deadlock is not possible. However, if B asks for them in the order 3, 2, 1, then deadlock is possible. With three resources, there are 3... | clipped_os_Page_468_Chunk6685 |
CHAP. 6 PROBLEMS 469 ions. In the Ethernet protocol, stations requesting the shared channel do not transmit frames if they sense the medium is busy. When such transmission has terminated, waiting stations each transmit their frames. Two frames that are transmitted at the same time will collide. If stations immediately ... | clipped_os_Page_469_Chunk6686 |
470 DEADLOCKS CHAP. 6 41. Program a simulation of the banker’s algorithm. Your program should cycle through each of the bank clients asking for a request and evaluating whether it is safe or unsafe. Output a log of requests and decisions to a file. 42. Write a program to implement the deadlock detection algorithm with ... | clipped_os_Page_470_Chunk6687 |
7 VIRTUALIZATION AND THE CLOUD In some situations, an organization has a multicomputer but does not actually want it. A common example is where a company has an email server, a Web server, an FTP server, some e-commerce servers, and others. These all run on different computers in the same equipment rack, all connected ... | clipped_os_Page_471_Chunk6688 |
472 VIRTUALIZATION AND THE CLOUD CHAP. 7 1960s. Even so, the way we use it today is definitely new. The main idea is that a VMM (Virtual Machine Monitor) creates the illusion of multiple (virtual) ma- chines on the same physical hardware. A VMM is also known as a hypervisor. As discussed in Sec. 1.7.5, we distinguish b... | clipped_os_Page_472_Chunk6689 |
SEC. 7.1 HISTORY 473 amount of critical state information about every process is kept in operating system tables, including information relating to open files, alarms, signal handlers, and more. When migrating a virtual machine, all that have to be moved are the memory and disk images, since all the operating system ta... | clipped_os_Page_473_Chunk6690 |
474 VIRTUALIZATION AND THE CLOUD CHAP. 7 SIMMON and CP-40. While CP-40 was a research project, it was reimplemented as CP-67 to form the control program of CP/CMS, a virtual machine operating system for the IBM System/360 Model 67. Later, it was reimplemented again and released as VM/370 for the System/370 series in 19... | clipped_os_Page_474_Chunk6691 |
SEC. 7.2 REQUIREMENTS FOR VIRTUALIZATION 475 hypervisor to provide this illusion and to do it efficiently. Indeed, hypervisors should score well in three dimensions: 1. Safety: the hypervisor should have full control of the virtualized re- sources. 2. Fidelity: the behavior of a program on a virtual machine should be i... | clipped_os_Page_475_Chunk6692 |
476 VIRTUALIZATION AND THE CLOUD CHAP. 7 sensitive state in user mode without causing a trap. For example, on x86 proces- sors prior to 2005, a program can determine whether it is running in user mode or kernel mode by reading its code-segment selector. An operating system that did this and discovered that it was actua... | clipped_os_Page_476_Chunk6693 |
SEC. 7.2 REQUIREMENTS FOR VIRTUALIZATION 477 machine-like software interface that explicitly exposes the fact that it is a virtu- alized environment. For instance, it offers a set of hypercalls, which allow the guest to send explicit requests to the hypervisor (much as a system call offers ker- nel services to applicat... | clipped_os_Page_477_Chunk6694 |
478 VIRTUALIZATION AND THE CLOUD CHAP. 7 Type 1 hypervisor Hardware (CPU, disk, network, interrupts, etc.) Hardware (CPU, disk, network, interrupts, etc.) Host OS (e.g., Linux) Control Domain Linux Windows Excel Word Mplayer Emacs Type 2 hypervisor Guest OS (e.g., Windows) Guest OS process Host OS process Figure 7-1. L... | clipped_os_Page_478_Chunk6695 |
SEC. 7.4 TECHNIQUES FOR EFFICIENT VIRTUALIZATION 479 runs on the bare metal. The virtual machine runs as a user process in user mode, and as such is not allowed to execute sensitive instructions (in the Popek-Goldberg sense). However, the virtual machine runs a guest operating system that thinks it is in kernel mode (a... | clipped_os_Page_479_Chunk6696 |
480 VIRTUALIZATION AND THE CLOUD CHAP. 7 ring 0. The remaining two rings are not used by any current operating system. In other words, hypervisors were free to use them as they pleased. As shown in Fig. 7-4, many virtualization solutions therefore kept the hypervisor in kernel mode (ring 0) and the applications in user... | clipped_os_Page_480_Chunk6697 |
SEC. 7.4 TECHNIQUES FOR EFFICIENT VIRTUALIZATION 481 it can be executed immediately. Otherwise, it is first translated, cached, then ex- ecuted. Eventually, most of the program will be in the cache and run at close to full speed. Various optimizations are used, for example, if a basic block ends by jumping to (or calli... | clipped_os_Page_481_Chunk6698 |
482 VIRTUALIZATION AND THE CLOUD CHAP. 7 needs to clean it up and restore the original processor context. Suppose, for instance, that the guest is running when an interrupt arrives from an external de- vice. Since a type 2 hypervisor depends on the host’s device drivers to handle the interrupt, it needs to reconfigure ... | clipped_os_Page_482_Chunk6699 |
SEC. 7.4 TECHNIQUES FOR EFFICIENT VIRTUALIZATION 483 instruction that may take as little as one to three cycles. Thus, the translated code is faster. Still, with modern VT hardware, usually the hardware beats the software. On the other hand, if the guest operating system modifies its page tables, this is very costly. T... | clipped_os_Page_483_Chunk6700 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.