mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Puranjay Mohan <puranjay@kernel.org>
Cc: bpf@vger.kernel.org, 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>,
	David Vernet <void@manifault.com>,
	Andrea Righi <arighi@nvidia.com>,
	Changwoo Min <changwoo@igalia.com>,
	sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH bpf-next v3 1/3] bpf, x86: Support fetching AND/OR/XOR atomics in arena
Date: Sat, 26 Sep 2026 07:02:58 -1000	[thread overview]
Message-ID: <95657985e60bb3287c53b960c64aaf86@kernel.org> (raw)
In-Reply-To: <20260925134828.2012199-2-puranjay@kernel.org>

Hello, Puranjay.

On Fri, Sep 25, 2026 at 06:48:20AM -0700, Puranjay Mohan wrote:
> The first CMPXCHG compares against an unrelated value, so barring
> coincidence it always loses and the arena form executes at least two
> locked CMPXCHGs every time. A losing locked CMPXCHG is still a full
> read-modify-write, so this is a real steady-state cost rather than an
> occasional retry, which is why the non-arena lowering keeps its load.

I'd prefer the v1 lowering with the load and the second extable entry.
The extra locked CMPXCHG is the common case rather than a retry, so on
x86 the fetching insn ends up more expensive than the load + cmpxchg loop
that BPF programs hand-roll today, e.g. the cmask helpers in
tools/sched_ext/include/scx/cid.bpf.h which are being converted to the
fetching builtins. As is, we'd likely keep the loop on x86 and only use
the fetching atomics on the other archs, which defeats the purpose.
Andrea raised the same concern on the scx side:

  https://github.com/sched-ext/scx/pull/3839#pullrequestreview-5318408089

The second extable entry is some added complexity in the JIT but that's
paid once, while the extra CMPXCHG is paid on every operation.

Thanks.

--
tejun

  reply	other threads:[~2026-09-26 17:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-25 13:48 [PATCH bpf-next v3 0/3] " Puranjay Mohan
2026-09-25 13:48 ` [PATCH bpf-next v3 1/3] " Puranjay Mohan
2026-09-26 17:02   ` Tejun Heo [this message]
2026-09-25 13:48 ` [PATCH bpf-next v3 2/3] selftests/bpf: Test " Puranjay Mohan
2026-09-25 14:44   ` bot+bpf-ci
2026-09-25 13:48 ` [PATCH bpf-next v3 3/3] sched_ext: Use fetching atomics for cmask instead of a cmpxchg loop Puranjay Mohan

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=95657985e60bb3287c53b960c64aaf86@kernel.org \
    --to=tj@kernel.org \
    --cc=andrii@kernel.org \
    --cc=arighi@nvidia.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=changwoo@igalia.com \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=puranjay@kernel.org \
    --cc=sched-ext@lists.linux.dev \
    --cc=song@kernel.org \
    --cc=void@manifault.com \
    --cc=yonghong.song@linux.dev \
    /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

all inboxes | Powered by JetHome®