09 - IO Subsystem Flashcards
State three classes of IO devices
Very wide range of devices that interact with the computer via input/output (IO):
(1) Human readable: graphical displays, keyboard, mouse, printers
(2) Machine readable: disks,tapes, CD, sensors
(3) Communications: modems, network interfaces,radios
Differences between IO devices
(1) Data rate : keyboard vs network
(2) Control complexity : printer vs disk
(3) Transfer unit and direction : blocks vs characters vs frame stores (???)
(4) Data representation (???)
(5) Error handling (???)
Why is the IO subsystem the “messiest” part of the OS.
(1) Variety of devices / applications
(2) Dimensions of variation
=> Character-stream or block
=> Sequential or random-access
=> Synchronous or asynchronous
=> Shareable or dedicated
=> Speed of operation
=> Read-write,read-only, or write-only
Why does OS need device classes.
5 or 6 dimensions of variation between IO devices : character stream or block …
Thus, completely homogenising device API is not possible so OS generally splits
devices into four classes
State the four types of device classes
- Block devices
- Character devices
- Network devices
- Misc devices
Examples : block devices
- disk drives, CD
- Commands : read, write, seek
- Access either
a (raw),
b via filesystem (“cooked”),
c or memory mapped.
Examples : character devices
e. g. keyboards, mice, serial
- Commands: get, put
- Layer libraries on top for line editing etc…
Examples : network devices
- Vary enough from block & character devices to get their own interface.
- Unix, Windows NT use Berkeley Socket interface… API for internet sockets, Unix domain sockets, used for IPC.
Examples : misc devices
- Current time, elapsed time, timers clocks.
UNIX : ioctl system call covers other odd aspects of IO
Examples of virtual devices
Terminal => terminal stream Frame buffer => window Raw mouse => event stream Disk block => files Parallel port => print spooler Raw ethernet frames => transport protocols
Explain how the OS creates an interface between user programs and raw hardware
??????????? 7 out of 20 §9
Describe how polled mode IO works
Consider simple device with three registers : status, data, command (diagram).
HOST can read / write these registers via bus.
Polled mode operation :
1. H repeatedly reads device_busy until clear
2. H sets e.g. (write) bit in command register, puts data into data register.
3. H sets command-ready and sets device_busy.
4. D performs write operation (slow)
5. D clears command_ready and then clears device_busy.
Problem with polled mode IO
?????
- Time wasted while D is writing the data / performing its IO operation.
Purpose of interrupt driven IO
- CPU speed»_space;» IO device speed
- CPU provides interrupt mechanism to handle mismatch between CPU and device speeds.
Describe : interrupt driven IO
- End of each instruction => CPU check interrupt lines for pending interrupt.
=> Need not precisely occur at definite point in instruction stream. - If line asserted, CPU:
2a Save PC, processor state.
2b Change processor mode => kernel mode
2c Index interrupt vector => jump to service routine.
3 Finish interrupt handling => use rti instruction to resume.
- More complex CPUs :
- Multiple priority levels of interrupt
- hardware vectoring of interrupt
- mode dependent registers
Handling interrupt
???????????????????????????? slide 11
Explain BLOCKING IO system calls
BLOCKING :
- Process suspended until IO completed.
- Easy to use and understand
- Insufficient for some needs (???? what ???)
Explain NONBLOCKING IO
- IO call returns as much as available. (??)
- Returns almost immediately with count of bytes read or written (possibly 0)
- Can be used by e.g. user interface code.
- Essentially application level “polled IO”.
Explain ASYNCHRONOUS IO
- Process runs concurrently as IO executes.
- IO subsystem explicitly signals to the process when its IO request is complete.
- Most flexible (and potentially efficient … why)
- Also most complex to use (why ….)
Why is IO buffering needed
- Cope with impedance mismatches between devices (speed, transfer size)
- OS may buffer data in memory.
Buffering strategies
- Single buffering : OS assigns a system buffer to the user request
- Double buffering : process consumes from one buffer, while system fills the next.
- Circular buffering : most useful for IO which occurs in bursts.
Explain single buffering
- OS assigns single buffer to user request ,
- OS performs transfer, moves buffer to user space when complete (remap or copy ????)
- Request new buffer for more IO, then reschedule app to consume (READAHEAD or ANTICIPATED INPUT ???)
- OS must track buffers
- Also affects swap logic - if IO is to same disk as swap device : doesn’t make sense to swap process out as it will be behind the now queued IO request ???
Make comparison between no buffering and single buffering
- t := time to input block,
- c : computation time between blocks
- With single buffering, time (what time ???) is max(c, t) + m, where m is the time to move data from buffer to user memory.
- Without buffering, execution time between blocks is t + c.
???? - For a terminal: is the buffer a line or a char, depends on user response required.
Double buffering
- e.g. used in video rendering
- Rough performance comparison : takes max(c, t) .: possible to keep device at full speed if c < t, but if c > t process will not have to wait for IO. ???
- Prevents need to suspend user process between IO operations
… also explains why two buffers is better than one buffer, twice as big. - Need to manage buffers and processes to ensure process doesn’t start consuming from an only partially filled buffer.
Circular buffering
- Allow consumption from buffer at fixed rate, potentially lower than burst rate of arriving data
- Typically use circular linked list = FIFO buffer with queue length ???
BURST RATE ???
???