Download Chapter 3 - Diuf

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Process management (computing) wikipedia , lookup

Mobile operating system wikipedia , lookup

Security-focused operating system wikipedia , lookup

Computer terminal wikipedia , lookup

Unix security wikipedia , lookup

VS/9 wikipedia , lookup

CP/M wikipedia , lookup

Distributed operating system wikipedia , lookup

Transcript
Lecture 9, 29 November 2011
OPERATING SYSTEMS
DESIGN AND IMPLEMENTATION
Third Edition
ANDREW S. TANENBAUM
ALBERT S. WOODHULL
Chapter 3
Input/Output
Annotated by B. Hirsbrunner
3.1.1 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. 0-13-142938-8
2
3.1.2 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. 0-13-142938-8
3
3.1.3 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. 0-13-142938-8
4
3.1.5 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. 0-13-142938-8
5
3.2.1 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. 0-13-142938-8
6
3.2.4 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. 0-13-142938-8
7
3.2.4 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. 0-13-142938-8
8
3.2.5 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. 0-13-142938-8
9
3.3 Deadlocks
3.3.1 Resources
Sequence of events required to use a resource:
1. Request the resource.
2. Use the resource.
3. Release the resource.
Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8
10
3.3.2 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. 0-13-142938-8
11
3.3.2 Conditions for Deadlock
1. Mutual exclusion
Each resource is either currently assigned to exactly one process or is
available
2. Hold and wait
Processes currently holding resources that where granted earlier can
request new resources
3. No preemption
Resources previously granted cannot be forcibly taken away from a
process
4. Circular wait
Presence of a cycle in the allocation graph
Property: if one of these conditions is absent, no deadlock is possible
Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8
12
3.3.2 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. 0-13-142938-8
13
3.3.2 Deadlock Handling Strategies
1. Ignore the problem altogether
2. Detection and recovery
3. Avoidance by careful resource
allocation
4. Prevention by negating one of the
four necessary conditions
Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8
14
3.3.2 How Deadlock Occurs
Figure 3-10. An example of how deadlock occurs
Avoidance: don't allocate ressource R to C (cycle!) or run only A and C or …
Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8
15
3.3.5 Deadlock Prevention
Figure 3-12. Summary of approaches to deadlock prevention.
Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8
16
3.3.6 Deadlock Avoidance
The Banker's Algorithm for a Single Resource
Idea: the banker does not necessarely have enough cash on hand to lend
every customer the full amount of each's line of credit at the same time
Figure 3-13. 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. 0-13-142938-8
17
3.4.2 Device Drivers in MINIX 3
Figure 3-16. Two ways of structuring user-system communication.
Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8
18
3.4.2 Block io_driver
Figure 3-18. 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. 0-13-142938-8
19
3.5.1 Shared Block io_driver
indirect function calls
Figure 3-19. 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. 0-13-142938-8
20
3.7 Disks
Read/Write timing factors:
1. Seek time
2. Rotational delay
3. Data transfer time
Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8
21
3.7.3 Disk Arm Scheduling Algorithms
Figure 3-21. Shortest Seek First (SSF) disk scheduling algorithm.
Figure 3-22. The elevator algorithm for scheduling disk requests.
Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8
22
3.8 Terminals
Figure 3-24. Terminal types.
Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8
23
3.8.1 Memory Mapped Terminals
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. 0-13-142938-8
24
3.8.1 RS-232 Terminals
Figure 3-27. 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. 0-13-142938-8
25
3.8.3 Terminal Input
Figure 3-33. Read request from the keyboard
when no characters are pending. 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.
Terminal driver message types
1. Read from the terminal (from FS on
behalf of a user process).
2. Write to the terminal (from FS on behalf of a user process).
3. Set terminal parameters for IOCTL (from FS on behalf of a user
process).
4. I/O occurred during last clock tick (from the clock interrupt).
5. Cancel previous request (from the file system when a signal occurs).
6. Open a device.
7. Close a device.
Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8
26
3.8.3 Terminal Input
Figure 3-34. 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. 0-13-142938-8
27
3.8.3 Terminal Output
Figure 3-35. Major procedures
used in terminal output.
The dashed line indicates
characters copied directly
to ramqueue by cons_write.
Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8
28