All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tamir Duberstein <tamird@kernel.org>
To: Emil Tsalapatis <emil@etsalapatis.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	Jiri Olsa <jolsa@kernel.org>, Shuah Khan <shuah@kernel.org>,
	Andrea Righi <arighi@nvidia.com>, Xu Kuohai <xukuohai@huawei.com>,
	bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org,
	Andrew Werner <awerner32@gmail.com>,
	Zvi Effron <zeffron@riotgames.com>,
	Andrii Nakryiko <andriin@fb.com>
Subject: Re: [PATCH bpf 5/6] libbpf: ringbuf: Prevent missed wakeups
Date: Thu, 18 Jun 2026 18:05:31 -0400	[thread overview]
Message-ID: <e46ccf4915a3358e42a372643eafa4b9@kernel.org> (raw)
In-Reply-To: <DJBYY5JF4YBQ.2QJVU2QKJ16N2@etsalapatis.com>

On Thu, Jun 18, 2026 at 02:41:54AM -0400, Emil Tsalapatis wrote:
[...]
> Sashiko is right on this, let's use regular kernel style for new
> comments.

Done in v2.

[...]
> The extra new variable feels overly complicated. I think this is
> becuase the new code is going off of the got_new_data pattern, which
> imo is also unnecessary. We should just remove got_new data and just
> do:
>
> while (true) {
> 	prod_pos = __atomic_load_n(r->producer_pos, __ATOMIC_ACQUIRE);
> 	if (cons_pos == prod_pos)
> 		break;
>
> 	while (cons_pos != prod_pos) {
> 		...
> 	}
> }

V2 removes `needs_wakeup` and leaves one fence after each batch that
advances the consumer position. I kept `got_new_data` because the
proposed unconditional outer loop would retry the same busy record
indefinitely. The revised loop retries a busy record once after
publishing progress and returns if the record is still busy.

[...]
> We just add an smp_mb() here. And since AFAICT smb_mb is available
> here, we can also avoid the move from smp_* to __atomic in the
> previous patch.

I kept the compiler atomics because `smp_mb()` is not a portable full
barrier in the tools headers. Only x86, arm64, and RISC-V define it
directly; the generic fallback can reduce `mb()` to a compiler barrier.
A single `__atomic_thread_fence()` after each batch orders the preceding
consumer-position stores without a full barrier after every record.

[...]
> Why __ATOMIC_RELAXED here? Maybe just declare the variable volatile
> and do regular reads?

I kept the stop flag as a relaxed atomic because `volatile` would leave
a C data race; the flag needs atomicity but no ordering.

[...]
> Label is unnecessary, just call break;

Done in v2.

  reply	other threads:[~2026-06-18 22:06 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-14  1:48 [PATCH bpf 0/6] libbpf: Fix ring buffer consumption Tamir Duberstein
2026-06-14  1:48 ` [PATCH bpf 1/6] libbpf: ringbuf: Honor zero consume bounds Tamir Duberstein
2026-06-17  0:35   ` Emil Tsalapatis
2026-06-14  1:48 ` [PATCH bpf 2/6] libbpf: ringbuf: Prevent NULL callback crash Tamir Duberstein
2026-06-17  0:44   ` Emil Tsalapatis
2026-06-18 20:49     ` Tamir Duberstein
2026-06-14  1:48 ` [PATCH bpf 3/6] libbpf: ringbuf: Handle position counter wrap Tamir Duberstein
2026-06-14  2:05   ` sashiko-bot
2026-06-17  1:19     ` Emil Tsalapatis
2026-06-18 21:12       ` Tamir Duberstein
2026-06-14  1:48 ` [PATCH bpf 4/6] libbpf: ringbuf: Use compiler atomics Tamir Duberstein
2026-06-14  1:59   ` sashiko-bot
2026-06-17  1:30   ` Emil Tsalapatis
2026-06-14  1:48 ` [PATCH bpf 5/6] libbpf: ringbuf: Prevent missed wakeups Tamir Duberstein
2026-06-14  1:57   ` sashiko-bot
2026-06-18  6:41   ` Emil Tsalapatis
2026-06-18 22:05     ` Tamir Duberstein [this message]
2026-06-14  1:48 ` [PATCH bpf 6/6] libbpf: ringbuf: Reject overwrite callback use Tamir Duberstein
2026-06-18  6:52   ` Emil Tsalapatis
2026-06-19  0:26     ` Tamir Duberstein

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=e46ccf4915a3358e42a372643eafa4b9@kernel.org \
    --to=tamird@kernel.org \
    --cc=andrii@kernel.org \
    --cc=andriin@fb.com \
    --cc=arighi@nvidia.com \
    --cc=ast@kernel.org \
    --cc=awerner32@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=xukuohai@huawei.com \
    --cc=yonghong.song@linux.dev \
    --cc=zeffron@riotgames.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.