Principles of Input and Output Devices
Principles of Input and Output Devices
Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze
Copyright Notice
© 2000-2005 David A. Solomon and Mark Russinovich
2
Roadmap for Section 6.1
3
Input/Output –
Principles of I/O Hardware
Major components of a computer system:
CPU, memories (primary/secondary), I/O system
I/O devices:
Block devices – store information in fixed-sized blocks;
typical sizes: 128-1024 bytes
Character devices – delivers/accepts stream of characters
Device controllers:
Connects physical device to system bus (Minicomputers, PCs)
Mainframes use a more complex model:
Multiple buses and specialized I/O computers (I/O channels)
Communication:
Memory-mapped I/O, controller registers
Direct Memory Access - DMA
4
I/O Hardware - Single Bus
Monitor Keyboard Floppy Disk
drive drive
System bus
5
I/O Hardware - Multiple Buses
Memory bus SCSI disk
SCSI bus
Video Network SCSI
controller controller controller
PCI bus
IDE disk USB
controller interface
keyboard mouse
USB bus
6
Diversity among I/O Devices
The I/O subsystem has to consider device characteristics:
Data rate:
may vary by several orders of magnitude
Complexity of control:
exclusive vs. shared devices
Unit of transfer:
stream of bytes vs. block-I/O
Data representations:
character encoding, error codes, parity conventions
Error conditions:
consequences, range of responses
Applications:
impact on resource scheduling, buffering schemes
7
Organization of the I/O Function
8
Flow of a blocking I/O request
Thread issues blocking read() 6. Driver may poll for status and
system call data; or set up DMA that will
generate interrupt
Kernel checks parameters; may
return buffered data and finish 7. Interrupt occurs; handler stores
data; signals device driver
Thread is removed from run
queue if physical I/O required; 8. Device driver receives signal;
added to wait queue for device; determines request status;
I/O request is scheduled signals kernel I/O subsystem
Device driver allocates kernel 9. Kernel transfers data or return
buffer; sends command to code to user space; removes
controller thread from wait queue
Device controller operates the 10. Thread resumes execution at
hardware to perform data transfer completion of read() call
9
Principles of I/O Software
Layered organization Structuring of
I/O software
Device independence
1. User-level software
2. Device-independent
Error handling OS software
Error should be handled as close to the 3. Device drivers
hardware as possible 4. Interrupt handlers
Transparent error recovery at low level
Synchronous vs. Asynchronous transfers
Most physical I/O is asynchronous
Kernel may provide synchronous I/O system
calls
Sharable vs. dedicated devices
Disk vs. printer
10
Interrupt Handlers
11
Device Driver
12
Device-independent I/O Software
13
Layers of the I/O System
User-Space I/O Software
System call libraries
I/O I/O
(read, write,...)
request reply
Spooling Layer I/O functions
Managing dedicated I/O I/O calls, spooling
devices in a User process
format I/O
multiprogramming system Device-independent Naming, protection
Daemon process, software buffering, blocking
spooling directory Setup registers,
Device drivers
lpd – line printer daemon, Check status
sendmail – simple mail Interrupt handlers Wakeup driver
transfer protocol Hardware Perform I/O op.
14
Application I/O Interfaces
Character-stream or block
Sequential or random-access
Synchronous or asynchronous
Sharable or dedicated
Speed of operation
Read/write, read only, write only
15
Example:
4.3 BSD kernel I/O structure
Network
interface Block-device driver character-device driver
The hardware
16
Further Reading
17