Skip to content

Commit 71c7a30

Browse files
makelinuxrostedt
authored andcommitted
tracing/hwlat: Replace sched_setaffinity with set_cpus_allowed_ptr
There is a problem with the behavior of hwlat in a container, resulting in incorrect output. A warning message is generated: "cpumask changed while in round-robin mode, switching to mode none", and the tracing_cpumask is ignored. This issue arises because the kernel thread, hwlatd, is not a part of the container, and the function sched_setaffinity is unable to locate it using its PID. Additionally, the task_struct of hwlatd is already known. Ultimately, the function set_cpus_allowed_ptr achieves the same outcome as sched_setaffinity, but employs task_struct instead of PID. Test case: # cd /sys/kernel/tracing # echo 0 > tracing_on # echo round-robin > hwlat_detector/mode # echo hwlat > current_tracer # unshare --fork --pid bash -c 'echo 1 > tracing_on' # dmesg -c Actual behavior: [573502.809060] hwlat_detector: cpumask changed while in round-robin mode, switching to mode none Link: https://lore.kernel.org/linux-trace-kernel/[email protected] Cc: Masami Hiramatsu <[email protected]> Fixes: 0330f7a ("tracing: Have hwlat trace migrate across tracing_cpumask CPUs") Signed-off-by: Costa Shulyupin <[email protected]> Acked-by: Daniel Bristot de Oliveira <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent a98151a commit 71c7a30

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

kernel/trace/trace_hwlat.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ static void move_to_next_cpu(void)
339339
cpumask_clear(current_mask);
340340
cpumask_set_cpu(next_cpu, current_mask);
341341

342-
sched_setaffinity(0, current_mask);
342+
set_cpus_allowed_ptr(current, current_mask);
343343
return;
344344

345345
change_mode:
@@ -446,7 +446,7 @@ static int start_single_kthread(struct trace_array *tr)
446446

447447
}
448448

449-
sched_setaffinity(kthread->pid, current_mask);
449+
set_cpus_allowed_ptr(kthread, current_mask);
450450

451451
kdata->kthread = kthread;
452452
wake_up_process(kthread);

0 commit comments

Comments
 (0)