From: Peter Zijlstra <peterz@infradead.org>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
davem@davemloft.net, daniel@iogearbox.net, jannh@google.com,
paulmck@linux.ibm.com, will.deacon@arm.com, mingo@redhat.com,
netdev@vger.kernel.org, kernel-team@fb.com,
Nicholas Piggin <npiggin@gmail.com>
Subject: Re: [PATCH v5 bpf-next 1/9] bpf: introduce bpf_spin_lock
Date: Thu, 31 Jan 2019 09:51:22 +0100 [thread overview]
Message-ID: <20190131085122.GE3103@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20190131084952.GG2296@hirez.programming.kicks-ass.net>
On Thu, Jan 31, 2019 at 09:49:52AM +0100, Peter Zijlstra wrote:
> On Wed, Jan 30, 2019 at 01:34:19PM -0800, Alexei Starovoitov wrote:
> > On Wed, Jan 30, 2019 at 10:05:29PM +0100, Peter Zijlstra wrote:
> > > +static inline void __bpf_spin_lock(struct bpf_spin_lock *lock)
> > > +{
> > > + atomic_t *l = (void *)lock;
> > > + do {
> > > + atomic_cond_read_relaxed(l, !VAL);
> >
> > wow. that's quite a macro magic.
>
> Yeah, C sucks for not having lambdas, this was the best we could come up
> with.
>
> This basically allows architectures to optimize the
> wait-for-variable-to-change thing. Currently only ARM64 does that, I
> have a horrible horrible patch that makes x86 use MONITOR/MWAIT for
> this, and I suppose POWER should use it but doesn't.
Nick, do you guys want something like this?
---
diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
index fbe8df433019..111984c5670d 100644
--- a/arch/powerpc/include/asm/barrier.h
+++ b/arch/powerpc/include/asm/barrier.h
@@ -99,6 +99,20 @@ do { \
#define barrier_nospec()
#endif /* CONFIG_PPC_BARRIER_NOSPEC */
+#define smp_cond_load_relaxed(ptr, cond_expr) ({ \
+ typeof(ptr) __PTR = (ptr); \
+ typeof(*ptr) VAL = READ_ONCE(*__PTR); \
+ if (unlikely(!(cond_expr))) { \
+ spin_begin(); \
+ do { \
+ spin_cpu_relax(); \
+ VAL = READ_ONCE(*__PTR); \
+ } while (!(cond_expr)); \
+ spin_end(); \
+ } \
+ VAL; \
+})
+
#include <asm-generic/barrier.h>
#endif /* _ASM_POWERPC_BARRIER_H */
next prev parent reply other threads:[~2019-01-31 8:51 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-28 2:50 [PATCH v5 bpf-next 0/9] introduce bpf_spin_lock Alexei Starovoitov
2019-01-28 2:50 ` [PATCH v5 bpf-next 1/9] bpf: " Alexei Starovoitov
2019-01-30 21:05 ` Peter Zijlstra
2019-01-30 21:34 ` Alexei Starovoitov
2019-01-31 8:49 ` Peter Zijlstra
2019-01-31 8:51 ` Peter Zijlstra [this message]
2019-01-28 2:50 ` [PATCH v5 bpf-next 2/9] bpf: add support for bpf_spin_lock to cgroup local storage Alexei Starovoitov
2019-01-28 2:50 ` [PATCH v5 bpf-next 3/9] tools/bpf: sync include/uapi/linux/bpf.h Alexei Starovoitov
2019-01-28 2:50 ` [PATCH v5 bpf-next 4/9] selftests/bpf: add bpf_spin_lock tests Alexei Starovoitov
2019-01-28 2:50 ` [PATCH v5 bpf-next 5/9] selftests/bpf: add bpf_spin_lock C test Alexei Starovoitov
2019-01-28 2:50 ` [PATCH v5 bpf-next 6/9] bpf: introduce BPF_F_LOCK flag Alexei Starovoitov
2019-01-28 2:50 ` [PATCH v5 bpf-next 9/9] selftests/bpf: test for BPF_F_LOCK Alexei Starovoitov
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=20190131085122.GE3103@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=alexei.starovoitov@gmail.com \
--cc=ast@kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=jannh@google.com \
--cc=kernel-team@fb.com \
--cc=mingo@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=npiggin@gmail.com \
--cc=paulmck@linux.ibm.com \
--cc=will.deacon@arm.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 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).