Presentation is loading. Please wait.

Presentation is loading. Please wait.

The part of OS that implements device management is called collectively as device manager, which includes device drivers and device driver infrastructure.

Similar presentations


Presentation on theme: "The part of OS that implements device management is called collectively as device manager, which includes device drivers and device driver infrastructure."— Presentation transcript:

1

2 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 2

3 3 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

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

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

6 6 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 7 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)...

8 8 App I/O Ctlr t1t1 t2t2 t3t3 t4t4 t5t5 t6t6 t7t7 t8t8 t9t9

9 9 App 1 App 2 I/O Ctlr t1t1 t2t2 t3t3 t4t4 Dashed line is App 1s activity Solid line is App 2s activity

10 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 10

11 Direct I/O 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) 11

12 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 12

13 13

14 14

15 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 15

16 16 read(device, …); Data Device Controller Command Status Data read function write function Hardware Interface System Interface

17 17 Command Status Data 0 Data 1 Data n-1 Logic busydoneError code... busy done 0 0 idle 0 1 finished 1 0 working 1 1 (undefined)

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

19 19 read(device, …); Data Device Controller Command Status Data read driver write driver Hardware Interface System Interface Device Status Table Device Handler Device Handler Interrupt Handler Interrupt Handler 6 7 8a 8b 9

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

21 21

22 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 22

23 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 23

24 I/O-bound process A processs overall execution time is dominated by the time to perform I/O operations Compute-bound process A processs 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 24

25 25 Compute-bound I/O-bound Time

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

27 27

28 28 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 … }

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

30 30 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

31 31 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

32 32

33 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 33

34 34 Water CompanyCustomer Office Water Consumers Water Producer Delivering Water Returning the Empties

35 35 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

36 36 Process Controller B Device A Process Controller B Device A BABA Hardware Driver

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

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

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

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

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

42 42 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

43 43 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...)

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

45 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 45

46 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 46

47 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; doesnt reverse Relies on existence of special homing command in device hardware 47

48 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 48

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

50 50 Shortest-Seek-Time-First (76), 29, 17, 12, 124, 137, 201, 269 => = 321 steps

51 51 Scan (76), 124, 137, 201, 269, 299, 29, 17, 12 => = 510 steps Look (76), 124, 137, 201, 269, 29, 17, 12 => = 450 steps

52 52 Circular Scan/ Circular Look Circular Look: (76), 124, 137, 201, 269, 12, 17, home = home Circular Scan: (76), 124, 137, 201, 269, 299, 12, 17, home = home

53 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 54

55 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 55


Download ppt "The part of OS that implements device management is called collectively as device manager, which includes device drivers and device driver infrastructure."

Similar presentations


Ads by Google