Implementing Processes, Threads, and Resources

Download Report

Transcript Implementing Processes, Threads, and Resources

Slide 5-1
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 5
Slide 5-2
Device
Management
Copyright © 2004 Pearson Education, Inc.
5
Operating Systems: A Modern Perspective, Chapter 5
Input/Output Devices
Slide 5-3
Output Device
Input Device
Copyright © 2004 Pearson Education, Inc.
Processor
Operating Systems: A Modern Perspective, Chapter 5
The Device Driver Interface
…
write(…);
…
Device Interface
Terminal
Driver
Printer
Driver
Disk
Driver
Terminal
Controller
Printer
Controller
Disk
Controller
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 5
Slide 5-4
Slide 5-5
Device Management Organization
Application
Process
System Interface
File
Manager
Device-Independent
Device-Dependent
Hardware Interface
Command
Status
Data
Device Controller
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 5
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)
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 5
Slide 5-6
Example: BSD UNIX Driver
open
close
ioctl
read
write
strategy
select
stop
Copyright © 2004 Pearson Education, Inc.
Prepare dev for operation
No longer using the device
Character dev specific info
Character dev input op
Character dev output op
Block dev input/output ops
Character dev check for data
Discontinue a stream output op
Operating Systems: A Modern Perspective, Chapter 5
Slide 5-7
Overlapping the Operation of a
Device and the CPU
. . .
read(dev_I, “%d”, x);
y = f(x)
. . .
. . .
startRead(dev_I, “%d”, x);
. . .
While(stillReading()) ;
y = f(x)
. . .
Data on device
Variable x
Register
Memory
CPU
Device dev_I
Copyright © 2004 Pearson Education, Inc.
Slide 5-8
Operating Systems: A Modern Perspective, Chapter 5
Overlapping CPU-Controller
Operations in a Process
App
I/O Ctlr
t1
Copyright © 2004 Pearson Education, Inc.
t2 t3 t4
t5
t6
t7
Operating Systems: A Modern Perspective, Chapter 5
t8
t9
Slide 5-9
Overlapping Processing and I/O
App 1
App 2
I/O Ctlr
t1
Copyright © 2004 Pearson Education, Inc.
t2
t3
Operating Systems: A Modern Perspective, Chapter 5
t4
Slide 5-10
Polling I/O Read Operation
read(device, …);
1
System Interface
Data
read function
5
write function
2
3
4
Hardware Interface
Command
Status
Data
Device Controller
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 5
Slide 5-11
Interrupt-driven I/O Operation
read(device, …);
1
Slide 5-12
9
8b
Data
System Interface
Device Status Table
4
read driver
2
7
Device
Handler
write driver
6
3
Interrupt
Handler
5
Hardware Interface
Command
Status
Data
Device Controller
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 5
8a
Device Independent Function Call
Trap Table
funci(…)
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
…
}
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 5
Slide 5-13
Driver-Kernel Interface
Slide 5-14
• 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)
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 5
Reconfigurable Device Drivers
Slide 5-15
System call interface
open(){…}
read(){…}
Entry Points for Device j
etc.
Driver for Device j
Copyright © 2004 Pearson Education, Inc.
Other
Kernel
services
Operating Systems: A Modern Perspective, Chapter 5
Handling Interrupts
Device driver J
int read(…) {
// Prepare for I/O
save_state(J);
out dev#
// Done (no return)
}
Device status table
J
Device interrupt handler J
void dev_handler(…) {
get_state(J);
//Cleanup after op
signal(dev[j]);
return_from_sys_call();
}
Interrupt Handler
Device Controller
Copyright © 2004 Pearson Education, Inc.
Slide 5-16
Operating Systems: A Modern Perspective, Chapter 5
Handling Interrupts(2)
Device driver J
Device interrupt handler J
int read(…) {
…
out dev#
// Return after interrupt
wait(dev[J});
return_from_sys_call();
}
void dev_handler(…) {
//Cleanup after op
signal(dev[j]);
}
Interrupt Handler
Device Controller
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 5
Slide 5-17
The Pure Cycle Water Company
Customer Office
Water Company
Returning the Empties
Water Producer
Water Consumers
Delivering Water
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 5
Slide 5-18
Slide 5-19
Hardware Buffering
Process
Controller
Process
Controller
Controller
Data
A
Device
Device
Unbuffered
Copyright © 2004 Pearson Education, Inc.
Process
B
Process reads bi-1
Controller reads bi
A
B
Device
Process reads bi
Controller reads bi+1
Operating Systems: A Modern Perspective, Chapter 5
Slide 5-20
Driver
Double Buffering in the Driver
Process
Process
A
A
B
Hardware
Controller
A
B
Device
Copyright © 2004 Pearson Education, Inc.
B
Controller
A
B
Device
Operating Systems: A Modern Perspective, Chapter 5
Circular Buffering
Buffer j
Buffer i
To data consumer
From data producer
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 5
Slide 5-21
A Generic Communications Device
Slide 5-22
Bus
Generic
Controller
Communications
Controller
Local
Device
Cabling connecting the
controller to the device
Device
•Printer
•Modem
•Network
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 5
Rotating Media
Track (Cylinder)
(a) Multi-surface Disk
Copyright © 2004 Pearson Education, Inc.
(b) Disk Surface
Operating Systems: A Modern Perspective, Chapter 5
Slide 5-23
Cylinder
(set of tracks)
(b) Cylinders
Slide 5-24
Storage
Device
Device Driver API
Driver
• Get disk description
• Set SCSI parms
•read/write ops
• Interrupt hander
SCSI API
•commands
•bits per byte
•etc.
Controller
(SCSI)
Magnetic Disk
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 5
Compute vs I/O Bound
Slide 5-25
Compute-bound
Time
I/O-bound
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 5
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
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 5
Slide 5-26
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
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 5
Slide 5-27
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
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 5
Slide 5-28
Optimizing Seek Time (cont)
Slide 5-29
• 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
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 5
Serial Port
CPU
Memory
Serial
Device
• Printer
• Terminal
• Modem
• Mouse
• etc.
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 5
Slide 5-30
Serial Port
Slide 5-31
Device Driver API
Device Driver
Software on the CPU
• Set UART parms
•read/write ops
•Interrupt hander
UART API
•parity
•bits per byte
•etc.
Bus Interface
Serial Device
(UART)
RS-232 Interface
• 9-pin connector
• 4-wires
• bit transmit/receive
• ...
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 5
Adding a Modem
CPU
Memory
Serial
Device
Modem
• Dialing & connecting
• Convert analog voice to/from digital
• Convert bytes to/from bit streams
• Transmit/receive protocol
Phone
Switched Telephone Network
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 5
Slide 5-32
Serial Communication
Slide 5-33
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
Copyright © 2004 Pearson Education, Inc.
Serial Device
RS-232
Modem
Operating Systems: A Modern Perspective, Chapter 5
Slide 5-34
Exploiting the Phone Network
Logical Communication
CPU
Memory
CPU
Comm
Device
Comm
Device
Modem
Modem
Phone
Phone
Switched Telephone Network
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 5
Memory
Slide 5-35
Data Networks
• Technology focus includes protocols and software
(more on this later … Chapter 15 and beyond ...)
Logical Communication
CPU
Memory
Network
Device
Network
Device
Data Network
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 5
CPU
Memory
MS Disk Description
0x 00
0x 03
0x 0b
0x 0d
0x 10
0x 11
0x 13
0x 15
0x 16
0x 18
0x 1a
0x 1c
0x 1e
Copyright © 2004 Pearson Education, Inc.
0x 02
0x 0a
0x 0c
0x 0f
0x 10
0x 12
0x 1 4
0x 15
0x 17
0x 19
0x 1b
0x 1d
…
< a jum p instruction to 0x 1e>
C om puter m anufacturer nam e
S ectors per cluster (M S -D O S reads/w rites a cluster of sectors)
R eserved sectors for th e boot reco rd
N um ber of F A T s
N um ber of root directory entries
N um ber of lo gical sectors
M edium descriptor b yte (used only on old v ersions of M S -D O S )
S ectors per F A T
S ectors per track
N um ber of surfaces (heads)
N um ber of hidden sectors
B ootstrap pro gram
Operating Systems: A Modern Perspective, Chapter 5
Slide 5-36
NT Driver Organization
D ata F lo w
I/O P o rtio n o f N ativ e A P I
F ilter D riv er
In term ed iate D riv er
F ilter D riv er
D ev ice D riv er
HAL
D ev ice
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 5
N T E xecutive
I/O M anager
F ile S y stem D riv er
Slide 5-37
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
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 5
Slide 5-38