Lesson 2: Syscalls and interrupts Flashcards
Privileged instructions
The way the OS talks with the hardware and storage. Only the OS can give these instructions and not a user.
Interrupts
The wat the hardware speaks to the OS
User mode
When the CPU is running the user’s code
Kernel mode
When the CPU is running the OS’s code
System calls
Moves from user mode to kernel mode
Privileged mode
= Kernel mode
How can user programs access or alter internal OS data structures or hardware?
Through system calls only (protection)
Difference between system calls and other internal OS functions
System calls check the validity of the parameters, whereas other internal OS functions don’t.
What’s the name of the process moving from the user to the kernel mode?
Trap
Trap
The process of switching between user and kernel mode
Mode bit
Provides ability to distinguish when system is running user code or kernel code. This way some instructions that are privileged can only be executed in the kernel mode.
What causes the mode to change from user to kernel?
System call
What causes the mode to change from kernel to user?
The return from the system call
What can cause a transition from user to kernel mode?
- A system call
2. An exception (e.g., divide by 0) - handled as part of the CPU architecture.
Is “echo”, “grep” and other functions in the shell part of the OS?
No. They are applications that run above the OS but can be considered as OS services.
What are the 6 layers of the computer system?
- Apps
- User interface - shell or windows
- Libraries - the interface the OS gives us so we can use it with other applications
- OS abstractions - file systems, jobs/processes/threads, sockets
- Drivers - interface to hardware
- Hardware
How does the computer communicate with IO devices?
Via busses
What are busses?
The way to connect to IO devices
Advantages of busses
- Versatility - easy to add new devices and move them between computer systems
- Low cost - share a single set of ways in multiple ways
Disadvantages of busses
- Communication bottleneck - the bandwidth of the bus limits the maximum IO throughput
- Max bus speed is limited by length of bus, number of devices on the bus, and the need to support a range of devices with varying latencies and data transfer rates.
Interrupts (hardware interrupts)
פסיקה
Way that devices can communicate with OS.
For example: The way the screen tells the OS that it finished writing something, the disk finished reading a file, etc.
IRQ
Interrupt request lines - special line that the interrupts travel through to get to the CPU.
Interrupt vector table (interrupt description table)
Every interrupt has a code that says what needs to happen with the interrupt occurs. The table saves the address where this code resides.
What does system calls cause?
A trap - aka software (or internal) interrupt.
Software interrupts
Either a system call or an exception
Exceptions are ____ interrupts
Exceptions are internal interrupts
Periodic vs aperiodic interrupts
Periodic - the clock (part of the CPU) does an interrupt periodically so the control can pass over to the OS.
Aperiodic - all the other types of interrupts we spoke about
Software vs hardware interrupts
Software: causes by a software, this includes traps and exceptions.
Hardware: caused by hardware, this includes interrupts from external devices.
Internal vs external interrupts
Generally: Internal=Software, External=Hardware
Synchronous vs. asynchronous interrupts
Synchronous: happens with the clock ticks (software, timer/clock interrupts).
Asynchronous: More tricky because you don’t know which command you need to go back to
Maskable vs. non-maskable interrupts
Maskable: hardware interrupts that can be delayed if more important interrupts is currently handled.
Where is there more overhead: in user mode vs kernel mode?
User, since you don’t have traps.
What are advantages of having a smaller kernel?
- Fewer traps –> less overhead –> higher throughput
- Smaller memory footprint
- More functions outside of kernel, so if they change, there’s no need to recompile the kernel.
What are disadvantages of having a smaller kernel?
Less protection
Monolithic kernel
The kernel has basic functions and you can load other modules into the memory when necessary
Microkernels
A few different kernels that work together
Difference between Monolithic kernels and Microkernels?
If they work on the same address space or not.
Single address space - monolithic.
Are system calls privileged?
No.
Interrupt controller
Serves a an intermediate between the hardware devices and the processor. it can take input from different devices, and alerts the processor.
APC
Asynchronous procedure call
For example: an interrupt, because the program can’t control it.
Why are interrupts characterized as APCs (Asynchronous procedure call)?
Because they aren’t part of the regular, pre-planned code. The program can’t control when it’ll be.
Mechanism of interrupts
(Similar to functions)
- Getting the interrupt
- Saving current state
- Transfer control & service the request (using an “interrupt vector”)
- Previous state is restored
- Return control (back to user mode)
Internal interrupts
Internal interruption (exception) occurs when the processor detects an error condition while executing an instruction (unlike external interrupts, which occur at random times during the execution of a program)
Examples of internal interrupts
Division by zero Segmentation fault Privileged instruction Invalid instruction Page fault
What happens when an exception occures?
- When an exception occurs, the address of the instruction which generated the exception is saved.
- Then the OS gives the exception handler a chance to fix the problem.
- If there was an handler, the program is restarted at the address of the fault and continue normally
Otherwise, the program is aborted.
What type of interrupt can happen between clock cycles?
Only external interrupts (and not internal ones)
Trap
A trap is a type of exception (internal interrupt), which occurs in the usual run of the program, but unlike it, it is not product of some error.
Trap causes switching to OS code and to kernel mode. Once in kernel mode, a trap handler is executed to service the request.
Breakpoints in debuggers are created by using ____.
Breakpoints in debuggers are created by using traps.
The system call is a wrapper function that runs in ____ mode which calls the interrupt which is handled in ____ mode.
The system call is a wrapper function that runs in user mode which calls the interrupt which is handled in kernel mode.