Brief #
- Memory
- Volatile, not persistent
- Poweroff => info lost
Persistence #
----- --------
| CPU | <----------> | Memory |
----- | --------
------
math: true
net <---- | I/O |------> Hard drive,
PCI | Chip | SATA SSD
------
|
| USB
mice, keyboards
Today: #
- Device interaction (I/O)
- Specific Device: Hard Drive
Future: #
- Device up => OS: File Systems
Generic Device: #
- Hardware interface (generalization)
- Command Register (What to do)
- Data Register
- Status register
- How does OS read and write these?
OS: Send commands
|
|
Device
|--------------------------------|
| ----- ------ -------- |
| | CMD | | Data | | Status | |
| ----- ------ -------- |
| |
| .... Varying levels of ..... |
| .... Complexity ..... |
| Simple: mouse to complex: RAID |
|--------------------------------|
2 Methods of Access #
- Special I/O instructions
- Memory-mapped I/O
Protocol of Access #
- Check if device is available
while (status == busy)
; // spin
- Move data
for (size of data)
move data => data register
- Move CMD
Write command => cmd register - Wait:
while (status == busy)
; //spin
Problems: #
- Lot of spinning (polling the device)
- Data movement: CPU intensive
Data move from Hard drive => CPU => Memory
Ideal: Hard drive => Memory
Solutions: #
- Instead of spinning, go to sleep (block)
while (status == busy)
sem_wait(&io);
What wakes it up?- Interrupt:
- Signal to system that device is done
- Run interrupt handler
sem_post(&io);
- DMA engine: hardware
OS can program the h/w to move data directly between memory/device
Old Approach #
data
spinning transfer spinning
CPU -------------||--------------||-----------|
Device |-----------|
New Approach #
(int, sleep)
CPU P1 P2.......P2||P2........P2..........P2|P1 run again
DMA |-----------|
Device |----------|
Hard Drive: How? #

- Rotate
- Fixed speed
- 3600 RPM ~ 15000 RPM
- Platter
- Can have 1 or more
- 2 sides (read/write)
- Track:
- Consists of sectors (512 bytes)
- To read or write:
- e.g. read a sector
address, (size)
(how many sectors)- To OS
- Disk Controller:
- internal action to read or write
- To do an I/O:
- Seek: moves disk arm to correct track
- Wait (Rotation): Wait for sector to rotate under head
- Transfer: read/write
- Example:
- avg seek: ~7ms
- avg rotate: ~3ms
- transfer: ~200MB/s
- Random I/Os: dominated by seek/rotation
- Throughput: = 0.5MB/s
- Random I/O is slow, sequential I/O is fast
- Disk Scheduler