SlideShare a Scribd company logo
1 of 138
Download to read offline
I/O Systems
Amir H. Payberah
amir@sics.se
Amirkabir University of Technology
(Tehran Polytechnic)
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 1 / 57
Motivation
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 2 / 57
Overview
I/O management is a major component of OS design and operation.
• Important aspect of computer operation
• I/O devices vary greatly
• Various methods to control them
• Performance management
• New types of devices frequent
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 3 / 57
Overview
I/O management is a major component of OS design and operation.
• Important aspect of computer operation
• I/O devices vary greatly
• Various methods to control them
• Performance management
• New types of devices frequent
Ports, busses, device controllers connect to various devices.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 3 / 57
Overview
I/O management is a major component of OS design and operation.
• Important aspect of computer operation
• I/O devices vary greatly
• Various methods to control them
• Performance management
• New types of devices frequent
Ports, busses, device controllers connect to various devices.
Device drivers encapsulate device details.
• Present uniform device-access interface to I/O subsystem.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 3 / 57
I/O Hardware
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 4 / 57
I/O Hardware
Incredible variety of I/O devices
• Storage, e.g., disks, tapes
• Transmission, e.g., network connections, bluetooth
• Human-interface, e.g., screen, keyboard, mouse, audio in and out
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 5 / 57
I/O Hardware
Incredible variety of I/O devices
• Storage, e.g., disks, tapes
• Transmission, e.g., network connections, bluetooth
• Human-interface, e.g., screen, keyboard, mouse, audio in and out
We only need to understand how the devices are attached and how
the software can control the hardware.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 5 / 57
Common Concepts in I/O Hardware
Common concepts: signals from I/O devices interface with com-
puter.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 6 / 57
Common Concepts in I/O Hardware
Common concepts: signals from I/O devices interface with com-
puter.
Port: connection point for device
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 6 / 57
Common Concepts in I/O Hardware
Common concepts: signals from I/O devices interface with com-
puter.
Port: connection point for device
Bus: set of wires and a protocol that specifies a set of messages
that can be sent on the wires.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 6 / 57
Common Concepts in I/O Hardware
Common concepts: signals from I/O devices interface with com-
puter.
Port: connection point for device
Bus: set of wires and a protocol that specifies a set of messages
that can be sent on the wires.
Controller: a collection of electronics that can operate a port, a bus,
or a device.
• Sometimes integrated and sometimes separate circuit board (host
adapter)
• Contains processor, microcode, private memory, bus controller, etc
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 6 / 57
Bus
PCI bus: connects the processor-memory subsystem to fast devices.
Expansion bus: connects relatively slow devices.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 7 / 57
Processor/Controller Interaction
How can the processor give commands and data to a controller to
accomplish an I/O transfer?
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 8 / 57
Processor/Controller Interaction
How can the processor give commands and data to a controller to
accomplish an I/O transfer?
Devices usually have registers where device driver places commands,
addresses, and data.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 8 / 57
Processor/Controller Interaction
How can the processor give commands and data to a controller to
accomplish an I/O transfer?
Devices usually have registers where device driver places commands,
addresses, and data.
Processor/controller interaction:
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 8 / 57
Processor/Controller Interaction
How can the processor give commands and data to a controller to
accomplish an I/O transfer?
Devices usually have registers where device driver places commands,
addresses, and data.
Processor/controller interaction:
• Direct I/O instructions: triggers bus lines to select the proper
device and to move bits into or out of a device register.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 8 / 57
Processor/Controller Interaction
How can the processor give commands and data to a controller to
accomplish an I/O transfer?
Devices usually have registers where device driver places commands,
addresses, and data.
Processor/controller interaction:
• Direct I/O instructions: triggers bus lines to select the proper
device and to move bits into or out of a device register.
• Memory-mapped I/O: device data and command registers mapped
to processor address space.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 8 / 57
Device I/O Port Locations on PCs
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 9 / 57
I/O Port Registers
The data-in register: read by the host to get input.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 10 / 57
I/O Port Registers
The data-in register: read by the host to get input.
The data-out register: written by the host to send output.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 10 / 57
I/O Port Registers
The data-in register: read by the host to get input.
The data-out register: written by the host to send output.
The status register: read by the host, and indicates states.
• whether the current command has completed.
• whether a byte is available to be read from the data-in register.
• whether a device error has occurred.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 10 / 57
I/O Port Registers
The data-in register: read by the host to get input.
The data-out register: written by the host to send output.
The status register: read by the host, and indicates states.
• whether the current command has completed.
• whether a byte is available to be read from the data-in register.
• whether a device error has occurred.
The control register: written by the host to start a command or to
change the mode of a device.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 10 / 57
Host Device Interaction
Polling
Interrupt
Direct memory access (DMA)
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 11 / 57
Polling (1/2)
A handshake between the host and a controller.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 12 / 57
Polling (1/2)
A handshake between the host and a controller.
Assume 2 bits for coordination. For each byte of I/O:
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 12 / 57
Polling (1/2)
A handshake between the host and a controller.
Assume 2 bits for coordination. For each byte of I/O:
1 Host reads the busy bit from the status register until 0.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 12 / 57
Polling (1/2)
A handshake between the host and a controller.
Assume 2 bits for coordination. For each byte of I/O:
1 Host reads the busy bit from the status register until 0.
2 Host sets the read or write bit and if write copies data into the
data-out register.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 12 / 57
Polling (1/2)
A handshake between the host and a controller.
Assume 2 bits for coordination. For each byte of I/O:
1 Host reads the busy bit from the status register until 0.
2 Host sets the read or write bit and if write copies data into the
data-out register.
3 Host sets the command-ready bit.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 12 / 57
Polling (1/2)
A handshake between the host and a controller.
Assume 2 bits for coordination. For each byte of I/O:
1 Host reads the busy bit from the status register until 0.
2 Host sets the read or write bit and if write copies data into the
data-out register.
3 Host sets the command-ready bit.
4 Controller sets the busy bit, executes transfer.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 12 / 57
Polling (1/2)
A handshake between the host and a controller.
Assume 2 bits for coordination. For each byte of I/O:
1 Host reads the busy bit from the status register until 0.
2 Host sets the read or write bit and if write copies data into the
data-out register.
3 Host sets the command-ready bit.
4 Controller sets the busy bit, executes transfer.
5 Controller clears the busy bit, error bit, and command-ready bit
when transfer done.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 12 / 57
Polling (2/2)
Step 1 is busy-wait cycle (polling) to wait for I/O from device.
• Reasonable if device is fast.
• But inefficient if device slow.
• CPU switches to other tasks? but if miss a cycle data
overwritten/lost.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 13 / 57
Interrupts
Polling can happen in 3 instruction cycles.
• read status, logical-and to extract status bit, and branch if not
zero.
• Inefficient, but more efficient way?
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 14 / 57
Interrupts
Polling can happen in 3 instruction cycles.
• read status, logical-and to extract status bit, and branch if not
zero.
• Inefficient, but more efficient way?
CPU interrupt-request line is triggered by I/O device.
• Checked by processor after each instruction.
• Saves state and jumps to interrupt-handler routine at a fixed
address in memory.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 14 / 57
Interrupts
Polling can happen in 3 instruction cycles.
• read status, logical-and to extract status bit, and branch if not
zero.
• Inefficient, but more efficient way?
CPU interrupt-request line is triggered by I/O device.
• Checked by processor after each instruction.
• Saves state and jumps to interrupt-handler routine at a fixed
address in memory.
Two interrupt request lines:
• Nonmaskable: reserved for events such as unrecoverable memory
errors.
• Maskable: it can be turned off by the CPU.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 14 / 57
Interrupt-Driven I/O Cycle
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 15 / 57
Interrupt Vector
The interrupt mechanism accepts an address: a number that selects
a specific interrupt-handling routine.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 16 / 57
Interrupt Vector
The interrupt mechanism accepts an address: a number that selects
a specific interrupt-handling routine.
This address is an offset in a table called the interrupt vector.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 16 / 57
Interrupt Vector
The interrupt mechanism accepts an address: a number that selects
a specific interrupt-handling routine.
This address is an offset in a table called the interrupt vector.
The interrupt vector contains the memory addresses of specialized
interrupt handlers.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 16 / 57
Interrupt Vector
The interrupt mechanism accepts an address: a number that selects
a specific interrupt-handling routine.
This address is an offset in a table called the interrupt vector.
The interrupt vector contains the memory addresses of specialized
interrupt handlers.
Computers have more devices than they have address elements in
the interrupt vector.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 16 / 57
Interrupt Vector
The interrupt mechanism accepts an address: a number that selects
a specific interrupt-handling routine.
This address is an offset in a table called the interrupt vector.
The interrupt vector contains the memory addresses of specialized
interrupt handlers.
Computers have more devices than they have address elements in
the interrupt vector.
• Use interrupt chaining: each element in the interrupt vector points
to the head of a list of interrupt handlers.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 16 / 57
Intel Pentium Processor Event-Vector Table
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 17 / 57
Other Interrupt Usages
Interrupt mechanism also used for exceptions.
• Divide by zero, terminate process, hardware error.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 18 / 57
Other Interrupt Usages
Interrupt mechanism also used for exceptions.
• Divide by zero, terminate process, hardware error.
Page fault executes when memory access error.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 18 / 57
Other Interrupt Usages
Interrupt mechanism also used for exceptions.
• Divide by zero, terminate process, hardware error.
Page fault executes when memory access error.
System call executes via trap to trigger kernel to execute request.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 18 / 57
Other Interrupt Usages
Interrupt mechanism also used for exceptions.
• Divide by zero, terminate process, hardware error.
Page fault executes when memory access error.
System call executes via trap to trigger kernel to execute request.
Multi-CPU systems can process interrupts concurrently.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 18 / 57
Other Interrupt Usages
Interrupt mechanism also used for exceptions.
• Divide by zero, terminate process, hardware error.
Page fault executes when memory access error.
System call executes via trap to trigger kernel to execute request.
Multi-CPU systems can process interrupts concurrently.
Used for time-sensitive processing, frequent, must be fast.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 18 / 57
Direct Memory Access (1/2)
Used to avoid programmed I/O (one byte at a time) for large data
movement.
Requires Direct Memory Access (DMA) controller
Bypasses CPU to transfer data directly between I/O device and
memory.
Version that is aware of virtual addresses can be even more efficient.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 19 / 57
Direct Memory Access (2/2)
OS writes DMA command block into memory.
• Source and destination addresses
• Read or write mode
• Count of bytes
• Writes location of command block to DMA controller
• Bus mastering of DMA controller - grabs bus from CPU: cycle
stealing from CPU but still much more efficient
• When done, interrupts to signal completion
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 20 / 57
Six Step Process to Perform DMA Transfer
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 21 / 57
Application I/O Interface
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 22 / 57
Application I/O Interface
I/O system calls encapsulate device behaviors in generic classes.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 23 / 57
Application I/O Interface
I/O system calls encapsulate device behaviors in generic classes.
Device-driver layer hides differences among I/O controllers from ker-
nel.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 23 / 57
Application I/O Interface
I/O system calls encapsulate device behaviors in generic classes.
Device-driver layer hides differences among I/O controllers from ker-
nel.
New devices talking already-implemented protocols need no extra
work.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 23 / 57
Application I/O Interface
I/O system calls encapsulate device behaviors in generic classes.
Device-driver layer hides differences among I/O controllers from ker-
nel.
New devices talking already-implemented protocols need no extra
work.
Each OS has its own I/O subsystem structures and device driver
frameworks.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 23 / 57
A Kernel I/O Structure
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 24 / 57
Characteristics of I/O Devices (1/2)
Devices vary in many dimensions
• Data-transfer mode: character or block
• Access method: sequential or random-access
• Transfer schedule: synchronous or asynchronous (or both)
• Sharing: sharable or dedicated
• Device speed: speed of operation
• I/O direction: read-write, read only, or write only
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 25 / 57
Characteristics of I/O Devices (2/2)
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 26 / 57
Character Devices
Character devices include keyboards, mouse, serial ports.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 27 / 57
Character Devices
Character devices include keyboards, mouse, serial ports.
A character device transfers bytes one by one.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 27 / 57
Character Devices
Character devices include keyboards, mouse, serial ports.
A character device transfers bytes one by one.
Commands include get() and put().
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 27 / 57
Block Devices
Block devices include disk drives.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 28 / 57
Block Devices
Block devices include disk drives.
Commands include read() and write() and seek() for random-
access devices.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 28 / 57
Block Devices
Block devices include disk drives.
Commands include read() and write() and seek() for random-
access devices.
Raw I/O: access a block device as a simple linear array of blocks.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 28 / 57
Block Devices
Block devices include disk drives.
Commands include read() and write() and seek() for random-
access devices.
Raw I/O: access a block device as a simple linear array of blocks.
Direct I/O: disable buffering and locking.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 28 / 57
Block Devices
Block devices include disk drives.
Commands include read() and write() and seek() for random-
access devices.
Raw I/O: access a block device as a simple linear array of blocks.
Direct I/O: disable buffering and locking.
Memory-mapped file access: file mapped to virtual memory and
clusters brought via demand paging.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 28 / 57
Network Devices
Varying enough from block and character to have own interface.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 29 / 57
Network Devices
Varying enough from block and character to have own interface.
Linux, Unix, Windows and many others include socket interface.
• Separates network protocol from network operation.
• Includes select() functionality.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 29 / 57
Clocks and Timers
Provide current time, elapsed time, and timer (trigger operation X
at time T)
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 30 / 57
Clocks and Timers
Provide current time, elapsed time, and timer (trigger operation X
at time T)
Programmable interval timer, the hardware used for timings, and
periodic interrupts.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 30 / 57
Clocks and Timers
Provide current time, elapsed time, and timer (trigger operation X
at time T)
Programmable interval timer, the hardware used for timings, and
periodic interrupts.
Normal resolution about 1/60 second.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 30 / 57
Clocks and Timers
Provide current time, elapsed time, and timer (trigger operation X
at time T)
Programmable interval timer, the hardware used for timings, and
periodic interrupts.
Normal resolution about 1/60 second.
Some systems provide higher-resolution timers.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 30 / 57
Blocking, Nonblocking and Asynchronous I/O
Blocking: process suspended until I/O completed
• Insufficient for some needs
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 31 / 57
Blocking, Nonblocking and Asynchronous I/O
Blocking: process suspended until I/O completed
• Insufficient for some needs
Nonblocking: I/O call returns as much as available
• User interface, data copy (buffered I/O)
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 31 / 57
Blocking, Nonblocking and Asynchronous I/O
Blocking: process suspended until I/O completed
• Insufficient for some needs
Nonblocking: I/O call returns as much as available
• User interface, data copy (buffered I/O)
• Implemented via multi-threading
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 31 / 57
Blocking, Nonblocking and Asynchronous I/O
Blocking: process suspended until I/O completed
• Insufficient for some needs
Nonblocking: I/O call returns as much as available
• User interface, data copy (buffered I/O)
• Implemented via multi-threading
• select() to find if data ready then read() or write() to
transfers.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 31 / 57
Blocking, Nonblocking and Asynchronous I/O
Blocking: process suspended until I/O completed
• Insufficient for some needs
Nonblocking: I/O call returns as much as available
• User interface, data copy (buffered I/O)
• Implemented via multi-threading
• select() to find if data ready then read() or write() to
transfers.
Asynchronous: process runs while I/O executes
• I/O subsystem signals process when I/O completed.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 31 / 57
Synchronous vs. Asynchronous I/O Methods
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 32 / 57
Vectored I/O
Vectored I/O allows one system call to perform multiple I/O oper-
ations.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 33 / 57
Vectored I/O
Vectored I/O allows one system call to perform multiple I/O oper-
ations.
The scatter-gather method is better than multiple individual I/O
calls.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 33 / 57
Vectored I/O
Vectored I/O allows one system call to perform multiple I/O oper-
ations.
The scatter-gather method is better than multiple individual I/O
calls.
• Decreases context switching and system call overhead.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 33 / 57
Vectored I/O
Vectored I/O allows one system call to perform multiple I/O oper-
ations.
The scatter-gather method is better than multiple individual I/O
calls.
• Decreases context switching and system call overhead.
• Some versions provide atomicity: avoid for example worry about
multiple threads changing data as reads/writes occurring.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 33 / 57
Vectored I/O
Vectored I/O allows one system call to perform multiple I/O oper-
ations.
The scatter-gather method is better than multiple individual I/O
calls.
• Decreases context switching and system call overhead.
• Some versions provide atomicity: avoid for example worry about
multiple threads changing data as reads/writes occurring.
For example, Unix readve() accepts a vector of multiple buffers to
read into or write from.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 33 / 57
Kernel I/O Subsystem
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 34 / 57
Kernel I/O Subsystem
Kernels provide many services related to I/O:
• Scheduling
• Buffering
• Caching
• Spooling
• Device reservation
• Error handling
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 35 / 57
Scheduling (1/2)
Determine a good order in which to execute I/O requests.
Some I/O request ordering via per-device queue.
Some OSs try fairness.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 36 / 57
Scheduling (2/2)
In asynchronous I/O the kernel must be able to keep track of many
I/O requests at the same time.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 37 / 57
Scheduling (2/2)
In asynchronous I/O the kernel must be able to keep track of many
I/O requests at the same time.
• The OS attaches the wait queue to a device-status table.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 37 / 57
Scheduling (2/2)
In asynchronous I/O the kernel must be able to keep track of many
I/O requests at the same time.
• The OS attaches the wait queue to a device-status table.
• The table contains an entry for each I/O device.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 37 / 57
Scheduling (2/2)
In asynchronous I/O the kernel must be able to keep track of many
I/O requests at the same time.
• The OS attaches the wait queue to a device-status table.
• The table contains an entry for each I/O device.
• If the device is busy with a request, the type of request and other
parameters will be stored in the table entry for that device.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 37 / 57
Buffering and Caching
Buffering: stores data in memory while transferring between devices.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 38 / 57
Buffering and Caching
Buffering: stores data in memory while transferring between devices.
• To cope with device speed mismatch.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 38 / 57
Buffering and Caching
Buffering: stores data in memory while transferring between devices.
• To cope with device speed mismatch.
• To cope with device transfer size mismatch, e.g., fragmentation and
reassembly of messages
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 38 / 57
Buffering and Caching
Buffering: stores data in memory while transferring between devices.
• To cope with device speed mismatch.
• To cope with device transfer size mismatch, e.g., fragmentation and
reassembly of messages
• To maintain copy semantics, e.g., copy semantics
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 38 / 57
Buffering and Caching
Buffering: stores data in memory while transferring between devices.
• To cope with device speed mismatch.
• To cope with device transfer size mismatch, e.g., fragmentation and
reassembly of messages
• To maintain copy semantics, e.g., copy semantics
Caching: faster device holding copy of data.
• Always just a copy
• Key to performance
• Sometimes combined with buffering
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 38 / 57
Spooling and Device Reservation
Spooling: a buffer that holds output for a device.
• If device can serve only one request at a time, i.e., printing
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 39 / 57
Spooling and Device Reservation
Spooling: a buffer that holds output for a device.
• If device can serve only one request at a time, i.e., printing
Device reservation: provides exclusive access to a device.
• System calls for allocation and de-allocation
• Watch out for deadlock
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 39 / 57
Error Handling
OS can recover from disk read, device unavailable, transient write
failures
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 40 / 57
Error Handling
OS can recover from disk read, device unavailable, transient write
failures
• Retry a read or write.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 40 / 57
Error Handling
OS can recover from disk read, device unavailable, transient write
failures
• Retry a read or write.
• Track error frequencies, stop using device with increasing frequency
of retry-able errors.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 40 / 57
Error Handling
OS can recover from disk read, device unavailable, transient write
failures
• Retry a read or write.
• Track error frequencies, stop using device with increasing frequency
of retry-able errors.
Most return an error number or code when I/O request fails.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 40 / 57
Error Handling
OS can recover from disk read, device unavailable, transient write
failures
• Retry a read or write.
• Track error frequencies, stop using device with increasing frequency
of retry-able errors.
Most return an error number or code when I/O request fails.
System error logs hold problem reports.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 40 / 57
I/O Protection
User process may accidentally or purposefully attempt to disrupt
normal operation via illegal I/O instructions.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 41 / 57
I/O 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.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 41 / 57
I/O 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.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 41 / 57
I/O 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.
Memory-mapped and I/O port memory locations must be protected
too.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 41 / 57
Use of a System Call to Perform I/O
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 42 / 57
Kernel Data Structures
Kernel keeps state info for I/O components, including open file ta-
bles, network connections, character device state
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 43 / 57
Kernel Data Structures
Kernel keeps state info for I/O components, including open file ta-
bles, network connections, character device state
Many complex data structures to track buffers, memory allocation,
dirty blocks.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 43 / 57
Kernel Data Structures
Kernel keeps state info for I/O components, including open file ta-
bles, network connections, character device state
Many complex data structures to track buffers, memory allocation,
dirty blocks.
Some use object-oriented methods and message passing to imple-
ment I/O
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 43 / 57
Kernel Data Structures
Kernel keeps state info for I/O components, including open file ta-
bles, network connections, character device state
Many complex data structures to track buffers, memory allocation,
dirty blocks.
Some use object-oriented methods and message passing to imple-
ment I/O
E.g., Windows uses message passing.
• Message with I/O information passed from user mode into kernel.
• Message modified as it flows through to device driver and back to
process.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 43 / 57
UNIX I/O Kernel Structure
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 44 / 57
Transforming I/O Requests
to Hardware Operations
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 45 / 57
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
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 46 / 57
Life Cycle of An I/O Request
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 47 / 57
STREAMS
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 48 / 57
STREAMS (1/2)
STREAM: a full-duplex communication channel between a user-level
process and a device in Unix System V and beyond.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 49 / 57
STREAMS (1/2)
STREAM: a full-duplex communication channel between a user-level
process and a device in Unix System V and beyond.
A STREAM consists of:
• STREAM head: interfaces with the user process.
• Driver end: interfaces with the device.
• Zero or more STREAM modules between them.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 49 / 57
STREAMS (2/2)
Each module contains a read queue and a write queue.
Message passing is used to communicate between queues.
Asynchronous internally, synchronous where user process communi-
cates with stream head.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 50 / 57
Performance
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 51 / 57
Performance
I/O is a major factor in system performance:
• Demands CPU to execute device driver, kernel I/O code
• Context switches due to interrupts
• Data copying
• Network traffic especially stressful
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 52 / 57
Inter-computer Communications
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 53 / 57
Improving Performance
Reduce number of context switches
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 54 / 57
Improving Performance
Reduce number of context switches
Reduce data copying
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 54 / 57
Improving Performance
Reduce number of context switches
Reduce data copying
Reduce interrupts by using large transfers, smart controllers, polling
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 54 / 57
Improving Performance
Reduce number of context switches
Reduce data copying
Reduce interrupts by using large transfers, smart controllers, polling
Use DMA
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 54 / 57
Improving Performance
Reduce number of context switches
Reduce data copying
Reduce interrupts by using large transfers, smart controllers, polling
Use DMA
Use smarter hardware devices
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 54 / 57
Improving Performance
Reduce number of context switches
Reduce data copying
Reduce interrupts by using large transfers, smart controllers, polling
Use DMA
Use smarter hardware devices
Balance CPU, memory, bus, and I/O performance for highest
throughput
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 54 / 57
Improving Performance
Reduce number of context switches
Reduce data copying
Reduce interrupts by using large transfers, smart controllers, polling
Use DMA
Use smarter hardware devices
Balance CPU, memory, bus, and I/O performance for highest
throughput
Move user-mode processes to kernel
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 54 / 57
Summary
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 55 / 57
Summary
I/O hardware: port, bus, controller
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 56 / 57
Summary
I/O hardware: port, bus, controller
I/O port registers: data-in, data-out, status, control
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 56 / 57
Summary
I/O hardware: port, bus, controller
I/O port registers: data-in, data-out, status, control
Host-device interaction: polling, interrupt, DMA
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 56 / 57
Summary
I/O hardware: port, bus, controller
I/O port registers: data-in, data-out, status, control
Host-device interaction: polling, interrupt, DMA
Devices: char, block, network
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 56 / 57
Summary
I/O hardware: port, bus, controller
I/O port registers: data-in, data-out, status, control
Host-device interaction: polling, interrupt, DMA
Devices: char, block, network
Kernel I/O: schedulling, buffering, caching, spooling, device reser-
vation, error handling
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 56 / 57
Summary
I/O hardware: port, bus, controller
I/O port registers: data-in, data-out, status, control
Host-device interaction: polling, interrupt, DMA
Devices: char, block, network
Kernel I/O: schedulling, buffering, caching, spooling, device reser-
vation, error handling
STREAMS
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 56 / 57
Summary
I/O hardware: port, bus, controller
I/O port registers: data-in, data-out, status, control
Host-device interaction: polling, interrupt, DMA
Devices: char, block, network
Kernel I/O: schedulling, buffering, caching, spooling, device reser-
vation, error handling
STREAMS
Performance
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 56 / 57
Questions?
Acknowledgements
Some slides were derived from Avi Silberschatz slides.
Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 57 / 57

More Related Content

What's hot

chapter-1-typical-configuration-of-computer.pdf
chapter-1-typical-configuration-of-computer.pdfchapter-1-typical-configuration-of-computer.pdf
chapter-1-typical-configuration-of-computer.pdfstudy material
 
การอ่านแบบไฟฟ้า และระบบพิกัดในงานเขียนแบบ
การอ่านแบบไฟฟ้า  และระบบพิกัดในงานเขียนแบบการอ่านแบบไฟฟ้า  และระบบพิกัดในงานเขียนแบบ
การอ่านแบบไฟฟ้า และระบบพิกัดในงานเขียนแบบNeeNak Revo
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java ProgrammingMath-Circle
 

What's hot (6)

chapter-1-typical-configuration-of-computer.pdf
chapter-1-typical-configuration-of-computer.pdfchapter-1-typical-configuration-of-computer.pdf
chapter-1-typical-configuration-of-computer.pdf
 
Working memory in computer
Working memory in computerWorking memory in computer
Working memory in computer
 
Java Enterprise Edition
Java Enterprise EditionJava Enterprise Edition
Java Enterprise Edition
 
JDBC
JDBCJDBC
JDBC
 
การอ่านแบบไฟฟ้า และระบบพิกัดในงานเขียนแบบ
การอ่านแบบไฟฟ้า  และระบบพิกัดในงานเขียนแบบการอ่านแบบไฟฟ้า  และระบบพิกัดในงานเขียนแบบ
การอ่านแบบไฟฟ้า และระบบพิกัดในงานเขียนแบบ
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java Programming
 

Viewers also liked

Introduction to Operating Systems - Part2
Introduction to Operating Systems - Part2Introduction to Operating Systems - Part2
Introduction to Operating Systems - Part2Amir Payberah
 
Process Management - Part2
Process Management - Part2Process Management - Part2
Process Management - Part2Amir Payberah
 
CPU Scheduling - Part2
CPU Scheduling - Part2CPU Scheduling - Part2
CPU Scheduling - Part2Amir Payberah
 
The Stratosphere Big Data Analytics Platform
The Stratosphere Big Data Analytics PlatformThe Stratosphere Big Data Analytics Platform
The Stratosphere Big Data Analytics PlatformAmir Payberah
 
Data Intensive Computing Frameworks
Data Intensive Computing FrameworksData Intensive Computing Frameworks
Data Intensive Computing FrameworksAmir Payberah
 
File System Interface
File System InterfaceFile System Interface
File System InterfaceAmir Payberah
 
CPU Scheduling - Part1
CPU Scheduling - Part1CPU Scheduling - Part1
CPU Scheduling - Part1Amir Payberah
 
Virtual Memory - Part1
Virtual Memory - Part1Virtual Memory - Part1
Virtual Memory - Part1Amir Payberah
 
Virtual Memory - Part2
Virtual Memory - Part2Virtual Memory - Part2
Virtual Memory - Part2Amir Payberah
 
P2P Content Distribution Network
P2P Content Distribution NetworkP2P Content Distribution Network
P2P Content Distribution NetworkAmir Payberah
 
File System Implementation - Part1
File System Implementation - Part1File System Implementation - Part1
File System Implementation - Part1Amir Payberah
 
Process Management - Part3
Process Management - Part3Process Management - Part3
Process Management - Part3Amir Payberah
 
Process Management - Part1
Process Management - Part1Process Management - Part1
Process Management - Part1Amir Payberah
 

Viewers also liked (20)

Introduction to Operating Systems - Part2
Introduction to Operating Systems - Part2Introduction to Operating Systems - Part2
Introduction to Operating Systems - Part2
 
Protection
ProtectionProtection
Protection
 
Main Memory - Part2
Main Memory - Part2Main Memory - Part2
Main Memory - Part2
 
Security
SecuritySecurity
Security
 
Cloud Computing
Cloud ComputingCloud Computing
Cloud Computing
 
Process Management - Part2
Process Management - Part2Process Management - Part2
Process Management - Part2
 
CPU Scheduling - Part2
CPU Scheduling - Part2CPU Scheduling - Part2
CPU Scheduling - Part2
 
Storage
StorageStorage
Storage
 
The Stratosphere Big Data Analytics Platform
The Stratosphere Big Data Analytics PlatformThe Stratosphere Big Data Analytics Platform
The Stratosphere Big Data Analytics Platform
 
Data Intensive Computing Frameworks
Data Intensive Computing FrameworksData Intensive Computing Frameworks
Data Intensive Computing Frameworks
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
 
File System Interface
File System InterfaceFile System Interface
File System Interface
 
CPU Scheduling - Part1
CPU Scheduling - Part1CPU Scheduling - Part1
CPU Scheduling - Part1
 
Virtual Memory - Part1
Virtual Memory - Part1Virtual Memory - Part1
Virtual Memory - Part1
 
Virtual Memory - Part2
Virtual Memory - Part2Virtual Memory - Part2
Virtual Memory - Part2
 
P2P Content Distribution Network
P2P Content Distribution NetworkP2P Content Distribution Network
P2P Content Distribution Network
 
File System Implementation - Part1
File System Implementation - Part1File System Implementation - Part1
File System Implementation - Part1
 
Main Memory - Part1
Main Memory - Part1Main Memory - Part1
Main Memory - Part1
 
Process Management - Part3
Process Management - Part3Process Management - Part3
Process Management - Part3
 
Process Management - Part1
Process Management - Part1Process Management - Part1
Process Management - Part1
 

Similar to I/O Systems Overview for OS Design

Unit 5 I/O organization
Unit 5   I/O organizationUnit 5   I/O organization
Unit 5 I/O organizationchidabdu
 
Unit2 p1 io organization-97-2003
Unit2 p1 io organization-97-2003Unit2 p1 io organization-97-2003
Unit2 p1 io organization-97-2003Swathi Veeradhi
 
chapter7-io organization.pptx
chapter7-io organization.pptxchapter7-io organization.pptx
chapter7-io organization.pptxgracemann365
 
Mca admission in india
Mca admission in indiaMca admission in india
Mca admission in indiaEdhole.com
 
COMPUTER ORGANIZATION NOTES Unit 3 4
COMPUTER ORGANIZATION NOTES  Unit 3 4COMPUTER ORGANIZATION NOTES  Unit 3 4
COMPUTER ORGANIZATION NOTES Unit 3 4Dr.MAYA NAYAK
 
Computer oganization input-output
Computer oganization input-outputComputer oganization input-output
Computer oganization input-outputDeepak John
 
COA-Unit5-ppt2.pptx
COA-Unit5-ppt2.pptxCOA-Unit5-ppt2.pptx
COA-Unit5-ppt2.pptxRuhul Amin
 
Computer organization
Computer organizationComputer organization
Computer organizationRvishnupriya2
 
Computer organization
Computer organization Computer organization
Computer organization vishnu973656
 
Unit 4 ca-input-output
Unit 4 ca-input-outputUnit 4 ca-input-output
Unit 4 ca-input-outputBBDITM LUCKNOW
 
Computer architecture input output organization
Computer architecture input output organizationComputer architecture input output organization
Computer architecture input output organizationMazin Alwaaly
 
Top schools in delhi ncr
Top schools in delhi ncrTop schools in delhi ncr
Top schools in delhi ncrEdhole.com
 

Similar to I/O Systems Overview for OS Design (20)

IO organization.ppt
IO organization.pptIO organization.ppt
IO organization.ppt
 
Unit 5 I/O organization
Unit 5   I/O organizationUnit 5   I/O organization
Unit 5 I/O organization
 
Unit2 p1 io organization-97-2003
Unit2 p1 io organization-97-2003Unit2 p1 io organization-97-2003
Unit2 p1 io organization-97-2003
 
I/O Channel IBM 370
I/O Channel IBM 370I/O Channel IBM 370
I/O Channel IBM 370
 
chapter7-io organization.pptx
chapter7-io organization.pptxchapter7-io organization.pptx
chapter7-io organization.pptx
 
Mca admission in india
Mca admission in indiaMca admission in india
Mca admission in india
 
COMPUTER ORGANIZATION NOTES Unit 3 4
COMPUTER ORGANIZATION NOTES  Unit 3 4COMPUTER ORGANIZATION NOTES  Unit 3 4
COMPUTER ORGANIZATION NOTES Unit 3 4
 
Computer oganization input-output
Computer oganization input-outputComputer oganization input-output
Computer oganization input-output
 
COA-Unit5-ppt2.pptx
COA-Unit5-ppt2.pptxCOA-Unit5-ppt2.pptx
COA-Unit5-ppt2.pptx
 
Io pro
Io proIo pro
Io pro
 
unit-5 ppt.ppt
unit-5 ppt.pptunit-5 ppt.ppt
unit-5 ppt.ppt
 
Computer organization
Computer organizationComputer organization
Computer organization
 
Computer organization
Computer organization Computer organization
Computer organization
 
IO_ORGANIZATION.pdf
IO_ORGANIZATION.pdfIO_ORGANIZATION.pdf
IO_ORGANIZATION.pdf
 
Unit 4 ca-input-output
Unit 4 ca-input-outputUnit 4 ca-input-output
Unit 4 ca-input-output
 
Computer architecture input output organization
Computer architecture input output organizationComputer architecture input output organization
Computer architecture input output organization
 
Ch11.ppt
Ch11.pptCh11.ppt
Ch11.ppt
 
Ca 2 note mano
Ca 2 note manoCa 2 note mano
Ca 2 note mano
 
Top schools in delhi ncr
Top schools in delhi ncrTop schools in delhi ncr
Top schools in delhi ncr
 
IO hardware
IO hardwareIO hardware
IO hardware
 

More from Amir Payberah

The Spark Big Data Analytics Platform
The Spark Big Data Analytics PlatformThe Spark Big Data Analytics Platform
The Spark Big Data Analytics PlatformAmir Payberah
 
Linux Module Programming
Linux Module ProgrammingLinux Module Programming
Linux Module ProgrammingAmir Payberah
 
File System Implementation - Part2
File System Implementation - Part2File System Implementation - Part2
File System Implementation - Part2Amir Payberah
 
Process Synchronization - Part2
Process Synchronization -  Part2Process Synchronization -  Part2
Process Synchronization - Part2Amir Payberah
 
Process Synchronization - Part1
Process Synchronization -  Part1Process Synchronization -  Part1
Process Synchronization - Part1Amir Payberah
 
Introduction to Operating Systems - Part3
Introduction to Operating Systems - Part3Introduction to Operating Systems - Part3
Introduction to Operating Systems - Part3Amir Payberah
 
Introduction to Operating Systems - Part1
Introduction to Operating Systems - Part1Introduction to Operating Systems - Part1
Introduction to Operating Systems - Part1Amir Payberah
 
Graph processing - Powergraph and GraphX
Graph processing - Powergraph and GraphXGraph processing - Powergraph and GraphX
Graph processing - Powergraph and GraphXAmir Payberah
 

More from Amir Payberah (10)

The Spark Big Data Analytics Platform
The Spark Big Data Analytics PlatformThe Spark Big Data Analytics Platform
The Spark Big Data Analytics Platform
 
Linux Module Programming
Linux Module ProgrammingLinux Module Programming
Linux Module Programming
 
File System Implementation - Part2
File System Implementation - Part2File System Implementation - Part2
File System Implementation - Part2
 
Process Synchronization - Part2
Process Synchronization -  Part2Process Synchronization -  Part2
Process Synchronization - Part2
 
Process Synchronization - Part1
Process Synchronization -  Part1Process Synchronization -  Part1
Process Synchronization - Part1
 
Threads
ThreadsThreads
Threads
 
Introduction to Operating Systems - Part3
Introduction to Operating Systems - Part3Introduction to Operating Systems - Part3
Introduction to Operating Systems - Part3
 
Introduction to Operating Systems - Part1
Introduction to Operating Systems - Part1Introduction to Operating Systems - Part1
Introduction to Operating Systems - Part1
 
Mesos and YARN
Mesos and YARNMesos and YARN
Mesos and YARN
 
Graph processing - Powergraph and GraphX
Graph processing - Powergraph and GraphXGraph processing - Powergraph and GraphX
Graph processing - Powergraph and GraphX
 

Recently uploaded

The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 

Recently uploaded (20)

The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 

I/O Systems Overview for OS Design

  • 1. I/O Systems Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic) Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 1 / 57
  • 2. Motivation Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 2 / 57
  • 3. Overview I/O management is a major component of OS design and operation. • Important aspect of computer operation • I/O devices vary greatly • Various methods to control them • Performance management • New types of devices frequent Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 3 / 57
  • 4. Overview I/O management is a major component of OS design and operation. • Important aspect of computer operation • I/O devices vary greatly • Various methods to control them • Performance management • New types of devices frequent Ports, busses, device controllers connect to various devices. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 3 / 57
  • 5. Overview I/O management is a major component of OS design and operation. • Important aspect of computer operation • I/O devices vary greatly • Various methods to control them • Performance management • New types of devices frequent Ports, busses, device controllers connect to various devices. Device drivers encapsulate device details. • Present uniform device-access interface to I/O subsystem. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 3 / 57
  • 6. I/O Hardware Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 4 / 57
  • 7. I/O Hardware Incredible variety of I/O devices • Storage, e.g., disks, tapes • Transmission, e.g., network connections, bluetooth • Human-interface, e.g., screen, keyboard, mouse, audio in and out Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 5 / 57
  • 8. I/O Hardware Incredible variety of I/O devices • Storage, e.g., disks, tapes • Transmission, e.g., network connections, bluetooth • Human-interface, e.g., screen, keyboard, mouse, audio in and out We only need to understand how the devices are attached and how the software can control the hardware. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 5 / 57
  • 9. Common Concepts in I/O Hardware Common concepts: signals from I/O devices interface with com- puter. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 6 / 57
  • 10. Common Concepts in I/O Hardware Common concepts: signals from I/O devices interface with com- puter. Port: connection point for device Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 6 / 57
  • 11. Common Concepts in I/O Hardware Common concepts: signals from I/O devices interface with com- puter. Port: connection point for device Bus: set of wires and a protocol that specifies a set of messages that can be sent on the wires. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 6 / 57
  • 12. Common Concepts in I/O Hardware Common concepts: signals from I/O devices interface with com- puter. Port: connection point for device Bus: set of wires and a protocol that specifies a set of messages that can be sent on the wires. Controller: a collection of electronics that can operate a port, a bus, or a device. • Sometimes integrated and sometimes separate circuit board (host adapter) • Contains processor, microcode, private memory, bus controller, etc Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 6 / 57
  • 13. Bus PCI bus: connects the processor-memory subsystem to fast devices. Expansion bus: connects relatively slow devices. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 7 / 57
  • 14. Processor/Controller Interaction How can the processor give commands and data to a controller to accomplish an I/O transfer? Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 8 / 57
  • 15. Processor/Controller Interaction How can the processor give commands and data to a controller to accomplish an I/O transfer? Devices usually have registers where device driver places commands, addresses, and data. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 8 / 57
  • 16. Processor/Controller Interaction How can the processor give commands and data to a controller to accomplish an I/O transfer? Devices usually have registers where device driver places commands, addresses, and data. Processor/controller interaction: Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 8 / 57
  • 17. Processor/Controller Interaction How can the processor give commands and data to a controller to accomplish an I/O transfer? Devices usually have registers where device driver places commands, addresses, and data. Processor/controller interaction: • Direct I/O instructions: triggers bus lines to select the proper device and to move bits into or out of a device register. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 8 / 57
  • 18. Processor/Controller Interaction How can the processor give commands and data to a controller to accomplish an I/O transfer? Devices usually have registers where device driver places commands, addresses, and data. Processor/controller interaction: • Direct I/O instructions: triggers bus lines to select the proper device and to move bits into or out of a device register. • Memory-mapped I/O: device data and command registers mapped to processor address space. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 8 / 57
  • 19. Device I/O Port Locations on PCs Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 9 / 57
  • 20. I/O Port Registers The data-in register: read by the host to get input. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 10 / 57
  • 21. I/O Port Registers The data-in register: read by the host to get input. The data-out register: written by the host to send output. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 10 / 57
  • 22. I/O Port Registers The data-in register: read by the host to get input. The data-out register: written by the host to send output. The status register: read by the host, and indicates states. • whether the current command has completed. • whether a byte is available to be read from the data-in register. • whether a device error has occurred. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 10 / 57
  • 23. I/O Port Registers The data-in register: read by the host to get input. The data-out register: written by the host to send output. The status register: read by the host, and indicates states. • whether the current command has completed. • whether a byte is available to be read from the data-in register. • whether a device error has occurred. The control register: written by the host to start a command or to change the mode of a device. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 10 / 57
  • 24. Host Device Interaction Polling Interrupt Direct memory access (DMA) Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 11 / 57
  • 25. Polling (1/2) A handshake between the host and a controller. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 12 / 57
  • 26. Polling (1/2) A handshake between the host and a controller. Assume 2 bits for coordination. For each byte of I/O: Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 12 / 57
  • 27. Polling (1/2) A handshake between the host and a controller. Assume 2 bits for coordination. For each byte of I/O: 1 Host reads the busy bit from the status register until 0. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 12 / 57
  • 28. Polling (1/2) A handshake between the host and a controller. Assume 2 bits for coordination. For each byte of I/O: 1 Host reads the busy bit from the status register until 0. 2 Host sets the read or write bit and if write copies data into the data-out register. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 12 / 57
  • 29. Polling (1/2) A handshake between the host and a controller. Assume 2 bits for coordination. For each byte of I/O: 1 Host reads the busy bit from the status register until 0. 2 Host sets the read or write bit and if write copies data into the data-out register. 3 Host sets the command-ready bit. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 12 / 57
  • 30. Polling (1/2) A handshake between the host and a controller. Assume 2 bits for coordination. For each byte of I/O: 1 Host reads the busy bit from the status register until 0. 2 Host sets the read or write bit and if write copies data into the data-out register. 3 Host sets the command-ready bit. 4 Controller sets the busy bit, executes transfer. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 12 / 57
  • 31. Polling (1/2) A handshake between the host and a controller. Assume 2 bits for coordination. For each byte of I/O: 1 Host reads the busy bit from the status register until 0. 2 Host sets the read or write bit and if write copies data into the data-out register. 3 Host sets the command-ready bit. 4 Controller sets the busy bit, executes transfer. 5 Controller clears the busy bit, error bit, and command-ready bit when transfer done. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 12 / 57
  • 32. Polling (2/2) Step 1 is busy-wait cycle (polling) to wait for I/O from device. • Reasonable if device is fast. • But inefficient if device slow. • CPU switches to other tasks? but if miss a cycle data overwritten/lost. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 13 / 57
  • 33. Interrupts Polling can happen in 3 instruction cycles. • read status, logical-and to extract status bit, and branch if not zero. • Inefficient, but more efficient way? Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 14 / 57
  • 34. Interrupts Polling can happen in 3 instruction cycles. • read status, logical-and to extract status bit, and branch if not zero. • Inefficient, but more efficient way? CPU interrupt-request line is triggered by I/O device. • Checked by processor after each instruction. • Saves state and jumps to interrupt-handler routine at a fixed address in memory. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 14 / 57
  • 35. Interrupts Polling can happen in 3 instruction cycles. • read status, logical-and to extract status bit, and branch if not zero. • Inefficient, but more efficient way? CPU interrupt-request line is triggered by I/O device. • Checked by processor after each instruction. • Saves state and jumps to interrupt-handler routine at a fixed address in memory. Two interrupt request lines: • Nonmaskable: reserved for events such as unrecoverable memory errors. • Maskable: it can be turned off by the CPU. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 14 / 57
  • 36. Interrupt-Driven I/O Cycle Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 15 / 57
  • 37. Interrupt Vector The interrupt mechanism accepts an address: a number that selects a specific interrupt-handling routine. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 16 / 57
  • 38. Interrupt Vector The interrupt mechanism accepts an address: a number that selects a specific interrupt-handling routine. This address is an offset in a table called the interrupt vector. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 16 / 57
  • 39. Interrupt Vector The interrupt mechanism accepts an address: a number that selects a specific interrupt-handling routine. This address is an offset in a table called the interrupt vector. The interrupt vector contains the memory addresses of specialized interrupt handlers. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 16 / 57
  • 40. Interrupt Vector The interrupt mechanism accepts an address: a number that selects a specific interrupt-handling routine. This address is an offset in a table called the interrupt vector. The interrupt vector contains the memory addresses of specialized interrupt handlers. Computers have more devices than they have address elements in the interrupt vector. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 16 / 57
  • 41. Interrupt Vector The interrupt mechanism accepts an address: a number that selects a specific interrupt-handling routine. This address is an offset in a table called the interrupt vector. The interrupt vector contains the memory addresses of specialized interrupt handlers. Computers have more devices than they have address elements in the interrupt vector. • Use interrupt chaining: each element in the interrupt vector points to the head of a list of interrupt handlers. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 16 / 57
  • 42. Intel Pentium Processor Event-Vector Table Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 17 / 57
  • 43. Other Interrupt Usages Interrupt mechanism also used for exceptions. • Divide by zero, terminate process, hardware error. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 18 / 57
  • 44. Other Interrupt Usages Interrupt mechanism also used for exceptions. • Divide by zero, terminate process, hardware error. Page fault executes when memory access error. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 18 / 57
  • 45. Other Interrupt Usages Interrupt mechanism also used for exceptions. • Divide by zero, terminate process, hardware error. Page fault executes when memory access error. System call executes via trap to trigger kernel to execute request. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 18 / 57
  • 46. Other Interrupt Usages Interrupt mechanism also used for exceptions. • Divide by zero, terminate process, hardware error. Page fault executes when memory access error. System call executes via trap to trigger kernel to execute request. Multi-CPU systems can process interrupts concurrently. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 18 / 57
  • 47. Other Interrupt Usages Interrupt mechanism also used for exceptions. • Divide by zero, terminate process, hardware error. Page fault executes when memory access error. System call executes via trap to trigger kernel to execute request. Multi-CPU systems can process interrupts concurrently. Used for time-sensitive processing, frequent, must be fast. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 18 / 57
  • 48. Direct Memory Access (1/2) Used to avoid programmed I/O (one byte at a time) for large data movement. Requires Direct Memory Access (DMA) controller Bypasses CPU to transfer data directly between I/O device and memory. Version that is aware of virtual addresses can be even more efficient. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 19 / 57
  • 49. Direct Memory Access (2/2) OS writes DMA command block into memory. • Source and destination addresses • Read or write mode • Count of bytes • Writes location of command block to DMA controller • Bus mastering of DMA controller - grabs bus from CPU: cycle stealing from CPU but still much more efficient • When done, interrupts to signal completion Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 20 / 57
  • 50. Six Step Process to Perform DMA Transfer Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 21 / 57
  • 51. Application I/O Interface Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 22 / 57
  • 52. Application I/O Interface I/O system calls encapsulate device behaviors in generic classes. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 23 / 57
  • 53. Application I/O Interface I/O system calls encapsulate device behaviors in generic classes. Device-driver layer hides differences among I/O controllers from ker- nel. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 23 / 57
  • 54. Application I/O Interface I/O system calls encapsulate device behaviors in generic classes. Device-driver layer hides differences among I/O controllers from ker- nel. New devices talking already-implemented protocols need no extra work. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 23 / 57
  • 55. Application I/O Interface I/O system calls encapsulate device behaviors in generic classes. Device-driver layer hides differences among I/O controllers from ker- nel. New devices talking already-implemented protocols need no extra work. Each OS has its own I/O subsystem structures and device driver frameworks. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 23 / 57
  • 56. A Kernel I/O Structure Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 24 / 57
  • 57. Characteristics of I/O Devices (1/2) Devices vary in many dimensions • Data-transfer mode: character or block • Access method: sequential or random-access • Transfer schedule: synchronous or asynchronous (or both) • Sharing: sharable or dedicated • Device speed: speed of operation • I/O direction: read-write, read only, or write only Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 25 / 57
  • 58. Characteristics of I/O Devices (2/2) Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 26 / 57
  • 59. Character Devices Character devices include keyboards, mouse, serial ports. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 27 / 57
  • 60. Character Devices Character devices include keyboards, mouse, serial ports. A character device transfers bytes one by one. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 27 / 57
  • 61. Character Devices Character devices include keyboards, mouse, serial ports. A character device transfers bytes one by one. Commands include get() and put(). Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 27 / 57
  • 62. Block Devices Block devices include disk drives. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 28 / 57
  • 63. Block Devices Block devices include disk drives. Commands include read() and write() and seek() for random- access devices. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 28 / 57
  • 64. Block Devices Block devices include disk drives. Commands include read() and write() and seek() for random- access devices. Raw I/O: access a block device as a simple linear array of blocks. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 28 / 57
  • 65. Block Devices Block devices include disk drives. Commands include read() and write() and seek() for random- access devices. Raw I/O: access a block device as a simple linear array of blocks. Direct I/O: disable buffering and locking. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 28 / 57
  • 66. Block Devices Block devices include disk drives. Commands include read() and write() and seek() for random- access devices. Raw I/O: access a block device as a simple linear array of blocks. Direct I/O: disable buffering and locking. Memory-mapped file access: file mapped to virtual memory and clusters brought via demand paging. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 28 / 57
  • 67. Network Devices Varying enough from block and character to have own interface. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 29 / 57
  • 68. Network Devices Varying enough from block and character to have own interface. Linux, Unix, Windows and many others include socket interface. • Separates network protocol from network operation. • Includes select() functionality. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 29 / 57
  • 69. Clocks and Timers Provide current time, elapsed time, and timer (trigger operation X at time T) Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 30 / 57
  • 70. Clocks and Timers Provide current time, elapsed time, and timer (trigger operation X at time T) Programmable interval timer, the hardware used for timings, and periodic interrupts. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 30 / 57
  • 71. Clocks and Timers Provide current time, elapsed time, and timer (trigger operation X at time T) Programmable interval timer, the hardware used for timings, and periodic interrupts. Normal resolution about 1/60 second. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 30 / 57
  • 72. Clocks and Timers Provide current time, elapsed time, and timer (trigger operation X at time T) Programmable interval timer, the hardware used for timings, and periodic interrupts. Normal resolution about 1/60 second. Some systems provide higher-resolution timers. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 30 / 57
  • 73. Blocking, Nonblocking and Asynchronous I/O Blocking: process suspended until I/O completed • Insufficient for some needs Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 31 / 57
  • 74. Blocking, Nonblocking and Asynchronous I/O Blocking: process suspended until I/O completed • Insufficient for some needs Nonblocking: I/O call returns as much as available • User interface, data copy (buffered I/O) Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 31 / 57
  • 75. Blocking, Nonblocking and Asynchronous I/O Blocking: process suspended until I/O completed • Insufficient for some needs Nonblocking: I/O call returns as much as available • User interface, data copy (buffered I/O) • Implemented via multi-threading Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 31 / 57
  • 76. Blocking, Nonblocking and Asynchronous I/O Blocking: process suspended until I/O completed • Insufficient for some needs Nonblocking: I/O call returns as much as available • User interface, data copy (buffered I/O) • Implemented via multi-threading • select() to find if data ready then read() or write() to transfers. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 31 / 57
  • 77. Blocking, Nonblocking and Asynchronous I/O Blocking: process suspended until I/O completed • Insufficient for some needs Nonblocking: I/O call returns as much as available • User interface, data copy (buffered I/O) • Implemented via multi-threading • select() to find if data ready then read() or write() to transfers. Asynchronous: process runs while I/O executes • I/O subsystem signals process when I/O completed. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 31 / 57
  • 78. Synchronous vs. Asynchronous I/O Methods Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 32 / 57
  • 79. Vectored I/O Vectored I/O allows one system call to perform multiple I/O oper- ations. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 33 / 57
  • 80. Vectored I/O Vectored I/O allows one system call to perform multiple I/O oper- ations. The scatter-gather method is better than multiple individual I/O calls. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 33 / 57
  • 81. Vectored I/O Vectored I/O allows one system call to perform multiple I/O oper- ations. The scatter-gather method is better than multiple individual I/O calls. • Decreases context switching and system call overhead. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 33 / 57
  • 82. Vectored I/O Vectored I/O allows one system call to perform multiple I/O oper- ations. The scatter-gather method is better than multiple individual I/O calls. • Decreases context switching and system call overhead. • Some versions provide atomicity: avoid for example worry about multiple threads changing data as reads/writes occurring. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 33 / 57
  • 83. Vectored I/O Vectored I/O allows one system call to perform multiple I/O oper- ations. The scatter-gather method is better than multiple individual I/O calls. • Decreases context switching and system call overhead. • Some versions provide atomicity: avoid for example worry about multiple threads changing data as reads/writes occurring. For example, Unix readve() accepts a vector of multiple buffers to read into or write from. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 33 / 57
  • 84. Kernel I/O Subsystem Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 34 / 57
  • 85. Kernel I/O Subsystem Kernels provide many services related to I/O: • Scheduling • Buffering • Caching • Spooling • Device reservation • Error handling Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 35 / 57
  • 86. Scheduling (1/2) Determine a good order in which to execute I/O requests. Some I/O request ordering via per-device queue. Some OSs try fairness. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 36 / 57
  • 87. Scheduling (2/2) In asynchronous I/O the kernel must be able to keep track of many I/O requests at the same time. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 37 / 57
  • 88. Scheduling (2/2) In asynchronous I/O the kernel must be able to keep track of many I/O requests at the same time. • The OS attaches the wait queue to a device-status table. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 37 / 57
  • 89. Scheduling (2/2) In asynchronous I/O the kernel must be able to keep track of many I/O requests at the same time. • The OS attaches the wait queue to a device-status table. • The table contains an entry for each I/O device. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 37 / 57
  • 90. Scheduling (2/2) In asynchronous I/O the kernel must be able to keep track of many I/O requests at the same time. • The OS attaches the wait queue to a device-status table. • The table contains an entry for each I/O device. • If the device is busy with a request, the type of request and other parameters will be stored in the table entry for that device. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 37 / 57
  • 91. Buffering and Caching Buffering: stores data in memory while transferring between devices. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 38 / 57
  • 92. Buffering and Caching Buffering: stores data in memory while transferring between devices. • To cope with device speed mismatch. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 38 / 57
  • 93. Buffering and Caching Buffering: stores data in memory while transferring between devices. • To cope with device speed mismatch. • To cope with device transfer size mismatch, e.g., fragmentation and reassembly of messages Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 38 / 57
  • 94. Buffering and Caching Buffering: stores data in memory while transferring between devices. • To cope with device speed mismatch. • To cope with device transfer size mismatch, e.g., fragmentation and reassembly of messages • To maintain copy semantics, e.g., copy semantics Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 38 / 57
  • 95. Buffering and Caching Buffering: stores data in memory while transferring between devices. • To cope with device speed mismatch. • To cope with device transfer size mismatch, e.g., fragmentation and reassembly of messages • To maintain copy semantics, e.g., copy semantics Caching: faster device holding copy of data. • Always just a copy • Key to performance • Sometimes combined with buffering Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 38 / 57
  • 96. Spooling and Device Reservation Spooling: a buffer that holds output for a device. • If device can serve only one request at a time, i.e., printing Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 39 / 57
  • 97. Spooling and Device Reservation Spooling: a buffer that holds output for a device. • If device can serve only one request at a time, i.e., printing Device reservation: provides exclusive access to a device. • System calls for allocation and de-allocation • Watch out for deadlock Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 39 / 57
  • 98. Error Handling OS can recover from disk read, device unavailable, transient write failures Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 40 / 57
  • 99. Error Handling OS can recover from disk read, device unavailable, transient write failures • Retry a read or write. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 40 / 57
  • 100. Error Handling OS can recover from disk read, device unavailable, transient write failures • Retry a read or write. • Track error frequencies, stop using device with increasing frequency of retry-able errors. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 40 / 57
  • 101. Error Handling OS can recover from disk read, device unavailable, transient write failures • Retry a read or write. • Track error frequencies, stop using device with increasing frequency of retry-able errors. Most return an error number or code when I/O request fails. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 40 / 57
  • 102. Error Handling OS can recover from disk read, device unavailable, transient write failures • Retry a read or write. • Track error frequencies, stop using device with increasing frequency of retry-able errors. Most return an error number or code when I/O request fails. System error logs hold problem reports. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 40 / 57
  • 103. I/O Protection User process may accidentally or purposefully attempt to disrupt normal operation via illegal I/O instructions. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 41 / 57
  • 104. I/O 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. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 41 / 57
  • 105. I/O 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. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 41 / 57
  • 106. I/O 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. Memory-mapped and I/O port memory locations must be protected too. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 41 / 57
  • 107. Use of a System Call to Perform I/O Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 42 / 57
  • 108. Kernel Data Structures Kernel keeps state info for I/O components, including open file ta- bles, network connections, character device state Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 43 / 57
  • 109. Kernel Data Structures Kernel keeps state info for I/O components, including open file ta- bles, network connections, character device state Many complex data structures to track buffers, memory allocation, dirty blocks. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 43 / 57
  • 110. Kernel Data Structures Kernel keeps state info for I/O components, including open file ta- bles, network connections, character device state Many complex data structures to track buffers, memory allocation, dirty blocks. Some use object-oriented methods and message passing to imple- ment I/O Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 43 / 57
  • 111. Kernel Data Structures Kernel keeps state info for I/O components, including open file ta- bles, network connections, character device state Many complex data structures to track buffers, memory allocation, dirty blocks. Some use object-oriented methods and message passing to imple- ment I/O E.g., Windows uses message passing. • Message with I/O information passed from user mode into kernel. • Message modified as it flows through to device driver and back to process. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 43 / 57
  • 112. UNIX I/O Kernel Structure Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 44 / 57
  • 113. Transforming I/O Requests to Hardware Operations Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 45 / 57
  • 114. 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 Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 46 / 57
  • 115. Life Cycle of An I/O Request Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 47 / 57
  • 116. STREAMS Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 48 / 57
  • 117. STREAMS (1/2) STREAM: a full-duplex communication channel between a user-level process and a device in Unix System V and beyond. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 49 / 57
  • 118. STREAMS (1/2) STREAM: a full-duplex communication channel between a user-level process and a device in Unix System V and beyond. A STREAM consists of: • STREAM head: interfaces with the user process. • Driver end: interfaces with the device. • Zero or more STREAM modules between them. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 49 / 57
  • 119. STREAMS (2/2) Each module contains a read queue and a write queue. Message passing is used to communicate between queues. Asynchronous internally, synchronous where user process communi- cates with stream head. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 50 / 57
  • 120. Performance Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 51 / 57
  • 121. Performance I/O is a major factor in system performance: • Demands CPU to execute device driver, kernel I/O code • Context switches due to interrupts • Data copying • Network traffic especially stressful Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 52 / 57
  • 122. Inter-computer Communications Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 53 / 57
  • 123. Improving Performance Reduce number of context switches Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 54 / 57
  • 124. Improving Performance Reduce number of context switches Reduce data copying Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 54 / 57
  • 125. Improving Performance Reduce number of context switches Reduce data copying Reduce interrupts by using large transfers, smart controllers, polling Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 54 / 57
  • 126. Improving Performance Reduce number of context switches Reduce data copying Reduce interrupts by using large transfers, smart controllers, polling Use DMA Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 54 / 57
  • 127. Improving Performance Reduce number of context switches Reduce data copying Reduce interrupts by using large transfers, smart controllers, polling Use DMA Use smarter hardware devices Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 54 / 57
  • 128. Improving Performance Reduce number of context switches Reduce data copying Reduce interrupts by using large transfers, smart controllers, polling Use DMA Use smarter hardware devices Balance CPU, memory, bus, and I/O performance for highest throughput Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 54 / 57
  • 129. Improving Performance Reduce number of context switches Reduce data copying Reduce interrupts by using large transfers, smart controllers, polling Use DMA Use smarter hardware devices Balance CPU, memory, bus, and I/O performance for highest throughput Move user-mode processes to kernel Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 54 / 57
  • 130. Summary Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 55 / 57
  • 131. Summary I/O hardware: port, bus, controller Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 56 / 57
  • 132. Summary I/O hardware: port, bus, controller I/O port registers: data-in, data-out, status, control Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 56 / 57
  • 133. Summary I/O hardware: port, bus, controller I/O port registers: data-in, data-out, status, control Host-device interaction: polling, interrupt, DMA Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 56 / 57
  • 134. Summary I/O hardware: port, bus, controller I/O port registers: data-in, data-out, status, control Host-device interaction: polling, interrupt, DMA Devices: char, block, network Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 56 / 57
  • 135. Summary I/O hardware: port, bus, controller I/O port registers: data-in, data-out, status, control Host-device interaction: polling, interrupt, DMA Devices: char, block, network Kernel I/O: schedulling, buffering, caching, spooling, device reser- vation, error handling Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 56 / 57
  • 136. Summary I/O hardware: port, bus, controller I/O port registers: data-in, data-out, status, control Host-device interaction: polling, interrupt, DMA Devices: char, block, network Kernel I/O: schedulling, buffering, caching, spooling, device reser- vation, error handling STREAMS Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 56 / 57
  • 137. Summary I/O hardware: port, bus, controller I/O port registers: data-in, data-out, status, control Host-device interaction: polling, interrupt, DMA Devices: char, block, network Kernel I/O: schedulling, buffering, caching, spooling, device reser- vation, error handling STREAMS Performance Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 56 / 57
  • 138. Questions? Acknowledgements Some slides were derived from Avi Silberschatz slides. Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 57 / 57