Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 5: I/O Systems.

Similar presentations


Presentation on theme: "Chapter 5: I/O Systems."— Presentation transcript:

1 Chapter 5: I/O Systems

2 How complex is the OS’s job?
Let’s look at one of the resources managed by the OS: I/O devices Fall 2018 CS/COE 1550 – Operating Systems – Sherif Khattab

3 CS/COE 1550 – Operating Systems – Sherif Khattab
Device controllers Electronic component controls the device May be able to handle multiple devices May be more than one controller per mechanical component (example: hard drive) Controller's tasks Convert serial bit stream to block of bytes Perform error correction as necessary Make available to main memory Block Devices A device that stores data in fixed‐sized blocks, each uniquely addressed, and can be randomly accessed Character Devices Device that delivers or accepts a stream of characters Fall 2018 CS/COE 1550 – Operating Systems – Sherif Khattab

4 Memory-Mapped I/O Memory I/O ports Separate I/O & memory space
0xFFF… I/O ports Separate I/O & memory space Memory-mapped I/O Hybrid: both memory-mapped & separate spaces CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5

5 Dynamic Frequency on XScale
Fall 2018 CS/COE 1550 – Operating Systems – Sherif Khattab

6 How is memory-mapped I/O done?
Single-bus All memory accesses go over a shared bus I/O and RAM accesses compete for bandwidth Dual-bus RAM access over high-speed bus I/O access over lower-speed bus Less competition More hardware (more expensive…) CPU Memory I/O CPU Memory I/O This port allows I/O devices access into memory CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5

7 Direct Memory Access (DMA) operation
CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5

8 Hardware’s view of interrupts
Bus CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5

9 I/O software: goals Device independence Uniform naming Error handling
Programs can access any I/O device No need to specify device in advance Uniform naming Name of a file or device is a string or an integer Doesn’t depend on the machine (underlying hardware) Error handling Done as close to the hardware as possible Isolate higher-level software Synchronous vs. asynchronous transfers Blocked transfers vs. interrupt-driven Buffering Data coming off a device cannot be stored in final destination Sharable vs. dedicated devices CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5

10 Programmed I/O: printing a page
Printed page Printed page Printed page User ABCD EFGH ABCD EFGH ABCD EFGH A AB ABCD EFGH ABCD EFGH Kernel CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5

11 Polling copy_from_user (buffer, p, count); // copy into kernel buffer
for (j = 0; j < count; j++) { // loop for each char while (*printer_status_reg != READY) ; // wait for printer to be ready *printer_data_reg = p[j]; // output a single character } return_to_user(); CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5

12 Interrupt-driven I/O Code run by system call
copy_from_user (buffer, p, count); j = 0; enable_interrupts(); while (*printer_status_reg != READY) ; *printer_data_reg = p[0]; scheduler(); // and block user Code run by system call if (count == 0) { unblock_user(); } else { *printer_data_reg = p[j]; count--; j++; } acknowledge_interrupt(); return_from_interrupt(); Code run at interrupt time CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5

13 I/O using DMA Code run by system call Code run at interrupt time
copy_from_user (buffer, p, count); set_up_DMA_controller(); scheduler(); // and block user Code run by system call acknowledge_interrupt(); unblock_user(); return_from_interrupt(); Code run at interrupt time CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5

14 Layers of I/O software User User-level I/O software & libraries
Device-independent OS software Operating system (kernel) Device drivers Interrupt handlers Hardware CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5

15 Interrupt handlers Interrupt handlers are “under the hood”
Driver starts an I/O operation If it blocks, it calls scheduler for the next process When devide ends, interrupt notifies CPU of completion Interrupt service routine bottom half Perform minimal actions at interrupt time Save regs not already saved by interrupt hardware Set up context for rest of interrupt handler Then unblocks driver that started it Some of the functionality can be done by the driver after it is unblocked (top half) CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5

16 What happens on an interrupt
Set up stack for interrupt service procedure Ack interrupt controller, reenable interrupts Copy registers from where saved Run service procedure (optional) Pick a new process to run next Set up MMU context for process to run next Load new process' registers Start running the new process CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5

17 Device drivers User space Device drivers go between device controllers and rest of OS Drivers standardize interface to widely varied devices Device drivers communicate with controllers over bus Controllers communicate with devices themselves User program Kernel space Rest of the OS Keyboard driver Disk driver Keyboard controller Disk controller CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5

18 Why a standard driver interface?
Non-standard driver interfaces Standard driver interfaces CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5

19 Buffering device input
User space User space User space User space Kernel space Kernel space Kernel space Kernel space 2 2 1 1 3 Unbuffered input Buffering in user space Buffer in kernel Copy to user space Double buffer in kernel CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5

20 Anatomy of an I/O request
CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5

21 Device-independent I/O software
Device-independent I/O software provides common “library” routines for I/O software Helps drivers maintain a standard appearance to the rest of the OS Uniform interface for many device drivers for Buffering Error reporting Allocating and releasing dedicated devices Suspending and resuming processes Common resource pool Device-independent block size (keep track of blocks) Other device driver resources CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 5


Download ppt "Chapter 5: I/O Systems."

Similar presentations


Ads by Google