Presentation is loading. Please wait.

Presentation is loading. Please wait.

Slide 5-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5.

Similar presentations


Presentation on theme: "Slide 5-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5."— Presentation transcript:

1 Slide 5-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5

2 Slide 5-2 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 5 Device Management

3 Slide 5-3 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Input/Output Devices Input Device Processor Output Device

4 Slide 5-4 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 The Device Driver Interface Device Interface … write(…); … Terminal Driver Terminal Driver Printer Driver Printer Driver Disk Driver Disk Driver Terminal Controller Terminal Controller Printer Controller Printer Controller Disk Controller Disk Controller

5 Slide 5-5 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Device Management Organization Application Process Application Process File Manager File Manager Device Controller Command Status Data Hardware Interface System Interface Device-Independent Device-Dependent

6 Slide 5-6 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)

7 Slide 5-7 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Example: BSD UNIX Driver open Prepare dev for operation close No longer using the device ioctl Character dev specific info read Character dev input op write Character dev output op strategy Block dev input/output ops select Character dev check for data stop Discontinue a stream output op

8 Slide 5-8 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Overlapping the Operation of a Device and the CPU Variable x Register Data on device... read(dev_I, “%d”, x); y = f(x)... Device dev_I Memory CPU... startRead(dev_I, “%d”, x);... While(stillReading()) ; y = f(x)...

9 Slide 5-9 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Overlapping CPU-Controller Operations in a Process App I/O Ctlr t1t1 t2t2 t3t3 t4t4 t5t5 t6t6 t7t7 t8t8 t9t9

10 Slide 5-10 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Overlapping Processing and I/O App 1 App 2 I/O Ctlr t1t1 t2t2 t3t3 t4t4

11 Slide 5-11 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Polling I/O Read Operation read(device, …); Data Device Controller Command Status Data read function write function 1 234 5 Hardware Interface System Interface

12 Slide 5-12 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Interrupt-driven I/O Operation read(device, …); Data Device Controller Command Status Data read driver write driver 1 2 3 4 5 Hardware Interface System Interface Device Status Table Device Handler Device Handler Interrupt Handler Interrupt Handler 6 7 8a 8b 9

13 Slide 5-13 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Device Independent Function Call func i (…) Trap Table 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 … }

14 Slide 5-14 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Driver-Kernel Interface 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)

15 Slide 5-15 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Reconfigurable Device Drivers Other Kernel services Other Kernel services Entry Points for Device j open(){…} read(){…} etc. System call interface Driver for Device j

16 Slide 5-16 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Handling Interrupts int read(…) { // Prepare for I/O save_state(J); outdev# // Done (no return) } Device driver J Device Controller Interrupt Handler void dev_handler(…) { get_state(J); //Cleanup after op signal(dev[j]); return_from_sys_call(); } Device interrupt handler J J Device status table

17 Slide 5-17 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Handling Interrupts(2) int read(…) { … outdev# // Return after interrupt wait(dev[J}); return_from_sys_call(); } Device driver J Device Controller Interrupt Handler void dev_handler(…) { //Cleanup after op signal(dev[j]); } Device interrupt handler J

18 Slide 5-18 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 The Pure Cycle Water Company Water CompanyCustomer Office Water Consumers Water Producer Delivering Water Returning the Empties

19 Slide 5-19 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Hardware Buffering Process Controller Data Device Process Controller B Device A Process Controller B Device A Unbuffered Process reads b i-1 Controller reads b i Process reads b i Controller reads b i+1

20 Slide 5-20 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Double Buffering in the Driver Process Controller B Device A Process Controller B Device A BABA Hardware Driver

21 Slide 5-21 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Circular Buffering From data producer To data consumer Buffer i Buffer j

22 Slide 5-22 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 A Generic Communications Device Generic Controller Generic Controller Local Device Local Device Communications Controller Communications Controller Device Cabling connecting the controller to the device Printer Modem Network Bus

23 Slide 5-23 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Rotating Media Track (Cylinder) Sector (a) Multi-surface Disk(b) Disk Surface(b) Cylinders Cylinder (set of tracks)

24 Slide 5-24 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Storage Device Magnetic Disk (SCSI) Controller Driver Get disk description Set SCSI parms read/write ops Interrupt hander SCSI API commands bits per byte etc. Device Driver API

25 Slide 5-25 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Compute vs I/O Bound Compute-bound I/O-bound Time

26 Slide 5-26 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

27 Slide 5-27 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 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

28 Slide 5-28 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 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

29 Slide 5-29 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Optimizing Seek Time (cont) 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

30 Slide 5-30 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Serial Port Serial Device Serial Device Memory CPU Printer Terminal Modem Mouse etc.

31 Slide 5-31 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Serial Port RS-232 Interface 9-pin connector 4-wires bit transmit/receive... Serial Device (UART) UART API parity bits per byte etc. Device Driver Set UART parms read/write ops Interrupt hander Software on the CPU Device Driver API Bus Interface

32 Slide 5-32 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Adding a Modem Serial Device Serial Device Memory CPU Modem Phone Switched Telephone Network Dialing & connecting Convert analog voice to/from digital Convert bytes to/from bit streams Transmit/receive protocol

33 Slide 5-33 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Serial Communication Modem RS-232 Serial Device 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

34 Slide 5-34 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Comm Device Comm Device Memory CPU Modem Phone Comm Device Comm Device Memory CPU Modem Phone Switched Telephone Network Exploiting the Phone Network Logical Communication

35 Slide 5-35 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 Data Networks Network Device Network Device Memory CPU Network Device Network Device Memory CPU Data Network Logical Communication Technology focus includes protocols and software (more on this later … Chapter 15 and beyond...)

36 Slide 5-36 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 MS Disk Description

37 Slide 5-37 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 NT Driver Organization

38 Slide 5-38 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 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

39 Slide 5-39 Copyright © 2004 Pearson Education, Inc. Operating Systems {week 14} Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.

40 Slide 5-40 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

41 Slide 5-41 Copyright © 2004 Pearson Education, Inc. 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

42 Slide 5-42 Copyright © 2004 Pearson Education, Inc. 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!)

43 Slide 5-43 Copyright © 2004 Pearson Education, Inc. I/O system structure

44 Slide 5-44 Copyright © 2004 Pearson Education, Inc. I/O request

45 Slide 5-45 Copyright © 2004 Pearson Education, Inc. I/O performance optimization (i) Disk access times are orders of magnitude slower than CPU execution times Improve I/O performance by: –Reducing the number of I/O requests –Implementing buffering –Implementing caching –Efficiently scheduling I/O requests do this at the application layer

46 Slide 5-46 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?

47 Slide 5-47 Copyright © 2004 Pearson Education, Inc. 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!)

48 Slide 5-48 Copyright © 2004 Pearson Education, Inc. Disk context switch 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

49 Slide 5-49 Copyright © 2004 Pearson Education, Inc. Disk I/O scheduling Goal: optimize disk performance 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) maximize throughput, ensure fairness, etc.

50 Slide 5-50 Copyright © 2004 Pearson Education, Inc. First-come-first-served (FCFS) Request reference string specifies requested tracks: 44, 20, 95, 4, 50, 52, 47, 61, 87, 25

51 Slide 5-51 Copyright © 2004 Pearson Education, Inc. First-come-first-served (FCFS) Request reference string specifies requested tracks: 98, 183, 37, 122, 14, 124, 65, 67

52 Slide 5-52 Copyright © 2004 Pearson Education, Inc. Shortest seek time first (SSTF) Request reference string specifies requested tracks: 44, 20, 95, 4, 50, 52, 47, 61, 87, 25

53 Slide 5-53 Copyright © 2004 Pearson Education, Inc. Shortest seek time first (SSTF) Request reference string specifies requested tracks: 98, 183, 37, 122, 14, 124, 65, 67

54 Slide 5-54 Copyright © 2004 Pearson Education, Inc. Elevator (SCAN) Request reference string specifies requested tracks: 44, 20, 95, 4, 50, 52, 47, 61, 87, 25 repeated end-to-end scans

55 Slide 5-55 Copyright © 2004 Pearson Education, Inc. Elevator (SCAN) Request reference string specifies requested tracks: 98, 183, 37, 122, 14, 124, 65, 67

56 Slide 5-56 Copyright © 2004 Pearson Education, Inc. Circular SCAN and LOOK 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


Download ppt "Slide 5-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5."

Similar presentations


Ads by Google