prepare_task_switch(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… prepare_task_switch(9) β€” like, the official kernel API manual, bestie ✨

Okay so real talk: this is a page from the Kernel API Manual and it's all about prepare_task_switch β€” the little pre-game ritual the scheduler does before it hands the CPU to somebody else. It's short, it's iconic, and it's load-bearing, so pay attention 🫢


✨ SYNOPSIS ✨

void prepare_task_switch (struct rq *rq , struct task_struct *prev ,
       struct task_struct *next );

That's the whole thing. Returns void. No notes. No drama. Just vibes and a context switch incoming πŸ¦‹


πŸŽ€ ARGUMENTS πŸŽ€

  • rq β€” the runqueue that's getting ready to do the switch. It's the one throwing the party πŸ’…
  • prev β€” the current task, aka the one being switched out. It's leaving the group chat 😭
  • next β€” the task we're going to switch to. Main character energy, arriving now πŸ‘‘

πŸ”₯ DESCRIPTION πŸ”₯

So here's the tea: this gets called with the rq lock held and interrupts off. That's not optional, that's the whole deal, no cap.

It must be paired with a subsequent finish_task_switch after the context switch. Like, they're a matching set. Separating them is giving "unfinished business" and we don't do that here πŸ™ˆ

What it actually does: prepare_task_switch sets up locking and calls architecture specific hooks. Architecture specific. Like, the arch code gets to do its own little thing. Slay ✨

⚠️ Genuine caution, bestie: rq lock held, interrupts off. Do not show up to this function unprepared. It is not a "figure it out as you go" situation πŸ’€

🌈 SEE ALSO 🌈

Kernel file ./kernel/sched/core.c β€” and like, a whole friend group of related functions:


And that's the page, periodt πŸŽ€ Huge thanks to ./kernel/sched for keeping the receipts β€” this one's from the October 2026 release of the Kernel API Manual. Go forth and switch tasks responsibly, babe πŸ§šπŸ’œ

πŸ“¦ where this page comes from