Interrupt


Mechanism

  1. Causes Process (进程) to temporarily suspend
  2. Save the state info of the process into the corresponding Process Control Block (PCB)
  3. Executes the Interrupt Handler
  4. 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


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


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 (外中断)