CPU_NEED_RESCHED(9)
π 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 inflagsand the__HAVE_PREEMPTIONC 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. ifRESCHED_KPREEMPTis not specified, thenRESCHED_UPREEMPTis specified instead. slay. π₯RESCHED_IDLEβ if this flag is specified inflags, the last thread observed running on the CPU was the idle LWP.RESCHED_REMOTEβ if this flag is specified inflags, the request is not for the current CPU. the opposite also holds true. ifciis 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 throughuserret().
π¦ 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
- nixpkgs unstable: netbsd-source 11.0
- Copyright (c) 2002, 2019 The NetBSD Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms