csky: smp_mb__after_spinlock
Subsystems (2)
[email protected]
maintainerHi,
While doing an audit of smp_mb__after_spinlock, I found that csky defines it, why?
CSKY only has smp_mb(), it doesn't override __atomic_acquire_fence or otherwise special cases it's atomic*_acquire() primitives. It has an explicit smp_mb() in its arch_spin_lock().
---
arch/csky/include/asm/spinlock.h +0 -3
@@ -88,9 +88,6 @@ static inline int arch_spin_is_contended(arch_spinlock_t *lock)#include <asm/qrwlock.h> -/* See include/linux/spinlock.h */ -#define smp_mb__after_spinlock () smp_mb() -#else /* CONFIG_QUEUED_RWLOCKS */ /*
[email protected]
maintainerQuoted 8 lines · On Wed, Aug 05, 2020 at 12:41:46PM +0200, [email protected] wrote:
Hi,
While doing an audit of
smp_mb__after_spinlock, I found that csky defines it, why?CSKY only has
smp_mb(), it doesn't override__atomic_acquire_fenceor otherwise special cases it's atomic*_acquire() primitives. It has an explicitsmp_mb()in itsarch_spin_lock().
Also, why have two implementations of all the locking ?
---
arch/csky/Kconfig +1 -1
@@ -7,7 +7,7 @@ config CSKY select ARCH_HAS_SYNC_DMA_FOR_CPU select ARCH_HAS_SYNC_DMA_FOR_DEVICE select ARCH_USE_BUILTIN_BSWAP - select ARCH_USE_QUEUED_RWLOCKS if NR_CPUS>2 + select ARCH_USE_QUEUED_RWLOCKS select ARCH_WANT_FRAME_POINTERS if !CPU_CK610 select COMMON_CLK select CLKSRC_MMIO
arch/csky/include/asm/spinlock.h +0 -167
177 lines not on this page · raw message
Quoted 210 lines · On Thu, Aug 6, 2020 at 3:55 AM <[email protected]> wrote:
Quoted 8 lines · On Wed, Aug 05, 2020 at 12:41:46PM +0200, [email protected] wrote:
Hi,
While doing an audit of
smp_mb__after_spinlock, I found that csky defines it, why?CSKY only has
smp_mb(), it doesn't override__atomic_acquire_fenceor otherwise special cases it's atomic*_acquire() primitives. It has an explicitsmp_mb()in itsarch_spin_lock().Also, why have two implementations of all the locking ?
---
arch/csky/Kconfig +1
-1@@ -7,7 +7,7 @@ config CSKY select ARCH_HAS_SYNC_DMA_FOR_CPU select ARCH_HAS_SYNC_DMA_FOR_DEVICE select ARCH_USE_BUILTIN_BSWAP - select ARCH_USE_QUEUED_RWLOCKS if NR_CPUS>2 + select ARCH_USE_QUEUED_RWLOCKS select ARCH_WANT_FRAME_POINTERS if !CPU_CK610 select COMMON_CLK select CLKSRC_MMIOarch/csky/include/asm/spinlock.h +0
-167@@ -6,8 +6,6 @@#include <linux/spinlock_types.h> #include <asm/barrier.h> -#ifdef CONFIG_QUEUED_RWLOCKS -/* * Ticket-based spin-locking. */ @@ -88,169 +86,4 @@ static inline int arch_spin_is_contended(arch_spinlock_t *lock)#include <asm/qrwlock.h> -/* See include/linux/spinlock.h */ -#define smp_mb__after_spinlock () smp_mb() - -#else /* CONFIG_QUEUED_RWLOCKS */ - -/* -* Test-and-set spin-locking. -*/ -static inline void arch_spin_lock (arch_spinlock_t *lock) -{ -u32 *p = &lock->lock; -u32 tmp; - - asmvolatile ( -"1: ldex.w %0, (%1) \n" -" bnez %0, 1b \n" -" movi %0, 1 \n" -" stex.w %0, (%1) \n" -" bez %0, 1b \n" - :"=&r" (tmp) - :"r" (p) - :"cc" ); -smp_mb (); -} - -static inline void arch_spin_unlock (arch_spinlock_t *lock) -{ -smp_mb (); -WRITE_ONCE (lock->lock,0 ); -} - -static inline int arch_spin_trylock (arch_spinlock_t *lock) -{ -u32 *p = &lock->lock; -u32 tmp; - - asmvolatile ( -"1: ldex.w %0, (%1) \n" -" bnez %0, 2f \n" -" movi %0, 1 \n" -" stex.w %0, (%1) \n" -" bez %0, 1b \n" -" movi %0, 0 \n" -"2: \n" - :"=&r" (tmp) - :"r" (p) - :"cc" ); - -if (!tmp) -smp_mb (); - -return !tmp; -} - -#define arch_spin_is_locked (x) (READ_ONCE((x)->lock) != 0) - -/* -* read lock/unlock/trylock -*/ -static inline void arch_read_lock (arch_rwlock_t *lock) -{ -u32 *p = &lock->lock; -u32 tmp; - - asmvolatile ( -"1: ldex.w %0, (%1) \n" -" blz %0, 1b \n" -" addi %0, 1 \n" -" stex.w %0, (%1) \n" -" bez %0, 1b \n" - :"=&r" (tmp) - :"r" (p) - :"cc" ); -smp_mb (); -} - -static inline void arch_read_unlock (arch_rwlock_t *lock) -{ -u32 *p = &lock->lock; -u32 tmp; - -smp_mb (); - asmvolatile ( -"1: ldex.w %0, (%1) \n" -" subi %0, 1 \n" -" stex.w %0, (%1) \n" -" bez %0, 1b \n" - :"=&r" (tmp) - :"r" (p) - :"cc" ); -} - -static inline int arch_read_trylock (arch_rwlock_t *lock) -{ -u32 *p = &lock->lock; -u32 tmp; - - asmvolatile ( -"1: ldex.w %0, (%1) \n" -" blz %0, 2f \n" -" addi %0, 1 \n" -" stex.w %0, (%1) \n" -" bez %0, 1b \n" -" movi %0, 0 \n" -"2: \n" - :"=&r" (tmp) - :"r" (p) - :"cc" ); - -if (!tmp) -smp_mb (); - -return !tmp; -} - -/* -* write lock/unlock/trylock -*/ -static inline void arch_write_lock (arch_rwlock_t *lock) -{ -u32 *p = &lock->lock; -u32 tmp; - - asmvolatile ( -"1: ldex.w %0, (%1) \n" -" bnez %0, 1b \n" -" subi %0, 1 \n" -" stex.w %0, (%1) \n" -" bez %0, 1b \n" - :"=&r" (tmp) - :"r" (p) - :"cc" ); -smp_mb (); -} - -static inline void arch_write_unlock (arch_rwlock_t *lock) -{ -smp_mb (); -WRITE_ONCE (lock->lock,0 ); -} - -static inline int arch_write_trylock (arch_rwlock_t *lock) -{ -u32 *p = &lock->lock; -u32 tmp; - - asmvolatile ( -"1: ldex.w %0, (%1) \n" -" bnez %0, 2f \n" -" subi %0, 1 \n" -" stex.w %0, (%1) \n" -" bez %0, 1b \n" -" movi %0, 0 \n" -"2: \n" - :"=&r" (tmp) - :"r" (p) - :"cc" ); - -if (!tmp) -smp_mb (); - -return !tmp; -} - -#endif /* CONFIG_QUEUED_RWLOCKS */ #endif /* __ASM_CSKY_SPINLOCK_H */
Signature · 4 lines
Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/
Guo Ren
maintainerHi Peter,
Quoted 9 lines · On Thu, Aug 6, 2020 at 3:53 AM <[email protected]> wrote:
Hi,
While doing an audit of
smp_mb__after_spinlock, I found that csky defines it, why?CSKY only has
smp_mb(), it doesn't override__atomic_acquire_fenceor otherwise special cases it's atomic*_acquire() primitives. It has an explicitsmp_mb()in itsarch_spin_lock().
Yes, csky didn't implement ACQUIRE/RELEASE in spinlock.h. So it is a redundant and side-effect wrong macro, we should remove it to fixup.
TODO:
- implement csky's ACQUIRE/RELEASE barrier
Quoted 1 line
Also, why have two implementations of all the locking?
I just kept my baby's codes :P. Now, we could remove it and just keep the ticket's one.
BTW, I want to change the spinlock to qspinlock, but csky only has 32-bit atomic operation in hardware.
Any plan to deal with this in spinlock?
Maybe for the embedded scenario, qspinlock seems a bit heavy, are any tickets-like comm spinlock infrastructures in the plan?
--
Best Regards
Guo Ren
[email protected]
maintainerQuoted 13 lines · Guo Ren
Hi Peter,
Quoted 9 lines · On Thu, Aug 6, 2020 at 3:53 AM <[email protected]> wrote:
Hi,
While doing an audit of
smp_mb__after_spinlock, I found that csky defines it, why?CSKY only has
smp_mb(), it doesn't override__atomic_acquire_fenceor otherwise special cases it's atomic*_acquire() primitives. It has an explicitsmp_mb()in itsarch_spin_lock().
Quoted 5 lines
Yes, csky didn't implement ACQUIRE/RELEASE in
spinlock.h. So it is a redundant and side-effect wrong macro, we should remove it to fixup.TODO:
- implement csky's ACQUIRE/RELEASE barrier
Fair enough; please Cc me when you get to it.
Quoted 7 lines
Quoted 1 line
Also, why have two implementations of all the locking?
I just kept my baby's codes :P. Now, we could remove it and just keep the ticket's one.
BTW, I want to change the spinlock to qspinlock, but csky only has 32-bit atomic operation in hardware.
Yeah, that's okay, you can do 'short' atomics using wider RmW.
Quoted 3 lines
Any plan to deal with this in spinlock?
Maybe for the embedded scenario, qspinlock seems a bit heavy,
I tend to agree, qspinlock only really makes sense when you have multiple cache domains and NUMA makes it shine.
Quoted 2 lines
are any
tickets-like comm spinlock infrastructures in the plan?
No. ticket locks are 'simple' and their implementation fairly straight forward. Also, since the generic code only has cmpxchg, a generic ticket lock would be sub-optimal on LL/SC (or even x86 for that matter).
It would look something like this, which I think is pretty terrible for just about any arch compared to what you can do with inline asm.
struct ticket_lock {
union {
atomic_t val;
struct {
#ifdef __LITTLE_ENDIAN
u16 head;
u16 tail;
#else
u16 tail;
u16 head;
#endif
};
};
};void ticket_lock(struct ticket_lock *lock)
{
unsigned int val = atomic_read(&lock->val);
struct ticket_lock lock;
do {
lock.val = ATOMIC_INIT(val);
lock.head++;
} while (!atomic_try_cmpxchg_relaxed(&lock->lock, &val, lock.val));
atomic_cond_read_acquire(&lock->val, (VAL >> 16) == lock.head);
}void ticket_unlock(struct ticket_lock *lock)
{
atomic_fetch_inc_release(&lock->val);
}