4 - Interrupts, Traps, Kernel Design, VMs Flashcards
At a LOW level, how do we write programs that interact with devices?
Special I/O instructions
Memory mapped devices
At a HIGH level, how do we write programs that interact with devices?
System calls provided by OS
There are blocking and non blocking versions of system calls
What is I/O busy waiting/spinning/busy looping?
CPU repeatedly checks if device is ready
What are some problems with busy waiting?
CPU is tied up while the slow I/O completes the operation
We are wasting power and generating heat (so what?)
What is I/O busy waiting with delay?
same as busy waiting, we just add a short delay to reduce CPU usage
CPU can do other things while program is sleeping
What are some problems with busy waiting?
- hard to estimate the right amount of sleep
* program might end up running longer than necessary
What are interrupts?
A mechanism to let the CPU know something ‘important’ happened
When the I/O device finishes the operation, it generates an interrupt,
letting the CPU know it’s done, or if there was an error
How is an interrupt handled?
Usually handled immediately
the CPU temporarily suspends its current activity (saves state)
The CPU then executes an ISR
- The CPU puts itself in a kernel mode (privileged mode)
- Which routine[s] gets executed is configured by OS
Eventually CPU restores the saved state and resumes original execution
What is an Interrupt Vector Table?
Each interrupt contains an address of a service routine
What are the two different types if interrupt?
Hardware & Software Interrupts
What are Hardware Interrupts?
The source of the interrupt is another device
Interrupts are UNPREDICATABLE
What are Software Interrupts? (exceptions/traps?)
Source of interrupt is CPU itself
What are the two types of software interrupt?
Intentional and unintentional
What are Unintentional software Interrupts?
EXCEPTIONS
occurs when CPU executes ‘invalid’ instruction
What are Intentional software Interrupts?
TRAPS
the purpose is to execute predefined routine in kernel mode
operating systems use traps to implement system calls
Differences between hardware and software interrupts?
Hardware Interrupts: • external event delivered to the CPU • origins: I/O, timer, user input, ... • asynchronous with the current activity of the CPU • the time of the event is not known and is not predictable
Software Interrupts: • internal events, eg. system calls, error conditions (div by zero) • synchronous with the current activity of the CPU • occurs as a result of execution of a machine instruction
Similarities between hardware and software interrupts?
put the CPU in a kernel mode
save the current state of the CPU
invoke a kernel routine, defined by the OS
resume the original operations when done, restoring user mode
What are the limits of interrupts?
Many small interrupts is inefficient
What is DMA?
Direct Memory Access
• DMA absorbs most interrupts
• DMA can save data directly into memory, without CPU even knowing
• result is less interrupts for CPU
What is the important trade-off when considering what to put in the kernel?
Stability vs. speed
Kernel code is faster but more bug prone
What is a monolithic kernel design?
the entire OS runs as a single program in kernel mode
fastest, but harder to port, more prone to bugs, potentially less stable
What is a microkernel?
only essential components in kernel ― running in kernel mode
• essential = code that must run in kernel mode
• the rest is implemented in user mode
• less bugs, easier to port, easier to extend, more stable, but slower
What is a hybrid kernel?
• trying to balance the cons/pros of monolithic kernels and microkernels
What does IPC stand for?
Inter-process communication?
What are Kernel Modules?
A type of hybrid kernel
Base is a small kernel with essential components, with dynamically loadable kernel parts (modules)
Drivers are often implemented as modules
When are kernel modules loaded?
Boot time
Later - e.g., when user plugs in USB device
What are some disadvantages to the layered approach in kernel design?
Hard to define layers
Less efficient
Not all problems can be adapted to layers
MAC OSX is a hybrid kernel
True or False?
True - XNU
GNU/Linux kernel is a hybrid kernel
True or False?
Technically false, but does have some layers and dynamically loadable modules
Win NT kernel is hybrid
True or False?
True
What is a VM?
Virtual Machine
Emulate computer systems
What is a Hypervisor?
Software or Hardware that manages VMs
What are the three different types of hypervisor
Bare-metal - Runs directly on hardware - fastest (VMWare)
Hosted - Runs on top of another OS - slower (VMWare, Virtual Box)
Hybrid - eg. Linux kernel can function as a hypervisor
through a KVM module
What is OS Virtualization? Examples?
The use of software to allow system hardware to run multiple instances of different operating systems concurrently.
What are three benefits of VMs?
Host system is protected from the VMs VMs are isolated from eachother Multiple different OSs can be running on the same computer concurrently Can save state System consolidation - Cost effective
Why do modern OSs move away from the standard monolithic
system structure?
Slow boot
Error prone
Harder to port