The hardware that holds up the operating system — exam-style exercises with the printer, the cache that hits and the base and limit registers (and the ISR that cost me half a point)
In an IC2 practice test I came across this sentence: “at the end of the ISR the CPU state must be saved”. It all sounded familiar: ISR, state, CPU… and I ticked it as correct. Half a point gone, because in that test wrong answers subtract. The state is saved before the ISR; otherwise the routine would trash the registers of the interrupted process. That day I learnt that in this topic the traps aren’t in the strange words, but in the order and in the “only”s.
This article is the practice side of the theory of the hardware that holds up the operating system. There’s no code to write here: there are questions like the exam ones, all original, each with its explanation, and three calculations to do with pen and paper.
Table of Contents
How to use this article
- Take the quiz without looking at the theory. Answer every question and press “Check” at the end. Multiple-answer questions subtract like in the exam: every wrong tick costs you.
- Read the explanation of each mistake. Every question explains why the right answer is right and why the other options fail.
- Calculations on paper. There is one on synchronous and asynchronous I/O, one on a cache with FIFO and LRU, and one on base and limit registers. Write the working down before filling in the boxes.
- Open questions in writing. Write your answer and compare it with the model answer and with the list of what the marker looks for.
If you get stuck, go back to the theory and take the quiz again: the “Try again” button shuffles the options.
Quiz: The hardware that holds up the OS
Complete how a computer’s I/O is organised:
Each device hooks onto the bus through its ____, which has a local ____ where the CPU leaves and picks up data. When the operation finishes, the controller ____ the CPU with an ____.
Words:
- system call
- interrupt
- controller
- cache
- driver
- ignores
- notifies
- buffer
Solution
Each device hooks onto the bus through its controller, which has a local buffer where the CPU leaves and picks up data. When the operation finishes, the controller notifies the CPU with an interrupt.
The controller is the piece of hardware that sits between the bus and the device. Its local buffer is where data is exchanged with the CPU, and the interrupt is how it reports back. Careful: the driver is OS software, not the piece that connects to the bus.
While VS Code is using the CPU, the printer raises an interrupt. What happens right after the CPU accepts the interrupt?
- It saves the CPU state and then runs the ISR
- It runs the ISR and saves the CPU state when it finishes
- It waits for VS Code to finish before dealing with the printer
- VS Code runs its own routine to deal with the printer
Solution
Answer: It saves the CPU state and then runs the ISR
Order of an interrupt: the CPU saves its state, runs the OS’s interrupt service routine (ISR), restores the state and the interrupted process carries on without noticing.
Match each term with its description:
| Polling | |
| Vectored interrupt | |
| Interrupt vector | |
| ISR |
Definitions:
- The CPU asks the devices one by one which one interrupted
- Controller memory where the I/O data is kept
- Area of main memory with the addresses of all the ISRs
- The device identifies itself by sending a number over the data bus
- OS code that handles one particular event
Solution
- Polling → The CPU asks the devices one by one which one interrupted
- Vectored interrupt → The device identifies itself by sending a number over the data bus
- Interrupt vector → Area of main memory with the addresses of all the ISRs
- ISR → OS code that handles one particular event
Polling and vectored interrupts are the two ways of finding out who interrupted. With vectored ones, the number the device sends is an index into the interrupt vector, and the vector entry points to the ISR. The leftover description is the controller’s local buffer.
The printer sends the number 7 over the bus. What is the table in main memory called where the CPU looks up slot 7 to know which routine to run?
Solution
Answer: Interrupt vector
The interrupt vector holds the address of every ISR. The device’s number is the index: the CPU doesn’t have to ask anyone.
The operating system is said to have a reactive behaviour. What does that mean?
- That it only wakes up when an event happens that it has to deal with
- That it runs non-stop on a CPU core reserved for it
- That it reacts to errors by closing the failing program
- That it only wakes up when the user presses a key or moves the mouse
Solution
Answer: That it only wakes up when an event happens that it has to deal with
The OS doesn’t switch itself on: an event wakes it up. That is why hardware that generates those events (interrupts, the timer) is needed.
Which of these events make operating system code run?
- The printer finishes printing a page
- A program executes the write() system call
- A program tries to divide an integer by zero
- A program adds two variables held in registers
- printf() copies text into a C library buffer without calling write() yet
Solution
Answer: The printer finishes printing a page · A program executes the write() system call · A program tries to divide an integer by zero
The three kinds of event are hardware interrupts (the printer), system calls (write) and exceptions (division by zero). Everything else is the program’s ordinary work in user mode.
About synchronising I/O and the OS, say whether each statement is true or false:
- With synchronous I/O, the CPU waits until the I/O finishes.
- With asynchronous I/O, the OS uses the wait to run other processes.
- Synchronous I/O gets more performance out of the system than asynchronous I/O.
- With asynchronous I/O, the OS finds out the operation has ended thanks to an interrupt.
- I/O is called asynchronous when the OS waits for the operation to finish before carrying on.
Solution
- T — With synchronous I/O, the CPU waits until the I/O finishes.
- T — With asynchronous I/O, the OS uses the wait to run other processes.
- F — Synchronous I/O gets more performance out of the system than asynchronous I/O.
- T — With asynchronous I/O, the OS finds out the operation has ended thanks to an interrupt.
- F — I/O is called asynchronous when the OS waits for the operation to finish before carrying on.
Waiting is synchronous; carrying on with something else and getting notified is asynchronous. That is why asynchronous I/O makes better use of the CPU.
Process A prints 2 pages: each one needs 30 ms of CPU and then 50 ms of printer. Process B needs 80 ms of CPU. Work out the time until both finish and the CPU usage with synchronous and asynchronous I/O (asynchronously, A gets the CPU as soon as each page is done):
| Process | Work |
|---|---|
| A | 30 ms CPU + 50 ms printer, twice |
| B | 80 ms CPU |
| Mode | Total time (ms) | Useful CPU (ms) | CPU usage (%) |
|---|---|---|---|
| Synchronous | |||
| Asynchronous |
Solution
| Mode | Total time (ms) | Useful CPU (ms) | CPU usage (%) |
|---|---|---|---|
| Synchronous | 240 | 140 | 58.33 |
| Asynchronous | 160 | 140 | 87.5 |
Useful CPU in both cases: 30 + 30 from A and 80 from B = 140 ms.
Synchronous: the CPU waits for each print, so A takes 2 × (30 + 50) = 160 ms and B goes afterwards: 160 + 80 = 240 ms. Usage: 140 / 240 = 58.33 %.
Asynchronous (the chart): A 0-30, B 30-80 while printing, A 80-110, B 110-140 and done; from 140 to 160 the CPU is idle waiting for the last page. Total 160 ms and usage 140 / 160 = 87.5 %.
Put in order what happens in asynchronous I/O when process A sends something to print:
- The OS handles the interrupt and decides to resume A
- The printer finishes and raises an interrupt
- The OS does a context switch and puts process B on the CPU
- A requests the printing with a system call
- The OS handles the call and passes the order to the controller
Solution
Correct order:
- A requests the printing with a system call
- The OS handles the call and passes the order to the controller
- The OS does a context switch and puts process B on the CPU
- The printer finishes and raises an interrupt
- The OS handles the interrupt and decides to resume A
The system call wakes the OS, the OS talks to the I/O, uses the wait for another process, and the end-of-I/O interrupt gives it control back.
Complete about I/O wait queues:
If a device is ____, the OS keeps the request in that device’s ____. Every time an operation finishes, the OS hands the device the ____ pending request.
Words:
- interrupt vector
- busy
- wait queue
- next
- cache
- free
Solution
If a device is busy, the OS keeps the request in that device’s wait queue. Every time an operation finishes, the OS hands the device the next pending request.
Each device has its own queue of pending requests, served in order. Your computer’s print queue is exactly that.
About hardware and software interrupts, say whether each statement is true or false:
- System calls are handled like interrupts, but the CPU itself triggers them.
- Exceptions are always caused by an I/O device.
- There is a machine instruction to trigger a software interrupt, such as INT on Intel.
- System calls are implemented with hardware interrupts.
- Each kind of event triggers a different ISR through the interrupt vector.
Solution
- T — System calls are handled like interrupts, but the CPU itself triggers them.
- F — Exceptions are always caused by an I/O device.
- T — There is a machine instruction to trigger a software interrupt, such as INT on Intel.
- F — System calls are implemented with hardware interrupts.
- T — Each kind of event triggers a different ISR through the interrupt vector.
Software interrupt = system call or exception: handled like a hardware one, but triggered by the CPU. The instructions are INT (Intel), TRAP (Motorola) and SYSCALL (MIPS).
Put these memories in order from fastest to slowest:
- Registers
- Cache memory
- Magnetic tape
- Solid-state drive (SSD)
- Magnetic hard disk
- Main memory
Solution
Correct order:
- Registers
- Cache memory
- Main memory
- Solid-state drive (SSD)
- Magnetic hard disk
- Magnetic tape
The hierarchy goes from the registers (inside the CPU) down to tape. Ordered by cost per byte it is the same list reversed: the fastest is the dearest.
What is the caching principle?
- Keeping the most frequently used information in the fastest memory
- Keeping the most used information in the memory with the largest capacity
- Copying the whole of main memory into the cache at boot
- Using the processor’s cache memory and nothing else
Solution
Answer: Keeping the most frequently used information in the fastest memory
If the most used data is in the fastest memory, most accesses are fast even though the rest of the hierarchy is slow.
About the cache, say whether each statement is true or false:
- The caching principle is also used in the disk cache and the web page cache.
- When the cache fills up, it is emptied completely and reloaded.
- The replacement policy decides which block leaves when a new one must go in and there is no room.
- The faster a memory is, the cheaper per byte it usually is.
Solution
- T — The caching principle is also used in the disk cache and the web page cache.
- F — When the cache fills up, it is emptied completely and reloaded.
- T — The replacement policy decides which block leaves when a new one must go in and there is no room.
- F — The faster a memory is, the cheaper per byte it usually is.
When it fills up, a single block leaves, whichever the policy says. And in the hierarchy, speed and price go together: fast is expensive.
Match each replacement policy with the block it throws out:
| FIFO | |
| LRU | |
| LFU | |
| Random |
Definitions:
- Any one
- The one that came into the cache before the others
- The one that takes up the most bytes
- The one that has gone unused for longest
- The one that has been used the fewest times
Solution
- FIFO → The one that came into the cache before the others
- LRU → The one that has gone unused for longest
- LFU → The one that has been used the fewest times
- Random → Any one
FIFO looks at arrival; LRU, at last use; LFU, at how often it is used. Size isn’t a criterion of these policies.
A 2-block cache receives the requests X, Y, X, Z, X, Y. Looking in the cache costs 2 ns and a miss adds 40 ns to go to RAM. Work out the hits and the average time per access with FIFO and with LRU (average time = 2 + miss rate × 40):
| Access | X | Y | X | Z | X | Y |
|---|---|---|---|---|---|---|
| FIFO cache after | X | X Y | X Y | Y Z | Z X | X Y |
| LRU cache after | X | X Y | Y X | X Z | Z X | X Y |
| Policy | Hits | Average time (ns) |
|---|---|---|
| FIFO | ||
| LRU |
Solution
| Policy | Hits | Average time (ns) |
|---|---|---|
| FIFO | 1 | 35.33 |
| LRU | 2 | 28.67 |
FIFO: only the third access (X) hits. When Z arrives, X leaves because it came in first, so the fifth access (X) misses. Miss rate 5/6: 2 + (5/6) × 40 = 2 + 33.33 = 35.33 ns.
LRU: the third and fifth accesses (X) hit, because using X in the third makes it the most recent and when Z arrives Y leaves. Miss rate 4/6: 2 + (4/6) × 40 = 2 + 26.67 = 28.67 ns.
Match each unit with its value:
| Bit | |
| Byte | |
| Word | |
| 1 KiB | |
| 1 KB |
Definitions:
- Between 8 and 64 bits depending on the CPU
- 1024 bytes
- 8 bits
- 1,000,000 bytes
- One of two values, 0 or 1
- 1000 bytes
Solution
- Bit → One of two values, 0 or 1
- Byte → 8 bits
- Word → Between 8 and 64 bits depending on the CPU
- 1 KiB → 1024 bytes
- 1 KB → 1000 bytes
KiB is binary (2 to the power of 10) and KB is decimal (10 to the power of 3). The word depends on the processor.
For the OS to work, what must user programs not be able to do freely?
- Read or write the operating system’s memory
- Read or write another program’s memory
- Give orders directly to the printer controller
- Use the CPU for as long as they like
- Open a file with open()
- Use the processor’s cache memory
Solution
Answer: Read or write the operating system’s memory · Read or write another program’s memory · Give orders directly to the printer controller · Use the CPU for as long as they like
The three protected resources are memory (the OS’s and everyone else’s), I/O and the CPU. Asking the OS for something with a system call is allowed: it is the legal way to do it.
About dual mode, say whether each statement is true or false:
- In privileged mode any instruction in the instruction set can be executed.
- In privileged mode only privileged instructions can be executed.
- If a program in user mode tries a privileged instruction, the CPU raises an exception.
- Supervisor mode, system mode and kernel mode are names for the same mode.
- Interrupt service routines run in user mode.
Solution
- T — In privileged mode any instruction in the instruction set can be executed.
- F — In privileged mode only privileged instructions can be executed.
- T — If a program in user mode tries a privileged instruction, the CPU raises an exception.
- T — Supervisor mode, system mode and kernel mode are names for the same mode.
- F — Interrupt service routines run in user mode.
In privileged mode anything goes; in user mode, a privileged instruction causes an exception. ISRs are OS code and run in privileged mode.
Put in order the mode changes from switching the computer on until your program makes a system call:
- The OS switches to user mode just before handing control to your program
- The CPU boots in privileged mode
- Your program executes the system call instruction
- The CPU switches to privileged mode by itself and runs OS code
Solution
Correct order:
- The CPU boots in privileged mode
- The OS switches to user mode just before handing control to your program
- Your program executes the system call instruction
- The CPU switches to privileged mode by itself and runs OS code
It boots with full power, the OS gives it up before handing the CPU to a program, and it only comes back with an interrupt, a system call or an exception.
Complete about system calls and dual mode:
The system call instruction ____ the processor to ____ mode. That way a user program changes mode voluntarily, but what runs next is ____.
Words:
- switches
- the program’s code
- disables
- OS code
- user
- privileged
Solution
The system call instruction switches the processor to privileged mode. That way a user program changes mode voluntarily, but what runs next is OS code.
The syscall is the only voluntary door into privileged mode, and on the other side there is only OS code: the program can’t sneak its own instructions in.
Your C assignment calls printf(“Hello\n”). Which statement is correct?
- printf() runs in user mode and uses the write() system call to write to the console
- printf() is part of the kernel and runs in privileged mode
- printf() gives orders directly to the screen controller
- printf() never needs the operating system
Solution
Answer: printf() runs in user mode and uses the write() system call to write to the console
The C library is ordinary code in user mode. Only the system call inside it (write) enters the kernel.
In which ways can the arguments of a system call be passed to the kernel?
- In CPU registers
- In a table in main memory
- On the stack
- In a temporary file on disk
- In a controller’s local buffer
Solution
Answer: In CPU registers · In a table in main memory · On the stack
Registers are the usual way; if the arguments don’t fit, a table in memory (with its address in a register) or the stack is used.
A process has base = 30000 and limit = 8000. For each address, say whether the access is valid (write yes or no) and which is the last valid address:
| Address | Valid? |
|---|---|
| 29999 | |
| 30000 | |
| 37999 | |
| 38000 | |
| Last valid |
Solution
| Address | Valid? |
|---|---|
| 29999 | no |
| 30000 | yes |
| 37999 | yes |
| 38000 | no |
| Last valid | 37999 |
Valid if address ≥ base and address < base + limit = 38000.
29999 < 30000: exception. 30000 is the first valid one (≥ base). 37999 < 38000: valid, and it is the last one. 38000 is not < 38000: exception.
About I/O and memory protection, say whether each statement is true or false:
- Special I/O instructions, such as in and out, must be privileged.
- If I/O is memory-mapped, its addresses must be forbidden in user mode.
- The circuit that checks base and limit is active in supervisor mode.
- An access outside the allowed range reaches the bus, but memory ignores it.
- The base and limit registers mark out an area of main memory.
Solution
- T — Special I/O instructions, such as in and out, must be privileged.
- T — If I/O is memory-mapped, its addresses must be forbidden in user mode.
- F — The circuit that checks base and limit is active in supervisor mode.
- F — An access outside the allowed range reaches the bus, but memory ignores it.
- T — The base and limit registers mark out an area of main memory.
The check is made in user mode (in privileged mode the OS can touch all of memory). An illegal access never reaches the bus: it turns into an exception.
Complete about CPU protection:
So that no process can ____ the CPU, the OS uses a ____. It loads it with a value, the counter goes down with every clock tick and, when it reaches ____, it raises an ____ with which the OS regains control.
Words:
- exception
- timer
- interrupt
- buffer
- share
- one
- zero
- hog
Solution
So that no process can hog the CPU, the OS uses a timer. It loads it with a value, the counter goes down with every clock tick and, when it reaches zero, it raises an interrupt with which the OS regains control.
The timer guarantees that the OS runs again even if a program is stuck in an infinite loop. And since changing it is privileged, the program can’t switch it off.
Match each operating system component with its description:
| System programs | |
| Kernel | |
| System call |
Definitions:
- The part of the OS that is always in memory and handles system calls and other events
- Utilities such as the shell, ls or the compiler, and background services
- Maths function library your program links against
- For the programmer, a subroutine; for the CPU, an instruction that changes mode
Solution
- System programs → Utilities such as the shell, ls or the compiler, and background services
- Kernel → The part of the OS that is always in memory and handles system calls and other events
- System call → For the programmer, a subroutine; for the CPU, an instruction that changes mode
System programs are what users perceive as “the OS”; the kernel is what works underneath, and system calls are the way of asking it for things.
Match each UNIX system call with what it manages:
| fork | |
| sbrk | |
| mkdir | |
| socket | |
| chmod |
Definitions:
- Networks
- Files
- CPU scheduling
- Processes
- Protection
- Memory
Solution
- fork → Processes
- sbrk → Memory
- mkdir → Files
- socket → Networks
- chmod → Protection
fork creates processes, sbrk asks for more memory, mkdir creates directories, socket opens a network connection and chmod changes permissions.
Put the steps of a typical operating system boot in order:
- The CPU starts executing at a fixed memory address
- The loader installs the kernel and modules and services load until everything is ready
- A small boot routine stored in ROM runs
- The routine finds the OS loader (boot loader) and loads it into memory
Solution
Correct order:
- The CPU starts executing at a fixed memory address
- A small boot routine stored in ROM runs
- The routine finds the OS loader (boot loader) and loads it into memory
- The loader installs the kernel and modules and services load until everything is ready
ROM → loader → kernel → services. The ROM already knows how to read from the devices, which is why it can find the loader.
Match each OS structure with its idea:
| Monolithic | |
| Layered | |
| Microkernel | |
| Loadable modules | |
| Hybrid |
Definitions:
- The minimum in the kernel; the rest in user space with messages
- Mixes several of the above
- A different kernel for each user
- Each level uses the services of the level below
- Pieces of code added to the kernel at runtime
- The whole kernel in a single address space
Solution
- Monolithic → The whole kernel in a single address space
- Layered → Each level uses the services of the level below
- Microkernel → The minimum in the kernel; the rest in user space with messages
- Loadable modules → Pieces of code added to the kernel at runtime
- Hybrid → Mixes several of the above
Examples: classic UNIX (monolithic), THE (layered), Mach (microkernel), Linux and Solaris (modules) and Windows, macOS or Android (hybrid).
What is the OS structure called that keeps only the essentials in the kernel and moves the other services to user mode?
Solution
Answer: Microkernel
The microkernel keeps only the basic mechanisms inside (multitasking, interrupts, communication between processes) and the rest are modules in user space.
About policies, mechanisms and microkernels, say whether each statement is true or false:
- A policy is a strategy, such as LRU; a mechanism is what lets you carry it out, such as a wait queue.
- In a microkernel, the policies go inside the kernel and the mechanisms outside.
- One drawback of the microkernel is that messages between modules cost performance.
- One advantage of the microkernel is that less code runs in privileged mode.
- Linux is monolithic, but modules can be added to it while it runs.
Solution
- T — A policy is a strategy, such as LRU; a mechanism is what lets you carry it out, such as a wait queue.
- F — In a microkernel, the policies go inside the kernel and the mechanisms outside.
- T — One drawback of the microkernel is that messages between modules cost performance.
- T — One advantage of the microkernel is that less code runs in privileged mode.
- T — Linux is monolithic, but modules can be added to it while it runs.
In the microkernel, mechanisms go inside and policies outside. Less privileged code = more security, at the price of the messages.
In the true-or-false ones, look for the words “only”, “always” and “at the end”. In this topic, nearly every trap sits in one of those three.
Open-answer questions
In the written exam the idea isn’t enough: you have to tell it in order and with the topic’s own words. Write your answer before looking at the model one.
A process A sends a document to the printer and the system works asynchronously. Explain what happens from the request until A runs again, and why this is faster than the synchronous way.
Solution
Model answer:
A requests the printing with a system call, which is a software interrupt: the CPU switches to privileged mode and the OS runs. The OS handles the call and talks to the printer controller: it leaves the data in its local buffer and gives it the order (if the printer were busy, it would put the request in its wait queue).
Since A has to wait for the printer, the OS doesn’t leave the CPU idle: it does a context switch and runs another process, B. The printer works on its own. When it finishes, its controller raises a hardware interrupt; the CPU saves B’s state, runs the printer’s ISR and the OS decides to resume A.
It performs better because the time the printer takes isn’t wasted: synchronously, the CPU would sit waiting (or asking) without doing anything useful.
What the marker looks for:
- The system call as the way of requesting I/O (and the switch to privileged mode)
- The dialogue with the controller (buffer, order) and the wait queue if it is busy
- The context switch to another process during the wait
- The end-of-I/O interrupt, with the state saved before the ISR
- The comparison with synchronous I/O: idle CPU versus CPU put to use
Compare polling and vectored interrupts as ways of finding out which device has interrupted. What role does the interrupt vector play?
Solution
Model answer:
With polling, the CPU asks each device, one after another, whether it was the one that interrupted. It is simple but slow: the more devices, the more questions and the more CPU time wasted.
With vectored interrupts, the interrupting device sends a number over the data bus. That number is an index into the interrupt vector, an area of main memory holding the addresses of all the interrupt service routines. The CPU looks up that slot and jumps straight to the right ISR without asking anyone.
The vector also serves every kind of event: hardware interrupts, system calls and exceptions all have their entry.
What the marker looks for:
- Definition of polling and its cost (it grows with the number of devices)
- The number the device sends with vectored interrupts
- The vector as a table of ISR addresses in main memory
- Conclusion: vectored interrupts are faster
Explain what dual-mode operation is, when the CPU switches from one mode to the other and how the hardware uses it to protect memory and the CPU.
Solution
Model answer:
The CPU defines a set of privileged instructions and works in two modes. In privileged mode (kernel, supervisor or system mode) any instruction can be executed; in user mode, trying a privileged instruction raises an exception.
The CPU boots in privileged mode. Before handing control to a program, the OS switches to user mode, and privileged mode only comes back when the OS regains control: through an interrupt, a system call or an exception. The system call instruction switches mode automatically, but what runs next is OS code.
Memory: the base and limit registers mark out the process’s area of main memory; in user mode, a circuit checks every access and, if it steps outside, raises an exception and the access never reaches the bus. CPU: the timer is loaded with a value, goes down with every clock tick and raises an interrupt at zero, so no process can hog the CPU. Changing these registers and the timer is privileged, which is why the program can’t switch them off.
What the marker looks for:
- The two modes and what happens with a privileged instruction in user mode
- When the mode changes (boot, handing over control, interrupt, call, exception)
- The system call as the voluntary way into privileged mode
- Base and limit registers with the check in user mode
- The timer and why the program can’t switch it off
Compare the monolithic and the microkernel structures. Include the difference between mechanisms and policies and an example of each structure.
Solution
Model answer:
In a monolithic system, all the kernel’s functionality is in a single address space, “everything in one big lump”. It is the simplest and fastest structure, because the parts call each other directly, but one part can’t be changed on its own: a change affects the rest. Example: classic UNIX.
In a microkernel, only the essentials stay in the kernel (basic multitasking, interrupt handling, communication between processes) and the other services are modules in user space that talk through messages. Example: Mach (1980).
Policies are the strategies for managing a resource (FIFO, LRU, SJF…) and mechanisms are the structures used to carry them out (queues, bitmaps, the timer…). The microkernel keeps the mechanisms inside and the policies outside. Advantages: new services without touching the kernel, easier to port and safer, because there is less privileged code. Drawback: messages between modules cost performance.
What the marker looks for:
- Monolithic: a single address space and the problem of changing it
- Microkernel: the minimum inside and services in user mode with messages
- Policy versus mechanism, with examples
- Advantages and drawback of the microkernel
- An example of each structure
In this topic’s open questions, organise the answer in the order things happen (who asks, who handles it, who reports back). A sketch with arrows in the margin helps you not to skip steps.
The whole topic in one drawing
Before the cheat sheet, the whole topic at a glance. The four branches are the four blocks of the theory, and each one has the four ideas that come up most.
Cheat sheet: The hardware that holds up the operating system
The essentials in 30 seconds
- Controller: connects the device to the bus, has a local buffer and reports with an interrupt.
- Interrupt: save the state before, run the OS’s ISR, restore and carry on.
- Reactive OS: it only wakes up with hardware interrupts, system calls and exceptions.
- Asynchronous > synchronous: the CPU does something else while the I/O works.
- Hierarchy: higher up, faster, dearer and smaller. Cache: most used data in the fastest memory.
- Dual mode: in privileged mode everything runs; in user mode, a privileged instruction raises an exception.
- Protection: privileged I/O, base and limit for memory, timer for the CPU.
If they ask you…
| They ask you… | Answer… |
|---|---|
| When is the CPU state saved? | Before running the ISR |
| Who writes the ISRs? | The operating system, not the applications |
| What is the interrupt vector? | An area of main memory with the addresses of all the ISRs |
| Polling or vectored? | Polling: the CPU asks. Vectored: the device sends a number |
| What is a software interrupt? | A system call or an exception: like a hardware one, but triggered by the CPU |
| Instructions to trigger one? | INT (Intel), TRAP (Motorola), SYSCALL (MIPS) |
| Which mode does the CPU boot in? | Privileged mode |
| When does it go back to privileged mode? | With an interrupt, a system call or an exception |
| Where are base and limit checked? | In user mode, on every access; if it fails, exception and the access never reaches the bus |
| How are system call arguments passed? | In registers (the usual way), in a table in memory or on the stack |
| Is the C library part of the OS? | No: it runs in user mode; printf() uses write() |
The protections in one table
| Resource | Risk | Protection |
|---|---|---|
| I/O | Talking to the devices directly | Privileged I/O instructions or I/O addresses forbidden in user mode |
| Memory | Touching the memory of the OS or of another process | Base and limit registers and an exception if it steps outside |
| CPU | Hogging the CPU (infinite loop) | A timer that raises an interrupt when it reaches zero |
| All of them | Switching the protections off | Dual mode: changing them is privileged |
Templates for the calculations
| Calculation | Formula | Example from the quiz |
|---|---|---|
| CPU usage | useful CPU / total time | Asynchronous: 140 / 160 = 87.5 % |
| Synchronous I/O | (CPU + I/O) for each page, plus the other process afterwards | 2 × (30 + 50) + 80 = 240 ms |
| Average time with a cache | cache time + miss rate × RAM time | LRU: 2 + (4/6) × 40 = 28.67 ns |
| Base and limit | valid if base ≤ addr < base + limit | base 30000, limit 8000: from 30000 to 37999 |
If you’re torn between two options…
| If you’re torn between… | Think about… |
|---|---|
| Synchronous and asynchronous | Does the CPU wait (synchronous) or do something else (asynchronous)? |
| FIFO and LRU | Does it matter when it came in (FIFO) or when it was last used (LRU)? |
| Policy and mechanism | Is it a strategy (policy) or a structure to carry it out (mechanism)? |
| Monolithic and microkernel | Everything inside (monolithic) or the minimum inside plus messages (microkernel)? |
| Controller and driver | Is it hardware (controller) or OS software (driver)? |
| Symptom in a statement | Likely reason it is false |
|---|---|
| “only” about privileged mode | Everything runs in privileged mode |
| “at the end of the ISR” | The state is saved before |
| “secondary memory” with base and limit | It is main memory |
| “in the one with the largest capacity” about the cache | It is the one with the shortest access time |
| “hardware interrupt” about system calls | They are software interrupts |
Before you hand it in, ask yourself
- Have I checked the order in every step-by-step question (save, ISR, restore)?
- Does any statement have an “only” or an “always” that makes it false?
- In the cache calculations, have I added the time to look in the cache on the misses too?
- With base and limit, have I used “less than” base + limit and not “less than or equal to”?
With this topic we close the introduction to operating systems. In the next one we’ll get into processes and threads: what exactly that thing is that the OS keeps interrupting, saving and resuming.
Keep goingAll Operating systems articlesDid this article help you? Here is how you can support SergioLearns →



