On 08/11/2016 04:22 PM, Waiman Long wrote:
On 08/11/2016 03:32 PM, Dave Hansen wrote:I just mean that it's implementing its own locking instead of being able
It's a real bummer that this all has to be open-coded. I have to wonderWhat do you mean by "open-coded"? Do you mean the function can be inlined?
if there were any alternatives that you tried that were simpler.
to use spinlocks or seqlocks, or some other existing primitive.
The contended case (where HPET_SEQ_LOCKED(seq)) doesn't do the cmpxchg.Is READ_ONCE()/smp_store_release() really strong enough here? ItThe cmpxchg() and smp_store_release() act as the lock/unlock sequence
guarantees ordering, but you need ordering *and* a guarantee that your
write is visible to the reader. Don't you need actual barriers for
that? Otherwise, you might be seeing a stale HPET value, and the spin
loop that you did waiting for it to be up-to-date was worthless. The
seqlock code, uses barriers, btw.
with the proper barriers. Another important point is that the hpet value
is visible to the other readers before the sequence number. This is
what the smp_store_release() is providing. cmpxchg is an actual barrier,
even though smp_store_release() is not. However, the x86 architecture
will guarantee the writes are in order, I think.
So it's entirely relying on the READ_ONCE() on the "reader" side and
the cmpxchg/smp_store_release() on the "writer". This probably works in
practice, but I'm not sure it's guaranteed behavior.