Skip to content

Commit 45e15c1

Browse files
committed
csky: Add qspinlock support
Enable qspinlock by the requirements mentioned in a8ad07e ("asm-generic: qspinlock: Indicate the use of mixed-size atomics"). C-SKY only has "ldex/stex" for all atomic operations. So csky give a strong forward guarantee for "ldex/stex." That means when ldex grabbed the cache line into $L1, it would block other cores from snooping the address with several cycles. The atomic_fetch_add & xchg16 has the same forward guarantee level in C-SKY. Qspinlock has better code size and performance in a fast path. Signed-off-by: Guo Ren <[email protected]> Signed-off-by: Guo Ren <[email protected]>
1 parent 4e8bb4b commit 45e15c1

File tree

5 files changed

+44
-2
lines changed

5 files changed

+44
-2
lines changed

arch/csky/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ config CSKY
88
select ARCH_HAS_SYNC_DMA_FOR_DEVICE
99
select ARCH_USE_BUILTIN_BSWAP
1010
select ARCH_USE_QUEUED_RWLOCKS
11+
select ARCH_USE_QUEUED_SPINLOCKS
1112
select ARCH_WANT_FRAME_POINTERS if !CPU_CK610 && $(cc-option,-mbacktrace)
1213
select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT
1314
select COMMON_CLK

arch/csky/include/asm/Kbuild

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ generic-y += asm-offsets.h
33
generic-y += extable.h
44
generic-y += gpio.h
55
generic-y += kvm_para.h
6-
generic-y += spinlock.h
7-
generic-y += spinlock_types.h
6+
generic-y += mcs_spinlock.h
87
generic-y += qrwlock.h
98
generic-y += qrwlock_types.h
9+
generic-y += qspinlock.h
1010
generic-y += parport.h
1111
generic-y += user.h
1212
generic-y += vmlinux.lds.h

arch/csky/include/asm/cmpxchg.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,26 @@ extern void __bad_xchg(void);
1515
__typeof__(*(ptr)) __ret; \
1616
unsigned long tmp; \
1717
switch (size) { \
18+
case 2: { \
19+
u32 ret; \
20+
u32 shif = ((ulong)__ptr & 2) ? 16 : 0; \
21+
u32 mask = 0xffff << shif; \
22+
__ptr = (__typeof__(ptr))((ulong)__ptr & ~2); \
23+
__asm__ __volatile__ ( \
24+
"1: ldex.w %0, (%4)\n" \
25+
" and %1, %0, %2\n" \
26+
" or %1, %1, %3\n" \
27+
" stex.w %1, (%4)\n" \
28+
" bez %1, 1b\n" \
29+
: "=&r" (ret), "=&r" (tmp) \
30+
: "r" (~mask), \
31+
"r" ((u32)__new << shif), \
32+
"r" (__ptr) \
33+
: "memory"); \
34+
__ret = (__typeof__(*(ptr))) \
35+
((ret & mask) >> shif); \
36+
break; \
37+
} \
1838
case 4: \
1939
asm volatile ( \
2040
"1: ldex.w %0, (%3) \n" \

arch/csky/include/asm/spinlock.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
#ifndef __ASM_CSKY_SPINLOCK_H
4+
#define __ASM_CSKY_SPINLOCK_H
5+
6+
#include <asm/qspinlock.h>
7+
#include <asm/qrwlock.h>
8+
9+
/* See include/linux/spinlock.h */
10+
#define smp_mb__after_spinlock() smp_mb()
11+
12+
#endif /* __ASM_CSKY_SPINLOCK_H */
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
#ifndef __ASM_CSKY_SPINLOCK_TYPES_H
4+
#define __ASM_CSKY_SPINLOCK_TYPES_H
5+
6+
#include <asm-generic/qspinlock_types.h>
7+
#include <asm-generic/qrwlock_types.h>
8+
9+
#endif /* __ASM_CSKY_SPINLOCK_TYPES_H */

0 commit comments

Comments
 (0)