Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 13: I/O Systems Modified by Dr. Neerja Mhaskar for CS 3SH3.

Similar presentations


Presentation on theme: "Chapter 13: I/O Systems Modified by Dr. Neerja Mhaskar for CS 3SH3."— Presentation transcript:

1 Chapter 13: I/O Systems Modified by Dr. Neerja Mhaskar for CS 3SH3

2 Overview Management of I/O devices forms a major component of operating system design and operation. Some of the challenges in designing the I/O subsystem are I/O devices vary greatly and as a result various methods are needed to control them With advancement in technology, new types of devices are frequent. These challenges are met by a combination of hardware and software techniques. Kernel uses device drivers to encapsulate device details. Device drivers - are modules that can be plugged into an OS to handle a particular device or category of similar devices

3 I/O Hardware I/O devices can broadly be categorized as
storage, communications, user-interface, and other Devices communicate with the computer: Via signals sent over wires or through the air. And through a connection point for the device called the - Port A common set of wires connecting multiple devices is termed a bus. Different types of buses shown in next slide. Controller – collection of electronics that can operate port, bus, device. Device drivers communicate with controllers for I/O requests.

4 A Typical PC Bus Structure
PCI bus - connects the processor–memory subsystem to fast devices Expansion bus  connects relatively slow devices, such as the keyboard and serial and USB ports SCSI bus connects a number of SCSI devices to a common SCSI controller. Daisy-chain bus (not shown), when a string of devices is connected to each other like beads on a chain, and only one of the devices is directly connected to the host.

5 I/O Hardware (Cont.) I/O instructions control devices.
Devices have addresses. Device controllers have registers where device driver places commands, addresses, and data to write, or read data from registers after command execution. Common types of registers are: Data-in register, data-out register, status register, control register Typically 1-4 bytes, or FIFO buffer

6 Memory Mapped I/O Device controllers support Memory-mapped I/O
Device-control registers are mapped into the address space of the processor. The CPU executes I/O requests using the standard data-transfer instructions to read and write the device-control registers at their mapped locations in physical memory. Memory-mapped I/O is suitable for devices which must move large quantities of data quickly, such as graphics cards.

7 Polling and Interrupts
Polling is constantly testing a port to see if data is available.  Polling is efficient if device is fast. Polling inefficient if host rarely finds device ready for service. In which case interrupts are used. See Chapter 1 lecture notes for details on interrupts.

8 Direct Memory Access For devices that transfer large quantities of data ( such as disk controllers ), it is wasteful to tie up the CPU, transferring data in and out of registers one byte at a time. Instead a special processor called (Direct Memory Access) DMA is used Bypasses CPU to transfer data directly between I/O device and memory

9 Application I/O Interface
User application access to a wide variety of different devices This is accomplished through layering, and Through encapsulating all of the device-specific code into device drivers, While application layers are presented with a common interface for all ( or at least large general categories of ) devices

10 A Kernel I/O Structure

11 Characteristics of I/O Devices
Devices differ on many different dimensions. They are broadly grouped by the OS into the following categories: Block Devices (e.g.: hard disks) Commands include read, write, seek Character Devices (e.g. keyboard) Commands include get(), put() Network Devices Linux, Unix, Windows and many others include socket interface Clocks and Timers Provide current time, elapsed time, timer

12 Non-blocking and Asynchronous I/O
Blocking system call - process suspended until I/O completed Process moved from ready queue to waiting queue After the system call completes, the application is moved back to the run queue Non-blocking system call - I/O call returns as much as available User interface, data copy (buffered I/O) Implemented via multi-threading Asynchronous system call - process runs while I/O executes The completion of the I/O at some future time is communicated to the application Vectored I/O allows one system call to perform multiple I/O operations

13 Kernel I/O Subsystem Kernels provide many services related to I/O
Scheduling - determine a good order of I/O requests for execution. asynchronous I/O – Kernel must be able to keep track of many I/O requests at the same time. To do this the OS might attach the wait queue to a device-status table Buffering - store data in memory while transferring between devices To cope with device speed mismatch To cope with device transfer size mismatch To maintain “copy semantics” Double buffering – two buffers to store data, to increase efficiency and throughput. This double buffering decouples the producer of data from the consumer, thus relaxing timing requirements between them.

14 Device-status Table

15 Kernel I/O Subsystem Caching - faster device holding copy of data
Always just a copy Key to performance Sometimes combined with buffering Spooling – A spool is a buffer that holds output for a device that cannot accept interleaved data streams E.g.: Printer Device reservation - provides exclusive access to a device System calls for allocation and de-allocation Watch out for deadlock

16 Kernel I/O Subsystem Cont…
Error Handling Operating systems can often compensate effectively for transient failures. Retry a read or write, for example Most system call return an error number or code when I/O request fails System error logs hold problem reports Protection User process may accidentally or purposefully attempt to disrupt normal operation via illegal I/O instructions All I/O instructions defined to be privileged I/O must be performed via system calls

17 Kernel I/O Subsystem Cont…
Kernel Data Structures Kernel keeps state info for I/O components, including open file tables, network connections, character device state etc. Many, many complex data structures to track buffers, memory allocation, “dirty” blocks Some use object-oriented methods and message passing to implement I/O

18 I/O Requests to Hardware Operations
Consider reading a file from disk for a process: Determine device holding file Translate name to device representation Physically read data from disk into buffer Make data available to requesting process Return control to process

19 Life Cycle of An I/O Request

20 End of Chapter 13


Download ppt "Chapter 13: I/O Systems Modified by Dr. Neerja Mhaskar for CS 3SH3."

Similar presentations


Ads by Google