51
5 Device Management

Device Management

  • Upload
    sen

  • View
    24

  • Download
    0

Embed Size (px)

DESCRIPTION

Device Management. 5. Input/Output Devices. Output Device. Processor. Input Device. The Device Driver Interface. … write(…); …. Device Interface. Terminal Driver. Printer Driver. Disk Driver. Terminal Controller. Printer Controller. Disk Controller. - PowerPoint PPT Presentation

Citation preview

Page 1: Device Management

5DeviceManagement

Page 2: Device Management

Input/Output Devices

Input Device Processor

Output Device

Page 3: Device Management

The Device Driver Interface

Device InterfaceDevice Interface

…write(…);…

TerminalDriver

TerminalDriver

PrinterDriver

PrinterDriver

DiskDriver

DiskDriver

TerminalController

TerminalController

PrinterController

PrinterController

DiskController

DiskController

Page 4: Device Management

Device Management Organization

ApplicationProcess

ApplicationProcess

FileManager

FileManager

Device Controller

CommandCommand StatusStatus DataData

Hardware Interface

System Interface

Device-IndependentDevice-Independent

Device-DependentDevice-Dependent

Page 5: Device Management

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)

Page 6: Device Management

Example: BSD UNIX Driver

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: Device Management

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_IMemory CPU

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

Page 8: Device Management

Gantt Chart• A Gantt chart is a graphical representation

of the duration of tasks against the progression of time.

http://www.ganttchart.com/

Page 9: Device Management

Gantt Chart

• Gantt charts are useful tools for planning and scheduling projects.

• Gantt charts allow you to assess how long a project should take.

• Gantt charts lay out the order in which tasks need to be carried out.

• Gantt charts help manage the dependencies between tasks.

• Gantt charts determine the resources needed.

Page 10: Device Management

Gantt Chart

• Gantt charts are useful tools when a project is under way.

• Gantt charts monitor progress.

• You can immediately see what should have been achieved at a point in time.

• Gantt charts allow you to see how remedial action may bring the project back on course.

Page 11: Device Management

• Henry Laurence Gantt (1861-1919) was a mechanical engineer, management consultant and industry advisor.

• Henry Laurence Gantt developed Gantt charts in the second decade of the 20th century.

• Gantt charts were used as a visual tool to show scheduled and actual progress of projects.

• Accepted as a commonplace project management tool today, it was an innovation of world-wide importance in the 1920s. 

• Gantt charts were used on large construction projects like the Hoover Dam started in 1931 and the interstate highway network started in 1956.

Page 12: Device Management

• Henry Gantts contribution to the management process is honored today through the Henry Laurence Gantt Medal. 

• The award established in 1929 is given for distinguished achievement in management and for service to the community.

Page 13: Device Management

Overlapping CPU-Controller Operations in a Process

App

I/O Ctlr

t1 t2 t3 t4 t5 t6 t7 t8 t9

Page 14: Device Management

Overlapping Processing and I/O

App 1

App 2

I/O Ctlr

t1 t2 t3 t4

Page 15: Device Management

I/O strategies

• 1. Direct I/O with Polling.

• 2. DMA I/O with Polling.

• 3. Direct I/O with Interrupt.

• 4. DMA I/O with Interrupt.

Page 16: Device Management

Polling I/O Read Operation

read(device, …);

Data

Device Controller

CommandCommand StatusStatus DataData

read function

write function

1

2 3 4

5

Hardware Interface

System Interface

Page 17: Device Management

Direct I/O with Polling (IN)• 1. The application process requires a read operation.• 2. The device driver queries the status register to

determine if the device is idle, if the device is busy, the driver waits for it to be idle.

• 3. The driver stores an input command into the controller’s command register, thereby, starting the device.

• 4. The driver repeatedly reads the status register while waiting for the device to complete its operation.

• 5. The driver copies the contents of the controller’s data register(s) into process’s space.

Page 18: Device Management

Direct I/O with Polling (OUT)• 1. Process requests an output operation.

• 2. Driver status register, busy? Wait.

• 3. Driver copies data from user space memory controller’s data registers.

• 4. The driver stores an output command into the command register, thereby starting the device.

• 5. The driver repeatedly reads the status register while waiting for the device to complete the operation.

Page 19: Device Management

Interrupt-driven I/O Operation

read(device, …);

Data

Device Controller

CommandCommand StatusStatus DataData

read driver

write driver

1

2

3

4

5Hardware Interface

System Interface

Device Status Table

DeviceHandler

DeviceHandler

InterruptHandler

InterruptHandler

6

7

8a

8b

9

Page 20: Device Management

Interrupt Driven I/O Operation• 1. Process requests a read operation

• 2. Top half of the driver queries the status register, idle? -> Yes! -> Wait!

• 3. If no longer busy, the driver stores command into the controller’s command register and thereby starting the device for read operation.

• 4. When read driver completes its work, information regarding the op -> device status table.

Page 21: Device Management

• Device Status Table contains an entry for each device in the system.

• 5. Eventually, the driver completes the operation and interrupt the CPU and cause the interrupt handler to run.

• 6. The interrupt handler determines which device caused the interrupt. It then branches to the device handler for that device.

• 7. The device handler retrieves the pending I/O status information from the device status table.

• 8. The device handler copies the contents of the controller’s data registers into the user process’s space (memory).

• 9. The device handler-behaving as the bottom half of the device driver invoked by the application process-thus returns control to the application process.

Page 22: Device Management

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

break; … case devM: devM_func_i(…);

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

Page 23: Device Management

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)

Page 24: Device Management

Reconfigurable Device Drivers

OtherKernel

services

OtherKernel

services

Entry Points for Device j

open(){…}

read(){…}

etc.

System call interface

Driver for Device j

Page 25: Device Management

Handling Interrupts

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 26: Device Management

Handling Interrupts(2)

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 27: Device Management

The Pure Cycle Water CompanyWater CompanyCustomer Office

Water Consumers

Water Producer

Delivering Water

Returning the Empties

Page 28: Device Management

Hardware Buffering

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 29: Device Management

Double Buffering in the Driver

ProcessProcess

Controller

B

Device

A

ProcessProcess

Controller

B

Device

A

BA BA

Har

dwar

eD

rive

r

Page 30: Device Management

Circular Buffering

From data producer

To data consumer

Buf

fer

i

Buf

fer

j

Page 31: Device Management

A Generic Communications Device

GenericController

GenericController

LocalDevice

LocalDevice

CommunicationsController

CommunicationsController

DeviceDevice

Cabling connecting thecontroller to the device

•Printer•Modem•Network

Bus

Page 32: Device Management

Rotating Media

Track (Cylinder)

Sect

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

Cylinder (set of tracks)

Page 33: Device Management

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

Page 34: Device Management

Compute vs I/O Bound

Compute-bound

I/O-bound

Time

Page 35: Device Management

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

Page 36: Device Management

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

Page 37: Device Management

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: (75), 87, 93, 99, 66, 36, 23– 12 + 6 + 6 + 33 + 30 + 13 = 100 steps

• Look: (75), 87, 93, 66, 36, 23– 12 + 6 + 27 + 30 + 13 = 87 steps

Page 38: Device Management

Optimizing Seek Time (cont)

• Requests = 23, 87, 36, 93, 66

• Circular Scan: (75), 87, 93, 99, 23, 36, 66– 12 + 6 + 6 + home + 23 + 13 + 30 = 90 + home

• Circular Look: (75), 87, 93, 23, 36, 66– 12 + 6 + home + 23 + 13 + 30 = 84 + home

Page 39: Device Management

Serial Port

SerialDevice

SerialDeviceMemoryMemory

CPUCPU

• Printer• Terminal• Modem• Mouse• etc.

Page 40: Device Management

UART

• universal

• asynchronous

• receiver-

• transmitter

Page 41: Device Management
Page 42: Device Management

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

Page 43: Device Management

Adding a Modem

SerialDevice

SerialDeviceMemoryMemory

CPUCPU

ModemModem

PhonePhone

Switched Telephone NetworkSwitched Telephone Network

• Dialing & connecting• Convert analog voice to/from digital• Convert bytes to/from bit streams• Transmit/receive protocol

Page 44: Device Management

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

Page 45: Device Management

CommDevice

CommDeviceMemoryMemory

CPUCPU

ModemModem

PhonePhone

CommDevice

CommDevice MemoryMemory

CPUCPU

ModemModem

PhonePhone

Switched Telephone NetworkSwitched Telephone Network

Exploiting the Phone Network

Logical CommunicationLogical Communication

Page 46: Device Management

Data Networks

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 47: Device Management

The USB Process

• When the host powers up, it queries all of the devices connected to the bus and assigns each one an address.

• This process is called enumeration -- devices are also enumerated when they connect to the bus.

• The host also finds out from each device what type of data transfer it wishes to perform:

Page 48: Device Management

• Interrupt - A device like a mouse or a keyboard, which will be sending very little data, would choose the interrupt mode.

• Bulk - A device like a printer, which receives data in one big packet, uses the bulk transfer mode. A block of data is sent to the printer (in 64-byte chunks) and verified to make sure it is correct.

• Isochronous - A streaming device (such as speakers) uses the isochronous mode. Data streams between the device and the host in real-time, and there is no error correction.

Page 49: Device Management

MS Disk Description-Boot Sector

0x00 0x02 <a jump instruction to 0x1e>0x03 0x0a Computer manufacturer name0x0b 0x0c Sectors per cluster (MS-DOS reads/writes a cluster of sectors)0x0d 0x0f Reserved sectors for the boot record0x10 0x10 Number of FATs0x11 0x12 Number of root directory entries0x13 0x14 Number of logical sectors0x15 0x15 Medium descriptor byte (used only on old versions of MS-DOS)0x16 0x17 Sectors per FAT0x18 0x19 Sectors per track0x1a 0x1b Number of surfaces (heads)0x1c 0x1d Number of hidden sectors0x1e … Bootstrap program

Page 50: Device Management

NT Driver Organization

I/O P o rtio n o f N a tiv e A P II/

O M

anag

er

D ev ice D riv e r

NT

Exe

cuti

ve

H A L

In te rm ed ia te D riv e r

F ile S y s tem D riv e r

F ilte r D riv e r

F ilte r D riv e r

D a ta F lo w

D ev ice

Page 51: Device Management

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