Skip to content

Commit a8ad07e

Browse files
Peter Zijlstrapalmer-dabbelt
authored andcommitted
asm-generic: qspinlock: Indicate the use of mixed-size atomics
The qspinlock implementation depends on having well behaved mixed-size atomics. This is true on the more widely-used platforms, but these requirements are somewhat subtle and may not be satisfied by all the platforms that qspinlock is used on. Document these requirements, so ports that use qspinlock can more easily determine if they meet these requirements. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Waiman Long <longman@redhat.com> Reviewed-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent 1bce111 commit a8ad07e

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

include/asm-generic/qspinlock.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,35 @@
22
/*
33
* Queued spinlock
44
*
5+
* A 'generic' spinlock implementation that is based on MCS locks. For an
6+
* architecture that's looking for a 'generic' spinlock, please first consider
7+
* ticket-lock.h and only come looking here when you've considered all the
8+
* constraints below and can show your hardware does actually perform better
9+
* with qspinlock.
10+
*
11+
* qspinlock relies on atomic_*_release()/atomic_*_acquire() to be RCsc (or no
12+
* weaker than RCtso if you're power), where regular code only expects atomic_t
13+
* to be RCpc.
14+
*
15+
* qspinlock relies on a far greater (compared to asm-generic/spinlock.h) set
16+
* of atomic operations to behave well together, please audit them carefully to
17+
* ensure they all have forward progress. Many atomic operations may default to
18+
* cmpxchg() loops which will not have good forward progress properties on
19+
* LL/SC architectures.
20+
*
21+
* One notable example is atomic_fetch_or_acquire(), which x86 cannot (cheaply)
22+
* do. Carefully read the patches that introduced
23+
* queued_fetch_set_pending_acquire().
24+
*
25+
* qspinlock also heavily relies on mixed size atomic operations, in specific
26+
* it requires architectures to have xchg16; something which many LL/SC
27+
* architectures need to implement as a 32bit and+or in order to satisfy the
28+
* forward progress guarantees mentioned above.
29+
*
30+
* Further reading on mixed size atomics that might be relevant:
31+
*
32+
* http://www.cl.cam.ac.uk/~pes20/popl17/mixed-size.pdf
33+
*
534
* (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.
635
* (C) Copyright 2015 Hewlett-Packard Enterprise Development LP
736
*

0 commit comments

Comments
 (0)