Skip to content

Latest commit

 

History

History
32 lines (18 loc) · 1.7 KB

timer_interrupt.md

File metadata and controls

32 lines (18 loc) · 1.7 KB

Timer Interrupt

Timer interrupts are created by PLIC in M-mode. If the platform supports SBI, it will create timer interrupts in S-mode.

The kernel handles timer interrupts in trap.c.

Interval

Timer interrupts happen at a fixed interval set via TIMER_INTERRUPTS_PER_SECOND. This also dictates the timer granularity for ms_sleep: E.g. at 100 for TIMER_INTERRUPTS_PER_SECOND, each timer interrupt happens after 10 milliseconds. ms_sleep will at least take one interrupt interval.

Timer Interrupt while a process executes

If an application was running when the timer interrupts occurred, it will:

  • Call u_mode_trap_vector (like a syscall)
  • user_mode_interrupt_handler() will call yield() for the process
  • yield() basically calls schedule() and switch back to the scheduler
  • Once rescheduled it basically returns to where it was interrupted in user mode

A timer interrupt can also happen while the process in in kernel mode (e.g. during a syscall). It also yields but on return will continue with the process in kernel mode.


Overview: kernel

Boot: boot_process | init_overview

Subsystems: interrupts | devices | file_system | memory_management processes | scheduling | syscalls