Skip to content

Latest commit

 

History

History
27 lines (20 loc) · 1.56 KB

life_cycle_cpu.md

File metadata and controls

27 lines (20 loc) · 1.56 KB

The life cycle of a CPU

Boot: (for details, see boot_process) entry.S -> start.c -> main.c calls schedule()

schedule(): schedule() enters an infinite loop and will never return. From now on the harts will do this forever:

  • look for a process to run (for details see scheduling)
    • If there is none, wait for an interrupt (wfi assembly instruction, CPU sleeps).
      • A timer interrupt or a device interrupt will wake this up (see interrupts).
        • This calls kernel_mode_interrupt_handler()
        • Both interrupt types will quickly do their things and then return to the scheduler which starts its next loop.
          • (There is no process the timer interrupt could force to yield)
    • If there is a process, context_switch() will load the processes context/registers, and return to that context.
      • A new process starts in forkret() (set in alloc_process()) which will return to user mode and thus start the application.
      • An existing process returns to its yield() call in S-mode.
        • This process can switch between kernel and user space until a wait() or timer interrupt (interrupts) will have the process call yield(). This switches back to the schedulers context via context_switch().

Overview: kernel

Boot: boot_process | init_overview

See also: life_cycle_cpu life_cycle_user_application