public inbox for linux-trace-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Nam Cao <namcao@linutronix.de>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org,
	Gabriele Monaco <gmonaco@redhat.com>,
	john.ogness@linutronix.de
Subject: Re: [PATCH] tracing: Remove pointless memory barriers
Date: Thu, 26 Jun 2025 11:35:20 -0400	[thread overview]
Message-ID: <20250626113520.315db641@gandalf.local.home> (raw)
In-Reply-To: <20250626151940.1756398-1-namcao@linutronix.de>

On Thu, 26 Jun 2025 17:19:40 +0200
Nam Cao <namcao@linutronix.de> wrote:


> However, the memory barriers I see in kernel/trace/ do not resemble the
> above pattern. Therefore I think they are redundant.

I'll focus my comments on the trace code as that's what I understand more.

> 
> Please let me know if there is an unobvious reason for them.

Sure!


>  static void turn_monitoring_on_with_reset(void)
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index 95ae7c4e58357..0dff4298fc0e5 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -936,7 +936,6 @@ int tracing_is_enabled(void)
>  	 * return the mirror variable of the state of the ring buffer.
>  	 * It's a little racy, but we don't really care.
>  	 */
> -	smp_rmb();
>  	return !global_trace.buffer_disabled;
>  }
>  
> @@ -1107,8 +1106,6 @@ void tracer_tracing_on(struct trace_array *tr)
>  	 * important to be fast than accurate.
>  	 */
>  	tr->buffer_disabled = 0;
> -	/* Make the flag seen by readers */
> -	smp_wmb();
>  }
>  
>  /**
> @@ -1640,8 +1637,6 @@ void tracer_tracing_off(struct trace_array *tr)
>  	 * important to be fast than accurate.
>  	 */
>  	tr->buffer_disabled = 1;
> -	/* Make the flag seen by readers */
> -	smp_wmb();
>  }

The above three interact with each other. Without the barriers, the
tr->buffer_disabled = 0, can be set on one CPU, and the other CPU can think
the buffer is still enabled and do work that will end up doing nothing. Or
it can be set to 1, and the other CPU still sees it disabled and will not
do work when it can.

>  
>  /**
> @@ -2710,8 +2705,6 @@ void trace_buffered_event_enable(void)
>  
>  static void enable_trace_buffered_event(void *data)
>  {
> -	/* Probably not needed, but do it anyway */
> -	smp_rmb();

As the comment says, this one actually isn't needed, and yes, it can be
removed.

-- Steve

>  	this_cpu_dec(trace_buffered_event_cnt);
>  }
>  


  reply	other threads:[~2025-06-26 15:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-26 15:19 [PATCH] tracing: Remove pointless memory barriers Nam Cao
2025-06-26 15:35 ` Steven Rostedt [this message]
2025-06-26 15:37   ` Steven Rostedt
2025-06-26 16:04   ` Nam Cao
2025-06-26 16:34     ` Steven Rostedt
2025-06-26 17:41       ` John Ogness
2025-07-03  8:05         ` Gabriele Monaco
2025-07-08  7:42           ` Nam Cao
2025-07-09 15:08             ` Steven Rostedt
2025-07-11  8:29               ` David Laight
2025-07-11 16:07                 ` Steven Rostedt
2025-07-09  8:22       ` David Laight
2025-07-22  0:49     ` 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=20250626113520.315db641@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=gmonaco@redhat.com \
    --cc=john.ogness@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=namcao@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