Download presentation
Presentation is loading. Please wait.
Published byGregory Benson Modified over 9 years ago
1
Silberschatz, Galvin and Gagne ©2009 Edited by Khoury, 2015 Operating System Concepts – 9 th Edition, Chapter 13: I/O Systems
2
13.2 Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests to Hardware Operations Performance
3
13.3 Objectives Explore the structure of an operating system’s I/O subsystem Discuss the principles of I/O hardware and its complexity Provide details of the performance aspects of I/O hardware and software
4
13.4 I/O Hardware Standard computer I/O devices Storage devices Transmission devices Human-interface devices Common concepts Communicate with rest of the system through a connection point (port) Various devices inter-connected to a common set of wired (bus) using standard protocols Devices can be connected to bus directly, or connected to other devices that are connected to the bus (daisy chain) Devices interface to system using a hardware controller Several devices can use the same controller
5
13.5 I/O Hardware PCI bus is the fastest and most common one Connects CPU/Memory to fastest devices Expansion bus used for slower or specialized devices AGP bus historically used for graphics cards Parallel ATA bus (aka IDE bus) used for storage devices
6
13.6 A Typical PC Bus Structure
7
13.7 I/O Hardware Controller has internal registers CPU communicates with device by reading/writing bytes in registers through controller’s I/O ports Data-in register to send information from the controller to the CPU Data-out register to send information from the CPU to the controller Status register to inform the CPU of the controller’s current status Command register to allow the CPU to send commands to the controller Some devices alternatively/also support memory-mapped I/O, interact with CPU through shared memory space
8
13.8 Perform functions Read busy bit Controller Status register Registers CPU Clear busy bit Set busy bit Read busy bit Command register Data-out register Data-in register Write command Write data for command Read busy bit Read command Clear busy bit Set busy bit Execute command Read input data Write output data Clear error bit Read output ready bit Set output ready bit Read output Polling
9
13.9 Interrupts Polling is very efficient Read status register + AND to extract busy bit + JNZ = 3 CPU cycles Problem: what if a device is rarely ready? Alternative: notify the CPU when a device is ready (interrupt) You need: An input line for hardware The CPU interrupt-request line Intel 80x86 has two, one maskable and one nonmaskable Priority mechanisms Lower-value interrupts have higher priority Maskable interrupts can be ignored, nonmaskable interrupts cannot
10
13.10 Direct Memory Access Having the CPU do polling and read/write data in data registers byte by byte is inefficient to transfer large amounts of data (programmed I/O) Wasteful of CPU time Alternative: Direct Memory Access (DMA) Bypasses CPU to transfer data directly between I/O device and memory through DMA controller CPU only needs to specify memory address and size to DMA controller DMA controller read/writes information between data registers and memory while Downside: Memory not accessible to CPU during this time But worth the trade-off
11
13.11 Direct Memory Access
12
13.12 Application I/O Interface Great variety of I/O devices Can vary in multiple ways
13
13.13 Application I/O Interface Devices separated into general types Kernel define standard set of interface functions for each kind Device drivers encapsulate device-specific details OS usually also have a backdoor system call to pass arbitrary commands directly from application to device driver ( ioctl() in Unix)
14
13.14 Application I/O Interface Block devices (disk drives) interface read(), write() seek() if random-access is supported Abstract device as a linear array of blocks (raw I/O) Give access to application without OS buffering or locking, for applications that do this themselves (direct I/O) Character devices (keyboards) interface Single-character read and write: get(), put() Libraries of stream functions include buffering and editing Network devices Devices connect to remote address through local socket select() function returns information on a set of sockets Which are ready to send or receive information Eliminates need for polling for network communication
15
13.15 Concurrent I/O Execution Blocking: process is suspended until I/O completed Easy to implement, use, and understand Inefficient if process can continue while I/O occurs I/O execution time unpredictable Nonblocking: I/O returns after maximum delay Makes I/O execution time predictable Process needs to handle partial I/O results if I/O not completed in allocated time Multithreading Process thread continues while I/O thread blocks Asynchronous: I/O operation returns immediately I/O operation completes after return call Process notified once I/O operation is complete Can use user interrupt, shared variable, notification function, etc.
16
13.16 Kernel I/O Subsystem Kernel services are essential to I/O Scheduling I/O is usually the slowest part of the system OS responsibility to schedule processes’ I/O requests for most efficient use Buffering Different devices have wildly different transfer speeds Different devices have different data-transfer sizes Copy semantics: make a copy of the data at the time of system call, so that subsequent changes to data by process do not cause a race condition Caching Keep a copy of frequently-needed data in faster memory Spooling Simultaneous Peripheral Operations On-Line Intercept and hold output for a device that can serve only one request at a time (ex.: printer), allowing the process to continue
17
13.17 Kernel I/O Subsystem Device reservation Provides exclusive access to a device Can cause deadlocks Error handling I/O operation can fail Error bit in status register informs system about controller’s successful execution of operation – but OS needs to check it! Many controllers also give an error code in data-in register – but again, the OS needs to check it (they seldom do) I/O protection Need to protect system from user processes misusing I/O devices I/O performed via system calls that check if the request is valid Kernel Data Structures Kernel maintains state information on usage of all I/O devices Example: the system-wide open-file table
18
13.18 Life Cycle of An I/O Request
19
13.19 Improving Performance I/O a major factor in system performance Interrupts looks smarter than polling; however Each interrupt involves two context switches Interrupt code longer than polling routine Interrupt needs to transfer data between different functions
20
13.20 Improving Performance How to improve performance? Reduce number of context switches Reduce data copying Reduce frequency of interrupts by using large transfers, smart controllers, polling Use DMA to minimize use of CPU in copying data Balance CPU, memory, bus, and I/O performance: overload of one causes idleness in others Move code towards hardware More specialized and efficient execution Execution by controller: frees up CPU Longer, more expensive development for less flexible or reusable code
21
13.21 Review What is polling? What’s the difference between a blocking, a non-blocking, and an asynchronous I/O operation?
22
13.22 Exercises Read everything except section 13.6 (Streams) If you have the “with Java” textbook, skip the Java sections and subtract 1 to the following section numbers 13.1 13.2 13.5 13.6 13.8 13.10 13.11 13.12 13.13 13.14
23
Silberschatz, Galvin and Gagne ©2009 Edited by Khoury, 2015 Operating System Concepts – 9 th Edition, End of Chapter 13
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.