CPU_NEED_RESCHED(9)

πŸ“¦ version 11.0, in nixpkgs unstable

πŸ’… NAME πŸ’…

okay so bestie, welcome to CPU_NEED_RESCHED(9) from the Kernel Developer’s Manual β€” and the name is literally cpu_need_resched β€” context switch notification. that’s the vibe. ✨


πŸŽ€ SYNOPSIS πŸŽ€

#include <sys/cpu.h>

void
cpu_need_resched(struct cpu_info *ci, struct lwp *l, int flags);

πŸ’– DESCRIPTION πŸ’–

okay so cpu_need_resched() is the machine-independent interface for the scheduler to notify machine-dependent code that a context switch from the current LWP l, on the cpu ci, is required. it’s giving β€œhey bestie, we gotta switch things up” energy. πŸ’…

this event may occur if a higher priority LWP appears on the run queue, or if the current LWP has exceeded its time slice. l is the last LWP observed running on the CPU. and no cap, it may no longer be running, because cpu_need_resched() can be called without holding scheduler locks. 😭

here’s the flag tea:

  • RESCHED_KPREEMPT β€” if this flag is specified in flags and the __HAVE_PREEMPTION C pre-processor macro is defined in <machine/intr.h>, machine-dependent code should make a context switch happen as soon as possible even if the CPU is running in kernel mode. if RESCHED_KPREEMPT is not specified, then RESCHED_UPREEMPT is specified instead. slay. πŸ”₯
  • RESCHED_IDLE β€” if this flag is specified in flags, the last thread observed running on the CPU was the idle LWP.
  • RESCHED_REMOTE β€” if this flag is specified in flags, the request is not for the current CPU. the opposite also holds true. if ci is not the current processor, cpu_need_resched() typically issues an inter processor call to the processor to make it notice the need of a context switch as soon as possible.
bestie, important: cpu_need_resched() is always called with kernel preemption disabled. always. πŸ‘‘

typically, the cpu_need_resched() function will perform the following operations:

  • Set a per-processor flag which is checked by userret(9) when returning to user-mode execution.
  • Post an asynchronous software trap (AST).
  • Send an inter processor interrupt to wake up cpu_idle(9) and/or force an user process across the user/kernel boundary, thus making a trip through userret().

πŸ¦‹ SEE ALSO πŸ¦‹


mwah πŸ’– this CPU_NEED_RESCHED(9) page is from Debian, dated November 17, 2019 β€” periodt, that’s the footer tea β˜•βœ¨

πŸ“¦ where this page comes from