Re: Do we need to correct barriering in circular-buffers.rst?
From: Peter Zijlstra
Date: Mon Sep 30 2019 - 08:02:39 EST
On Mon, Sep 30, 2019 at 01:54:40PM +0200, Peter Zijlstra wrote:
> On Mon, Sep 30, 2019 at 11:33:52AM +0200, Peter Zijlstra wrote:
> > Like I said before, something like: "disallowing store hoists over control
> > flow depending on a volatile load" would be sufficient I think.
>
> We need to add 'control flow depending on an inline-asm' to that. We
> also very much use that.
An example of that would be something like:
bool spin_try_lock(struct spinlock *lock)
{
u32 zero = 0;
if (atomic_try_cmpxchg_relaxed(&lock->val, &zero, 1)) {
smp_acquire__after_ctrl_dep(); /* aka smp_rmb() */
return true;
}
return false;
}
(I think most our actual trylock functions use cmpxchg_acquire(), but the
above would be a valid implementation -- and it is the simplest
construct using smp_acquire__after_ctrl_dep() I could come up with in a
hurry)