the part of os that implements device management is called collectively as device manager, which...
Post on 30-Mar-2015
219 Views
Preview:
TRANSCRIPT
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
Device InterfaceDevice Interface
…write(…);…
TerminalDriver
TerminalDriver
PrinterDriver
PrinterDriver
DiskDriver
DiskDriver
TerminalController
TerminalController
PrinterController
PrinterController
DiskController
DiskController
4
ApplicationProcess
ApplicationProcess
FileManager
FileManager
Device Controller
CommandCommand StatusStatus DataData
Hardware Interface
System Interface
Device-IndependentDevice-Independent
Device-DependentDevice-Dependent
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
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
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). . .
8
App
I/O Ctlr
t1 t2 t3 t4 t5 t6 t7 t8 t9
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
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
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
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
14
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
read(device, …);
Data
Device Controller
CommandCommand StatusStatus DataData
read function
write function
1
2 3 4
5
Hardware Interface
System Interface
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)
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
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
At the end of each instruction cycle, we check if an interrupt has occurred
20
21
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
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
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
25
Compute-bound
I/O-bound
Time
Device drivers Application programming interface
Coordination among application processes, drivers, and device controllers
Performance optimization
26
27
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 …}
29
OtherKernel
services
OtherKernel
services
Entry Points for Device j
open(){…}
read(){…}
etc.
System call interface
Driver for Device j
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
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
32
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
Water CompanyCustomer Office
Water Consumers
Water Producer
Delivering Water
Returning the Empties
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
36
ProcessProcess
Controller
B
Device
A
ProcessProcess
Controller
B
Device
A
BA BA
Har
dwar
eD
rive
r
37
- Producer-consumer problem
From data producer
To data consumer
Buf
fer
i
Buf
fer
j
A spool is a buffer that holds output for a device that cannot accept interleaved data streams Printer is an example
38
Character devices vs. block devices
Communication devices Sequentially accessed storage devices Randomly accessed storage devices
39
40
GenericController
GenericController
LocalDevice
LocalDevice
CommunicationsController
CommunicationsController
DeviceDevice
Cabling connecting thecontroller to the device
•Printer•Modem•Network
Bus
41
SerialDevice
SerialDeviceMemoryMemory
CPUCPU
• Printer• Terminal• Modem• Mouse• etc.
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
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 ...)
44
Track (Cylinder)
Sect
or(a) Multi-surface Disk (b) Disk Surface (b) Cylinders
Cylinder (set of tracks)
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
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
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
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
First-Come-First-Served(76), 124, 17, 269, 201, 29, 137, 12
=> 48 + 107 + 252 + 68 + 172 + 108 + 125 = 880 steps
50
Shortest-Seek-Time-First (76), 29, 17, 12, 124, 137, 201, 269
=> 47 + 12 + 5 + 112 + 13 + 64 + 68 = 321 steps
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
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
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
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
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
top related