i/o devices. characteristics of i/o devices block devices information are stored and accessed in...

29
I/O Devices

Upload: randolf-dean

Post on 29-Jan-2016

255 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: I/O Devices. Characteristics of I/O Devices  Block Devices  Information are stored and accessed in fixed-size blocks  Addressable, can have sequential

I/O Devices

Page 2: I/O Devices. Characteristics of I/O Devices  Block Devices  Information are stored and accessed in fixed-size blocks  Addressable, can have sequential

Characteristics of I/O Devices

Block Devices Information are stored and accessed in fixed-size blocks Addressable, can have sequential or random accesses E.g., disks

Character Devices Can only be accessed character by character Sequential accesses only E.g., terminals, printers, mouse

Page 3: I/O Devices. Characteristics of I/O Devices  Block Devices  Information are stored and accessed in fixed-size blocks  Addressable, can have sequential

I/O Communication Techniques

General Cycle CPU issues an I/O request to a device controller

I/O AR is used to address the I/O moduleWait for the operation to complete

How to know whether the operation is completed Read from or write to I/O module

Where to fetch or store I/O data

Various Techniques Programmed I/O Interrupt-Driven I/O Direct Memory Access Memory Mapped I/O

I/O BR- Used by some I/O

Page 4: I/O Devices. Characteristics of I/O Devices  Block Devices  Information are stored and accessed in fixed-size blocks  Addressable, can have sequential

I/O Cycle – CPU’s RollCPU starts I/O- This is for read op

CPU periodically checks whether I/O has completed- No interrupt

I/O device has put the info in I/O BRCPU take it from I/O BR and put it in memory

CPU after initiating I/O, just “ignores” itI/O device interrupts when completes- Used in current systems- The rest is the same

Not only uses interrupt, but also uses DMA- Direct memory access- Previous schemes for block I/O

CPU takes the input word by word Too much work for CPU

- I/O device directly put input in memory- Interrupt after I/O fully completes- E.g., disk I/O are handled this way

DMA and cycle stealing- Single bus: DMA-MM and CPU-MM share the same bus- DMA needs the bus to put the input in memory (or take the output from memory) while CPU continues to use it- I/O device needs to steal cycles from CPU- Bus supports cycle stealing and will give I/O priority

Page 5: I/O Devices. Characteristics of I/O Devices  Block Devices  Information are stored and accessed in fixed-size blocks  Addressable, can have sequential

I/O Communication Techniques

Programmed I/O CPU cycles are wasted to keep on checking I/O status

Interrupt-Driven I/O CPU can do useful work while I/O is in operation For each data transfer (word by word), the CPU need to

intervene Data transfer from I/O module to CPU then to memory (for

read, vice versa for write) the interrupt handling cost is still high

Page 6: I/O Devices. Characteristics of I/O Devices  Block Devices  Information are stored and accessed in fixed-size blocks  Addressable, can have sequential

I/O Communication Techniques

Direct Memory Access Need to support “cycle stealing”CPU gets interrupted at the end of the entire data transfers,

but not each data transfer Most suitable for block devices

Memory Mapped I/OEach controller has fixed registers and these registers are

part of memory address space CPU writes to registers the access command and

parameters When I/O is done the results are stored in the registers Can be used for character devices

Page 7: I/O Devices. Characteristics of I/O Devices  Block Devices  Information are stored and accessed in fixed-size blocks  Addressable, can have sequential

Devices

Disk DeviceBlock device, block I/O

Keyboard and displaysCharacter device, stream I/O

Clock deviceCharacter device

Page 8: I/O Devices. Characteristics of I/O Devices  Block Devices  Information are stored and accessed in fixed-size blocks  Addressable, can have sequential

Disk Device

Disk Hardware Tracks and sectors

A disk has many tracks Each track contains many sections

– Some has fixed number of sectors per track

– Some has variant number of sectors per track (Zoned)

Disk is accessed by sectors (corresponding to blocks)

Platters Some disk system has multiple disk platters

Cylinders The same track on multiple disk platters form a cylinder

Page 9: I/O Devices. Characteristics of I/O Devices  Block Devices  Information are stored and accessed in fixed-size blocks  Addressable, can have sequential

Sample Disk DeviceA platter of a 5.25" hard disk- 20 tracks-16 sectors per track- 512 bytes per sector- ECC for each sector

Page 10: I/O Devices. Characteristics of I/O Devices  Block Devices  Information are stored and accessed in fixed-size blocks  Addressable, can have sequential

Sample Disk DeviceProblem in large sized disks- Internal tracks and external tracks have very different sizes- cannot divide each track to same number of sectorsZoned bit recording- Divide the disk to different zones- Have the same number of sector in each zoneThis sample disk- Has 20 tracks- Divided into five zones- The outermost blue zone has 5 tracks, each has 16 sectors- The innermost red zone has 3 tracks of 9 sectors- The sizes of the sectors are fairly uniform

Page 11: I/O Devices. Characteristics of I/O Devices  Block Devices  Information are stored and accessed in fixed-size blocks  Addressable, can have sequential

Sample Disk Device

Zone Tracks in ZoneSectors Per

TrackData Transfer Rate

(Mbits/s)

0 624 792 372.0

1 1,424 780 366.4

2 1,680 760 357.0

3 1,616 740 347.6

4 2,752 720 338.2

5 2,880 680 319.4

6 1,904 660 310.0

7 2,384 630 295.9

8 3,328 600 281.8

9 4,432 540 253.6

10 4,528 480 225.5

11 2,192 440 206.7

12 1,600 420 197.3

13 1,168 400 187.9

14 18,15 370 173.8

Sample disk format data- 20 GB disk platter- Zones, tracks, sectors

Page 12: I/O Devices. Characteristics of I/O Devices  Block Devices  Information are stored and accessed in fixed-size blocks  Addressable, can have sequential

Disk Device

How to read/write diskDisk head (disk arm) moves to the correct trackDisk rotates to the correct sector

Disk rotates constantly

Fixed head versus movable headMost disks have movable headFixed head has one head per track

Single/double sidedSingle/multiple platter(s)

Page 13: I/O Devices. Characteristics of I/O Devices  Block Devices  Information are stored and accessed in fixed-size blocks  Addressable, can have sequential

Sample Disk Device

8 tracks per cylinder- Double sided disk

Page 14: I/O Devices. Characteristics of I/O Devices  Block Devices  Information are stored and accessed in fixed-size blocks  Addressable, can have sequential

Disk Device

Disk AddressingOnly address the sectors, no need for offset within a sectorOld style: physical address

Addressed by: (platter #, track #, sector #) BIOS limitation: only address up to 65536 tracks

New addressing scheme: logical address Number the sectors contiguously 28 bits are used to address the sector number Still can only address 128GB disk

Page 15: I/O Devices. Characteristics of I/O Devices  Block Devices  Information are stored and accessed in fixed-size blocks  Addressable, can have sequential

Disk Device

On each sectorSync: some fixed bytes to indicate the starting of a sector

Otherwise, how to recognize the sectors on a disk

ID: sector address (e.g., volume #, sector #, etc.)Data: always 512B (up to now)ECC codeGap: to separate important fields

Page 16: I/O Devices. Characteristics of I/O Devices  Block Devices  Information are stored and accessed in fixed-size blocks  Addressable, can have sequential

Disk Access Time

Seek Time - disk head moves to proper track Ts = nm + s

n: number of tracks to be traversed m: traverse time per track s: start up time

Generally, the average seek time is given

Rotational Delay - rotate to proper sectorTr: determined by the revolutionary speed

Consider a 3600 rpm diskOne revolution takes 16.7msec Average rotational delay = 1/2 revolution = 8.3msec

Page 17: I/O Devices. Characteristics of I/O Devices  Block Devices  Information are stored and accessed in fixed-size blocks  Addressable, can have sequential

Disk Access Time

Transfer Time - transfer data Tt= r * (b / N)

b: number of bytes to be transferred N: number of bytes per track r: rotation speed

Total access time= Ts + Tr + Tt

Page 18: I/O Devices. Characteristics of I/O Devices  Block Devices  Information are stored and accessed in fixed-size blocks  Addressable, can have sequential

Disk Access Time (Example)

Disk spec512 bytes per sector256 sectors per track 3600 rpmTraverse time per track = 1 msec Startup time = 3msec

Read a fileFile size: 1MBConsecutively allocatedStarting track = 15Current track = 5

Rotational delay:3600 rpm 60 rps 1/60 sec per revolution 16.7 msec per revolutionRotational delay = 1/2 revolution time= 8.3msec

Transfer rate:Transfer a track in 16.7 msec256 sectors/track, 0.5KB/sector Transfer 128KB per 16.7msec1MB file requires 8 tracksTransfer time = 16.7 * 8= 133.6 msec

Seek time= (155)*1ms + 3ms= 13 msec Total time required

= 13 + 8.3 + 133.6 msec= 154.9 msec

Page 19: I/O Devices. Characteristics of I/O Devices  Block Devices  Information are stored and accessed in fixed-size blocks  Addressable, can have sequential

Disk Access Time (Example)

Disk spec512 bytes per sector256 sectors per track 7200 rpmAverage seek time = 10 msec

Read a fileFile size: 1MBDynamically allocated

Rotational delay:7200 rpm 120 rps 1/120 sec per revolution 8.3 msec per revolutionRotational delay = 4.2 msec

Transfer rate:Transfer a track in 8.3 msecOne sector requires 8.3 / 256 msec= 32.4 sec per 512 bytes

Total time required= (10 + 4.2 + 0.032) * 2048= 29081 msec = 29 sec

Page 20: I/O Devices. Characteristics of I/O Devices  Block Devices  Information are stored and accessed in fixed-size blocks  Addressable, can have sequential

Disk Access Time Samples

Series Seagate U6Maxtor

DiamondMaxVL40

WesternDigital

WDx00AB

Formatted Capacity(GB)

80/60/40 40/30/20/10 80/60/40/30

Internal Transfer Rate(max) (Mbits/sec)

436 374 424

Average Seek Time,Read (ms)

8.9 9.5 9.5

Track-to-Track Seek,Read (ms)

1.2 1.0 2.0

Average Latency (ms) 5.55 5.55 5.0

Buffer Size 2 MB 2 MBs 2 MB

Spindle Speed (RPM) 5400 5400 5400

Page 21: I/O Devices. Characteristics of I/O Devices  Block Devices  Information are stored and accessed in fixed-size blocks  Addressable, can have sequential

OS Issues for Disk Devices

Disk Allocation Strategies Allocation for files Try to put data blocks of a file close together

To avoid additional seek time and rotational delay

Discussed with the file systems

Disk-arm Scheduling Algorithms Try to read closest track next

To reduce seek time

Page 22: I/O Devices. Characteristics of I/O Devices  Block Devices  Information are stored and accessed in fixed-size blocks  Addressable, can have sequential

Disk-arm Scheduling Algroithms

First-Come-First-Served simple, but less efficient

Scan Serve the request closest to current track toward the current

arm direction C-Scan

Always consider forward direction of arm movement FScan

Problem in other Scan algorithms: Arm-stickiness (starvation problem)

Use two queues, when one queue is served, all new requests go to the other queue

Page 23: I/O Devices. Characteristics of I/O Devices  Block Devices  Information are stored and accessed in fixed-size blocks  Addressable, can have sequential

Disk-arm Scheduling Algroithms

Consider the scenarioRequest sequence: 5, 102, 95, 102, 210, 80, 45, 200, 105Current arm location: 90 with forward direction

First-Come-First-Served 90 – 5 – 102 – 210 – 80 – 45 – 200 – 105Total tracks traversed: 85+97+108+130+35+155+95 =705

Scan 90 – 95 – 102 – 102 – 105 – 200 – 210 – 80 – 45 – 5 Total tracks traversed: 90 --- 210 --- 5 = 325

C-Scan90 – 95 – 102 – 102 – 105 – 200 – 210 – 5 – 45 – 80 Total tracks traversed: 90 --- 210 --- 5 --- 80 = 400

Page 24: I/O Devices. Characteristics of I/O Devices  Block Devices  Information are stored and accessed in fixed-size blocks  Addressable, can have sequential

Clock Device

Clock deviceHold register

Every clock has a different speed (quartz oscillation) Hold register holds the count = # oscillations per unit time

Counter At the beginning of each time unit, set to hold register Decremented the counter When counter = 0, generate an interrupt signal

Each interrupt period is called a clock tick

Page 25: I/O Devices. Characteristics of I/O Devices  Block Devices  Information are stored and accessed in fixed-size blocks  Addressable, can have sequential

Clock Device

Clock deviceClock register

At each clock tick, increase the clock value Consists of 2 words Record time since 1/1/1970, in # seconds Another register to keep finer readings

Clock device Keep track of time Provide alarm service Every clock tick Check whether any alarm is up User or OS can “setTimer”

Page 26: I/O Devices. Characteristics of I/O Devices  Block Devices  Information are stored and accessed in fixed-size blocks  Addressable, can have sequential

Clock Device

Alarm service by OSOS maintain a list of timer requests

Requests from OS and users E.g., refresh monitor every 1/30 seconds E.g., CPU time quantum expiration E.g., sleep (5)

List is in sorted orderEach entry:

Time is kept in terms of # clock ticks from previous entry

First entry is copied to a register The register decremented at every clock tickWhen the register = 0, an timer interrupt is generated

Page 27: I/O Devices. Characteristics of I/O Devices  Block Devices  Information are stored and accessed in fixed-size blocks  Addressable, can have sequential

Timer Requests Example

Example:Each clock tick = 1 secCurrent time: 15:59:59 and 999850 secCurrent request and list of requests as follows

Requests Next time quantum: 100 sec after, issued at current time User request: usleep (35), set at 3 time units after User request: alarm at 16:00 exact, set at the same time as above

– Convert: 147 sec after

10

Current timer

5 15 10

List of timers

8

27 60 50

Page 28: I/O Devices. Characteristics of I/O Devices  Block Devices  Information are stored and accessed in fixed-size blocks  Addressable, can have sequential

Terminal Device

Include keyboard and displayUse RS-232 protocol transmits 1-bit at a time Transmission rate: 1.2-19.2Kbps

CPU gets interrupted for every character typedEcho whatever being typedOverhead for CPU

New intelligent terminal system directly route the typed character from keyboard to monitor

CPU only gets interrupted after the <return>

Page 29: I/O Devices. Characteristics of I/O Devices  Block Devices  Information are stored and accessed in fixed-size blocks  Addressable, can have sequential

Readings

Sections 11.1-11.2, 11.5Section 1.7