Chapter 2 -- Computer System Structure
Hardware and Interrupts
-
Basic overview of hardware
-
CPU connected to a system bus with a memory controller and several I/O
controllers.
-
Devices also connected to CPU via interrupt lines.
-
CPU and device talk via shared memory
-
Devices can request the CPU's attention via an interrupt
-
CPU can request the device's attention via writing to a special part of
'memory'.
-
Other models are possible.
-
Interrupts
-
Definition -- asynch hardware event causing change in CPU flow of control.
-
Types
-
Processor exception
-
Error (division by zero, illegal instruction)
-
Normal (VM page missing, emulated instructions)
-
Software (some CPUs use for system calls)
-
synonym for TRAP
-
Generated by a device
-
I/O completion (not normally I/O start)
-
Clock timer. (Time of day, scheduling)
-
Attributes
-
Maskable??
-
Maximum latency allowed
-
Shared?
-
Interrupt handling
-
Interrupt table in RAM
-
Save enough info to be able to restart
-
put on stack (yours or a fixed one or system)
-
Normally interrupt code must save registers
-
Modern RISC is to make interrupt spill hard to understand
-
Exec interrupt routine
-
Maybe did some service (I/O, instruction emulation?)
-
Maybe handled a problem (VM, divide by zero??)
-
Maybe killed process
-
Resume execution
-
Interrupt Priority
-
Often interrupts DISABLE other interrupts
-
this function built into hardware to avoid race condition
-
Disabled interrupts are often MISSED but sometimes DELAYED/QUEUED
-
Sometimes interrupts disabled for O.S. needs
-
changing important system table, SMP needs, etc.
-
Can screw I/O if disabled for two long.
-
Some interrupts cannot be disabled (NMI, clock, page fault).
Memory and Storage Hierarchy
- Memory Hierarchy
- Memory goals
- Free
- Fast
- Nonvolatile
- Portable
- Random access
- Hierarchy
CPU registers -- access in nanoseconds
CPU Cache -- access in 10 nanoseconds
Second level cache -- access in 30 nanoseconds
Main memory -- access in 100 nanoseconds
Electronic disk -- access in 100 nanoseconds
- useful to overcome address space limits
- can use cheap RAM
Magnetic disk -- access in 10,000 nanoseconds
- describe track/sector/platter/cylindar
- Can have a change media event
- normally sector write is atomic
- hard drive heads float, floppy heads ride surface
Magnetic tape -- access in 10's of seconds
- Can have a change media event
- have blocks (like sector) can have track.
- explain helix scan
- VM stored on levels down to mag disk
- Files stored on levels up to electronic disk.
- Caching Problems
- Different apps on same CPU can read different values for the same variable
- Different CPUs can read different values for the same RAM location. --
this must be fixed!
- After media switch, caching can cause WRONG values to be read from floppy
disk or tape.
I/O System Calls
- I/O structure
- Controllers
- hardware
- Load control registers
- Access the "go" register.
- Await interrupt.
- Sometimes controller can do DMA
- Sometimes controller has internal buffers.
- O.S. structure: synchronous
- App does something (I/O request, VM, etc.).
- O.S. gets system call, translates into device I/O.
- device driver translates I/O into "dev-speak".
- wait to I/O to complete (jmp to self)
- O.S. gets interrupt, gives control to device driver
- Driver copies/moves data, sets completion flag
- Process continues
- ADVANTAGE: Simple
- DISADVANTAGE: no overlapping I/O and computation
- O.S. structure: Asynchronous
- App does something (I/O request, VM, etc.).
- O.S. gets system call, translates into device I/O.
- device driver translates I/O into "dev-speak".
- Another process continues
- O.S. gets interrupt, gives control to device driver
- Driver copies/moves data, sets completion flag
- Scheduler notices flag, allows original process to continue
- ADVANTAGE: Overlapping computation and I/O
- DISADVANTAGE: complex, need more than one app for overlap
- O.S. structure: Application Asynchronous
- App does something (I/O request, VM, etc.).
- O.S. gets system call, translates into device I/O.
- device driver translates I/O into "dev-speak".
- Original application continues (subject to scheduling)
- O.S. gets interrupt, gives control to device driver
- Driver copies/moves data
- Driver can notify app, --OR--
- Driver notifies O.S., which tells app
- ADVANTAGE: single apps can overlap I/O and computation
- DISADVANTAGE: I/O interface becomes complex
- O.S. structure: device driven
- Device generates interrupt with data ready
- Data stored in buffer (if room)
- When app requests, data presented)
- Device driver structure
- regular interface for ease of programming
- list standard operations (init, r/w, stat, change media)
- Sometimes classes (block, char)
- Often have top (start request) and bottom (interrupt driven) halves.
- Can have multiple outstanding requests
- Keep list
- Sort list??
- Hardware protection needed
for security from bad apps
- Memory protection
- interrupt handler
- OS code
- OS data
- OS stack
- memory mapped devices
- memory given to other applications
- CPU protection
- Keep users out of kernel CPU mode.
- don't allow users to access the MMU.
- All very long running instructions (shift, pointer-follow, vector-op)
must be interruptable.
- Timer protection
Good questions: 2.4, 2.5,
2.6, 2.7 2.8, 2.9, 2.10