Skip to content

Commit 0bb0a5c

Browse files
stkidrostedt
authored andcommitted
tracing/timerlat: Fix duplicated kthread creation due to CPU online/offline
osnoise_hotplug_workfn() is the asynchronous online callback for "trace/osnoise:online". It may be congested when a CPU goes online and offline repeatedly and is invoked for multiple times after a certain online. This will lead to kthread leak and timer corruption. Add a check in start_kthread() to prevent this situation. Cc: [email protected] Cc: Masami Hiramatsu <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Link: https://lore.kernel.org/[email protected] Fixes: c8895e2 ("trace/osnoise: Support hotplug operations") Signed-off-by: Wei Li <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent ad68670 commit 0bb0a5c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

kernel/trace/trace_osnoise.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,6 +2007,10 @@ static int start_kthread(unsigned int cpu)
20072007
void *main = osnoise_main;
20082008
char comm[24];
20092009

2010+
/* Do not start a new thread if it is already running */
2011+
if (per_cpu(per_cpu_osnoise_var, cpu).kthread)
2012+
return 0;
2013+
20102014
if (timerlat_enabled()) {
20112015
snprintf(comm, 24, "timerlat/%d", cpu);
20122016
main = timerlat_main;
@@ -2061,11 +2065,10 @@ static int start_per_cpu_kthreads(void)
20612065
if (cpumask_test_and_clear_cpu(cpu, &kthread_cpumask)) {
20622066
struct task_struct *kthread;
20632067

2064-
kthread = per_cpu(per_cpu_osnoise_var, cpu).kthread;
2068+
kthread = xchg_relaxed(&(per_cpu(per_cpu_osnoise_var, cpu).kthread), NULL);
20652069
if (!WARN_ON(!kthread))
20662070
kthread_stop(kthread);
20672071
}
2068-
per_cpu(per_cpu_osnoise_var, cpu).kthread = NULL;
20692072
}
20702073

20712074
for_each_cpu(cpu, current_mask) {

0 commit comments

Comments
 (0)