Introduction • One OS function is to control devices – significant fraction of code (80-90% of Linux) • Want all devices to be simple to use – convenient Operating Systems – ex: stdin/stdout , pipe, re-direct • Want to optimize access to device – efficient Input/Output Devices – devices have very different needs (Ch 5: 5.1-5.5) Outline Hardware • Device controllers • Introduction (done) • Types of I/O devices ← ← • Hardware • Direct Memory Access (DMA) • Software • Specific Devices – Hard disk drives – Clocks Device Controllers I/O Device Types • Mechanical and electronic component • block - access is independent – ex- disk The quick brown fox jumped over the lazy dogs. The Mechanical • character - access is serial quick brown fox... – ex- printer, network Disk Printer Controller Controller Electronic CPU Memory • other – ex- clocks (just generate interrupts) System bus • OS deals with electronic – device controller 1
Direct Memory Access (DMA) Outline • Very Old – Controller reads from device • Introduction (done) – OS polls controller for data • Old • Hardware (done) ← ← – Controller reads from device • Software – Controller interrupts OS • Specific Devices – OS copies data to memory • DMA – Hard disk drives – Clocks – Controller reads from device – Terminals – Controller copies data to memory – Controller interrupts OS Interrupt Handlers I/O Software Structure CPU I/O Controller • Layered User Level Software 1) Device driver initiates 1) Initiates I/O Device Independent I/O (I/O device processing Software (CPU executing, request) checking for interrupts Device Drivers 2) I/O complete. between instructions) Generate interrupt. 3) Receives interrupt, Interrupt Handlers transfer to handler 4) Handler processes Hardware ( Resume processing) (Talk from bottom up) Device Drivers Interrupt Handler • Device dependent code • Make interrupt handler as small as possible – includes interrupt handler – interrupts disabled • Accept abstract requests – Split into two pieces – ex: “read block n ” • First part does minimal amount of work • See that they are executed by device hardware – defer rest until later in the rest of the device driver – registers – Windows: “deferred procedure call” (DPC) – hardware commands – Linux: “top-half” handler • After error check • Second part does most of work • Implementation specific – pass data to device-independent software – 3rd party vendors 2
Device-Independent I/O Software User-Space I/O Software • Much driver code independent of device • Ex: count = write(fd, buffer, bytes); • Exact boundary is system-dependent • Put parameters in place for system call – sometimes inside for efficiency • Can do more: formatting • Perform I/O functions common to all devices – printf(), gets() • Examples: • Spooling – naming protection block size – spool directory, daemon – buffering storage allocation error reporting – ex: printing, USENET I/O System Summary Outline I/O Reply Make I/O call; Format I/O; • Introduction User Processes (done) Spooling I/O Request Device Independent Naming, protection, • Hardware (done) Software blocking, buffering, allocation • Software (done) ← ← Setup device registers; • Specific Devices Device Drivers check status – Hard disk drives Wakeup driver when – Clocks Interrupt Handlers I/O completed Hardware Perform I/O operation HDD - Zoom Hard Disk Drives (HDD) – Platters • Controller + 3000-10,000 RPM (floppy 360 RPM) often on disk – Tracks • Cache to – Cylinders speed access – Sectors Ex: hdb: Conner Peripherals 540MB CFS540A, 516MB w/64kB Cache, CHS=1050/16/63 – 1050 cylinders (tracks), 16 heads (8 platters), 63 sectors per track • Disk Arms all move together • If multiple drives – overlapping seeks but one read/write at a time 3
Disk Arm Scheduling First-Come First-Served (FCFS) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 • Read time: x x x x x x x – seek time (arm to cylinder) – rotational delay (time for sector under head) Time – transfer time (take bits off disk) • Seek time dominates • 14+13+2+6+3+12+3=53 • How does disk arm scheduling affect seek? • Service requests in order that they arrive • Little can be done to optimize • What if many requests? Shortest Seek First (SSF) Elevator (SCAN) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 x x x x x x x x x x x x x x Time Time • 1+2+6+3+2+17 = 31 • Usually, a little worse avg seek time than SSF • 1+2+6+9+3+2 = 23 – But avoids more fair, avoids starvation • Suppose many requests? • C-SCAN has less variance – Stay in middle • Note, seek getting faster, rotational not – Starvation! – Someday, change algorithms Redundant Array of Inexpensive Error Handling Disks (RAID) • Common errors: – programming error (non-existent sector) CPU – transient checksum error (dust on head) – permanent checksum error (bad block) • For speed – seek error (arm went to wrong cylinder) – Pull data in parallel – controller error (controller refuses command) • For fault-tolerance – Example: 38 disks, form 32 bit word, 6 check bits – Example: 2 disks, have exact copy on one disk 4
Clock Hardware Clock Software Uses • Time of day to time quantum • time of day – 64-bit, in seconds, or relative to boot Pulse from 5 to 300 MHz • interrupt after quantum • accounting of CPU usage Crystal Oscillator Decrement counter – separate timer or pointer to PCB when == 0 - generate interrupt • alarm() system calls – separate clock or linked list of alarms with ticks Holding register to load counter Can control clock ticks 5
Recommend
More recommend