From: Linus Torvalds <torvalds@linux-foundation.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
Masami Hiramatsu <mhiramat@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Andrew Morton <akpm@linux-foundation.org>,
joel@joelfernandes.org, linke li <lilinke99@qq.com>,
Rabin Vincent <rabin@rab.in>
Subject: Re: [PATCH 0/6] tracing/ring-buffer: Fix wakeup of ring buffer waiters
Date: Fri, 8 Mar 2024 12:39:10 -0800 [thread overview]
Message-ID: <CAHk-=wgsNgewHFxZAJiAQznwPMqEtQmi1waeS2O1v6L4c_Um5A@mail.gmail.com> (raw)
In-Reply-To: <20240308183816.676883229@goodmis.org>
On Fri, 8 Mar 2024 at 10:38, Steven Rostedt <rostedt@goodmis.org> wrote:
>
> A patch was sent to "fix" the wait_index variable that is used to help with
> waking of waiters on the ring buffer. The patch was rejected, but I started
> looking at associated code. Discussing it on IRC with Mathieu Desnoyers
> we discovered a design flaw.
Honestly, all of this seems excessively complicated.
And your new locking shouldn't be necessary if you just do things much
more simply.
Here's what I *think* you should do:
struct xyz {
...
atomic_t seq;
struct wait_queue_head seq_wait;
...
};
with the consumer doing something very simple like this:
int seq = atomic_read_acquire(&my->seq);
for (;;) {
.. consume outstanding events ..
seq = wait_for_seq_change(seq, my);
}
and the producer being similarly trivial, just having a
"add_seq_event()" at the end:
... add whatever event ..
add_seq_event(my);
And the helper functions for this are really darn simple:
static inline int wait_for_seq_change(int old, struct xyz *my)
{
int new;
wait_event(my->seq_wait,
(new = atomic_read_acquire(&my->seq)) != old);
return new;
}
static inline void add_seq_event(struct xyz *my)
{
atomic_fetch_inc_release(&my->seq);
wake_up(&my->seq_wait);
}
Note how you don't need any new locks, and note how "wait_event()"
will do all the required optimistic stuff for you (ie it will check
that "has seq changed" before even bothering to add itself to the wait
queue etc).
So the above is not only short and sweet, it generates fairly good
code too, and doesn't it look really simple and fairly understandable?
And - AS ALWAYS - the above isn't actually tested in any way, shape or form.
Linus
next prev parent reply other threads:[~2024-03-08 20:39 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-08 18:38 [PATCH 0/6] tracing/ring-buffer: Fix wakeup of ring buffer waiters Steven Rostedt
2024-03-08 18:38 ` [PATCH 1/6] ring-buffer: Fix waking up ring buffer readers Steven Rostedt
2024-03-08 18:38 ` [PATCH 2/6] ring-buffer: Fix resetting of shortest_full Steven Rostedt
2024-03-08 18:38 ` [PATCH 3/6] tracing: Use .flush() call to wake up readers Steven Rostedt
2024-03-08 18:38 ` [PATCH 4/6] tracing: Fix waking up tracing readers Steven Rostedt
2024-03-08 19:13 ` Steven Rostedt
2024-03-08 18:38 ` [PATCH 5/6] ring-buffer: Restructure ring_buffer_wait() to prepare for updates Steven Rostedt
2024-03-08 18:38 ` [PATCH 6/6] tracing/ring-buffer: Fix wait_on_pipe() race Steven Rostedt
2024-03-08 20:39 ` Linus Torvalds [this message]
2024-03-08 21:35 ` [PATCH 0/6] tracing/ring-buffer: Fix wakeup of ring buffer waiters Steven Rostedt
2024-03-08 21:39 ` Linus Torvalds
2024-03-08 21:41 ` Linus Torvalds
2024-03-10 16:19 ` 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='CAHk-=wgsNgewHFxZAJiAQznwPMqEtQmi1waeS2O1v6L4c_Um5A@mail.gmail.com' \
--to=torvalds@linux-foundation.org \
--cc=akpm@linux-foundation.org \
--cc=joel@joelfernandes.org \
--cc=lilinke99@qq.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=rabin@rab.in \
--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).