• 沒有找到結果。

I/O Systems

在文檔中 OPERATING SYSTEM CONCEPTS (頁 69-73)

64 Chapter 13 I/O Systems

For each of theseI/Oscenarios, would you design the operating system to use buffering, spooling, caching, or a combination? Would you use polledI/O, or interrupt-drivenI/O? Give reasons for your choices.

Answer:

a. A mouse used with a graphical user interface

Buffering may be needed to record mouse movement during times when higher-priority operations are taking place. Spooling and caching are inappropriate. Inter-rupt drivenI/Ois most appropriate.

b. A tape drive on a multitasking operating system (assume no device preallocation is available)

Buffering may be needed to manage throughput difference between the tape drive and the source or destination of theI/O, Caching can be used to hold copies of data that resides on the tape, for faster access. Spooling could be used to stage data to the device when multiple users desire to read from or write to it. Interrupt drivenI/O is likely to allow the best performance.

c. A disk drive containing user files

Buffering can be used to hold data while in transit from user space to the disk, and visa versa. Caching can be used to hold disk-resident data for improved perfor-mance. Spooling is not necessary because disks are shared-access devices. Interrupt-drivenI/Ois best for devices such as disks that transfer data at slow rates.

d. A graphics card with direct bus connection, accessible through memory-mapped I/O

Buffering may be needed to control multiple access and for performance (double-buffering can be used to hold the next screen image while displaying the current one). Caching and spooling are not necessary due to the fast and shared-access natures of the device. Polling and interrupts are only useful for input and for I/O completion detection, neither of which is needed for a memory-mapped device.

13.3 The example of handshaking in Section 13.2 used 2 bits: abusybit and acommand-ready bit. Is it possible to implement this handshaking with only 1 bit? If it is, describe the protocol. If it is not, explain why 1 bit is insufficient.

Answer: No answer.

13.4 Describe three circumstances under which blockingI/Oshould be used. Describe three circumstances under which nonblocking I/Oshould be used. Why not just implement nonblockingI/Oand have processes busy-wait until their device is ready?

Answer:

Generally, blockingI/Ois appropriate when the process will only be waiting for one spe-cific event. Examples include a disk, tape, or keyboard read by an application program.

Non-blockingI/Ois useful when I/O may come from more than one source and the order of theI/Oarrival is not predetermined. Examples include network daemons listening to more than one network socket, window managers that accept mouse movement as well as keyboard input, andI/O-management programs, such as a copy command that copies data betweenI/Odevices. In the last case, the program could optimize its performance by buffering the input and output and using non-blockingI/Oto keep both devices fully occupied.

Non-blocking I/O is more complicated for programmers, because of the asynchonous rendezvous that is needed when anI/Ooccurs. Also, busy waiting is less efficient than interrupt-drivenI/Oso the overall system performance would decrease.

Answers to Exercises 65

13.5 Why might a system use interrupt-drivenI/Oto manage a single serial port, but polling I/Oto manage a front-end processor, such as a terminal concentrator?

Answer: Polling can be more efficient than interrupt-drivenI/O. This is the case when theI/Ois frequent and of short duration. Even though a single serial port will perform I/O relatively infrequently and should thus use interrupts, a collection of serial ports such as those in a terminal concentrator can produce a lot of shortI/Ooperations, and interrupting for each one could create a heavy load on the system. A well-timed polling loop could alleviate that load without wasting many resources through looping with no I/Oneeded.

13.6 Polling for anI/O completion can waste a large number ofCPUcycles if the processor iterates a busy-waiting loop many times before theI/Ocompletes. But if theI/Odevice is ready for service, polling can be much more efficient than is catching and dispatching an interrupt. Describe a hybrid strategy that combines polling, sleeping, and interrupts forI/Odevice service. For each of these three strategies (pure polling, pure interrupts, hybrid), describe a computing environment in which that strategy is more efficient than is either of the others.

Answer: No answer.

13.7 UNIXcoordinates the activities of the kernel I/O components by manipulating shared in-kernel data structures, whereas WindowsNTuses object-oriented message passing be-tween kernelI/Ocomponents. Discuss three pros and three cons of each approach.

Answer:

Three pros of theUNIX method: Very efficient, low overhead and low amount of data movement

Fast implementation — no coordination needed with other kernel components Simple, so less chance of data loss

Three cons: No data protection, and more possible side-effects from changes so more difficult to debug

Difficult to implement new I/O methods: new data structures needed rather than just new objects

Complicated kernelI/Osubsystem, full of data structures, access routines, and locking mechanisms

13.8 How doesDMAincrease system concurrency? How does it complicate hardware design?

Answer:

DMAincreases system concurrency by allowing theCPUto perform tasks while theDMA system transfers data via the system and memory busses. Hardware design is compli-cated because the DMAcontroller must be integrated into the system, and the system must allow theDMAcontroller to be a bus master. Cycle stealing may also be necessary to allow theCPUandDMAcontroller to share use of the memory bus.

13.9 Write (in pseudocode) an implementation of virtual clocks, including the queuing and management of timer requests for the kernel and applications. Assume that the hardware provides three timer channels.

Answer: No answer.

13.10 Why is it important to scale up system bus and device speeds as theCPUspeed increases?

Answer:

Consider a system which performs 50%I/Oand 50% computes. Doubling theCPU per-formance on this system would increase total system perper-formance by only 50%. Doubling both system aspects would increase performance by 100%. Generally, it is important to

66 Chapter 13 I/O Systems

remove the current system bottleneck, and to increase overall system performance, rather than blindly increasing the performance of individual system components.

13.11 Distinguish between aSTREAMSdriver and aSTREAMSmodule.

Answer: ) No answer.

在文檔中 OPERATING SYSTEM CONCEPTS (頁 69-73)