Presentation is loading. Please wait.

Presentation is loading. Please wait.

OPERATING SYSTEMS DESIGN AND IMPLEMENTATION Third Edition ANDREW S

Similar presentations


Presentation on theme: "OPERATING SYSTEMS DESIGN AND IMPLEMENTATION Third Edition ANDREW S"— Presentation transcript:

1 OPERATING SYSTEMS DESIGN AND IMPLEMENTATION Third Edition ANDREW S
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION Third Edition ANDREW S. TANENBAUM ALBERT S. WOODHULL Chapter 3 Input/Output Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

2 Figure 3-1. Some typical device, network, and bus data rates.
I/O Devices Figure 3-1. Some typical device, network, and bus data rates. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

3 Device Controllers Figure 3-2. A model for connecting the CPU, memory, controllers, and I/O devices. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

4 Typical Intel Chipset Layout (Wiki Images)
Frontside/Backside buses Frontside bus Northbridge Mem Ctrlr Hub Internal bus Southbridge I/O Ctrlr Hub PCI bus LPC bus (images from Wiki Images) Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

5 Memory-Mapped I/O Figure 3-3. (a) Separate I/O and memory space. (b) Memory-mapped I/O. (c) Hybrid. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

6 Direct Memory Access (DMA)
Figure 3-4. Operation of a DMA transfer. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

7 Goals of the I/O Software
Figure 3-5. Layers of the I/O software system. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

8 Device-Independent I/O Software
Figure 3-6. Functions of the device-independent I/O software. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

9 Uniform Interfacing for Device Drivers
Figure 3-7. (a) Without a standard driver interface. (b) With a standard driver interface. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

10 User-Space I/O Software
Figure 3-8. Layers of the I/O system and the main functions of each layer. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

11 Resources The sequence of events required to use a resource:
Request the resource. Use the resource. Release the resource. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

12 Definition of Deadlock
A set of processes is deadlocked if each process in the set is waiting for an event that only another process in the set can cause. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

13 Conditions for Deadlock
Mutual exclusion Hold and wait No preemption Circular wait Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

14 Deadlock Modeling Figure 3-9. Resource allocation graphs. (a) Holding a resource. (b) Requesting a resource. (c) Deadlock. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

15 Deadlock Handling Strategies
Ignore the problem altogether (ostrich) Detection and recovery (optimistic) Avoidance by careful resource allocation (banker) Prevention by negating one of the four necessary conditions Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

16 Deadlock Avoidance (1) Figure An example of how deadlock occurs and how it can be avoided. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

17 Deadlock Prevention (1)
Figure Summary of approaches to deadlock prevention. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

18 Deadlock Prevention (2)
Figure (a) Numerically ordered resources. (b) A resource graph. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

19 Deadlock Prevention (3)
Two-Phase Locking Growing phase – acquire locks Use resources Shrinking phase – release locks Prevents roll-backs in transaction systems Does NOT directly prevent deadlock Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

20 Resource Trajectories
Figure Two process resource trajectories. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

21 The Banker’s Algorithm for a Single Resource
Figure Three resource allocation states: (a) Safe. (b) Safe. (c) Unsafe. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

22 The Banker’s Algorithm for Multiple Resources
Figure The banker’s algorithm with multiple resources. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

23 The Banker’s Algorithm for Multiple Resources
D E 2 3 6 3 4 2 Tape drive Plotter Printer CD ROM Resource Allocation Graph with B requesting two CD ROMs Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

24 Safe State Checking Algorithm
Look for a row, R, whose unmet resource needs are all smaller than or equal to A. If no such row exists, the system will eventually deadlock since no process can run to completion. Assume the process of the row chosen requests all the resources it needs (which is guaranteed to be possible) and finishes. Mark that process as terminated and add all its resources to the A vector. Repeat steps 1 and 2 until either all processes are marked terminated, in which case the initial state was safe, or until a deadlock occurs, in which case it was not. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

25 Device Drivers in MINIX 3 (1)
Figure Two ways of structuring user-system communication. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

26 Device Drivers in MINIX 3 (2)
Figure Fields of the messages sent by the file system to the block device drivers and fields of the replies sent back. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

27 Device-Independent I/O Software in MINIX 3
Figure Outline of the main procedure of an I/O device driver. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

28 Block Device Drivers in MINIX 3
Figure A shared I/O task main procedure using indirect calls. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

29 Device Driver Operations
OPEN CLOSE READ WRITE IOCTL SCATTERED_IO Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

30 RAM Disk Hardware and Software
Figure A RAM disk. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

31 Disk Software Read/Write timing factors: Seek time Rotational delay
Data transfer time Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

32 Disk Arm Scheduling Algorithms (1)
Sequence of seeks Figure Shortest Seek First (SSF) disk scheduling algorithm. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

33 Disk Arm Scheduling Algorithms (2)
Sequence of seeks Figure The elevator algorithm for scheduling disk requests. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

34 Common Hard Drive Errors
Programming error - request for nonexistent sector Transient checksum error - caused by dust on the head Permanent checksum error - disk block physically damaged Seek error - the arm sent to cylinder 6 but it went to 7 Controller error - controller refuses to accept commands Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

35 Hard Disk Driver in MINIX 3 (1)
Figure (a) The control registers of an IDE hard disk controller. The numbers in parentheses are the bits of the logical block address selected by each register in LBA mode. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

36 Write Precompensation
A circular disk drive platter is divided into sectors (pie slices). If the same number of sectors are placed on an outer track as on an inner track, the sectors are physically smaller on the inner track. However, all the sectors hold the same amount of data. Write precompensation causes the drive to increase the current used when writing to the inner tracks to compensate for the greater density. The write precompensation field in the control registers for a drive indicates the track number where write precompensation begins. Many modern disks have a variable number of sectors per track, and do not need write precompensation. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

37 Hard Disk Driver in MINIX 3 (2)
Figure (b) The fields of the Select Drive/Head register. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

38 Floppy Disk Drive Characteristics that complicate the driver:
Removable media. Multiple disk formats. Motor control. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

39 Figure 3-24. Terminal types.
Terminals (1) Figure Terminal types. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

40 Figure 3-25. Memory-mapped terminals write directly into video RAM.
Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

41 Terminals (3) Figure (a) A video RAM image for the IBM monochrome display. (b) The corresponding screen. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

42 RS-232 Terminals Figure An RS-232 terminal communicates with a computer over a communication line, one bit at a time. The computer and the terminal are completely independent. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

43 Input Software (1) Figure (a) Central buffer pool. (b) Dedicated buffer for each terminal. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

44 Figure 3-29. Characters that are handled specially in canonical mode.
Input Software (2) Figure Characters that are handled specially in canonical mode. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

45 Input Software (3) Figure The termios structure. In MINIX 3 tc_flag _t is a short, speed_t is an int, and cc_t is a char. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

46 Input Software (4) Figure MIN and TIME determine when a call to read returns in noncanonical mode. N is the number of bytes requested. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

47 Output Software (1) Figure The ANSI escape sequences accepted by the terminal driver on output. ESC denotes the ASCII escape character (0x1B), and n, m, and s are optional numeric parameters. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

48 Output Software (2) Figure The ANSI escape sequences accepted by the terminal driver on output. ESC denotes the ASCII escape character (0x1B), and n, m, and s are optional numeric parameters. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

49 Terminal Driver in MINIX (1)
Terminal driver message types: Read from the terminal (from FS on behalf of a user process). Write to the terminal (from FS on behalf of a user process). Set terminal parameters for IOCTL (from FS on behalf of a user process). Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

50 Terminal Driver in MINIX (2)
Terminal driver message types (continued): I/O occurred during last clock tick (from the clock interrupt). Cancel previous request (from the file system when a signal occurs). Open a device. Close a device. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

51 Terminal Input (1) Figure Read request from the keyboard when no characters are pending. FS is the file system. TTY is the terminal driver. The TTY receives a message for every keypress and queues scan codes as they are entered. Later these are interpreted and assembled into a buffer of ASCII codes which is copied to the user process. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

52 Terminal Input (2) Figure Input handling in the terminal driver. The left branch of the tree is taken to process a request to read characters. The right branch is taken when a keyboard message is sent to the driver before a user has requested input. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

53 Terminal Output (1) Figure Major procedures used in terminal output. The dashed line indicates characters copied directly to ramqueue by cons_write. Note: “pause_escape” should be “parse_escape” Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

54 Terminal Output (2) Figure Fields of the console structure that relate to the current screen position. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

55 Terminal Output (3) c_org points to start of RAM allocated for console display (origin). c_limit indicates the end of the RAM allocated for console display. These are constants set by the system. c_start is where the controller starts reading in RAM for first line, and all locations for character displays are relative to this location. c_row and c_column indicate current position relative to upper left corner of display. c_curr can be derived from c_row, c_column, and c_start, but is kept redundantly to make operation faster. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

56 Figure 3-37. A few entries from a keymap source file.
Loadable Keymaps Figure A few entries from a keymap source file. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

57 Device-Independent Terminal Driver (1)
Figure Default termios flag values. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

58 Device-Independent Terminal Driver (2)
Figure POSIX calls and IOCTL operations. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

59 Terminal Driver Support Code
Figure The fields in a character code as it is placed into the input queue. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

60 Keyboard Driver (1) Figure Scan codes in the input buffer, with corresponding key actions below, for a line of text entered at the keyboard. L and R represent the left and right Shift keys. + and - indicate a key press and a key release. The code for a release is 128 more than the code for a press of the same key. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

61 Recall Keyboard Driver (2)
Figure Escape codes generated by the numeric keypad. When scan codes for ordinary keys are translated into ASCII codes the special keys are assigned ‘‘pseudo ASCII’’ codes with values greater than 0xFF. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

62 Figure 3-44. Finite state machine for processing escape sequences.
Display Driver (1) Figure Finite state machine for processing escape sequences. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

63 Output Software (2) Figure The ANSI escape sequences accepted by the terminal driver on output. ESC denotes the ASCII escape character (0x1B), and n, m, and s are optional numeric parameters. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

64 Figure 3-43. The function keys detected by func_key().
Keyboard Driver (3) Figure The function keys detected by func_key(). Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

65 Figure 3-45. Some of the 6845’s registers.
Display Driver (2) Figure Some of the 6845’s registers. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved

66 Recall Terminal Output (2)
Figure Fields of the console structure that relate to the current screen position. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved


Download ppt "OPERATING SYSTEMS DESIGN AND IMPLEMENTATION Third Edition ANDREW S"

Similar presentations


Ads by Google