Device Management Device Management Organization Application - - PowerPoint PPT Presentation
Device Management Device Management Organization Application - - PowerPoint PPT Presentation
Device Management Device Management Organization Application Application Process Process API File File Manager Manager Device Device Driver Driver Hardware Interface Command Status Data Command Status Data Device Controller
Device Management Organization
Application Process Application Process File Manager File Manager Device Driver Device Driver Device Controller
Command Command Status Status Data Data
Hardware Interface API
Read with Polling
read(device, …); Data
Device Controller
Command Command Status Status Data Data read function write function 1 2 3 4 5
Hardware Interface System Interface
Read with Interrupts
read(device, …); Data
Device Controller
Command Command Status Status Data 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
CPU-I/O Overlap
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) . . .
I/O - CPU Overlap
App 1 App 2 I/O Ctlr t1 t2 t3 t4 App I/O Ctlr t1 t2 t3 t4 t5 t6 t7 t8 t9
Overlapping App 1’s I/O with App 2 Overlapping App CPU with its own I/O
Memory Mapped I/O
Primary Memory
Device 0 Device 1 Device n-1
Primary Memory
Device 0 Device 1 Device n-1 Device Addresses Memory Addresses Memory Addresses
Direct Memory Access
Primary Memory CPU Controller Device Primary Memory CPU Controller Device
Hardware Buffering
Process Process Controller Data Device Process Process Controller B Device A
Unbuffered Process reads bi-1 Controller reads bi
Hardware Buffering
Process Process Controller Data Device Process Process Controller B Device A Process Process Controller B Device A
Unbuffered Process reads bi-1 Controller reads bi Process reads bi Controller reads bi+1
Buffering in the Driver
Process Process Controller B Device A B A
Hardware Driver
Buffering in the Driver
Process Process Controller B Device A Process Process Controller B Device A B A B A
Hardware Driver
A Ring Buffer
From data producer To data consumer Buffer i Buffer j
Compute vs. I/O Bound
Compute-bound I/O-bound Time
Application Programming Interface
- Functions available to application programs
- Abstract all devices 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)
BSD UNIX Driver
- pen
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
Driver/Kernel Interface
- Drivers separate from rest of kernel
- Kernel makes calls on specific functions,
drivers implement them
- Drivers use other kernel functions for:
– Device allocation – Resource (e.g., memory) allocation – Scheduling – Etc. (Varies from OS to OS)
Reconfigurable Drivers
Other kernel services Other kernel services Entry Points for Device j
- pen(){…}
read(){…}
etc. System call interface Driver for Device j
NT Driver Organization
I/O Portion of Native API I/O Manager Device Driver NT Executive HAL Intermediate Driver File System Driver Filter Driver Filter Driver Data Flow Device
NT Device Drivers
- API model is the same as 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
Serial Communication Device
Modem RS-232
- 9-pin connector
- 4-wires
- bit serial
- etc.
Controller UART
- parity
- bits per byte
- etc.
Driver
- Set UART parms
- read/write ops
- Interrupt hander
Rotating Magnetic Media
Sector (Block) Storage media Read/write heads Track/Cylinder
MS Disk Geometry
0x00 0x02 <a jump instruction to 0x1e> 0x03 0x0a Computer manufacturer name 0x0b 0x0c Sectors per cluster (discussed in Exercise 11) 0x0d 0x0f Reserved sectors for the boot record 0x10 0x10 Number of FATs 0x11 0x12 Number of root directory entries 0x13 0x14 Number of logical sectors 0x15 0x15 Medium descriptor byte (used only on old versions of MS-DOS) 0x16 0x17 Sectors per FAT 0x18 0x19 Sectors per track 0x1a 0x1b Number of surfaces (heads) 0x1c 0x1d Number of hidden sectors 0x1e … Bootstrap program
Disk Delays & Optimizations
- Disk seek time: Delay while R/W head
moves to the destination track/cylinder
- Disk latency time: Delay waiting for proper
sector to rotate under R/W head
- Transfer time: Time to copy bits from disk
surface to memory
- Access time = seek + latency + transfer
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
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
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