Download I/O Subsystem: An Overview of Input/Output Operations in Computer Systems - Prof. Michael and more Study notes Operating Systems in PDF only on Docsity! 1 CMSC 412 Fall 2005 I/O Subsystem Announcements • Reading – Chapter 13 • Project 5 due Friday, 6pm • Project 6 posted Friday – On I/O (stdin, stdout, message passing) 2 A Typical PC Bus Structure I/O Hardware • I/O instructions control devices • Devices have addresses, used by – Direct I/O instructions •inb, outb on Intel x86 – Memory-mapped I/O • Device registers to communicate with device – Status register, Command register, Data- in register, Data-out register, etc.
Interrupt-Driven |
/0 Cycle
1
vice driver nates VO
—
(CPU executing checks for
interrupts between instructions
¥
PN
TO controler
Intiates VO
2
(CPU recehving interrupt,
transfers contro to
Interrupt handler
Interrupt handler
processes dat
(CPU resumes
processing of
Interrupted task
input ready, output
complete, or eror
‘generates interrupt signal
Intel Pentium Processor
Event-Vector Table
vector number description
0 divide error
1 debug exception
2 null interrupt
3 breakpoint
4 INTO-detected overflow
5 bound range exception
6 invalid opcode
7 device not available
8 double fault
9 ‘coprocessor segment overrun (reserved)
10 invalid task state segment
1" segment not present
12 stack fault
13 general protection
14 page fault
15 (Intel reserved, do not use)
16 floating-point error
17 alignment check
18 machine check
19831 (Intel reserved, do not use)
326255 maskable interrupts
6 Direct Memory Access (DMA) • Used to avoid programmed I/O for large data movement • Requires DMA controller – Shepherds the data transfer rather than the CPU – Uses the memory bus, preventing the CPU from using it Six Step Process to Perform DMA Transfer 7 Coping with Many Devices • Devices vary in many dimensions – Character-stream or block – Sequential or random-access – Sharable or dedicated – Speed of operation – read-write, read only, or write only • May have multiple devices of the same type (e.g. two serial ports, two disks) Characteristics of I/O Devices 10 UNIX I/O Kernel Structure System Call Layer • Another abstraction boundary – Hides differences in device APIs from user application. • Example: read() system call – Can perform on a file, a network socket, a message queue (pipe), a keyboard, … – Some of these are block-oriented, some are character-oriented. I/O subsystem hides that fact from user 11 Block and Character Devices • Block devices include disk drives – Commands include read, write, seek – Raw I/O or file-system access – Memory-mapped file access possible • Character devices include keyboards, mice, serial ports – Commands include get, put – Libraries layered on top allow line editing Network Devices • Varying enough from block and character to have own interface • Unix and Windows NT/9i/2000 include socket interface – Separates network protocol from network operation • Implementation approaches vary widely (pipes, FIFOs, streams, queues, mailboxes) 12 Clocks and Timers • Provide current time, elapsed time, timer • If programmable interval time used for timings, periodic interrupts • ioctl (on UNIX) covers odd aspects of I/O such as clocks and timers Blocking and Nonblocking I/O • Blocking - process suspended until I/O completed – Easy to use and understand – Inhibits application-level concurrency • Nonblocking - I/O call returns as much data as is available, fails, etc. – Returns count of bytes read or written – select() system call to poll • Used to implement user-level multi-threading 15 Error Handling • OS can recover from disk read, device unavailable, transient write failures • Most return an error number or code when I/O request fails • System error logs hold problem reports 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 16 Life Cycle of An I/O Request Performance • I/O 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 17 Intercomputer Communications Improving Performance • Reduce number of context switches • Reduce data copying • Reduce interrupts by using large transfers, smart controllers, polling • Use DMA • Balance CPU, memory, bus, and I/O performance for highest throughput