finish_task_switch(9)
π 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
wake_q_add(9)wake_q_add_safe(9)task_curr(9)try_to_wake_up(9)task_call_func(9)cpu_curr_snapshot(9)wake_up_process(9)preempt_notifier_register(9)preempt_notifier_unregister(9)prepare_task_switch(9)schedule_tail(9)schedule_preempt_disabled(9)preempt_schedule_notrace(9)init_idle(9)curr_task(9)
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
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms