Introduction 2
Overview
- CPU design
- Address spaces, interruts
- OS structures/implementation
CPU design
- A CPU basic cycle consist of fetch[取], decode, execute
- Every CPU has his own instruction set
- CPU has a set of registers
- Registers are used to store data and for special functions (e.g. program counter, program status word – mode bit)
- The compiler/programmer decides what to keep in the registers
- Context switching[上下文切换] must save and restore the CPU’s internal state, including its registers
Memory Management Unit (MMU)
- Memory adsresses from 0 to MAX
- Variables are mnemonic[帮助记忆的] names for memory addresses
You don’t know where the process will run in physical memory at compile time
- Multiple processes run on modern machines
- The compiler assumes that it will start running at 0 (logical address space)
- An offset[补偿] is added at runtime by the MMU (physical address space)
physical address = logical address + offset
Modern computer use a logical and physical memory addresses:
- Every process has a logical address space – [0,MAX64] (theoretically理论上)
- The machine has a physical address space – [0, MAX ] (MAX determined by the amount of physical memory)
Address translation takes place in MMU
physical = f (logical )
A context switch between processes invalidates[使无效] the MMU (as well as registers, cache, … )
Timer interrupts
- Interrupts temporarily pause a process’s normal operation
- Different types of interrupts:
- Timer interrupts by CPU clock
- I/O interrupts for I/O completion or error codes
- Software generated, e.g. errors and exceptions
- Timer generates an interrupt
- CPU finishes current instruction and tests for interrupt
- Transfer to interrupt service routine
- Hardware saves current process state (PSW, program counter)
- Set program counter to interrupt service routine
- Save registers and other state information
- Carry out[执行] interrupt service routine (scheduler)
- Restore next process to run
Moore’s “law”
Moore’s “law”: “The number of transistors on an integrated circuit (chip) doubles roughly every two years”
- Closely linked, but not necessarily related to performance
- The “power wall” slows performance improvements of single core/single processor systems
- A few cores for multiple “programs” is easy to justify
- How to use massively[大规模的] parallel computers/CPUs/many core machines
- Can we extract parallelism automatically, can we implement parallelism at the lowest level (similar to multiprogramming)
Multi-core, hyperthreaded processors
- Modern CPUs contain multiple cores and are often hyper-threaded
- Evolution in hardware has implications on operating system design
- XP did not support multi processor architectures
- Process scheduling needs to account for load balancing and CPU affinity[亲和性]
- Cache coherency[缓存一致性] becomes important
Memory
- Memory hierarchies[层级] used to balance cost and performance
- Fast and expensive memory is used for caching
- Slow and inexpensive memory is used for long term storage
- Memory includes, registers, L1/L2 cache, main/core memory, disk, etc.
- L2 Cache can be shared or dedicated[专注的] to individual cores
- Cache management is mainly done by hardware
- The CPU can only access main memory directly (i.e. files have to be brought into memory first)
I/O Devices
- Device driver interacts[交互] with the controller, controller interacts with the device (e.g., disk controller)
- The operating system/device driver typically communicates with the controller through registers
- I/O can take place through:
- Busy waiting
- Interrupt based
- Direct memory access (using DMA chip)
Operating System Structure
- Systems contain a lot of functionality
- Operating Systems are structured by Micro kernels[微内核] and Monolithic[单内核]
Micro Kernels
- All non-essential functionality is extracted[取出] from the kernel
- Communication, memory management and CPU scheduling are likely to be included in the kernel
- The file system, GUI, device drivers are likely to be user processes
除了保留基本功能,其他功能移出到user mode
- Micro kernels are more easy to extend, more portable[便携], and usually more reliable
- Frequent system calls and kernel traps[陷阱] cause significant overhead[开销] (mode switches)
- Some Unix version, Mac OS X, Minix, and early versions of Windows (NT4.0) were (partially) micro kernels
Monolithic Systems
- All procedures are linked together into one single executable running in kernel mode
- Monolithic kernels are difficult to maintain
- Current versions of Windows, Linux are implemented as monolithic kernels
操作系统高度紧密,移植性不佳。但是若设计完善,效率高
Summary
- Operating Systems are closely linked to computer architecture
- Address translation and interrupts
- OS structures