Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Slide 5-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Slide 5-2 Device Management Copyright © 2004 Pearson Education, Inc. 5 Operating Systems: A Modern Perspective, Chapter 5 Input/Output Devices Slide 5-3 Output Device Input Device Copyright © 2004 Pearson Education, Inc. Processor Operating Systems: A Modern Perspective, Chapter 5 The Device Driver Interface … write(…); … Device Interface Terminal Driver Printer Driver Disk Driver Terminal Controller Printer Controller Disk Controller Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Slide 5-4 Slide 5-5 Device Management Organization Application Process System Interface File Manager Device-Independent Device-Dependent Hardware Interface Command Status Data Device Controller Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 System Call Interface • Functions available to application programs • Abstract all devices (and files) to a few interfaces • Make interfaces as similar as possible – Block vs character – Sequential vs direct access • Device driver implements functions (one entry point per API function) Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Slide 5-6 Example: BSD UNIX Driver open close ioctl read write strategy select stop Copyright © 2004 Pearson Education, Inc. Prepare dev for operation No longer using the device Character dev specific info Character dev input op Character dev output op Block dev input/output ops Character dev check for data Discontinue a stream output op Operating Systems: A Modern Perspective, Chapter 5 Slide 5-7 Overlapping the Operation of a Device and the CPU . . . read(dev_I, “%d”, x); y = f(x) . . . . . . startRead(dev_I, “%d”, x); . . . While(stillReading()) ; y = f(x) . . . Data on device Variable x Register Memory CPU Device dev_I Copyright © 2004 Pearson Education, Inc. Slide 5-8 Operating Systems: A Modern Perspective, Chapter 5 Overlapping CPU-Controller Operations in a Process App I/O Ctlr t1 Copyright © 2004 Pearson Education, Inc. t2 t3 t4 t5 t6 t7 Operating Systems: A Modern Perspective, Chapter 5 t8 t9 Slide 5-9 Overlapping Processing and I/O App 1 App 2 I/O Ctlr t1 Copyright © 2004 Pearson Education, Inc. t2 t3 Operating Systems: A Modern Perspective, Chapter 5 t4 Slide 5-10 Polling I/O Read Operation read(device, …); 1 System Interface Data read function 5 write function 2 3 4 Hardware Interface Command Status Data Device Controller Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Slide 5-11 Interrupt-driven I/O Operation read(device, …); 1 Slide 5-12 9 8b Data System Interface Device Status Table 4 read driver 2 7 Device Handler write driver 6 3 Interrupt Handler 5 Hardware Interface Command Status Data Device Controller Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 8a Device Independent Function Call Trap Table funci(…) dev_func_i(devID, …) { // Processing common to all devices … switch(devID) { case dev0: dev0_func_i(…); break; case dev1: dev1_func_i(…); break; … case devM: devM_func_i(…); break; }; // Processing common to all devices … } Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Slide 5-13 Driver-Kernel Interface Slide 5-14 • Drivers are distinct from main part of kernel • Kernel makes calls on specific functions, drivers implement them • Drivers use kernel functions for: – – – – Device allocation Resource (e.g., memory) allocation Scheduling etc. (varies from OS to OS) Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Reconfigurable Device Drivers Slide 5-15 System call interface open(){…} read(){…} Entry Points for Device j etc. Driver for Device j Copyright © 2004 Pearson Education, Inc. Other Kernel services Operating Systems: A Modern Perspective, Chapter 5 Handling Interrupts Device driver J int read(…) { // Prepare for I/O save_state(J); out dev# // Done (no return) } Device status table J Device interrupt handler J void dev_handler(…) { get_state(J); //Cleanup after op signal(dev[j]); return_from_sys_call(); } Interrupt Handler Device Controller Copyright © 2004 Pearson Education, Inc. Slide 5-16 Operating Systems: A Modern Perspective, Chapter 5 Handling Interrupts(2) Device driver J Device interrupt handler J int read(…) { … out dev# // Return after interrupt wait(dev[J}); return_from_sys_call(); } void dev_handler(…) { //Cleanup after op signal(dev[j]); } Interrupt Handler Device Controller Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Slide 5-17 The Pure Cycle Water Company Customer Office Water Company Returning the Empties Water Producer Water Consumers Delivering Water Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Slide 5-18 Slide 5-19 Hardware Buffering Process Controller Process Controller Controller Data A Device Device Unbuffered Copyright © 2004 Pearson Education, Inc. Process B Process reads bi-1 Controller reads bi A B Device Process reads bi Controller reads bi+1 Operating Systems: A Modern Perspective, Chapter 5 Slide 5-20 Driver Double Buffering in the Driver Process Process A A B Hardware Controller A B Device Copyright © 2004 Pearson Education, Inc. B Controller A B Device Operating Systems: A Modern Perspective, Chapter 5 Circular Buffering Buffer j Buffer i To data consumer From data producer Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Slide 5-21 A Generic Communications Device Slide 5-22 Bus Generic Controller Communications Controller Local Device Cabling connecting the controller to the device Device •Printer •Modem •Network Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Rotating Media Track (Cylinder) (a) Multi-surface Disk Copyright © 2004 Pearson Education, Inc. (b) Disk Surface Operating Systems: A Modern Perspective, Chapter 5 Slide 5-23 Cylinder (set of tracks) (b) Cylinders Slide 5-24 Storage Device Device Driver API Driver • Get disk description • Set SCSI parms •read/write ops • Interrupt hander SCSI API •commands •bits per byte •etc. Controller (SCSI) Magnetic Disk Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Compute vs I/O Bound Slide 5-25 Compute-bound Time I/O-bound Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Disk Optimizations • Transfer Time: Time to copy bits from disk surface to memory • Disk latency time: Rotational delay waiting for proper sector to rotate under R/W head • Disk seek time: Delay while R/W head moves to the destination track/cylinder • Access Time = seek + latency + transfer Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Slide 5-26 Optimizing Seek Time • Multiprogramming on I/O-bound programs => set of processes waiting for disk • Seek time dominates access time => minimize seek time across the set • Tracks 0:99; Head at track 75, requests for 23, 87, 36, 93, 66 • FCFS: 52+ 64 + 51 + 57 + 27 = 251 steps Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Slide 5-27 Optimizing Seek Time (cont) • Requests = 23, 87, 36, 93, 66 • SSTF: (75), 66, 87, 93, 36, 23 – 11 + 21 + 6 + 57 + 13 = 107 steps • Scan/Elevator: (75), 87, 93, 99, 66, 36, 23 – 12 + 6 + 6 + 33 + 30 + 13 = 100 steps (goes to highest track -99 – even if no request) • Look/Elevator: (75), 87, 93, 66, 36, 23 – 12 + 6 + 27 + 30 + 13 = 87 steps Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Slide 5-28 Optimizing Seek Time (cont) Slide 5-29 • Requests = 23, 87, 36, 93, 66 • Circular Scan/Elevator: (75), 87, 93, 99, 23, 36, 66 (always in the same direction – home return) – 12 + 6 + 6 + home + 23 + 13 + 30 = 90 + home • Circular Look/Elevator: (75), 87, 93, 23, 36, 66 – 12 + 6 + home + 23 + 13 + 30 = 84 + home Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Serial Port CPU Memory Serial Device • Printer • Terminal • Modem • Mouse • etc. Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Slide 5-30 Serial Port Slide 5-31 Device Driver API Device Driver Software on the CPU • Set UART parms •read/write ops •Interrupt hander UART API •parity •bits per byte •etc. Bus Interface Serial Device (UART) RS-232 Interface • 9-pin connector • 4-wires • bit transmit/receive • ... Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Adding a Modem CPU Memory Serial Device Modem • Dialing & connecting • Convert analog voice to/from digital • Convert bytes to/from bit streams • Transmit/receive protocol Phone Switched Telephone Network Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Slide 5-32 Serial Communication Slide 5-33 Device Driver •Set UART parms •read/write ops •Interrupt hander Driver-Modem Protocol • Dialing & connecting • Convert analog voice to/from digital • Convert bytes to/from bit streams • Transmit/receive protocol Copyright © 2004 Pearson Education, Inc. Serial Device RS-232 Modem Operating Systems: A Modern Perspective, Chapter 5 Slide 5-34 Exploiting the Phone Network Logical Communication CPU Memory CPU Comm Device Comm Device Modem Modem Phone Phone Switched Telephone Network Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Memory Slide 5-35 Data Networks • Technology focus includes protocols and software (more on this later … Chapter 15 and beyond ...) Logical Communication CPU Memory Network Device Network Device Data Network Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 CPU Memory MS Disk Description 0x00 0x03 0x0b 0x0d 0x10 0x11 0x13 0x15 0x16 0x18 0x1a 0x1c 0x1e Copyright © 2004 Pearson Education, Inc. 0x02 0x0a 0x0c 0x0f 0x10 0x12 0x14 0x15 0x17 0x19 0x1b 0x1d … <a jump instruction to 0x1e> Computer manufacturer name Sectors per cluster (MS-DOS reads/writes a cluster of sectors) Reserved sectors for the boot record Number of FATs Number of root directory entries Number of logical sectors Medium descriptor byte (used only on old versions of MS-DOS) Sectors per FAT Sectors per track Number of surfaces (heads) Number of hidden sectors Bootstrap program Operating Systems: A Modern Perspective, Chapter 5 Slide 5-36 NT Driver Organization Data Flow I/O Portion of Native API Filter Driver Intermediate Driver Filter Driver Device Driver HAL Device Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 NT Executive I/O Manager File System Driver Slide 5-37 NT Device Drivers • API model is the same as for a file • Extend device management by adding modules to the stream • Device driver is invoked via an Interrupt Request Packet (IRP) – IRP can come from another stream module – IRP can come from the OS – Driver must respond to minimum set of IRPs • See Part I of notes Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Slide 5-38 Slide 5-39 Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D. Operating Systems {week 14} Copyright © 2004 Pearson Education, Inc. I/O system • The Input/Output (I/O) System has two primary objectives: – Handle application I/O requests • Map logical address to physical disk or device address • Send response back to the application – Optimize I/O performance • Depends on request type and device type Copyright © 2004 Pearson Education, Inc. Slide 5-40 Disk drives & the disk controller • Disks and other devices operate in parallel to the CPU (but are much slower) – Typical disk drive mechanism: – Arm seeks to the appropriate track – Disk rotates until the desired sector is accessed Copyright © 2004 Pearson Education, Inc. Slide 5-41 Disk access time • Disk access time is the sum of the seek time and the rotational latency – Cache surrounding sectors or entire track to improve performance – Principle of locality (again!) Copyright © 2004 Pearson Education, Inc. Slide 5-42 I/O system structure Copyright © 2004 Pearson Education, Inc. Slide 5-43 I/O request Copyright © 2004 Pearson Education, Inc. Slide 5-44 I/O performance optimization (i) Slide 5-45 • Disk access times are orders of magnitude slower than CPU execution times • Improve I/O performance by: – – – – do this at the application layer Reducing the number of I/O requests Implementing buffering Implementing caching Efficiently scheduling I/O requests Copyright © 2004 Pearson Education, Inc. I/O performance optimization (ii) • Use buffering to make physical I/O requests as large as possible – This reduces the number of I/O requests – Space-time tradeoff – Misleads programmers? – Other disadvantages? Copyright © 2004 Pearson Education, Inc. Slide 5-46 Slide 5-47 I/O performance optimization (iii) • Use caching to keep retrieved data in fast memory for potential future access – Eliminates one or more I/O requests – Space-time tradeoff – Principle of locality (yet again!) Copyright © 2004 Pearson Education, Inc. Disk context switch Slide 5-48 • A disk context switch occurs when switching from one I/O request to another – Disk context switch time is substantially higher than process context switch – Disk context switch time is substantially lower than disk read/write operation – The time to complete the nth I/O operation depends on where the (n-1)th operation finished Copyright © 2004 Pearson Education, Inc. Disk I/O scheduling • Goal: optimize disk performance Slide 5-49 maximize throughput ensure fairness, etc. • Scheduling algorithm determines which pending disk I/O request to select next: – First-Come-First-Served (FCFS) – Shortest Seek Time First (SSTF) – Elevator (SCAN) and Circular SCAN (C-SCAN) Copyright © 2004 Pearson Education, Inc. First-come-first-served (FCFS) Slide 5-50 • Request reference string specifies requested 44, 20, 95, 4, 50, 52, 47, 61, 87, 25 tracks: Copyright © 2004 Pearson Education, Inc. First-come-first-served (FCFS) Slide 5-51 • Request reference string specifies requested 98, 183, 37, 122, 14, 124, 65, 67 tracks: Copyright © 2004 Pearson Education, Inc. Shortest seek time first (SSTF) Slide 5-52 • Request reference string specifies requested 44, 20, 95, 4, 50, 52, 47, 61, 87, 25 tracks: Copyright © 2004 Pearson Education, Inc. Shortest seek time first (SSTF) Slide 5-53 • Request reference string specifies requested 98, 183, 37, 122, 14, 124, 65, 67 tracks: Copyright © 2004 Pearson Education, Inc. Elevator (SCAN) Slide 5-54 • Request reference string specifies requested 44, 20, 95, 4, 50, 52, 47, 61, 87, 25 tracks: repeated end-to-end scans Copyright © 2004 Pearson Education, Inc. Elevator (SCAN) Slide 5-55 • Request reference string specifies requested 98, 183, 37, 122, 14, 124, 65, 67 tracks: Copyright © 2004 Pearson Education, Inc. Circular SCAN and LOOK Slide 5-56 • Circular SCAN (C-SCAN) scans in one direction – When it reaches one end of the disk, it returns to the beginning of the disk without servicing any requests on the return trip • LOOK (and C-LOOK) algorithms – Disk arm moves in one direction as long as there are pending requests in that direction – Otherwise, it reverses direction immediately Copyright © 2004 Pearson Education, Inc.