linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Linux trace kernel <linux-trace-kernel@vger.kernel.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH] fgraph: Use CPU hotplug mechanism to initialize idle shadow stacks
Date: Mon, 21 Oct 2024 14:58:10 +0900	[thread overview]
Message-ID: <20241021145810.9a9daec35cb83a04fe10208a@kernel.org> (raw)
In-Reply-To: <20241018214300.6df82178@rorschach>

On Fri, 18 Oct 2024 21:43:00 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:

> From: Steven Rostedt <rostedt@goodmis.org>
> 
> The function graph infrastructure allocates a shadow stack for every task
> when enabled. This includes the idle tasks. The first time the function
> graph is invoked, the shadow stacks are created and never freed until the
> task exits. This includes the idle tasks.
> 
> Only the idle tasks that were for online CPUs had their shadow stacks
> created when function graph tracing started. If function graph tracing is
> enabled and a CPU comes online, the idle task representing that CPU will
> not have its shadow stack created, and all function graph tracing for that
> idle task will be silently dropped.
> 
> Instead, use the CPU hotplug mechanism to allocate the idle shadow stacks.
> This will include idle tasks for CPUs that come online during tracing.
> 
> This issue can be reproduced by:
> 
>  # cd /sys/kernel/tracing
>  # echo 0 > /sys/devices/system/cpu/cpu1/online
>  # echo 0 > set_ftrace_pid
>  # echo function_graph > current_tracer
>  # echo 1 > options/funcgraph-proc
>  # echo 1 > /sys/devices/system/cpu/cpu1
>  # grep '<idle>' per_cpu/cpu1/trace | head
> 
> Before, nothing would show up.
> 
> After:
>  1)    <idle>-0    |   0.811 us    |                        __enqueue_entity();
>  1)    <idle>-0    |   5.626 us    |                      } /* enqueue_entity */
>  1)    <idle>-0    |               |                      dl_server_update_idle_time() {
>  1)    <idle>-0    |               |                        dl_scaled_delta_exec() {
>  1)    <idle>-0    |   0.450 us    |                          arch_scale_cpu_capacity();
>  1)    <idle>-0    |   1.242 us    |                        }
>  1)    <idle>-0    |   1.908 us    |                      }
>  1)    <idle>-0    |               |                      dl_server_start() {
>  1)    <idle>-0    |               |                        enqueue_dl_entity() {
>  1)    <idle>-0    |               |                          task_contending() {
> 
> Note, if tracing stops and restarts, the old way would then initialize
> the onlined CPUs.
> 

Looks good to me, except one comment below;

Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

[...]
>  int register_ftrace_graph(struct fgraph_ops *gops)
>  {
> +	static bool fgraph_initialized;
>  	int command = 0;
>  	int ret = 0;
>  	int i = -1;
>  
>  	mutex_lock(&ftrace_lock);
>  
> +	if (!fgraph_initialized) {
> +		ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "fgraph_idle_init",

Nit: Maybe it is better to call it as "tracing/fgraph:online" ?

Thank you,

> +					fgraph_cpu_init, NULL);
> +		if (ret < 0) {
> +			pr_warn("fgraph: Error to init cpu hotplug support\n");
> +			return ret;
> +		}
> +		fgraph_initialized = true;
> +		ret = 0;
> +	}
> +
>  	if (!fgraph_array[0]) {
>  		/* The array must always have real data on it */
>  		for (i = 0; i < FGRAPH_ARRAY_SIZE; i++)
> -- 
> 2.45.2
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

  reply	other threads:[~2024-10-21  5:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-19  1:43 [PATCH] fgraph: Use CPU hotplug mechanism to initialize idle shadow stacks Steven Rostedt
2024-10-21  5:58 ` Masami Hiramatsu [this message]
2024-10-22  3:35   ` Steven Rostedt
2024-10-25  1:30   ` Steven Rostedt
2024-12-10 15:11 ` Linus Walleij
2024-12-10 16:31   ` Steven Rostedt
2024-12-10 23:24   ` Masami Hiramatsu
2024-12-11 14:23     ` Linus Walleij
2024-12-11 16:09       ` Steven Rostedt

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=20241021145810.9a9daec35cb83a04fe10208a@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    /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;
as well as URLs for NNTP newsgroup(s).