Download presentation
Presentation is loading. Please wait.
1
Chöông 9: I/O System Thieát bò phaàn cöùng I/O
Giao dieän I/O cho öùng duïng Caùc dòch vuï cuûa I/O subsystem Hieäu suaát I/O
2
Toång quan Caùc thieát bò I/O khaùc bieät veà chöùc naêng, toác ñoä,… neân caàn coù caùc phöông thöùc quaûn lyù, ñieàu khieån töông öùng khaùc nhau Chính laø chöùc naêng cuûa I/O subsystem cuûa OS Caùc trình ñieàu khieån thieát bò (device driver) cung caáp cho I/O subsystem moät giao dieän thuaàn nhaát ñeå truy caäp caùc thieát bò memory-mapped I/O: Each control register is assigned a unique memory address to which no memory is assigned.
3
Thieát bò phaàn cöùng I/O
Keát noái vaät lyù giöõa heä thoáng maùy tính vaø caùc thieát bò I/O Port (connection point) USB port Bus (daisy chain, shared direct access) Ñieàu khieån Controller (device controller, SCSI host adapter) Giao tieáp giöõa CPU vaø thieát bò I/O I/O port: ñòa chæ I/O ñeå laäp trình. Duøng leänh I/O leân I/O port ñeå taùc ñoäng leân caùc thanh ghi döõ lieäu / traïng thaùi / leänh cuûa controller. Memory-mapped I/O Each control register is assigned a unique memory address to which no memory is assigned. memory-mapped I/O: Each control register is assigned a unique memory address to which no memory is assigned.
4
Caáu truùc bus trong PC
5
Moät soá I/O port trong PC
controller controller controller
6
Caùc kyõ thuaät thöïc hieän I/O (1/3)
Kyõ thuaät polling (busy waiting) Kieåm tra traïng thaùi cuûa thieát bò khi muoán thöïc hieän I/O ready hoaëc busy hoaëc error Tieâu toán thôøi gian trong voøng laëp ñeå kieåm tra traïng thaùi (busy-wait) vaø thöïc hieän I/O. Programmed I/O
7
Caùc kyõ thuaät thöïc hieän I/O (2/3)
Kyõ thuaät I/O duøng ngaét quaõng (interrupt-driven I/O) CPU coù moät ngoõ Interrupt Request (INTR), ñöôïc kích hoaït bôûi thieát bò I/O Neáu ngaét xaûy ra (INTR = active), CPU chuyeån quyeàn ñieàu khieån cho trình phuïc vuï ngaét (interrupt handler) Caùc ngaét coù theå che ñöôïc (maskable) hoaëc khoâng che ñöôïc (non-maskable) Heä thoáng coù moät baûng vector ngaét chöùa ñòa chæ caùc trình phuïc vuï ngaét Ngaét cuõng coù theå duøng xöû lyù caùc söï kieän khaùc trong heä thoáng (loãi chia cho 0, loãi vi phaïm vuøng nhôù,…)
8
PC interrupt (1) Programmable Interrupt processor Controller (2)
IRQ 0 Programmable Interrupt Controller INTR processor IRQ 1 INTA (2) IRQ 15 local bus 1 byte interrupt number (k) (3) (4) Take exception to address k*4
9
Baûng vector ngaét treân Pentium processor
10
Caùc kyõ thuaät thöïc hieän I/O (3/3)
Kyõ thuaät I/O duøng direct memory access (DMA) Caùc kyõ thuaät polling vaø interrupt-driven I/Oø khoâng thích hôïp khi thöïc hieän di chuyeån khoái löôïng lôùn döõ lieäu. Kyõ thuaät DMA caàn coù phaàn cöùng hoã trôï ñaëc bieät, ñoù laø DMA controller Kyõ thuaät DMA thöïc hieän truyeàn döõ lieäu tröïc tieáp giöõa thieát bò I/O vaø boä nhôù maø khoâng caàn söï can thieäp cuûa CPU.
11
6 böôùc thöïc hieän DMA
12
Giao dieän I/O cho öùng duïng
OS cung caáp moät giao dieän I/O chuaån hoùa, ñoàng nhaát cho caùc öùng duïng. Ví duï: moät öùng duïng in taøi lieäu ra maùy in maø khoâng caàn bieát hieäu maùy in, ñaëc tính maùy in,… Giao dieän laø caùc I/O system call Module ñieàu khieån thieát bò (device driver) thöïc hieän giao dieän ñöôïc chuaån hoùa cuûa I/O subsystem qua ñoù giaáu ñöôïc söï khaùc bieät giöõa caùc caùc boä ñieàu khieån thieát bò (device controller) khaùc nhau
13
Caáu truùc I/O trong OS
14
Ñaëc tính cuûa caùc thieát bò I/O
15
Caùc dòch vuï I/O cho öùng duïng
Giao dieän chuaån cho nhoùm thieát bò coù lieân quan Thieát bò khoái (block device) Disk Taùc vuï: read, write, seek Thieát bò kí töï (character device) Keyboard, mouse, serial port, line printer,… Taùc vuï: get, put Thieát bò maïng (network device) Block hoaëc character. Socket interface treân Unix, Windows/NT,… Clock vaø timer Cung caáp thôøi gian hieän taïi, timer Coù theå laäp trình ñöôïc.
16
System call yeâu caàu I/O
Blocking: process bò suspended cho ñeán khi I/O hoaøn taát. Deã daøng söû duïng Khoâng hieäu quaû trong moät soá tröôøng hôïp Nonblocking: process seõ tieáp tuïc thöïc thi ngay sau leänh goïi I/O. Ví duï: data copy (buffered I/O) Thöôøng hieän thöïc vôùi multithreading Khoù kieåm soaùt keát quaû thöïc hieän I/O Asynchronous: process vaãn thöïc thi trong luùc heä thoáng ñang thöïc hieän I/O. Khoù söû duïng I/O subsystem baùo hieäu cho process khi I/O hoaøn taát Asynchronous I/O: The read() or write() call returns a small object instead of a count. separate set of methods in unix: aio_read(), aio_write() The user can call methods on the returned object to check “how much” of the I/O has completed.
17
I/O subsystem I/O subsystem cung caáp caùc chöùc naêng
Ñònh thôøi caùc yeâu caàu I/O Caùc yeâu caàu I/O xeáp haøng taïi caùc haøng ñôïi cuûa moãi thieát bò Baûo ñaûm coâng baèng, hieäu suaát cao. Ñeäm döõ lieäu (buffering): löu döõ lieäu taïm thôøi trong boä nhôù khi thöïc hieän I/O Giaûi quyeát tröôøng hôïp cheânh leäch toác ñoä, kích thöôùc döõ lieäu khi thöïc hieän I/O Caching Spooling Xöû lyù loãi (error handling) OS can recover from disk read, device unavailable, transient write failures Most return an error number or code when I/O request fails System error logs hold problem reports
18
Chain of events triggered by a user keystroke on a typical UNIX system
[The Context-Switch Overhead Inflicted by Hardware Interrupts (and the Enigma of Do-Nothing Loops) Dan Tsafrir] The chain of events triggered by a user keystroke on a typical UNIX system. The key press generates a hardware interrupt that invokes an appropriate handler-routine and consequently propagates through a chain of connected blocked-waiting processes, each of which is awakened as a result of a matching context switch. This sequence usually takes place immediately after the keystroke, because all the processes involved are “I/O bound” and therefore possess a relatively high priority that allows them to preempt any currently running “CPU bound” application. The end result is that the context switch to and from the interrupt-handler is often temporally coupled with an application-to-application switch. Dan Tsafrir
19
Hieäu suaát I/O Hieäu suaát I/O aûnh höôûng raát lôùn ñeán hieäu suaát toaøn heä thoáng. I/O gaây taûi cao do CPU thöïc hieän caùc leänh ñieàu khieån cuûa device driver, cuûa kernel I/O code. Chuyeån ngöõ caûnh vì caùc I/O interrupt, chi phí copy döõ lieäu göûi nhaän. Network traffic gaây toác ñoä context switch cao. Taêng hieäu suaát I/O Giaûm soá laàn chuyeån ngöõ caûnh, giaûm thieåu quaù trình copy döõ lieäu (baèng caching,…) Giaûm soá laàn ngaét quaõng (truyeàn khoái döõ lieäu lôùn, duøng caùc boä controller thoâng minh, duøng kyõ thuaät polling,…) Söû duïng DMA neáu coù theå.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.