public inbox for linux-trace-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Nam Cao <namcao@linutronix.de>
To: Gabriele Monaco <gmonaco@redhat.com>
Cc: John Ogness <john.ogness@linutronix.de>,
	Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] tracing: Remove pointless memory barriers
Date: Tue, 8 Jul 2025 09:42:19 +0200	[thread overview]
Message-ID: <20250708074219.K7BthlGg@linutronix.de> (raw)
In-Reply-To: <564f10574f11bd7ca42fcc5fb4d6c5625dc17205.camel@redhat.com>

On Thu, Jul 03, 2025 at 10:05:59AM +0200, Gabriele Monaco wrote:
> Hi all,
Hi Gabriele,

> these statements made me curious: I always thought of memory barriers as a way
> to order reads and writes to the same address across different CPUs (in other
> words, for visibility).
> 
> For instance I'd do something like:
> 
> CPU 1             CPU2
> 
> write(x)
> smp_mb()
>                   <implicit paired barrier>
>                   READ_ONCE(x)
> 
> Now, I get there isn't much we can do if reader and writer are racing, but, as
> Steve said, I'm expecting the presence of barriers to make the racing window
> smaller.
> 
> Am I misinterpreting the whole thing here? Are those barriers just ordering
> reads with reads and writes with writes (hence useful only with multiple
> variables)?

From "WHAT ARE MEMORY BARRIERS?" section in
https://www.kernel.org/doc/Documentation/memory-barriers.txt

    "Memory barriers [...] impose a perceived partial ordering over the
    memory operations on either side of the barrier."

and also have a look at "WHAT MAY NOT BE ASSUMED ABOUT MEMORY BARRIERS?"
later on:

    "There is no guarantee that any of the memory accesses specified before
    a memory barrier will be _complete_ by the completion of a memory
    barrier instruction"

Or data memory barrier explanation from Arm
(https://developer.arm.com/documentation/den0042/0100/Memory-Ordering/Memory-barriers)

    "This instruction ensures that all memory accesses in program order
    before the barrier are observed in the system before any explicit
    memory accesses that appear in program order after the barrier. It does
    not affect the ordering of any other instructions executing on the
    processor, or of instruction fetches."

So yes, smp_rmb() is only useful inbetween reads, and smp_wmb() is only
userful inbetween writes.

Best regards,
Nam

  reply	other threads:[~2025-07-08  7:42 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
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 [this message]
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=20250708074219.K7BthlGg@linutronix.de \
    --to=namcao@linutronix.de \
    --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=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