the part of os that implements device management is called collectively as device manager, which...

55

Upload: nehemiah-brinkley

Post on 30-Mar-2015

219 views

Category:

Documents


0 download

TRANSCRIPT

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

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

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

3

Device InterfaceDevice Interface

…write(…);…

TerminalDriver

TerminalDriver

PrinterDriver

PrinterDriver

DiskDriver

DiskDriver

TerminalController

TerminalController

PrinterController

PrinterController

DiskController

DiskController

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

4

ApplicationProcess

ApplicationProcess

FileManager

FileManager

Device Controller

CommandCommand StatusStatus DataData

Hardware Interface

System Interface

Device-IndependentDevice-Independent

Device-DependentDevice-Dependent

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

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

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

6

open Prepare dev for operationclose No longer using the deviceioctl Character dev specific inforead Character dev input opwrite Character dev output opstrategy Block dev input/output opsselect Character dev check for datastop Discontinue a stream output op

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

7

Variable x Register

Data on device

. . .read(dev_I, “%d”, x);y = f(x). . .

Device dev_IMemory CPU

. . .startRead(dev_I, “%d”, x);. . .While(stillReading()) ;y = f(x). . .

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

8

App

I/O Ctlr

t1 t2 t3 t4 t5 t6 t7 t8 t9

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

9

App 1

App 2

I/O Ctlr

t1 t2 t3 t4

Dashed line is App 1’s activitySolid line is App 2’s activity

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

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

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

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

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

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

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

13

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

14

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

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

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

16

read(device, …);

Data

Device Controller

CommandCommand StatusStatus DataData

read function

write function

1

2 3 4

5

Hardware Interface

System Interface

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

17

CommandCommand StatusStatusData 0Data 0

Data 1Data 1

Data n-1Data n-1LogicLogic

busy done Error code . . .. . .busy done 0 0 idle 0 1 finished 1 0 working 1 1 (undefined)

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

18

…// Start the device…While(busy == 1) wait();// Device I/O complete…done = 0;

…while((busy == 0) && (done == 1)) wait();// Do the I/O operationbusy = 1;…

busy done

Sof

twar

eH

ard

war

e

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

19

read(device, …);

Data

Device Controller

CommandCommand StatusStatus DataData

read driver

write driver

1

2

3

4

5Hardware Interface

System InterfaceDevice Status Table

DeviceHandler

DeviceHandler

InterruptHandler

InterruptHandler

6

7

8a

8b

9

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

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

20

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

21

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

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

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

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

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

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

24

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

25

Compute-bound

I/O-bound

Time

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

Device drivers Application programming interface

Coordination among application processes, drivers, and device controllers

Performance optimization

26

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

27

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

28

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(…);

break; … case devM: devM_func_i(…);

break; };// Processing common to all devices …}

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

29

OtherKernel

services

OtherKernel

services

Entry Points for Device j

open(){…}

read(){…}

etc.

System call interface

Driver for Device j

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

30

int read(…) {// Prepare for I/O save_state(J); out dev#// Done (no return)}

Device driver J

Device ControllerDevice Controller

Interrupt HandlerInterrupt 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

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

31

int read(…) { … out dev#// Return after interrupt wait(dev[J}); return_from_sys_call();}

Device driver J

Device ControllerDevice Controller

Interrupt HandlerInterrupt Handler

void dev_handler(…) {//Cleanup after op signal(dev[j]);}

Device interrupt handler J

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

32

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

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

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

34

Water CompanyCustomer Office

Water Consumers

Water Producer

Delivering Water

Returning the Empties

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

35

ProcessProcess

Controller

Data

Device

ProcessProcess

Controller

B

Device

A

ProcessProcess

Controller

B

Device

A

Unbuffered Process reads bi-1

Controller reads bi

Process reads bi

Controller reads bi+1

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

36

ProcessProcess

Controller

B

Device

A

ProcessProcess

Controller

B

Device

A

BA BA

Har

dwar

eD

rive

r

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

37

- Producer-consumer problem

From data producer

To data consumer

Buf

fer

i

Buf

fer

j

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

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

38

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

Character devices vs. block devices

Communication devices Sequentially accessed storage devices Randomly accessed storage devices

39

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

40

GenericController

GenericController

LocalDevice

LocalDevice

CommunicationsController

CommunicationsController

DeviceDevice

Cabling connecting thecontroller to the device

•Printer•Modem•Network

Bus

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

41

SerialDevice

SerialDeviceMemoryMemory

CPUCPU

• Printer• Terminal• Modem• Mouse• etc.

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

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 CPUDevice Driver API

Bus Interface

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

43

NetworkDevice

NetworkDeviceMemoryMemory

CPUCPU

NetworkDevice

NetworkDevice MemoryMemory

CPUCPU

Data NetworkData Network

Logical CommunicationLogical Communication

• Technology focus includes protocols and software (more on this later … Chapter 15 and beyond ...)

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

44

Track (Cylinder)

Sect

or(a) Multi-surface Disk (b) Disk Surface (b) Cylinders

Cylinder (set of tracks)

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

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

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

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

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

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

47

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

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

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

49

First-Come-First-Served(76), 124, 17, 269, 201, 29, 137, 12

=> 48 + 107 + 252 + 68 + 172 + 108 + 125 = 880 steps

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

50

Shortest-Seek-Time-First (76), 29, 17, 12, 124, 137, 201, 269

=> 47 + 12 + 5 + 112 + 13 + 64 + 68 = 321 steps

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

51

Scan (76), 124, 137, 201, 269, 299, 29, 17, 12 => 48 + 13 + 64 + 68 + 30 + 270 + 12 + 5

= 510 stepsLook (76), 124, 137, 201, 269, 29, 17, 12 => 48 + 13 + 64 + 68 + 240 + 12 + 5 = 450 steps

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

52

Circular Scan/ Circular Look• Circular Look: (76), 124, 137, 201, 269, 12, 17, 29

48 + 13 + 64 + 68 + home + 12 + 5 + 12 = 222 + home

• Circular Scan: (76), 124, 137, 201, 269, 299, 12, 17, 2948 + 13 + 64 + 68 + 30 + home + 12 + 5 + 12 = 282 + home

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

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 168-170

53

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

54

I/O Portion of Native API

I/O M

anag

er

Device Driver

NT

Exec

utiv

e

HAL

Intermediate Driver

File System Driver

Filter Driver

Filter Driver

Data Flow

Device

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

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