You are on page 1of 14

I/O Systems

Concepts to understand how the devices are attached and how the software
can control the hardware.
Port
• The device communicates with the machine via a connection point
Bus
• Set of wires and protocol that specifies a set of messages that can be
sent on the wires.
 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

1
I/O Systems
• PCI Express
 Throughput of up to 16 GB per second
• HyperTransport
 Throughput of up to 25 GB per second
Daisy chain
• When device A has a cable that plugs into device B, and device B
has a cable that plugs into device C, and device C plugs into a port
on the computer
Controller
• Collection of electronics that can operate a port, a bus, or a device.

2
Characteristics I/O devices
 Six main Characteristics of I/O devices are:
• Character-stream or block. A character-stream device
transfers bytes one by one, whereas a block device
transfers a block of bytes as a unit.

• Sequential or random access. A sequential device transfers


data in a fixed order determined by the device and random-
access device can instruct the device to seek to any of the
available data storage locations.

• Synchronous or asynchronous. A synchronous device


performs data transfers with predictable response times.
Asynchronous device exhibits irregular or unpredictable
response times not coordinated with other computer events.

3
Characteristics of I/O Devices
• Sharable or dedicated. A sharable device can be used concurrently
by several processes or threads; a dedicated device cannot.

• Speed of operation. Device speeds range from a few bytes per


second to a few gigabytes per second.

• Read–write, read only, or write only. Some devices perform both


input and output, but others support only one data transfer direction.

4
Application I/O Interface

 Block and Character Devices


 Network Devices
 Clocks and Timers
 Nonblocking and Asynchronous I/O
 Vectored I/O

5
Application I/O Interface
 Block and Character Devices
 Block-device interface or raw I/O
• read(), write(), and seek()
• Memory-mapped file access can be layered on top of block-device drivers
 The actual data transfers are performed only when needed to satisfy
access to the memory image.
 Memory mapping is also convenient for programmers : access to a
memory- mapped file is as simple as reading from and writing to
memory.
 Character stream interface
• “spontaneously” that is, at times that cannot necessarily be predicted by the
application.
• get() or put() one character
• Convenient for input devices such as keyboards, mice, printers and
modems.

6
Application I/O Interface

 Network Devices
• Network socket interface: The system calls in the socket
interface which enable an application for
• Creation of a socket
• Connect a local socket to a remote address
• To listen for any remote application to plug into the
local socket
• To send and receive packets over the connection.
• The use of select() system calls eliminates the polling
and busy waiting that would otherwise be necessary for
network I/O.

7
Application I/O Interface
 Clocks and Timers are used for giving the current time, the
elapsed time and set a timer to trigger operation X at time T.
 Operating system, use above functions but unfortunately, the
system calls that implement these functions are not
standardized across operating systems.

• Programmable interval timer is the hardware to measure


elapsed time and to trigger operations
 Scheduler uses this mechanism to generate an interrupt
 Disk I/O subsystem uses it to invoke the periodic flushing of
dirty cache buffers to disk
 Network subsystem uses it to cancel operations that are
proceeding too slowly
 Operating system may also provide an interface for user
processes to use timers.

8
Application I/O Interface
 Nonblocking and Asynchronous I/O
 Blocking system call
• the execution of the application is suspended and application is moved from OS run
queue to a wait queue.
• the application is moved back to the run queue after the system call
• The physical actions performed by I/O devices are generally asynchronous(varying
or unpredictable amount of time)
• blocking application code is easier to understand than nonblocking application

 Nonblocking call
• does not halt the execution of the application for an extended time.
• Keyboard ,mouse input and video application that reads frames from a file on disk
while simultaneously decompressing and displaying the output on the display.
• select() system call for network sockets is an example

9
Application I/O Interface
 Nonblocking and Asynchronous I/O Continues….

 asynchronous system call


• An asynchronous call returns immediately, without waiting for the
I/O to complete
• Disk and network I/O are examples.

 The difference between nonblocking and asynchronous system calls


• nonblocking read() returns immediately with whatever data are
available—the full number of bytes requested, fewer, or none at all.
An asynchronous read() call requests a transfer that will be
performed completely at some future time.
 .

10
Application I/O Interface
 Vectored I/O
• Allows one system call to perform multiple I/O operations involving
multiple locations
• Scatter-gather method is useful
 increase throughput and decrease system overhead
 atomicity, assuring that all the I/O is done without interruption

11
Improve the efficiency of I/O
 We can utilize several principles to improve the efficiency of I/O:
• Reduce the number of context switches.
• Reduce the number of times that data must be copied in memory
while passing between device and application.
• Reduce the frequency of interrupts by using large transfers, smart
controllers and polling (if busy waiting can be minimized).
• Increase concurrency by using DMA-knowledgeable controllers or
channels to offload simple data copying from the CPU.
• Move processing primitives into hardware, to allow their operation in
device controllers to be concurrent with CPU and bus operation.
• Balance CPU, memory subsystem, bus, and I/O performance,
because an overload in any one area will cause idleness in others.

12
STREAMS
 The streams mechanism in UNIX provides a bi-directional pipeline between a
user process and a device driver, onto which additional modules can be added.

 The user process interacts with the stream head.


 The device driver interacts with the device end.
 Zero or more stream modules can be pushed onto the stream, using ioctl( ).
These modules may filter and/or modify the data as it passes through the
stream.
 Each module has a read queue and a write queue.
 Flow control can be optionally supported, in which case each module will
buffer data until the adjacent module is ready to receive it. Without flow
control, data is passed along as soon as it is ready.

13
STREAMS Continues…
 User processes communicate with the stream head using either read( ) and
write( ) ( or putmsg( ) and getmsg( ) for message passing. )

 Streams I/O is asynchronous ( non-blocking ), except for the interface between


the user process and the stream head.

 The device driver must respond to interrupts from its device - If the adjacent
module is not prepared to accept data and the device driver's buffers are all full,
then data is typically dropped.

 Streams are widely used in UNIX, and are the preferred approach for device
drivers. For example, UNIX implements sockets using streams.

14

You might also like