i/o s y s te m scs315/spring04/lectures/lecture32.pdf · 1 03 /1 6 /2 004 c s c i 3 1 5 o p e ra...

24
1 03 /1 6 /2 004 C S C I 315 O p e ra tin g S y s te m s D e s ig n 1 I/O S y s te m s No tic e : T he slides for this lecture have been largely based on those accom panying the textbook Op e ra tin g S y s te m s C oncepts w ith Java , b y S ilb e rs c h a tz , G a lv in , a n d G a g n e (2 003 ). M a n y, if n o t a ll, o f th e illu s tra tio n s c o n ta in e d in th is p re s e n ta tio n c o m e from th is s o u rc e .

Upload: others

Post on 19-Aug-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: I/O S y s te m scs315/Spring04/lectures/lecture32.pdf · 1 03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S ys te m s D e s ig n 1 I/O S y s te m s No tic e : T h e s lid e s fo r th

1

03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S y s te m s D e s ig n 1

I/O S y s te m s

No tic e : T h e s lid e s fo r th is le c tu re h a v e b e e n la rg e ly b a s e d o n th o s e a c c o m p a n y in g th e te x tb o o k Op e ra tin g S y s te m s C o n c e p ts w ith J a v a , b y S ilb e rs c h a tz , G a lv in , a n d G a g n e (2 003 ). M a n y , if n o t a ll, o f th e illu s tra tio n s c o n ta in e d in th is p re s e n ta tio n c o m e fro m th is s o u rc e .

Page 2: I/O S y s te m scs315/Spring04/lectures/lecture32.pdf · 1 03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S ys te m s D e s ig n 1 I/O S y s te m s No tic e : T h e s lid e s fo r th

2

03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S y s te m s D e s ig n 2

D ire c t M e m o ry A c c e s s (D M A )• U s e d to a v o id p ro g ra m m e d I/O fo r la rg e

d a ta m o v e m e n t.

• R e q u ire s D M A c o n tro lle r.

• T h e c o n tro lle r a llo w s fo r d a ta to b e tra n s fe rre d d ire c tly b e tw e e n I/O d e v ic e a n d m e m o ry w ith o u t C P U in te rv e n tio n .

Page 3: I/O S y s te m scs315/Spring04/lectures/lecture32.pdf · 1 03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S ys te m s D e s ig n 1 I/O S y s te m s No tic e : T h e s lid e s fo r th

3

03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S y s te m s D e s ig n 3

D M A T ra n s fe r

Page 4: I/O S y s te m scs315/Spring04/lectures/lecture32.pdf · 1 03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S ys te m s D e s ig n 1 I/O S y s te m s No tic e : T h e s lid e s fo r th

4

03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S y s te m s D e s ig n 4

A p p lic a tio n I/O In te rfa c e• I/O s y s te m c a lls e n c a p s u la te d e v ic e b e h a v io rs in

g e n e ric c la s s e s .• D e v ic e -d riv e r la y e r h id e s d iffe re n c e s a m o n g I/O

c o n tro lle rs fro m k e rn e l.• D e v ic e s v a ry in m a n y d im e n s io n s :

– C h a ra c te r-s tre a m o r b lo c k .– S e q u e n tia l o r ra n d o m -a c c e s s .– S h a ra b le o r d e d ic a te d .– S p e e d o f o p e ra tio n .– R e a d -w rite , re a d o n ly , o r w rite o n ly .

Page 5: I/O S y s te m scs315/Spring04/lectures/lecture32.pdf · 1 03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S ys te m s D e s ig n 1 I/O S y s te m s No tic e : T h e s lid e s fo r th

5

03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S y s te m s D e s ig n 5

C h a ra c te ris tic s o f I/O D e v ic e s

Page 6: I/O S y s te m scs315/Spring04/lectures/lecture32.pdf · 1 03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S ys te m s D e s ig n 1 I/O S y s te m s No tic e : T h e s lid e s fo r th

6

03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S y s te m s D e s ig n 6

B lo c k a n d C h a ra c te r D e v ic e s• B lo c k d e v ic e s in c lu d e d is k d riv e s .

– C o m m a n d s in c lu d e read(), write(), seek().

– R a w I/O o r file -s y s te m a c c e s s .– M e m o ry -m a p p e d file a c c e s s p o s s ib le .

• C h a ra c te r d e v ic e s in c lu d e k e y b o a rd s , m ic e , s e ria l p o rts .– C o m m a n d s in c lu d e get(), put().– L ib ra rie s la y e re d o n to p a llo w lin e e d itin g .

Page 7: I/O S y s te m scs315/Spring04/lectures/lecture32.pdf · 1 03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S ys te m s D e s ig n 1 I/O S y s te m s No tic e : T h e s lid e s fo r th

7

03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S y s te m s D e s ig n 7

N e tw o rk D e v ic e s• D iffe re n t e n o u g h fro m b lo c k a n d c h a ra c te r to

h a v e th e ir o w n in te rfa c e .

• U n ix a n d W in d o w s N T /9 x /2 000 in c lu d e s o c k e tin te rfa c e :– S e p a ra te s n e tw o rk p ro to c o l fro m n e tw o rk

o p e ra tio n .– In c lu d e s select() fu n c tio n a lity .

• A p p ro a c h e s v a ry w id e ly (p ip e s , F IF O s , s tre a m s , q u e u e s , m a ilb o x e s ).

Page 8: I/O S y s te m scs315/Spring04/lectures/lecture32.pdf · 1 03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S ys te m s D e s ig n 1 I/O S y s te m s No tic e : T h e s lid e s fo r th

8

03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S y s te m s D e s ig n 8

C lo c k s a n d T im e rs

• P ro v id e :– c u rre n t tim e , – e la p s e d tim e , – tim e r.

• If p ro g ra m m a b le in te rv a l tim e u s e d fo r tim in g s , p e rio d ic in te rru p ts .

• ioctl (o n U N IX ) c o v e rs o d d a s p e c ts o f I/O s u c h a s c lo c k s a n d tim e rs .

Page 9: I/O S y s te m scs315/Spring04/lectures/lecture32.pdf · 1 03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S ys te m s D e s ig n 1 I/O S y s te m s No tic e : T h e s lid e s fo r th

9

03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S y s te m s D e s ig n 9

B lo c k in g a n d N o n b lo c k in g I/O• B lo c k in g - p ro c e s s s u s p e n d e d u n til I/O c o m p le te d .

– E a s y to u s e a n d u n d e rs ta n d .– In s u ffic ie n t fo r s o m e n e e d s .

• No n b lo c k in g - I/O c a ll re tu rn s a s m u c h a s a v a ila b le .– U s e r in te rfa c e , d a ta c o p y (b u ffe re d I/O ).– Im p le m e n te d v ia m u lti-th re a d in g .– R e tu rn s q u ic k ly w ith c o u n t o f b y te s re a d o r w ritte n .

• A s y n c h r o n o u s - p ro c e s s ru n s w h ile I/O e x e c u te s .– D iffic u lt to u s e .– I/O s u b s y s te m s ig n a ls p ro c e s s w h e n I/O c o m p le te d .

Page 10: I/O S y s te m scs315/Spring04/lectures/lecture32.pdf · 1 03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S ys te m s D e s ig n 1 I/O S y s te m s No tic e : T h e s lid e s fo r th

10

03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S y s te m s D e s ig n 1 0

K e rn e l I/O S u b s y s te m• S c h e d u lin g

– S o m e I/O re q u e s t o rd e rin g v ia p e r-d e v ic e q u e u e .– S o m e O S s try fa irn e s s .

• B u ffe r in g - s to re d a ta in m e m o ry w h ile tra n s fe rrin g b e tw e e n d e v ic e s :– T o c o p e w ith d e v ic e s p e e d m is m a tc h .– T o c o p e w ith d e v ic e tra n s fe r s iz e m is m a tc h .– T o m a in ta in “c o p y s e m a n tic s ”.

Page 11: I/O S y s te m scs315/Spring04/lectures/lecture32.pdf · 1 03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S ys te m s D e s ig n 1 I/O S y s te m s No tic e : T h e s lid e s fo r th

11

03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S y s te m s D e s ig n 1 1

N o B u ffe rin g

d is kb u ffe r(s iz e n)

a p p lic a tio n

a d d re s s x D M AC o n tr o lle r

( x ,n)

n o co p y s e m a n tics

Page 12: I/O S y s te m scs315/Spring04/lectures/lecture32.pdf · 1 03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S ys te m s D e s ig n 1 I/O S y s te m s No tic e : T h e s lid e s fo r th

12

03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S y s te m s D e s ig n 1 2

B u ffe rin g in K e rn e l S p a c e

d is kb u ffe r(s iz e n)

a p p lic a tio n

a d d re s s x

D M AC o n tr o lle r

( y ,n)

O S K e r n e l

b u ffe r(s iz e n)

y

co p y s e m a n ticsr e s p e c te d

Page 13: I/O S y s te m scs315/Spring04/lectures/lecture32.pdf · 1 03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S ys te m s D e s ig n 1 I/O S y s te m s No tic e : T h e s lid e s fo r th

13

03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S y s te m s D e s ig n 1 3

C a c h in g in K e rn e l S p a c e

d is k

a p p lic a tio nO S K e r n e l

I/O re q u e s t g o e s to b u ffe r c a c h e b e fo re a d is k a c c e s s is m a d e

K e rn e l b u ffe rs a re u s e d a s c a c h e fo r th e d is k d e v ic e .C o n s e q u e n c e : th e E A T c a n b e s u b s ta n tia lly re d u c e d .

Page 14: I/O S y s te m scs315/Spring04/lectures/lecture32.pdf · 1 03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S ys te m s D e s ig n 1 I/O S y s te m s No tic e : T h e s lid e s fo r th

14

03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S y s te m s D e s ig n 1 4

O u tp u t w ith o u t S p o o lin gp r in te r

p r o c e s s A

p r o c e s s B

p r o c e s s C

A te x tA te x tA te x tB te x tA te x tA te x tC te x tA te x tA te x tA te x t

( A te x t, tim e = 0 ), (A te x t, tim e = 1 ),( A te x t, tim e = 2 ), (A te x t, tim e = 4 ),( A te x t, tim e = 5 ), (A te x t, tim e = 7 ),( A te x t, tim e = 8 ), (A te x t, tim e = 9 )

(B te x t, tim e = 3 )

(C te x t, tim e = 6 )

Page 15: I/O S y s te m scs315/Spring04/lectures/lecture32.pdf · 1 03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S ys te m s D e s ig n 1 I/O S y s te m s No tic e : T h e s lid e s fo r th

15

03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S y s te m s D e s ig n 1 5

O u tp u t w ith S p o o lin g

p r in te rp r o c e s s A

p r o c e s s B

p r o c e s s C

A te x tA te x tA te x t

B te x t

A te x tA te x t

C te x t

A te x tA te x tA te x t

(A te x t, tim e = 0 ), (A te x t, tim e = 1 ),(A te x t, tim e = 2 ), (A te x t, tim e = 4 ),(A te x t, tim e = 5 ), (A te x t, tim e = 7 ),(A te x t, tim e = 8 ), (A te x t, tim e = 9 )

(B te x t, tim e = 3 )

(C te x t, tim e = 6 )

S p o o le r

Page 16: I/O S y s te m scs315/Spring04/lectures/lecture32.pdf · 1 03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S ys te m s D e s ig n 1 I/O S y s te m s No tic e : T h e s lid e s fo r th

16

03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S y s te m s D e s ig n 1 6

E rro r H a n d lin g

• O S c a n re c o v e r fro m d is k re a d , d e v ic e u n a v a ila b le , tra n s ie n t w rite fa ilu re s .

• M o s t re tu rn a n e rro r n u m b e r o r c o d e w h e n I/O re q u e s t fa ils .

• S y s te m e rro r lo g s h o ld p ro b le m re p o rts .

Page 17: I/O S y s te m scs315/Spring04/lectures/lecture32.pdf · 1 03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S ys te m s D e s ig n 1 I/O S y s te m s No tic e : T h e s lid e s fo r th

17

03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S y s te m s D e s ig n 1 7

I/O R e q u e s ts to H a rd w a re O p e ra tio n s

• C o n s id e r re a d in g a file fro m d is k fo r a p ro c e s s :– D e te rm in e d e v ic e h o ld in g file . – T ra n s la te n a m e to d e v ic e re p re s e n ta tio n .– P h y s ic a lly re a d d a ta fro m d is k in to b u ffe r.– M a k e d a ta a v a ila b le to re q u e s tin g p ro c e s s .– R e tu rn c o n tro l to p ro c e s s .

Page 18: I/O S y s te m scs315/Spring04/lectures/lecture32.pdf · 1 03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S ys te m s D e s ig n 1 I/O S y s te m s No tic e : T h e s lid e s fo r th

18

03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S y s te m s D e s ig n 1 8

L ife C y c le o f A n I/O R e q u e s t

Page 19: I/O S y s te m scs315/Spring04/lectures/lecture32.pdf · 1 03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S ys te m s D e s ig n 1 I/O S y s te m s No tic e : T h e s lid e s fo r th

19

03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S y s te m s D e s ig n 1 9

S T R E A M S

• S T R E A M – a fu ll-d u p le x c o m m u n ic a tio n c h a n n e l b e tw e e n a u s e r-le v e l p ro c e s s a n d a d e v ic e .

• A S T R E A M c o n s is ts o f:- S T R E A M h e a d in te rfa c e s w ith th e u s e r p ro c e s s

- d riv e r e n d in te rfa c e s w ith th e d e v ic e- z e ro o r m o re S T R E A M m o d u le s b e tw e e n th e m .

• E a c h m o d u le c o n ta in s a r e a d q u e u e a n d a w r ite q u e u e .

• M e s s a g e p a s s in g is u s e d to c o m m u n ic a te b e tw e e n q u e u e s .

Page 20: I/O S y s te m scs315/Spring04/lectures/lecture32.pdf · 1 03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S ys te m s D e s ig n 1 I/O S y s te m s No tic e : T h e s lid e s fo r th

2 0

03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S y s te m s D e s ig n 2 0

T h e S T R E A M S S tru c tu re

Page 21: I/O S y s te m scs315/Spring04/lectures/lecture32.pdf · 1 03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S ys te m s D e s ig n 1 I/O S y s te m s No tic e : T h e s lid e s fo r th

2 1

03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S y s te m s D e s ig n 2 1

P e rfo rm a n c e

I/O a m a jo r fa c to r in s y s te m p e rfo rm a n c e :

– D e m a n d s C P U to e x e c u te d e v ic e d riv e r, k e rn e l I/O c o d e .

– C o n te x t s w itc h e s d u e to in te rru p ts .– D a ta c o p y in g .– N e tw o rk tra ffic e s p e c ia lly s tre s s fu l.

Page 22: I/O S y s te m scs315/Spring04/lectures/lecture32.pdf · 1 03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S ys te m s D e s ig n 1 I/O S y s te m s No tic e : T h e s lid e s fo r th

2 2

03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S y s te m s D e s ig n 2 2

In te rc o m p u te r C o m m u n ic a tio n s

Page 23: I/O S y s te m scs315/Spring04/lectures/lecture32.pdf · 1 03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S ys te m s D e s ig n 1 I/O S y s te m s No tic e : T h e s lid e s fo r th

2 3

03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S y s te m s D e s ig n 2 3

Im p ro v in g P e rfo rm a n c e

• R e d u c e n u m b e r o f c o n te x t s w itc h e s .• R e d u c e d a ta c o p y in g . • R e d u c e in te rru p ts b y u s in g la rg e tra n s fe rs ,

s m a rt c o n tro lle rs , p o llin g .• U s e D M A .• B a la n c e C P U , m e m o ry , b u s , a n d I/O

p e rfo rm a n c e fo r h ig h e s t th ro u g h p u t.

Page 24: I/O S y s te m scs315/Spring04/lectures/lecture32.pdf · 1 03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S ys te m s D e s ig n 1 I/O S y s te m s No tic e : T h e s lid e s fo r th

2 4

03 /1 6 /2 004 C S C I 3 1 5 O p e ra tin g S y s te m s D e s ig n 2 4

D e v ic e -F u n c tio n a lity P ro g re s s io n