Download I/O Systems - McMaster Computing and Software

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

Security-focused operating system wikipedia , lookup

Process management (computing) wikipedia , lookup

Spring (operating system) wikipedia , lookup

VS/9 wikipedia , lookup

CP/M wikipedia , lookup

DNIX wikipedia , lookup

Mobile operating system wikipedia , lookup

Distributed operating system wikipedia , lookup

Transcript
Chapter 13: I/O Systems
Operating System Concepts – 9th Edition
Modified by Dr. Neerja Mhaskar for CS 3SH3
Silberschatz, Galvin and Gagne ©2013
Overview
n
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
l
I/O devices vary greatly and as a result various methods are
needed to control them
l
With advancement in technology, new types of devices are
frequent.
n
These challenges are met by a combination of hardware and
software techniques.
n
Kernel uses device drivers to encapsulate device details.
l
Device drivers - are modules that can be plugged into an OS
to handle a particular device or category of similar devices
Operating System Concepts – 9th Edition
13.2
Silberschatz, Galvin and Gagne ©2013
I/O Hardware
n I/O devices can broadly be categorized as
l
storage, communications, user-interface, and other
n Devices communicate with the computer:
l
Via signals sent over wires or through the air.
l
And through a connection point for the device called the Port
l
A common set of wires connecting multiple devices is
termed a bus. Different types of buses shown in next slide.
n Controller – collection of electronics that can operate port,
bus, device.
l
Device drivers communicate with controllers for I/O
requests.
Operating System Concepts – 9th Edition
13.3
Silberschatz, Galvin and Gagne ©2013
A Typical PC Bus Structure
n
PCI bus - connects the
processor–memory
subsystem to fast devices
n
Expansion bus connects
relatively slow devices, such
as the keyboard and serial
and USB ports
n
SCSI bus connects a number
of SCSI devices to a
common SCSI controller.
n
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.
Operating System Concepts – 9th Edition
13.4
Silberschatz, Galvin and Gagne ©2013
I/O Hardware (Cont.)
n I/O instructions control devices.
n Devices have addresses.
n Device controllers have registers where device driver
places commands, addresses, and data to write, or read
data from registers after command execution.
l
Common types of registers are: Data-in register, dataout register, status register, control register
l
Typically 1-4 bytes, or FIFO buffer
Operating System Concepts – 9th Edition
13.5
Silberschatz, Galvin and Gagne ©2013
Memory Mapped I/O
n Device controllers support Memory-mapped I/O
l
Device-control registers are mapped into the address
space of the processor.
l
The CPU executes I/O requests using the standard datatransfer instructions to read and write the device-control
registers at their mapped locations in physical memory.
l
Memory-mapped I/O is suitable for devices which must
move large quantities of data quickly, such as graphics
cards.
Operating System Concepts – 9th Edition
13.6
Silberschatz, Galvin and Gagne ©2013
Polling and Interrupts
n Polling is constantly testing a port to see if data is
available.
l
Polling is efficient if device is fast.
l
Polling inefficient if host rarely finds device ready
for service. In which case interrupts are used.
n See Chapter 1 lecture notes for details on
interrupts.
Operating System Concepts – 9th Edition
13.7
Silberschatz, Galvin and Gagne ©2013
Direct Memory Access
n 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.
n Instead a special processor called (Direct Memory
Access) DMA is used
n Bypasses CPU to transfer data directly between I/O
device and memory
Operating System Concepts – 9th Edition
13.8
Silberschatz, Galvin and Gagne ©2013
Application I/O Interface
n User application access to a wide variety of different
devices
l
This is accomplished through layering, and
l
Through encapsulating all of the device-specific
code into device drivers,
l
While application layers are presented with a
common interface for all ( or at least large
general categories of ) devices
Operating System Concepts – 9th Edition
13.9
Silberschatz, Galvin and Gagne ©2013
A Kernel I/O Structure
Operating System Concepts – 9th Edition
13.10
Silberschatz, Galvin and Gagne ©2013
Characteristics of I/O Devices
Devices differ on many different dimensions. They are broadly
grouped by the OS into the following categories:
l
Block Devices (e.g.: hard disks)
 Commands
l
Character Devices (e.g. keyboard)
 Commands
l
include read, write, seek
include get(), put()
Network Devices
 Linux,
Unix, Windows and many others include socket
interface
l
Clocks and Timers
 Provide
Operating System Concepts – 9th Edition
current time, elapsed time, timer
13.11
Silberschatz, Galvin and Gagne ©2013
Non-blocking and Asynchronous I/O
n
n
n
Blocking system call - process suspended until I/O completed
l
Process moved from ready queue to waiting queue
l
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
l
n

The completion of the I/O at some future time is communicated
to the application
Vectored I/O
l
allows one system call to perform multiple I/O operations
Operating System Concepts – 9th Edition
13.12
Silberschatz, Galvin and Gagne ©2013
Kernel I/O Subsystem
Kernels provide many services related to I/O
n
n
Scheduling - determine a good order of I/O requests for execution.
l
asynchronous I/O – Kernel must be able to keep track of many I/O
requests at the same time.
l
To do this the OS might attach the wait queue to a device-status
table
Buffering - store data in memory while transferring between devices
l
To cope with device speed mismatch
l
To cope with device transfer size mismatch
l
To maintain “copy semantics”
l
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.
Operating System Concepts – 9th Edition
13.13
Silberschatz, Galvin and Gagne ©2013
Device-status Table
Operating System Concepts – 9th Edition
13.14
Silberschatz, Galvin and Gagne ©2013
Kernel I/O Subsystem
n Caching - faster device holding copy of data
l
Always just a copy
l
Key to performance
l
Sometimes combined with buffering
n Spooling –
l
A spool is a buffer that holds output for a device that
cannot accept interleaved data streams
 E.g.:
Printer
n Device reservation - provides exclusive access to a device
l
System calls for allocation and de-allocation
l
Watch out for deadlock
Operating System Concepts – 9th Edition
13.15
Silberschatz, Galvin and Gagne ©2013
Kernel I/O Subsystem Cont…
n Error Handling
l
Operating systems can often compensate effectively for
l
transient failures.
 Retry
a read or write, for example
l
Most system call return an error number or code when I/O
request fails
l
System error logs hold problem reports
n Protection
l
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
Operating System Concepts – 9th Edition
13.16
Silberschatz, Galvin and Gagne ©2013
Kernel I/O Subsystem Cont…
n Kernel Data Structures
l
Kernel keeps state info for I/O components,
including open file tables, network connections,
character device state etc.
l
Many, many complex data structures to track
buffers, memory allocation, “dirty” blocks
l
Some use object-oriented methods and
message passing to implement I/O
Operating System Concepts – 9th Edition
13.17
Silberschatz, Galvin and Gagne ©2013
I/O Requests to Hardware Operations
n
Consider reading a file from disk for a process:
l
Determine device holding file
l
Translate name to device representation
l
Physically read data from disk into buffer
l
Make data available to requesting process
l
Return control to process
Operating System Concepts – 9th Edition
13.18
Silberschatz, Galvin and Gagne ©2013
Life Cycle of An I/O Request
Operating System Concepts – 9th Edition
13.19
Silberschatz, Galvin and Gagne ©2013
End of Chapter 13
Operating System Concepts – 9th Edition
Silberschatz, Galvin and Gagne ©2013