All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Costa Shulyupin <costa.shul@redhat.com>,
	Daniel Bristot de Oliveira <bristot@kernel.org>
Subject: [for-linus][PATCH 8/8] tracing/hwlat: Replace sched_setaffinity with set_cpus_allowed_ptr
Date: Sun, 19 Mar 2023 12:46:51 -0400	[thread overview]
Message-ID: <20230319164749.324599670@goodmis.org> (raw)
In-Reply-To: 20230319164643.513018619@goodmis.org

From: Costa Shulyupin <costa.shul@redhat.com>

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/20230316144535.1004952-1-costa.shul@redhat.com

Cc: Masami Hiramatsu <mhiramat@kernel.org>
Fixes: 0330f7aa8ee63 ("tracing: Have hwlat trace migrate across tracing_cpumask CPUs")
Signed-off-by: Costa Shulyupin <costa.shul@redhat.com>
Acked-by: Daniel Bristot de Oliveira <bristot@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 kernel/trace/trace_hwlat.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/trace_hwlat.c b/kernel/trace/trace_hwlat.c
index c4945f8adc11..2f37a6e68aa9 100644
--- a/kernel/trace/trace_hwlat.c
+++ b/kernel/trace/trace_hwlat.c
@@ -339,7 +339,7 @@ static void move_to_next_cpu(void)
 	cpumask_clear(current_mask);
 	cpumask_set_cpu(next_cpu, current_mask);
 
-	sched_setaffinity(0, current_mask);
+	set_cpus_allowed_ptr(current, current_mask);
 	return;
 
  change_mode:
@@ -446,7 +446,7 @@ static int start_single_kthread(struct trace_array *tr)
 
 	}
 
-	sched_setaffinity(kthread->pid, current_mask);
+	set_cpus_allowed_ptr(kthread, current_mask);
 
 	kdata->kthread = kthread;
 	wake_up_process(kthread);
-- 
2.39.1

      parent reply	other threads:[~2023-03-19 16:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-19 16:46 [for-linus][PATCH 0/8] tracing: Minor fixes for 6.3 Steven Rostedt
2023-03-19 16:46 ` [for-linus][PATCH 1/8] tracing: Fix wrong return in kprobe_event_gen_test.c Steven Rostedt
2023-03-19 16:46 ` [for-linus][PATCH 2/8] tracing/osnoise: set several trace_osnoise.c variables storage-class-specifier to static Steven Rostedt
2023-03-19 16:46 ` [for-linus][PATCH 3/8] trace/hwlat: Do not wipe the contents of per-cpu thread data Steven Rostedt
2023-03-19 16:46 ` [for-linus][PATCH 4/8] trace/hwlat: Do not start per-cpu thread if it is already running Steven Rostedt
2023-03-19 16:46 ` [for-linus][PATCH 5/8] ftrace: Set direct_ops storage-class-specifier to static Steven Rostedt
2023-03-19 16:46 ` [for-linus][PATCH 6/8] tracing: Make splice_read available again Steven Rostedt
2023-03-19 16:46 ` [for-linus][PATCH 7/8] ring-buffer: remove obsolete comment for free_buffer_page() Steven Rostedt
2023-03-19 16:46 ` Steven Rostedt [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230319164749.324599670@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=bristot@kernel.org \
    --cc=costa.shul@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mhiramat@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.