Full Transcript

I/O Devices Storage Systems CSC 790 Lecture 1 I/O Devices The concept of an input/output (I/O) device How should I/O be integrated into systems? What are the general mechanisms? How can we make them efficient? System Architecture Why Do We Need a Hierarchical Structure? Phy...

I/O Devices Storage Systems CSC 790 Lecture 1 I/O Devices The concept of an input/output (I/O) device How should I/O be integrated into systems? What are the general mechanisms? How can we make them efficient? System Architecture Why Do We Need a Hierarchical Structure? Physics: The faster a bus is, the shorter it must be Cost: Engineering a bus for high performance is quite costly Modern System Architecture (Direct Media Interface) A Canonical Device Status register: can be read to see the current status of the device Command register: tells the device to perform a certain task Data: passes data to the device or get data from the device. How Does The OS Interact With The Device? Through the hardware interface Registers By reading and writing to the registers OS requires: To know if the device is busy or not To provide instruction to the device To pass data to the device if necessary Polling Device // programmed I/O (PIO) Polling Issues What is wrong with device polling? Inefficient! It wastes a great deal of CPU time just waiting for the device to complete its activity! But it could instead switch to another ready process Better CPU utilization! How To Avoid The Costs of Polling? Ref: https://www.vectorstock.com/royalty-free-vector/bear-thinking-character-style-cartoon-vector-14196134 The Interrupt OS issues a request to the device Puts the calling process to sleep Context switches to another ready task When the device is finished with the operation, it raises a hardware interrupt CPU jumps to the interrupt service routine (ISR) Also known as interrupt handler Interrupt handler wakes up the process waiting for the I/O device The Interrupt (cont.) Interrupt allows: Overlap of communication Overlap of I/O Improved utilization! Polling vs Interrupt Timeline with polling Timeline with interrupt Interrupt Issues Interrupts is not always the best solution! Why? What if a device that performs its tasks very quickly? Will slow down the system Switching to another process Handling the interrupt Expensive! Switching back to the issuing process Use polling instead! What if there are a lot of interrupts? For example, in networks, when a huge stream of incoming packets each generate an interrupt Known as Livelock OS only processes interrupts What is the solution? Ref: https://www.vectorstock.com/royalty-free-vector/bear-thinking-character-style-cartoon-vector-14196134 What is the solution? Hybrid approach! If device is fast: use polling If device is slow: use interrupt If speed of device is unknown: poll a little and then interrupt Coalescing Combine multiple interrupts into one Reduces the number of interrupts Another Problem: Data Movement When using programmed I/O (PIO) to transfer a large chunk of data to a device, the CPU is once again overburdened with a rather trivial task How to lower PIO overheads? Direct Memory Access (DMA) A DMA engine is specific device within a system Orchestrate transfers between devices and main memory without much CPU intervention How to Communicate With Devices? I/O instructions Specify a way for the OS to send data to specific device registers on x86, the in and out instructions can be used These instructions are usually privileged OS thus is the only entity allowed to directly communicate Memory mapped I/O Device registers available as if they were memory locations OS issues a load (to read) or store (to write) the address (register) hardware then routes the load/store to the device instead of main memory How to Build a Device Neutral OS? There could be many types of devices Each of these devices may have very specific interfaces For example, how to design a file system that works with HDD, SSD, or USB drives? Abstraction! At the lowest level, a piece of software in the OS must know in detail how a device works -> Device Driver The File System Stack Reference Operating Systems: Three Easy Pieces by Remzi H Arpaci-Dusseau, Andrea C Arpaci-Dusseau Questions?

Use Quizgecko on...
Browser
Browser