OSes: 2. Structs 1 Operating Systems v Objective –to give a (selective) overview of computer system architectures Certificate Program in Software Development CSE-TC and CSIM, AIT September -- November, Computer-System Structures (Ch. 2, S&G)
OSes: 2. Structs 2 Contents 1.A Modern Computer System 2.Interrupts 3.I/O 4.Caching 5.Protection
OSes: 2. Structs 3 1. A Modern Computer System Fig 2.1, p.24 CPU disk controller printer controller tape-drive controller memory controller memory Line Printer system bus continued I/O controller
OSes: 2. Structs 4 v CPU and device controllers (drivers) can execute concurrently. v Access to shared memory must be controlled. v A hard-wired bootstrap program loads and starts the OS kernel.
OSes: 2. Structs 5 2. Interrupts v Modern OSes are driven by interrupts (traps) sent when events occur in hardware or software. v Types of events: –completion of I/O, division by 0, system calls, etc. continued
OSes: 2. Structs 6 v An interrupt causes the OS to stop its current task, and switch execution to an interrupt-processing routine. v At the end of the routine, the old task is resumed –the old task’s details must be stored during the interrupt processing continued
OSes: 2. Structs 7 v The addresses of the interrupt routines are stored in a fixed segment of memory (an interrupt vector). v The OS selects a routine from the interrupt vector based on the ‘type’ of the interrupt it received. continued
OSes: 2. Structs 8 v Features of interrupts: –disabling of other interrupts during interrupt processing –prioritisation
OSes: 2. Structs 9 System Calls v System calls are implemented using interrupts. Fig 2.9, p.44 : system call n : case n : read : user program resident monitor return 3 trap to monitor 1 perform I/O 2
OSes: 2. Structs I/O v Synchronous I/O –the user process waits during I/O processing v Asynchronous I/O –control returns to the user without waiting for the I/O to complete
OSes: 2. Structs 11 I/O Forms Fig. 2.3, p.27 requesting process device driver interrupt handler hardware data transfer user kernel time Synchronous requesting process device driver interrupt handler hardware data transfer user kernel time Asynchronous
OSes: 2. Structs Synchronous I/O v Waiting is done either with: –a special wait instruction –a busy-wait loop, such as: loop: jmp loop v A busy-wait generates instruction fetches, and so may lead to contention with the I/O. v Only one I/O process involved.
OSes: 2. Structs Asynchronous I/O v Big advantage: the CPU is not affected while slow I/O is carried out. v Many I/O requests can be in action at once –the implementation requires an I/O device status table
OSes: 2. Structs 14 I/O Device Status Table Fig 2.4, p.28 dev: card reader 1 status: idle dev: line printer 3 status: busy dev: disk unit 1 status: idle dev: disk unit 2 status: idle dev: disk unit 3 status: busy : file: xxx op: read addr: length: 2000 file: yyy op: write addr: 6543 length: 500 PID: 3445 addr: length: 1345
OSes: 2. Structs Direct Memory Access (DMA) v Device controllers transfer data blocks to/from memory directly, bypassing the CPU –only one interrupt generated per block –much faster than interrupt driven character transfer
OSes: 2. Structs Memory Mapped I/O v I/O device registers is mapped to memory so that reads/writes to those memory addresses go straight to the device –used for fast and frequently used device –e.g. video controller, serial port
OSes: 2. Structs Caching v The cache is fast memory between the CPU and main memory –the CPU looks in the cache first for data –new data taken from main memory is also placed in the cache for quick access next time v Instruction caching v Cache management –can affect performance drastically
OSes: 2. Structs 18 Cache Coherency v Must ensure that the data in the cache is always the same as its original version in main memory. v Complicated by multiprocessor and distributed environments –several caches, replicated memory
OSes: 2. Structs Protection v 5.1. Dual-mode Operation v 5.2. Memory Protection v 5.3. CPU Protection
OSes: 2. Structs Dual-mode Operation v User mode v Monitor mode –supervisor mode, root, superuser, system mode, priveleged mode v Implemented in hardware v OS always runs in monitor mode
OSes: 2. Structs Memory Protection v The interrupt vector must be protected from modification by users. v The interrupt processing routines must be similarily protected.
OSes: 2. Structs 22 Partitioning Memory Fig 2.7, p.40 monitor job 1 job 2 job3 job base register limit register
OSes: 2. Structs 23 v Only addresses within the job’s memory space are accessible. CPU >=< basebase + limit trap to OS monitor -- addressing error memory address yes no Fig 2.8, p.41
OSes: 2. Structs CPU Protection v Each process is interrupted after a fixed time –this breaks infinite loops in poor code which would otherwise hog the CPU –allows the OS to time-slice users by context switching