Interrupt
- When an interrupt occurs, Program Counter jumps to Interrupt Handler & execute
Mechanism
- Causes Process (进程) to temporarily suspend
- Save the state info of the process into the corresponding Process Control Block (PCB)
- Executes the Interrupt Handler
- When Interrupt Handler is done, the running Process (进程) is restarted and the state is restored from the PCB
Free the CPU, no more Polling
We don’t need to get CPU to keep Polling for response which may take a long time to produce. Instead, send a notification to the CPU via interrupt. Thus, CPU is able to do other stuff while waiting for a response
Generally can't be interrupted
Interrupts are allowed to run to completion without being interrupted by other sources. For example, if a keyboard’s interrupt is interrupted, we may lose the input from the keyboard
However, there are exceptions (This part I haven’t explored yet)
Busy State
As long as the Interrupt Handler is running, other interrupts may not be handled, and interrupts are generally not queued
But Interrupt Priorities exist in some systems to handle Simultaneous Interrupts
Tip
Interrupts should complete quickly to prevent the above problems
Software Interrupt
- Follow the Synchronous Sequential Circuit behaviour
- Request a service or privileged operations (System Call (系统调用)) from the Kernel
Syscall brings Better Security
Programs in User Space switching Privilege Level themselves is dangerous. With Software Interrupt, the CPU is preconfigured by Kernel with where in the kernel code to jump to
Trap Interrupt
Used to switch from User Mode to Kernel Mode. See Trap Interrupt (陷入) for more details.
Upcall
- Known as Signal in Unix-like, or Asynchronous Events in Windows
- Follow the Asynchronous Sequential Circuit behaviour, can occur at any time. Primarily focused on Inter-Process Communication (IPC) and event handling within a process
- Upcall allows us to insert Upcall Handler to Process (进程), a way to bridge the gap between process and Hardware interrupts (外中断)
How is the upcall passed to the process?
This upcall instructions are ‘inserted’ by the Interrupt Handler when the interrupt handler saves the process’s Program Counter during an Interrupts (中断) like Context Switch. Instead of saving the Memory Address of the current process instruction, the interrupt handler saves the memory address of the upcall instructions, so when the process is switched back, the process executes the upcall that is passed to it.
Example
Generated by the kernel itself
- Async IO notification
- Logout — to notify applications that they should save file data and cleanly terminate
- Resource adjustment - Java process can adapt to different amounts of available memory by changing the frequency of how often it runs its Garbage Collector. The more memory, the less time
Generated by another process
- Termination signal –
SIGKILL
Asynchronous I/O notification
A separate notification sent via an upcall to the application when the I/O completes. This eliminates waiting (idle) process that waits for IO System Call (系统调用) to complete!
Upcall Handler
- A fixed set of Instruction the Kernel wants the Process (进程) to handle
- The process can register its own signal handler with the kernel to overwrite the default upcall handler the kernel provides
Hardware interrupts (外中断)
- Raised by hardware devices. Follow the Asynchronous Sequential Circuit behaviour, can occur at any time
- One example is Timer Chip used for Preemptive Scheduling
- We have a Interrupt Controller like the RISCV CLINT in RISCV to handle interrupt sources that share the same interrupt pin
Alarm Signal
Sent after a specified number of seconds has elapsed to notify a process of an event
Turn off interrupt in XV6-RISCV
This is achieved by writing to the Control & Status Registers (CSRs) -
sstatus
. The code snippets below going down the Abstraction
intr_off()
is the entry pointWe can see from code snippet below, to disable the interrupt is setting the second bit from right on the
sstatus
registerEventually, it boils down to Assembly language