Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers.

Similar presentations


Presentation on theme: "1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers."— Presentation transcript:

1 1 Today I/O Systems Storage

2 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers

3 3 Connection to CPU Devices connect to ports or system bus: Allows devices to communicate w/CPU Controller: electronics to operate a port, bus or device Communication between controller & CPU: Ports (programmed I/O) Direct-Memory Access (DMA)

4 4 Ports (a.k.a. Programmed I/O) CPU gives command/data to controller through registers 4 registers Status indicates device busy, data ready, error Control indicates command to perform Data-in read by CPU to get input from device Data-out written by CPU to device Handshaking between CPU & controller Controller: clear busy bit (status) for new command CPU: set command-ready bit (command)

5 5 Polling: An Example CPU wants to write a byte to a device CPU: Busy-wait until status = idle Set command-ready bit, write to data-out register Controller: Reads command register set status = busy Read from data-out register, does I/O to device Change status to idle or error

6 6 Interrupts Avoids busy waiting Device interrupts CPU when I/O operation is complete CPU detects interrupt (sense interrupt-request line) after each instruction On interrupt: Determine which device caused interrupt Interrupt vector to dispatch interrupt to correct handler

7 7 Interrupt-driven I/O Cycle

8 8 DMA Ports (“programmed I/O”) Fine for small amounts of data, low-speed Too expensive for large data transfers! Solution: Direct Memory Access (DMA) Offload CPU large data transfers by a special- purpose processor (DMA handler) DMA interrupts CPU when entire transfer complete

9 9 Steps in DMA Transfer CPU writes a DMA command block into memory Pointer to source, destination, # of bytes for the transfer CPU writes address of command block to DMA controller DMA controller directly performs transfer without help from CPU Handshaking between DMA controller & device controller DMA interrupts CPU when entire transfer complete

10 10 I/O – Outline I/O Systems I/O hardware basics I/O Services Buffering & Caching

11 11 Low-Level Device Characteristics Transfer unit: character, block Access method: sequential, random Sharing: dedicated, sharable (by multiple threads/processes) Speed: a few bytes to gigabytes per second I/O direction: read-only, write-only, read-write Examples: terminal, CD-ROM, modem, keyboard, tape, graphics controller

12 12 Application I/O Interface High-level abstractions to hide device details Block devices (read, write, seek) Also memory-mapped File abstraction Character-stream devices (get, put) Keyboard, printers, etc. Network devices (socket connections) Blocking & non-blocking Blocking: wait until operation completes Non-blocking: returns immediately (or after timeout) with whatever data is available (none, some, all)

13 13 I/O – Outline I/O Systems I/O hardware basics Services provided by OS Buffering & Caching

14 14 I/O Buffering Buffer = memory area to store data temporarily Disk buffer: stores block when read from disk DMA: transferred over bus by DMA controller into buffer in physical memory

15 15 Why Buffering? Speed mismatches between device, CPU Compute contents of display in buffer (slow), send buffer to screen (fast) Different data transfer sizes ftp brings file over network one packet at a time, stores to disk one block at a time Minimizes time user process blocks on write Copy data to kernel buffer, return to user Kernel: writes from buffer to disk at later time

16 16 Caching Cache: region of fast memory that holds copy of data Example: CPU cache, TLB Cache write policies Write-through Write to memory & disk (high reliability) Write-back Write only to memory (committing later) Trade-off between speed & reliability

17 17 I/O Summary I/O expensive for several reasons: Slow devices & slow communication links Contention from multiple processes Approaches to improving performance: Caching – reduces data copying Reduce interrupt frequency via large data transfers DMA controllers – offload computation from CPU

18 18 Storage Goal: Improve performance of storage systems (i.e., the disk) Disk Head Scheduling

19 19 Disk Operations Disks are SLOW! 1 disk seek = 40,000,000 cycles Latency: Seek – position head over track/cylinder Rotational delay – time for sector to rotate underneath head Bandwidth: Transfer time – move bytes from disk to memory

20 20 Calculating Disk Operations Time Read/write n bytes: Can’t reduce transfer time Can we reduce latency? I/O time = seek + rotational delay + transfer(n)

21 21 Reducing Latency Minimize seek time & rotational latency: Smaller disks Faster disks Sector size tradeoff Scheduling

22 22 Disk Head Scheduling Schedule order of disk accesses Reduce length & number of seeks Algorithms FCFS SSTF SCAN, C-SCAN LOOK, C-LOOK

23 23 FCFS First-come, first-serve Example: disk tracks – (65, 40, 18, 78) assume head at track 50 Total seek time? 15+25+22+60 = 122 651878 40 disk I/O time = seek + rotational delay + transfer(n)

24 24 SSTF Shortest-seek-time first (like SJF) Example: disk tracks – (65, 40, 18, 78) assume head at track 50 Total seek time? 10+22+47+13 = 92 Is this optimal? 651878 40 disk I/O time = seek + rotational delay + transfer(n)

25 25 SCAN Always move back and forth across disk a.k.a. elevator Example: disk tracks – (65, 40, 18, 78) assume head at track 50, moving forwards, total 100 cylinders Total seek time? 15+13+22+60+22=132 When is this good? 651878 40 disk I/O time = seek + rotational delay + transfer(n)

26 26 C-SCAN Circular SCAN: Go back to start of disk after reaching end Example: disk tracks – (65, 40, 18, 78) assume head at track 50, moving forwards, total 100 cylinders Total seek time? 15+13+22+100+18+22=190 Can be expensive, but more fair 651878 40 disk I/O time = seek + rotational delay + transfer(n)

27 27 LOOK variants Instead of going to end of disk, go to last request in each direction SCAN, C-SCAN → LOOK, C-LOOK

28 28 Exercises 200 cylinders, currently at 140, moving forwards (5, 15, 90, 180, 80, 10 ) FCFS SSTF SCAN LOOK C-SCAN C-LOOK Find sequence & total seek time First = 0, last = 200

29 29 Solutions


Download ppt "1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers."

Similar presentations


Ads by Google