chapter 11 i/o processingcs325/osp_11.pdfchapter 11 i/o processing 11.1 basic issues in device...

34
Betriebssysteme ws2000/2001 Prof. H. D. Clausen 1 S 2004 CS 325 1 Chapter Chapter 11 I/O Processing 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers Memory-Mapped vs Explicit Device Interfaces Programmed I/O with Polling Programmed I/O with Interrupts Direct Memory Access (DMA) 11.5 Device Management Buffering Error Handling Disk Scheduling Device Sharing 11.6 The Abstract I/O Interface S 2004 CS 325 2 Metric Units Metric Units Prefix Exponent (10^n) ======================== Milli -3 Micro -6 Nano -9 Pico -12 Femto -15 Atto -18 Zepto -21 Yocto -24 Prefix Exponent (10^n) ======================== Kilo 3 Mega 6 Giga 9 Tera 12 Peta 15 Exa 18 Zetta 21 Yotta 24

Upload: others

Post on 22-Jun-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 1

S 2004 CS 325 1

ChapterChapter 11 I/O Processing11 I/O Processing11.1 Basic Issues in Device Management11.2 A Hierarchical Model11.3 I/O Devices11.4 Device Drivers

– Memory-Mapped vs Explicit Device Interfaces – Programmed I/O with Polling – Programmed I/O with Interrupts – Direct Memory Access (DMA)

11.5 Device Management– Buffering– Error Handling – Disk Scheduling – Device Sharing

11.6 The Abstract I/O Interface

S 2004 CS 325 2

Metric UnitsMetric Units

Prefix Exponent (10^n)========================Milli -3Micro -6Nano -9Pico -12Femto -15Atto -18Zepto -21Yocto -24

Prefix Exponent (10^n)========================Kilo 3Mega 6Giga 9Tera 12Peta 15Exa 18Zetta 21Yotta 24

Page 2: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 2

S 2004 CS 325 3

Basic issuesBasic issues

• I/O devices:– communication devices

* input only (keyboard, mouse, joystick)

* output only (printer, display)

* input/output (network card)

– storage devices

* input/output (disk, tape)

* input only (CD-ROM)

S 2004 CS 325 4

Basic issuesBasic issues

• main tasks of I/O system:– present logical (abstract) view of devices

* hide details of hardware interface

* hide error handling

– facilitate efficient use

* overlap CPU and I/O

– support sharing of devices

* protection when device is shared (disk)

* scheduling when exclusive access needed (printer)

Page 3: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 3

S 2004 CS 325 5

S 2004 CS 325 6

A hierarchical model of I/OA hierarchical model of I/O

Figure 11-1• abstract I/O interface

– block devices, character devices, network

• device-independent software– buffering, scheduling, caching

• device-dependent software– I/O drivers (supplied by device manufacturer)

Page 4: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 4

S 2004 CS 325 7

Hierarchical Model of I/O SystemHierarchical Model of I/O System

Device Driver

Device-IndependentI/O Software

Hardware

S 2004 CS 325 8

I/O devicesI/O devices

• display monitors– character or graphics oriented

Figure 11-2

– different data rates:

* 25 x 80 characters vs 800 x 600 x 256

* 30-60 times/sec

Page 5: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 5

S 2004 CS 325 9

I/O devicesI/O devices

• keyboards– most common: QWERTY

– very low data rate (<10 char/sec)

• pointing devices– mouse (optical, optical-mechanical)

– trackball

– joystick

– low data rate (hundreds of bytes/sec)

S 2004 CS 325 10

I/O devicesI/O devices

• printers– line printers, dot-matrix, ink-jet, laser

– low data rates

– character-oriented

• scanners– digitize picture into bit map (similar to video RAM)

– low data rates

Page 6: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 6

S 2004 CS 325 11

I/O devicesI/O devices

• (floppy) disks– surface, tracks/surface, sectors/track, bytes/sector

– all sectors numbered sequentially 0..(n-1): logical disk

Figure 11-3 (a,b)

S 2004 CS 325 12

track 0

track 1

track 2

0

0

0

0

1

1

1

1

22

22

33

33

17

17

17

17

Fig. 11-3: disk numbering(a) physical

Page 7: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 7

S 2004 CS 325 13

track 0

track 1

track 2

54

36

18

0

55

37

19

1

5638

202

5

4

213

71

53

35

17

Fig. 11-3: disk numbering(b) logical

22

23

39

40

41

57

58

S 2004 CS 325 14

I/O devicesI/O devices

• floppy disks– track skew

* account for seek to next track to minimize latency

Figure 11-3 (c)– double-sided floppy

* tracks with same diameter: cylinder

* number all sector within cylinder consecutively to minimize seek

Figure 11-3 (d)

Page 8: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 8

S 2004 CS 325 15

track 0

track 1

track 2

69

52

35

0

70

53

18

1

7136

192

5

4

203

68

51

34

17

21

22

37

38

39

54

55

Fig. 11-3: disk numbering(c) with track skew

S 2004 CS 325 16

track 0

track 1

track 2

88/106

53/71

0/18

89/10736/54

1/19

37/552/20

4/22

38/56

3/21

122/140

87/105

52/70

17/35

39/57

Fig. 11-3: disk numbering(d) double sided

Page 9: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 9

S 2004 CS 325 17

I/O devicesI/O devices• hard disks

– multiple surfaces

Figure 11-4– higher densities and data rates than floppy

floppy hard disk

bytes/sec 512 512-4096

sec/track 9, 15, 18, 36 100-400

tracks/surf 40, 80, 160 1000-10,000

# surf 1-2 2-24

seek 30-100 ms 5-12 ms

rotation 400-700 rpm 3600-10,000 rpm

S 2004 CS 325 18

Page 10: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 10

S 2004 CS 325 19

track 0Fig. 11-4: organization of a hard disk

S 2004 CS 325 20

I/O devicesI/O devices

• optical disks

– CD-ROM, CD-R (WORM), CD-RW

– originally designed for music

– data stored as continuous spiral, subdivided into sectors

– constant linear speed (200-530 rpm)

– higher storage capacity than magnetic disks: 0.66 GB/surface

Page 11: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 11

S 2004 CS 325 21

I/O devicesI/O devices

• data transfer rates of disks– sustained: continuous data delivery

– peek: transfer once r/w head is in place

* depends on rotation speed and data density

* 1 revolution passes over all sectors of 1 track

– Example: 7200 rpm, 100 sect/track, 512 B/sect

* 7200 rpm: 60,000/7200=8.3 ms/rev

* 8.3/100 = 0.083 ms/sector

* 512 bytes transferred in 0.083 ms: ~6MB/s

S 2004 CS 325 22

sectors per surface1,000 – 10,00040, 80, 160tracks per surface(number of cylinders

(200 - 530)*1000 rpm

3,600 - 10,000 rpm

400 - 700 rpm

rotational speed

80 – 400 ms5 – 12 ms30 – 100 msseek time - average

NA0.5 – 1.5 ms3 – 5 msseek time - adjacent

1 - 22 - 241 - 2nmber of surfaces

333,000100 - 4009, 15, 18, 36sectors per track

2048512 - 4,096512bytes per sector

CD ROM DiskHard DiskFloppy DiskCharacteristic

Fig 11-5: Disk Characteristics

Page 12: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 12

S 2004 CS 325 23

I/O devicesI/O devices

• magnetic tapes (reel or cartridge)– large storage capacity (GB)

– data transfer rate: ~ 2 MB/sec

• networks (interface card)– Ethernet, token ring, slotted ring

* controller implements protocol to accept, transmit, receive

packets

– modem

* convert between analog and digital (phone lines)

* character-oriented (like printer and keyboard)

S 2004 CS 325 24

Device driversDevice drivers

• accept command from application– get/put char, read/write block, send/rec. packet

• interact with device controller (HW) to carry out command

• typical device controller interface: set of registersFigure 11-6

• Example: serial or parallel port on PC– generic driver reads/writes chars to registers

Page 13: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 13

S 2004 CS 325 25

Fig 11-6: device controller interface

opcoderegister

Driver

. . . operand registers

write

read

Device

busy register

status register

data buffer read/write

. . .

S 2004 CS 325 26

Fig 11-7: device addressing (a) explicit

Main memory

addresses

. . .

0

opcodedev_0

. . .

n-1

operand1

operand 0

dev_1 opcode

. . .operand1

operand 0

device 0 controller

device 1 controller

Page 14: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 14

S 2004 CS 325 27

Device driversDevice drivers

• memory-mapped vs explicit dev interface– similar idea to memory-mapped files

Figure 11-7

– explicit: special I/O instruction: io_store cpu_reg, dev_no, dev_reg

– memory-mapped: regular CPU instruction: store cpu_reg, n(n is a memory address)

S 2004 CS 325 28

Fig 11-7: device addressing (b) memory-mapped

Main memory

addresses

. . .

0

opcoden

. . .

n-1

operand1

operand 0n+2

opcode

. . .operand1

operand 0

device 0 controller

device 1 controller

n+1

. . .

Page 15: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 15

S 2004 CS 325 29

Device Addressing

store cpu reg, kio store cpu reg, dev no, dev reg

Store to memory vs. store to device interface

Input:i = 0;do {

write_reg(opcode, read);while (busy_flag == true) {...??...};mm in area[i] = data_buffer;increment i;compute;

} while (data_available)

Polling:

S 2004 CS 325 30

Device IO

Output:i = 0;do { compute;

data_buffer = mm_out_area[i];increment i;write_reg(opcode, write);while (busy_flag == true) {...??...};

} while (data_available)

Polling:

Page 16: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 16

S 2004 CS 325 31

Programmed I/O with pollingProgrammed I/O with polling

• CPU is responsible for – moving every char to/from controller buffer

– detecting when I/O operation completed

• protocol to input a character:Figure 11-8

S 2004 CS 325 32

Fig 11-8: programmed I/O with polling

opcoderegister

CPU operands

Device

busy

status

data buffer

2

. . . 1

3

main memory

Controller

4

5

6

6

Page 17: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 17

S 2004 CS 325 33

Programmed I/O with pollingProgrammed I/O with polling

• driver operation to input sequence of charsi = 0;do { write_reg(opcode, read);

while (busy_flag == true) {…};mm_in_area[i] = data_buffer;increment i;compute;

} while (data_available)

• what to do while waiting?– idle (busy wait)– some other computation

* how frequently to poll? -- Figure 11-9– give up CPU

* device may remain unused for a long time

S 2004 CS 325 34

Programmed I/O with pollingProgrammed I/O with polling

• driver operation to output sequence of charsi = 0;do { compute;

data_buffer = mm_in_area[i]; increment i; write_reg(opcode, write);while (busy_flag == true) {…};

} while (data_available)

• what to do while waiting?– idle (busy wait)– some other computation

* how frequently to poll? -- Figure 11-9– give up CPU

* device may remain unused for a long time

Page 18: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 18

S 2004 CS 325 35

Fig 11-9: frequency of polling

star

t

test

star

t

test

star

t

star

t

S 2004 CS 325 36

Programmed I/O with interruptsProgrammed I/O with interrupts

• CPU is responsible for

– moving chars to/from controller buffer, but

• interrupt signal informs CPU when I/O operation completes

• protocol to input a character:Figure 11-10

Page 19: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 19

S 2004 CS 325 37

Fig 11-10: programmed IO with interrupts

opcoderegister

CPU operands

Device

busy

status

data buffer

2

. . . 1

3

main memory

Controller

4

5

6

6interrupt

S 2004 CS 325 38

DMADMA• driver operation to input sequence of chars

write_reg(mm_buf, m);

write_reg(count, n);

write_reg(opcode, read);

block to wait for interrupt;

– writing opcode triggers DMA controller

– DMA controller issues interrupt after n chars in memory

• I/O processor (channel)– extended DMA controller

– executes I/O program in own memory

Page 20: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 20

S 2004 CS 325 39

Device IO with InterruptInput:

i = 0;do { write_reg(opcode, read);

block to wait for interrupt;mm_in_area[i] = data_buffer;increment i;compute;

} while (data_available)

Output:i = 0;do { compute;

data_buffer = mm_out_area[i];increment i;write reg(opcode, write);block to wait for interrupt;

} while (data_available)

S 2004 CS 325 40

Use of I/O InterruptsUse of I/O InterruptsInput:

i := 0;

repeatRead;wait_for_interrupt; in_area[i] := in; Increment i; Compute

until all_data_in

Output:i := 0;repeat

Compute;out := outarea[i];Increment i;Write;wait_for_interrupt

until all_data_out

Page 21: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 21

S 2004 CS 325 41

Programmed I/O with interruptsProgrammed I/O with interrupts

• Example: keyboard driveri = 0;do { block to wait for interrupt;

mm_in_area[i] = data_buffer;increment i;compute(mm_in_area[]);

} while (data_buffer != ENTER)

• timing of interrupt-driven I/OFigure 11-11

– more OS overhead but better device utilization

S 2004 CS 325 42

Fig 11-11: timing of interrupt-driven IO

star

t

star

t

inte

rrup

t

readC

PU

other processes

user processes

operating system

device

driver scheduler

. . .

. . .

Interrupthandler driver scheduler

. . .

. .

Page 22: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 22

S 2004 CS 325 43

Programmed I/O with interruptsProgrammed I/O with interrupts• compare polling with interrupts:

i = 0;do { write_reg(opcode, read);

while (busy_flag == true) {…};mm_in_area[i] = data_buffer;increment i;compute;

} while (…)

i = 0;do { write_reg(opcode, read);

block to wait for interrupt;mm_in_area[i] = data_buffer;increment i;compute;

} while (…)

S 2004 CS 325 44

DMADMA

• CPU only initiates operation• DMA controller transfers data directly to/from main

memory• interrupt when transfer completed• protocol to input data using DMA:

Figure 11-12

Page 23: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 23

S 2004 CS 325 45

Fig 11-12: IO with DMA

opcoderegister

CPU operands

Device

busy

status

data buffer

2

. . . 1

3

main memory

Controller

4

5

6

6interrupt

S 2004 CS 325 46

Device managementDevice management

• circular buffer

– when average times to fill and empty are comparable but vary

over time: circular buffer absorbs bursts

– producer and consumer each use an index

* nextin gives position of next input

* nextout gives position of next output

* both are incremented modulo n at end of operation

Page 24: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 24

S 2004 CS 325 47

Circular Buffer User Process:

do { buffer.remove(data);compute(data);

} while (data_available)

Driver:do {

write_reg(...);block to wait for interrupt;buffer.deposit(data_buffer);

} while (data_available)

S 2004 CS 325 48

Fig 11-13: buffer types

consumer

producer FIFO

Buffer Pool

consumer

producer

. . .

. . .

Page 25: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 25

S 2004 CS 325 49

Device managementDevice management

• device-independent techniques• reasons for buffering

– allows asynchronous operation of producers and consumers

– allows different granularities of data

– consumer or producer can be swapped out while waiting for

buffer fill/empty

S 2004 CS 325 50

Device managementDevice management

• single buffer operationFigure 11-14 (a)

• double buffer (buffer swapping)Figure 11-14 (b)

– increases overlap

– ideal when:

time to fill = time to empty = constant

– when times differ, benefits diminish

Page 26: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 26

S 2004 CS 325 51

Double BufferDouble Bufferprocedure Get( I );begin

while busy[ch] do; //waitRead(ch, next(p_rec), buf[I]);if i==1 then i := 2 else i := 1;

end

i := 2; // initial readRead(ch, first(p_rec), buf[1]);repeat

Get( i );Compute (buf[I]);

until all_records_in;

1

2

S 2004 CS 325 52

Fig 11-14: buffering

copy data buffer

CPU

(a) single buffer

poll ... fill data buffer

poll copy data

buffer

Device

star

t

star

t

copy data buffer[1]CPU ...

Device

star

t(1)

star

(2)

(b) double buffer – buffer swapping

fill data buffer

fill data buffer[2]

poll

copy data buffer[2]

fill data buffer[1]

Page 27: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 27

S 2004 CS 325 53

Buffer SwappingInput:

i = 0;b = 1;write_reg(mm buf, buf[2]);write_reg(opcode, read);do { while (busy_flag == true);/*busy-wait*/

write_reg(mm_buf, buf[b]);write_reg(opcode, read);if (b == 1) b = 2; else b = 1;mm_in_area[i] = buf[b];increment i;compute;

} while (data_available)

S 2004 CS 325 54

Fig. 11-15: Unix C-Lists

front

rear

count = 104

25 char

64 char

15 char

NIL

Page 28: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 28

S 2004 CS 325 55

Hash table

h1

NIL

Fig 11-16: Unix buffer cache

h2

h3

h4

h5

h6

h7 b75b74b73b72b71

b52b51

b11

b23b22b21

NIL

NIL

locked LRU age empty

S 2004 CS 325 56

Device managementDevice management

• error handling– persistent vs transient; SW vs HW

– persistent SW error* repair/reinstall program

– other errors: build in defense mechanisms

– Examples: * transient SW errors: error correcting codes, retransmission* transient HW errors: retry disk seek/read/write* persistent HW errors: redundancy in storage media

Page 29: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 29

S 2004 CS 325 57

Device managementDevice management

• bad block detection and handling– block may be defective as a manufacturing fault or during use

(a common problem)

– parity bit is used to detect faulty block

– the controller bypasses faulty block by renumbering

– a spare block is used instead

– two possible remappings:

Figure 11-17* more work but contiguity of allocation preserved

S 2004 CS 325 58

Fig 11-17: handling of bad blocks

Logicalblock

b[0]

Physicalblock

Logicalblock

Physicalblock

b[1]

. .

b[k]. . .

. . .

. . b[k+1] b[n]

. .

spares

b[0] b[1]

. .

b[k]. . .

. . .

. . b[k+1] b[n]

. .

spares

Page 30: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 30

S 2004 CS 325 59

Device managementDevice management

• stable storage– some applications cannot tolerate any loss of data (even

temporarily)

– stable storage protocols: * use 2 independent disks, A and B* write: write to A; if successful, write to B* read: read from A and B; if A!=B, go to recovery* recovery from media failure: A or B contains correct data; remap

failed disk block * recovery from crash: if before writing A, B is correct; if after

writing A, A is correct; recover

S 2004 CS 325 60

Fig 11-18: stable storage

(a) bad block

X

Disk BDisk A

Page 31: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 31

S 2004 CS 325 61

Fig 11-18: stable storage

(b) block mismatch

Disk A Disk B

X Y

S 2004 CS 325 62

Device managementDevice management

• RAID (redundant array of independent disks)– increased performance through parallel access

– increased reliability through redundant data

– maintain exact replicas of all disks

Figure 11-19(a)* most reliable but wasteful

– maintain only partial recovery information (e.g. error correcting codes)

Figure 11-19(b)

Page 32: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 32

S 2004 CS 325 63

Fig 11-19: (a) RAID –fully replication

. . .

. . .

b1 b2 bn

b1’ b2’ bn’

S 2004 CS 325 64

Fig 11-19: (b) RAID -derived recovery information

. . .b1 b2 bn

f(b1, b2, … bn)

Page 33: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 33

S 2004 CS 325 65

Device managementDevice management

• disk scheduling– minimize seek time and rotational delay

– requests from different processes arrive concurrently: * scheduler must attempt to preserve locality

– rotational delay:* order requests to blocks on each track in the direction of rotation:

access in one rotation* proceed with next track on same cylinder

S 2004 CS 325 66

Device managementDevice management

• minimizing seek time: more difficult– r/w arm can move in two directions

– minimize total travel distance

– guarantee fairness

– FIFO: simple, fair, but inefficient

Figure 11-20 (a)

– SSTF: most efficient but prone to starvation

Figure 11-20 (b)

– Scan: fair, acceptable performance

Figure 11-20 (c)

Page 34: Chapter 11 I/O Processingcs325/OSP_11.pdfChapter 11 I/O Processing 11.1 Basic Issues in Device Management 11.2 A Hierarchical Model 11.3 I/O Devices 11.4 Device Drivers – Memory-Mapped

Betriebssysteme ws2000/2001

Prof. H. D. Clausen 34

S 2004 CS 325 67

Fig 11-20: information

0 1 2 3 4 5 6 7 8 9 10 11 12 …

Total distance traveledFIFO

0 1 2 3 4 5 6 7 8 9 10 11 12 …

0 1 2 3 4 5 6 7 8 9 10 11 12 …

SSTF

Scan

23 cylinders

14 cylinders

20 cylinders