From: linke <lilinke99@qq.com>
To: rostedt@goodmis.org
Cc: lilinke99@qq.com, linux-kernel@vger.kernel.org,
linux-trace-kernel@vger.kernel.org,
mathieu.desnoyers@efficios.com, mhiramat@kernel.org
Subject: Re: [PATCH] ring-buffer: use READ_ONCE() to read cpu_buffer->commit_page in concurrent environment
Date: Thu, 29 Feb 2024 20:32:26 +0800 [thread overview]
Message-ID: <tencent_BE8C3169030CD9C2FC7548832C2994921609@qq.com> (raw)
Hi Steven, sorry for the late reply.
>
> Now the reason for the above READ_ONCE() is because the variables *are*
> going to be used again. We do *not* want the compiler to play any games
> with that.
>
I don't think it is because the variables are going to be used again.
Compiler optimizations barely do bad things in single thread programs. It
is because cpu_buffer->commit_page may change concurrently and should be
accessed atomically.
/* Make sure commit page didn't change */
curr_commit_page = READ_ONCE(cpu_buffer->commit_page);
curr_commit_ts = READ_ONCE(curr_commit_page->page->time_stamp);
/* If the commit page changed, then there's more data */
if (curr_commit_page != commit_page ||
curr_commit_ts != commit_ts)
return 0;
This code read cpu_buffer->commit_page and time_stamp again to check
whether commit page changed. It shows that cpu_buffer->commit_page and
time_stamp may be changed by other threads.
commit_page = cpu_buffer->commit_page;
commit_ts = commit_page->page->time_stamp;
So the commit_page and time_stamp above is read while other threads may
change it. I think it is a data race if it is not atomic. Thus it is
necessary to use READ_ONCE() here.
next reply other threads:[~2024-02-29 12:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-29 12:32 linke [this message]
2024-02-29 15:21 ` [PATCH] ring-buffer: use READ_ONCE() to read cpu_buffer->commit_page in concurrent environment Steven Rostedt
-- strict thread matches above, loose matches on Subject: below --
2024-03-01 5:37 linke
2024-03-01 15:49 ` Steven Rostedt
2024-03-01 16:37 ` Mathieu Desnoyers
2024-03-01 17:11 ` Steven Rostedt
2024-02-29 12:32 linke
2024-02-25 3:05 linke li
2024-02-25 20:03 ` Steven Rostedt
2024-02-26 18:53 ` 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=tencent_BE8C3169030CD9C2FC7548832C2994921609@qq.com \
--to=lilinke99@qq.com \
--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;
as well as URLs for NNTP newsgroup(s).