Presentation is loading. Please wait.

Presentation is loading. Please wait.

Device Management.

Similar presentations

Presentation on theme: "Device Management."— Presentation transcript:

1 Device Management

2 Device Drivers The part of OS that implements device management is called collectively as device manager, which includes device drivers and device driver infrastructure Device drivers can be complex However, the drivers for different devices implement a similar interface so that a higher-level component has a uniform interface for different devices

3 Device Driver Interface
Device Interface write(…); Terminal Driver Printer Disk Controller

4 Device Management Organization
Application Process File Manager Device Controller Command Status Data Hardware Interface System Interface Device-Independent Device-Dependent

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)

6 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

7 Overlapping the Operation of a Device and the CPU
. . . startRead(dev_I, “%d”, x); While(stillReading()) ; y = f(x) . . . read(dev_I, “%d”, x); y = f(x) Data on device Variable x Register Device dev_I Memory CPU

8 Overlapping CPU-Controller Operations in a Process
I/O Ctlr t1 t2 t3 t4 t5 t6 t7 t8 t9

9 Overlapping Processing and I/O
I/O Ctlr t1 t2 t3 t4 Dashed line is App 1’s activity Solid line is App 2’s activity

10 Device Management Responsible for directly manipulating the hardware devices Several strategies Direct I/O: CPU stays in control Use device polling Use interrupts Memory-mapped I/O Direct memory access

11 I/O Strategies Direct I/O Direct Memory Access (DMA)
The CPU is responsible for determining when the I/O operation has completed and then for transferring the data between the primary memory and the device controller data registers Polling or interrupt-driven I/O This seems not effective for devices with large transfers, such as a disk drive Direct Memory Access (DMA)

12 Direct-Memory Access Direct memory access controllers
Can read/write data directly from/to primary memory addresses with no CPU intervention after the driver has started the I/O operation

13 Direct-Memory Access – cont.

14 Direct-Memory Access – cont.

15 I/O Strategies – cont. Direct I/O or DMA for data transferring
Polling or interrupt-driven I/O strategies Direct I/O with polling DMA I/O with polling Not supported in general Direct I/O with interrupts DMA I/O with interrupts

16 Direct I/O with Polling
read(device, …); Data Device Controller Command Status read function write function 1 2 3 4 5 Hardware Interface System Interface

17 Device Controllers – cont.
Command Status Data 0 Data 1 Data n-1 Logic busy done Error code . . . busy done idle finished working (undefined)

18 Polling I/O busy done Software Hardware … // Start the device
While(busy == 1) wait(); // Device I/O complete done = 0; while((busy == 0) && (done == 1)) // Do the I/O operation busy = 1; busy done Software Hardware

19 Interrupt-Driven I/O System Interface Hardware Interface
read(device, …); Data Device Controller Command Status read driver write driver 1 2 3 4 5 Hardware Interface System Interface Device Status Table Device Handler Interrupt 6 7 8a 8b 9

20 Review: Interrupt Handling
At the end of each instruction cycle, we check if an interrupt has occurred

21 Interrupt-Driven Direct-Memory Access – cont.

22 Interrupt-Driven Versus Polling
In general, an interrupt-driven system will have a higher CPU utilization than a polling-based system The CPU time on polling by one process may be utilized by another process to perform computation

23 Comparison of Polling and Interrupt-Driven I/O Performance
Polling is normally superior from the viewpoint of a single process Because overhead of polling is less Interrupt-driven I/O approach gives better overall system performance

24 I/O-bound and Compute-bound Processes
I/O-bound process A process’s overall execution time is dominated by the time to perform I/O operations Compute-bound process A process’s time on I/O is small compared to the amount of time spent using the CPU Many processes have I/O-bound and compute-bound phases

25 Phases of a Process Compute-bound I/O-bound Time

26 Device Manager Design Device drivers
Application programming interface Coordination among application processes, drivers, and device controllers Performance optimization

27 The Kernel Interface

28 Device-Independent Function Call
funci(…) Trap Table dev_func_i(devID, …) { // Processing common to all devices switch(devID) { case dev0: dev0_func_i(…); break; case dev1: dev1_func_i(…); case devM: devM_func_i(…); }; }

29 Re-configurable Device Drivers
Other Kernel services Entry Points for Device j open(){…} read(){…} etc. System call interface Driver for Device j

30 Handling Interrupts Device driver J Device interrupt handler J
Device status table int read(…) { // Prepare for I/O save_state(J); out dev# // Done (no return) } void dev_handler(…) { get_state(J); //Cleanup after op signal(dev[j]); return_from_sys_call(); } J Interrupt Handler Device Controller

31 Handling Interrupts – cont.
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

32 CPU-device Interactions

33 Buffering Buffering A technique to keep slower I/O devices busy during times when a process is not requiring I/O operations Input buffering Output buffering

34 The Pure Cycle Water Company
Customer Office Water Company Returning the Empties Water Producer Water Consumers Delivering Water

35 Buffering – cont. Unbuffered Process reads bi-1 Controller reads bi
Data Device B A Unbuffered Process reads bi-1 Controller reads bi Process reads bi Controller reads bi+1

36 Double Buffering Process Controller B Device A Hardware Driver

37 Circular Buffers - Producer-consumer problem To data consumer Buffer i
From data producer To data consumer Buffer i Buffer j - Producer-consumer problem

38 Spooling A spool is a buffer that holds output for a device that cannot accept interleaved data streams Printer is an example

39 Device Characteristics
Character devices vs. block devices Communication devices Sequentially accessed storage devices Randomly accessed storage devices

40 Communication Devices
Generic Controller Local Device Communications Cabling connecting the controller to the device Printer Modem Network Bus

41 Serial Port CPU Memory Serial Device Printer Terminal Modem Mouse etc.

42 Serial Port RS-232 Interface Serial Device (UART) UART API
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

43 Logical Communication
Data Networks Technology focus includes protocols and software (more on this later … Chapter 15 and beyond ...) Network Device Memory CPU Data Network Logical Communication

44 Randomly Accessed Devices
Cylinder (set of tracks) Track (Cylinder) Sector (a) Multi-surface Disk (b) Disk Surface (b) Cylinders

45 Optimizing Access to Rotating Devices
Access time has three major components Seek time – the time for the disk arm to move the heads to the cylinder containing the desired sector Rotational latency – the additional time waiting for the disk to rotate the desired sector to the disk head Transfer Time - time to copy bits from disk surface to memory

46 Optimize Access Times Several techniques used to try to optimize the time required to service an I/O request FCFS – first come, first served Requests are serviced in order received No optimization SSTF – shortest seek time first Find track “closest” to current track Could prevent distant requests from being serviced

47 Optimize Access Times – cont.
Scan/Look Starts at track 0, moving towards last track, servicing requests for tracks as it passes them Reverses direction when it reaches last track Look is variant; ceases scan in a direction once last track request in that direction has been handled Circular Scan/Look Similar to scan/look but always moves in same direction; doesn’t reverse Relies on existence of special homing command in device hardware

48 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 Example: Tracks 0:299; Head at track 76, requests for 124, 17, 269, 201, 29, 137, 12

49 Optimizing Access to Rotating Devices
First-Come-First-Served (76), 124, 17, 269, 201, 29, 137, 12 => = 880 steps

50 Optimizing Access to Rotating Devices – cont.
Shortest-Seek-Time-First (76), 29, 17, 12, 124, 137, 201, 269 => = 321 steps

51 Optimizing Access to Rotating Devices – cont.
Scan (76), 124, 137, 201, 269, 299, 29, 17, 12 => = 510 steps Look (76), 124, 137, 201, 269, 29, 17, 12 => = 450 steps

52 Optimizing Access to Rotating Devices – cont.
Circular Scan/ Circular Look Circular Look: (76), 124, 137, 201, 269, 12, 17, 29 home = home Circular Scan: (76), 124, 137, 201, 269, 299, 12, 17, 29 home = home

53 Device Management in Linux
While it builds on the same basic principles, it is more complex and with more details There are a lot of device drivers included and you can also develop your own device drivers for specific purpose devices Linux divides into char-oriented devices and block oriented devices fs/blk_dev.c fs/char_dev.c See pp

54 NT Driver Organization

55 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

Download ppt "Device Management."

Similar presentations

Ads by Google