finish_task_switch(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… finish_task_switch(9) β€” Kernel API Manual ✨

πŸŽ€ NAME πŸŽ€

finish_task_switch β€” clean up after a task-switch. That's the whole name, periodt.

⭐ SYNOPSIS ⭐

struct rq * finish_task_switch (struct task_struct *prev );

πŸ’– ARGUMENTS πŸ’–

  • prev β€” the thread we just switched away from. Hiii, previous task, we still see you. πŸ‘‘

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so bestie, here's the situation: finish_task_switch must be called after the context switch, and it's paired with a prepare_task_switch call before the context switch. They're a matching set, no cap.

finish_task_switch will reconcile locking set up by prepare_task_switch, and do any other architecture-specific cleanup actions. It's giving cleanup era, and honestly? Slay.

Not me remembering that we may have delayed dropping an mm in context_switch. If so, we finish that here outside of the runqueue lock.

🚨 Doing it with the lock held can cause deadlocks; see schedule for details. So please don't. πŸ’€

The context switch has flipped the stack from under us and restored the local variables which were saved when this task called schedule in the past. 'prev == current' is still correct, but we need to recalculate this_rq because prev may have moved to another CPU. Literally recalculating the vibe check. 🌈

🧚 SEE ALSO 🧚

Kernel file: ./kernel/sched/core.c


Cute little sign-off: this page comes from the ./kernel/sched source/version, stamped October 2026, and it's all about finish_task_switch(9). Bye bestie, go forth and finish that task switch correctly. πŸ«ΆπŸ’…

πŸ“¦ where this page comes from