Skip to content

Commit 36c6e17

Browse files
Valentin SchneiderPeter Zijlstra
authored andcommitted
sched/core: Print out straggler tasks in sched_cpu_dying()
Since commit 1cf12e0 ("sched/hotplug: Consolidate task migration on CPU unplug") tasks are expected to move themselves out of a out-going CPU. For most tasks this will be done automagically via BALANCE_PUSH, but percpu kthreads will have to cooperate and move themselves away one way or another. Currently, some percpu kthreads (workqueues being a notable exemple) do not cooperate nicely and can end up on an out-going CPU at the time sched_cpu_dying() is invoked. Print the dying rq's tasks to shed some light on the stragglers. Signed-off-by: Valentin Schneider <valentin.schneider@arm.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Valentin Schneider <valentin.schneider@arm.com> Tested-by: Valentin Schneider <valentin.schneider@arm.com> Link: https://lkml.kernel.org/r/20210113183141.11974-1-valentin.schneider@arm.com
1 parent 9c7d901 commit 36c6e17

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

kernel/sched/core.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7574,6 +7574,25 @@ static void calc_load_migrate(struct rq *rq)
75747574
atomic_long_add(delta, &calc_load_tasks);
75757575
}
75767576

7577+
static void dump_rq_tasks(struct rq *rq, const char *loglvl)
7578+
{
7579+
struct task_struct *g, *p;
7580+
int cpu = cpu_of(rq);
7581+
7582+
lockdep_assert_held(&rq->lock);
7583+
7584+
printk("%sCPU%d enqueued tasks (%u total):\n", loglvl, cpu, rq->nr_running);
7585+
for_each_process_thread(g, p) {
7586+
if (task_cpu(p) != cpu)
7587+
continue;
7588+
7589+
if (!task_on_rq_queued(p))
7590+
continue;
7591+
7592+
printk("%s\tpid: %d, name: %s\n", loglvl, p->pid, p->comm);
7593+
}
7594+
}
7595+
75777596
int sched_cpu_dying(unsigned int cpu)
75787597
{
75797598
struct rq *rq = cpu_rq(cpu);
@@ -7583,7 +7602,10 @@ int sched_cpu_dying(unsigned int cpu)
75837602
sched_tick_stop(cpu);
75847603

75857604
rq_lock_irqsave(rq, &rf);
7586-
BUG_ON(rq->nr_running != 1 || rq_has_pinned_tasks(rq));
7605+
if (rq->nr_running != 1 || rq_has_pinned_tasks(rq)) {
7606+
WARN(true, "Dying CPU not properly vacated!");
7607+
dump_rq_tasks(rq, KERN_WARNING);
7608+
}
75877609
rq_unlock_irqrestore(rq, &rf);
75887610

75897611
calc_load_migrate(rq);

0 commit comments

Comments
 (0)