Bài giảng Unit OS6: Device Management

ppt 17 trang huongle 3460
Bạn đang xem tài liệu "Bài giảng Unit OS6: Device Management", để tải tài liệu gốc về máy bạn click vào nút DOWNLOAD ở trên

Tài liệu đính kèm:

  • pptbai_giang_unit_os6_device_management.ppt

Nội dung text: Bài giảng Unit OS6: Device Management

  1. Unit OS6: Device Management 6.1. Principles of I/O Systems Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze
  2. Copyright Notice © 2000-2005 David A. Solomon and Mark Russinovich These materials are part of the Windows Operating System Internals Curriculum Development Kit, developed by David A. Solomon and Mark E. Russinovich with Andreas Polze Microsoft has licensed these materials from David Solomon Expert Seminars, Inc. for distribution to academic organizations solely for use in academic environments (and not for commercial use) 2
  3. Roadmap for Section 6.1 PrinciplesPrinciples ofof I/OI/O HardwareHardware StructuringStructuring ofof I/OI/O SoftwareSoftware LayersLayers ofof anan I/OI/O SystemSystem OperationOperation ofof anan I/OI/O SystemSystem 3
  4. Input/Output – Principles of I/O Hardware Major components of a computer system: CPU, memories (primary/secondary), I/O system I/O devices: Block devices – store information in fixed-sized blocks; typical sizes: 128-1024 bytes Character devices – delivers/accepts stream of characters Device controllers: Connects physical device to system bus (Minicomputers, PCs) Mainframes use a more complex model: Multiple buses and specialized I/O computers (I/O channels) Communication: Memory-mapped I/O, controller registers Direct Memory Access - DMA 4
  5. I/O Hardware - Single Bus Monitor Keyboard Floppy Disk drive drive Video Keyboard Floppy Disk CPU Memory Controller Controller Controller Controller System bus 5
  6. I/O Hardware - Multiple Buses Memory bus SCSI disk PCI bridge/ CPU Memory SCSI disk memory Cache controller SCSI disk SCSI bus Video Network SCSI controller controller controller PCI bus IDE disk USB controller interface keyboard mouse USB bus 6
  7. Diversity among I/O Devices The I/O subsystem has to consider device characteristics: Data rate: may vary by several orders of magnitude Complexity of control: exclusive vs. shared devices Unit of transfer: stream of bytes vs. block-I/O Data representations: character encoding, error codes, parity conventions Error conditions: consequences, range of responses Applications: impactimpact onon resourceresource scheduling,scheduling, bufferingbuffering schemesschemes 7
  8. Organization of the I/O Function Programmed I/O with polling: The processor issues an I/O command on behalf of a process The process busy waits for completion of the operation before proceeding Interrupt-driven I/O: The processor issues an I/O command and continues to execute The I/O module interrupts the processor when it has finished I/O The initiator process may be suspended pending the interrupt Direct memory access (DMA): A DMA module controls exchange of data between I/O module and main memory The processor requests transfer of a block of data from DMA and is interruptedinterrupted onlyonly afterafter thethe entireentire blockblock hashas beenbeen transferredtransferred 8
  9. Flow of a blocking I/O request 1. Thread issues blocking read() 1. Driver may poll for status and system call data; or set up DMA that will generate interrupt 2. Kernel checks parameters; may generate interrupt return buffered data and finish 2. Interrupt occurs; handler stores data; signals device 3. Thread is removed from run stores data; signals device driver queue if physical I/O required; driver added to wait queue for device; 3. Device driver receives signal; I/O request is scheduled determines request status; signals kernel I/O subsystem 4. Device driver allocates kernel signals kernel I/O subsystem buffer; sends command to 4. Kernel transfers data or return controller code to user space; removes thread from wait queue 5. Device controller operates the thread from wait queue hardware to perform data 5. Thread resumes execution at transfer completion of read() call 9
  10. Principles of I/O Software Layered organization Structuring of I/O software Device independence 1. User-level software 2. Device-independent Error handling OS software Error should be handled as close to the 3. Device drivers hardware as possible 4. Interrupt handlers Transparent error recovery at low level Synchronous vs. Asynchronous transfers Most physical I/O is asynchronous Kernel may provide synchronous I/O system calls Sharable vs. dedicated devices Disk vs. printer 10
  11. Interrupt Handlers Should be hidden by the operating system Every thread starting an I/O operation should block until I/O has completed and interrupt occurs Interrupt handler transfers data from device (controller) and un-blocks process 11
  12. Device Driver Contains all device-dependent code Handles one device Translates abstract requests into device commands Writes controller registers Accesses mapped memory Queues requests Driver may block after issuing a request: Interrupt will un-block driver (returning status information) 12
  13. Device-independent I/O Software Functions of device-independent I/O software: Uniform interfacing for the device drivers Device naming Device protection Providing a device-independent block size Buffering Storage allocation on block devices Allocating and releasing dedicated devices Error reporting 13
  14. Layers of the I/O System User-Space I/O Software System call libraries (read, write, ) I/O I/O request reply Spooling Layer I/O functions Managing dedicated I/O User process I/O calls, spooling devices in a format I/O multiprogramming Device-independent Naming, protection system software buffering, blocking Daemon process, Device drivers Setup registers, spooling directory Check status Interrupt handlers lpdlpd – line printer daemon, Wakeup driver sendmail – simple mail Hardware Perform I/O op. transfer protocol 14
  15. Application I/O Interfaces The OS system call interface distinguished device classes: Character-stream or block Sequential or random-access Synchronous or asynchronous Sharable or dedicated Speed of operation Read/write, read only, write only 15
  16. Example: 4.3 BSD kernel I/O structure System-call interface to the kernel socket Plain file Cooked Raw Raw cooked TTY block block tty protocols File interface interface interface Line system discipline Network interface Block-device driver character-device driver The hardware 16
  17. Further Reading Abraham Silberschatz, Peter B. Galvin, Operating System Concepts, John Wiley & Sons, 6th Ed., 2003; Chapter 2 - Computer-System Structures Chapter 13 - I/O Systems 17