Linux Trace Kernel
 help / color / mirror / Atom feed
From: Daniel Bristot de Oliveira <bristot@kernel.org>
To: Costa Shulyupin <costa.shul@redhat.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	"open list:TRACING" <linux-kernel@vger.kernel.org>,
	"open list:TRACING" <linux-trace-kernel@vger.kernel.org>
Cc: bwensley@redhat.com, constantine.shulyupin@gmail.com
Subject: Re: [PATCH] tracing/hwlat: Replace sched_setaffinity with set_cpus_allowed_ptr
Date: Thu, 16 Mar 2023 18:15:48 +0100	[thread overview]
Message-ID: <51e64093-5e2f-18fa-db04-8d6789362921@kernel.org> (raw)
In-Reply-To: <20230316144535.1004952-1-costa.shul@redhat.com>

On 3/16/23 15:45, Costa Shulyupin wrote:
> 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
> 
> Signed-off-by: Costa Shulyupin <costa.shul@redhat.com>

I tested it and... it works.

Acked-by: Daniel Bristot de Oliveira <bristot@kernel.org>

Thanks
-- Daniel

> ---
>  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 d440ddd5fd8b..444dfc31f258 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);


      reply	other threads:[~2023-03-16 17:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-16 14:45 [PATCH] tracing/hwlat: Replace sched_setaffinity with set_cpus_allowed_ptr Costa Shulyupin
2023-03-16 17:15 ` Daniel Bristot de Oliveira [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=51e64093-5e2f-18fa-db04-8d6789362921@kernel.org \
    --to=bristot@kernel.org \
    --cc=bwensley@redhat.com \
    --cc=constantine.shulyupin@gmail.com \
    --cc=costa.shul@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=rostedt@goodmis.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox