IO
Protocol Variants
Mist devices have a status
register (if it's doing a transfer.
status
registercommand
registerdata
register
Usually interrupts will be more efficient
PIO vs. DMA
Programmed IO - PIO
For every word or byte of data that gets transferred the operating system has to put in an instruction for each. Keyboards will usually used PIO since not much data is necessary to transfer.
DMA
Large sizes of data being transferred. For large magnetic disk drives DMA is always used. A block is typically 512 bytes. An interrupt will be raised to let the operating system know that the operation was completed.
Special Instructions vs Memory Mapped IO
Special Instructions
There are instructions in the instruction set architecture (ISA). There are some ISA that have special set of instructions for IO.
Memory Mapped IO
All devices on the system are mapped to memory in the proccesor's address space. Thus special IO instructions are not needed. Thus X86 instructions for moving can be used to move data from a register to a devices register.
It doesn't really matter which is done in a given architecture. They both can work equally well.
Device Driver
Suffices to create an abstraction for the variety of devices and allow data to be sent and received by the device without the operation system adding extra code. 70% of an OS is device drivers.
Basic Interface
Magnetic drives have moving parts. One or more platter inside the drive, that are covered with magnetic films. A spindle is in the middle and the platter rotates around the spindle. Each surface is divided into rings called tracks. The tracks are divided into numbered sectors numbered from the inner most track to the outer most track.
Positioning
The platters are not perfectly align or perfectly concentric. It is difficult to put the head over the track.
Time To Read
Seek Time
Time it takes to position the head over the track. It has to be accelerated nad allowed to settle. Takes typically 4-10 ms.
Rotation Delay
- depends on how fast the drive spins
- typically 7200 rpm ➡︎ 0.83 milliseconds for a rotation
Transfer Time
- quite fast (faster of the three delays)
- depends on how fast the platter is rotating
- 100 MB per second is the maximum
- 5ms to transfer data on overage
Skew
- When consecutive sectors are being read but the sectors are on different tracks there would be a delay even though they are next to each other. Thus the tracks are skewed or rotated as you go out from the middle
Zones
- The data stored into each sector has a higher capacity as you moved towards outside tracks. Thus they are separated into zones where outside tracks are split into more sectors. This ill allow more data to be store on the disk with better performance.
Cache
- Both average read and write time gets faster
- For reads the disk will read the track into cache and
- For writes the drive won't immediately write the data but save it in cache
I/O Schedulers
FCFS (First Come First Serve)
- For each request we get the whole latency
- If the requests are ordered so the sections are hit back to back then the latency to move the head to the next section is removed
- Performance: depends on how the requests come in
SPTF (Shortest Positioning Time First)
- Do the transfer that's closest to the head's current position.
- Can be implemented in the disk
- The OS can't do it so if the operating system tries to it will become SST (Shortest Seek Time) instead.
SSTF (Shortest Seek Time First)
- Closer sections get serviced first
- However starvation is an issue with this.
SCAN (Elevator Algorithm)
- Has one direction of movement and will service requests in that direction until it hits the inner or outer radius. Then it will reverse directions
- Eliminates starvation but fairness is an issue for things on the edges that will only get called once while things in the middle will get called twice.
Circular Scan
- Instead of reversing direction go back to the first section so fairness is distributed
LOOK
- Works just like SCAN but as the head moves in one direction it will reverse direction if there is no other requests in that direction.
Types of Schedulers
Work Conserving
- If there is work to do: do it then
- Downsides: Often a batch of requests done as a set will have better performance
Non-Work Conserving
- Wait a given period before processing the request queue
- Linux: CFQ (Completely Fair Queue)