* [PATCH] csky: Move to generic ticket-spinlock @ 2022-03-18 8:34 guoren 2022-03-18 10:57 ` Arnd Bergmann 2022-03-18 22:48 ` Palmer Dabbelt 0 siblings, 2 replies; 6+ messages in thread From: guoren @ 2022-03-18 8:34 UTC (permalink / raw) To: palmer; +Cc: linux-csky, linux-arch, linux-kernel, Guo Ren From: Guo Ren <guoren@linux.alibaba.com> There is no benefit from custom implementation for ticket-spinlock, so move to generic ticket-spinlock for easy maintenance. Signed-off-by: Guo Ren <guoren@linux.alibaba.com> Cc: Palmer Dabbelt <palmer@rivosinc.com> --- arch/csky/include/asm/Kbuild | 2 + arch/csky/include/asm/spinlock.h | 82 +------------------------- arch/csky/include/asm/spinlock_types.h | 20 +------ 3 files changed, 4 insertions(+), 100 deletions(-) diff --git a/arch/csky/include/asm/Kbuild b/arch/csky/include/asm/Kbuild index 904a18a818be..d94434288c31 100644 --- a/arch/csky/include/asm/Kbuild +++ b/arch/csky/include/asm/Kbuild @@ -3,6 +3,8 @@ generic-y += asm-offsets.h generic-y += extable.h generic-y += gpio.h generic-y += kvm_para.h +generic-y += ticket-lock.h +generic-y += ticket-lock-types.h generic-y += qrwlock.h generic-y += user.h generic-y += vmlinux.lds.h diff --git a/arch/csky/include/asm/spinlock.h b/arch/csky/include/asm/spinlock.h index 69f5aa249c5f..8bc179ba0d8d 100644 --- a/arch/csky/include/asm/spinlock.h +++ b/arch/csky/include/asm/spinlock.h @@ -3,87 +3,7 @@ #ifndef __ASM_CSKY_SPINLOCK_H #define __ASM_CSKY_SPINLOCK_H -#include <linux/spinlock_types.h> -#include <asm/barrier.h> - -/* - * Ticket-based spin-locking. - */ -static inline void arch_spin_lock(arch_spinlock_t *lock) -{ - arch_spinlock_t lockval; - u32 ticket_next = 1 << TICKET_NEXT; - u32 *p = &lock->lock; - u32 tmp; - - asm volatile ( - "1: ldex.w %0, (%2) \n" - " mov %1, %0 \n" - " add %0, %3 \n" - " stex.w %0, (%2) \n" - " bez %0, 1b \n" - : "=&r" (tmp), "=&r" (lockval) - : "r"(p), "r"(ticket_next) - : "cc"); - - while (lockval.tickets.next != lockval.tickets.owner) - lockval.tickets.owner = READ_ONCE(lock->tickets.owner); - - smp_mb(); -} - -static inline int arch_spin_trylock(arch_spinlock_t *lock) -{ - u32 tmp, contended, res; - u32 ticket_next = 1 << TICKET_NEXT; - u32 *p = &lock->lock; - - do { - asm volatile ( - " ldex.w %0, (%3) \n" - " movi %2, 1 \n" - " rotli %1, %0, 16 \n" - " cmpne %1, %0 \n" - " bt 1f \n" - " movi %2, 0 \n" - " add %0, %0, %4 \n" - " stex.w %0, (%3) \n" - "1: \n" - : "=&r" (res), "=&r" (tmp), "=&r" (contended) - : "r"(p), "r"(ticket_next) - : "cc"); - } while (!res); - - if (!contended) - smp_mb(); - - return !contended; -} - -static inline void arch_spin_unlock(arch_spinlock_t *lock) -{ - smp_mb(); - WRITE_ONCE(lock->tickets.owner, lock->tickets.owner + 1); -} - -static inline int arch_spin_value_unlocked(arch_spinlock_t lock) -{ - return lock.tickets.owner == lock.tickets.next; -} - -static inline int arch_spin_is_locked(arch_spinlock_t *lock) -{ - return !arch_spin_value_unlocked(READ_ONCE(*lock)); -} - -static inline int arch_spin_is_contended(arch_spinlock_t *lock) -{ - struct __raw_tickets tickets = READ_ONCE(lock->tickets); - - return (tickets.next - tickets.owner) > 1; -} -#define arch_spin_is_contended arch_spin_is_contended - +#include <asm/ticket-lock.h> #include <asm/qrwlock.h> #endif /* __ASM_CSKY_SPINLOCK_H */ diff --git a/arch/csky/include/asm/spinlock_types.h b/arch/csky/include/asm/spinlock_types.h index db87a12c3827..0bb7f6022a3b 100644 --- a/arch/csky/include/asm/spinlock_types.h +++ b/arch/csky/include/asm/spinlock_types.h @@ -3,25 +3,7 @@ #ifndef __ASM_CSKY_SPINLOCK_TYPES_H #define __ASM_CSKY_SPINLOCK_TYPES_H -#ifndef __LINUX_SPINLOCK_TYPES_RAW_H -# error "please don't include this file directly" -#endif - -#define TICKET_NEXT 16 - -typedef struct { - union { - u32 lock; - struct __raw_tickets { - /* little endian */ - u16 owner; - u16 next; - } tickets; - }; -} arch_spinlock_t; - -#define __ARCH_SPIN_LOCK_UNLOCKED { { 0 } } - +#include <asm/ticket-lock-types.h> #include <asm-generic/qrwlock_types.h> #endif /* __ASM_CSKY_SPINLOCK_TYPES_H */ -- 2.25.1 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] csky: Move to generic ticket-spinlock 2022-03-18 8:34 [PATCH] csky: Move to generic ticket-spinlock guoren @ 2022-03-18 10:57 ` Arnd Bergmann 2022-03-19 3:58 ` Guo Ren 2022-03-18 22:48 ` Palmer Dabbelt 1 sibling, 1 reply; 6+ messages in thread From: Arnd Bergmann @ 2022-03-18 10:57 UTC (permalink / raw) To: Guo Ren Cc: Palmer Dabbelt, linux-csky, linux-arch, Linux Kernel Mailing List, Guo Ren On Fri, Mar 18, 2022 at 9:34 AM <guoren@kernel.org> wrote: > @@ -3,6 +3,8 @@ generic-y += asm-offsets.h > generic-y += extable.h > generic-y += gpio.h > generic-y += kvm_para.h > +generic-y += ticket-lock.h > +generic-y += ticket-lock-types.h > generic-y += qrwlock.h > generic-y += user.h > generic-y += vmlinux.lds.h If these headers are not included from architecture-independent code, they should not be marked as generic-y, same as for the qrwlock.h header > +#include <asm/ticket-lock.h> > #include <asm/qrwlock.h> > > ... > +#include <asm/ticket-lock-types.h> > #include <asm-generic/qrwlock_types.h> > So these should all become #include <asm-generic/...h> It would however make sense to have the trivial two-line version of the two header files and put them into asm-generic/spinlock.h and asm-generic/spinlock-types.h, replacing the current version. If you do that, then you need a 'generic-y' line for spinlock.h, but not for the other ones. Arnd ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] csky: Move to generic ticket-spinlock 2022-03-18 10:57 ` Arnd Bergmann @ 2022-03-19 3:58 ` Guo Ren 0 siblings, 0 replies; 6+ messages in thread From: Guo Ren @ 2022-03-19 3:58 UTC (permalink / raw) To: Arnd Bergmann Cc: Palmer Dabbelt, linux-csky, linux-arch, Linux Kernel Mailing List, Guo Ren Hi Arnd, On Fri, Mar 18, 2022 at 6:58 PM Arnd Bergmann <arnd@arndb.de> wrote: > > On Fri, Mar 18, 2022 at 9:34 AM <guoren@kernel.org> wrote: > > @@ -3,6 +3,8 @@ generic-y += asm-offsets.h > > generic-y += extable.h > > generic-y += gpio.h > > generic-y += kvm_para.h > > +generic-y += ticket-lock.h > > +generic-y += ticket-lock-types.h > > generic-y += qrwlock.h > > generic-y += user.h > > generic-y += vmlinux.lds.h > > If these headers are not included from architecture-independent code, > they should > not be marked as generic-y, same as for the qrwlock.h header > > > +#include <asm/ticket-lock.h> > > #include <asm/qrwlock.h> > > > > ... > > +#include <asm/ticket-lock-types.h> > > #include <asm-generic/qrwlock_types.h> > > > > So these should all become > > #include <asm-generic/...h> > > It would however make sense to have the trivial two-line version > of the two header files and put them into asm-generic/spinlock.h > and asm-generic/spinlock-types.h, replacing the current version. > > If you do that, then you need a 'generic-y' line for spinlock.h, > but not for the other ones. Thx for the suggestion, I've sent V2 based on Palmer's series to make the ticket spinlock more generic. Please have a look: https://lore.kernel.org/linux-arch/20220319035457.2214979-1-guoren@kernel.org/T/#t > > Arnd -- Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/ ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] csky: Move to generic ticket-spinlock 2022-03-18 8:34 [PATCH] csky: Move to generic ticket-spinlock guoren 2022-03-18 10:57 ` Arnd Bergmann @ 2022-03-18 22:48 ` Palmer Dabbelt 2022-03-19 4:01 ` Guo Ren 1 sibling, 1 reply; 6+ messages in thread From: Palmer Dabbelt @ 2022-03-18 22:48 UTC (permalink / raw) To: guoren; +Cc: linux-csky, linux-arch, linux-kernel, guoren On Fri, 18 Mar 2022 01:34:21 PDT (-0700), guoren@kernel.org wrote: > From: Guo Ren <guoren@linux.alibaba.com> > > There is no benefit from custom implementation for ticket-spinlock, > so move to generic ticket-spinlock for easy maintenance. > > Signed-off-by: Guo Ren <guoren@linux.alibaba.com> > Cc: Palmer Dabbelt <palmer@rivosinc.com> Thanks, one less port to look at ;) Looks like there were a few comments on the v1, and I wasn't going to target this at the upcoming merge window anyway because I wanted to give the various RISC-V vendors time to test stuff. LMK if you want me to add this to the others, but I was planning on posting a stable tag either way so no big deal on my end. > --- > arch/csky/include/asm/Kbuild | 2 + > arch/csky/include/asm/spinlock.h | 82 +------------------------- > arch/csky/include/asm/spinlock_types.h | 20 +------ > 3 files changed, 4 insertions(+), 100 deletions(-) > > diff --git a/arch/csky/include/asm/Kbuild b/arch/csky/include/asm/Kbuild > index 904a18a818be..d94434288c31 100644 > --- a/arch/csky/include/asm/Kbuild > +++ b/arch/csky/include/asm/Kbuild > @@ -3,6 +3,8 @@ generic-y += asm-offsets.h > generic-y += extable.h > generic-y += gpio.h > generic-y += kvm_para.h > +generic-y += ticket-lock.h > +generic-y += ticket-lock-types.h > generic-y += qrwlock.h > generic-y += user.h > generic-y += vmlinux.lds.h > diff --git a/arch/csky/include/asm/spinlock.h b/arch/csky/include/asm/spinlock.h > index 69f5aa249c5f..8bc179ba0d8d 100644 > --- a/arch/csky/include/asm/spinlock.h > +++ b/arch/csky/include/asm/spinlock.h > @@ -3,87 +3,7 @@ > #ifndef __ASM_CSKY_SPINLOCK_H > #define __ASM_CSKY_SPINLOCK_H > > -#include <linux/spinlock_types.h> > -#include <asm/barrier.h> > - > -/* > - * Ticket-based spin-locking. > - */ > -static inline void arch_spin_lock(arch_spinlock_t *lock) > -{ > - arch_spinlock_t lockval; > - u32 ticket_next = 1 << TICKET_NEXT; > - u32 *p = &lock->lock; > - u32 tmp; > - > - asm volatile ( > - "1: ldex.w %0, (%2) \n" > - " mov %1, %0 \n" > - " add %0, %3 \n" > - " stex.w %0, (%2) \n" > - " bez %0, 1b \n" > - : "=&r" (tmp), "=&r" (lockval) > - : "r"(p), "r"(ticket_next) > - : "cc"); > - > - while (lockval.tickets.next != lockval.tickets.owner) > - lockval.tickets.owner = READ_ONCE(lock->tickets.owner); > - > - smp_mb(); > -} > - > -static inline int arch_spin_trylock(arch_spinlock_t *lock) > -{ > - u32 tmp, contended, res; > - u32 ticket_next = 1 << TICKET_NEXT; > - u32 *p = &lock->lock; > - > - do { > - asm volatile ( > - " ldex.w %0, (%3) \n" > - " movi %2, 1 \n" > - " rotli %1, %0, 16 \n" > - " cmpne %1, %0 \n" > - " bt 1f \n" > - " movi %2, 0 \n" > - " add %0, %0, %4 \n" > - " stex.w %0, (%3) \n" > - "1: \n" > - : "=&r" (res), "=&r" (tmp), "=&r" (contended) > - : "r"(p), "r"(ticket_next) > - : "cc"); > - } while (!res); > - > - if (!contended) > - smp_mb(); > - > - return !contended; > -} > - > -static inline void arch_spin_unlock(arch_spinlock_t *lock) > -{ > - smp_mb(); > - WRITE_ONCE(lock->tickets.owner, lock->tickets.owner + 1); > -} > - > -static inline int arch_spin_value_unlocked(arch_spinlock_t lock) > -{ > - return lock.tickets.owner == lock.tickets.next; > -} > - > -static inline int arch_spin_is_locked(arch_spinlock_t *lock) > -{ > - return !arch_spin_value_unlocked(READ_ONCE(*lock)); > -} > - > -static inline int arch_spin_is_contended(arch_spinlock_t *lock) > -{ > - struct __raw_tickets tickets = READ_ONCE(lock->tickets); > - > - return (tickets.next - tickets.owner) > 1; > -} > -#define arch_spin_is_contended arch_spin_is_contended > - > +#include <asm/ticket-lock.h> > #include <asm/qrwlock.h> > > #endif /* __ASM_CSKY_SPINLOCK_H */ > diff --git a/arch/csky/include/asm/spinlock_types.h b/arch/csky/include/asm/spinlock_types.h > index db87a12c3827..0bb7f6022a3b 100644 > --- a/arch/csky/include/asm/spinlock_types.h > +++ b/arch/csky/include/asm/spinlock_types.h > @@ -3,25 +3,7 @@ > #ifndef __ASM_CSKY_SPINLOCK_TYPES_H > #define __ASM_CSKY_SPINLOCK_TYPES_H > > -#ifndef __LINUX_SPINLOCK_TYPES_RAW_H > -# error "please don't include this file directly" > -#endif > - > -#define TICKET_NEXT 16 > - > -typedef struct { > - union { > - u32 lock; > - struct __raw_tickets { > - /* little endian */ > - u16 owner; > - u16 next; > - } tickets; > - }; > -} arch_spinlock_t; > - > -#define __ARCH_SPIN_LOCK_UNLOCKED { { 0 } } > - > +#include <asm/ticket-lock-types.h> > #include <asm-generic/qrwlock_types.h> > > #endif /* __ASM_CSKY_SPINLOCK_TYPES_H */ ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] csky: Move to generic ticket-spinlock 2022-03-18 22:48 ` Palmer Dabbelt @ 2022-03-19 4:01 ` Guo Ren 2022-03-22 17:48 ` Palmer Dabbelt 0 siblings, 1 reply; 6+ messages in thread From: Guo Ren @ 2022-03-19 4:01 UTC (permalink / raw) To: Palmer Dabbelt; +Cc: linux-csky, linux-arch, Linux Kernel Mailing List, Guo Ren Hi Palmer, On Sat, Mar 19, 2022 at 6:48 AM Palmer Dabbelt <palmer@rivosinc.com> wrote: > > On Fri, 18 Mar 2022 01:34:21 PDT (-0700), guoren@kernel.org wrote: > > From: Guo Ren <guoren@linux.alibaba.com> > > > > There is no benefit from custom implementation for ticket-spinlock, > > so move to generic ticket-spinlock for easy maintenance. > > > > Signed-off-by: Guo Ren <guoren@linux.alibaba.com> > > Cc: Palmer Dabbelt <palmer@rivosinc.com> > > Thanks, one less port to look at ;) > > Looks like there were a few comments on the v1, and I wasn't going to > target this at the upcoming merge window anyway because I wanted to give Agree, we needn't so hurry. > the various RISC-V vendors time to test stuff. LMK if you want me to > add this to the others, but I was planning on posting a stable tag > either way so no big deal on my end. Yes, I hope csky's could be in the series. And I updated V2 with Arnd's suggestion, please have a look: https://lore.kernel.org/linux-arch/20220319035457.2214979-1-guoren@kernel.org/T/#t > > > --- > > arch/csky/include/asm/Kbuild | 2 + > > arch/csky/include/asm/spinlock.h | 82 +------------------------- > > arch/csky/include/asm/spinlock_types.h | 20 +------ > > 3 files changed, 4 insertions(+), 100 deletions(-) > > > > diff --git a/arch/csky/include/asm/Kbuild b/arch/csky/include/asm/Kbuild > > index 904a18a818be..d94434288c31 100644 > > --- a/arch/csky/include/asm/Kbuild > > +++ b/arch/csky/include/asm/Kbuild > > @@ -3,6 +3,8 @@ generic-y += asm-offsets.h > > generic-y += extable.h > > generic-y += gpio.h > > generic-y += kvm_para.h > > +generic-y += ticket-lock.h > > +generic-y += ticket-lock-types.h > > generic-y += qrwlock.h > > generic-y += user.h > > generic-y += vmlinux.lds.h > > diff --git a/arch/csky/include/asm/spinlock.h b/arch/csky/include/asm/spinlock.h > > index 69f5aa249c5f..8bc179ba0d8d 100644 > > --- a/arch/csky/include/asm/spinlock.h > > +++ b/arch/csky/include/asm/spinlock.h > > @@ -3,87 +3,7 @@ > > #ifndef __ASM_CSKY_SPINLOCK_H > > #define __ASM_CSKY_SPINLOCK_H > > > > -#include <linux/spinlock_types.h> > > -#include <asm/barrier.h> > > - > > -/* > > - * Ticket-based spin-locking. > > - */ > > -static inline void arch_spin_lock(arch_spinlock_t *lock) > > -{ > > - arch_spinlock_t lockval; > > - u32 ticket_next = 1 << TICKET_NEXT; > > - u32 *p = &lock->lock; > > - u32 tmp; > > - > > - asm volatile ( > > - "1: ldex.w %0, (%2) \n" > > - " mov %1, %0 \n" > > - " add %0, %3 \n" > > - " stex.w %0, (%2) \n" > > - " bez %0, 1b \n" > > - : "=&r" (tmp), "=&r" (lockval) > > - : "r"(p), "r"(ticket_next) > > - : "cc"); > > - > > - while (lockval.tickets.next != lockval.tickets.owner) > > - lockval.tickets.owner = READ_ONCE(lock->tickets.owner); > > - > > - smp_mb(); > > -} > > - > > -static inline int arch_spin_trylock(arch_spinlock_t *lock) > > -{ > > - u32 tmp, contended, res; > > - u32 ticket_next = 1 << TICKET_NEXT; > > - u32 *p = &lock->lock; > > - > > - do { > > - asm volatile ( > > - " ldex.w %0, (%3) \n" > > - " movi %2, 1 \n" > > - " rotli %1, %0, 16 \n" > > - " cmpne %1, %0 \n" > > - " bt 1f \n" > > - " movi %2, 0 \n" > > - " add %0, %0, %4 \n" > > - " stex.w %0, (%3) \n" > > - "1: \n" > > - : "=&r" (res), "=&r" (tmp), "=&r" (contended) > > - : "r"(p), "r"(ticket_next) > > - : "cc"); > > - } while (!res); > > - > > - if (!contended) > > - smp_mb(); > > - > > - return !contended; > > -} > > - > > -static inline void arch_spin_unlock(arch_spinlock_t *lock) > > -{ > > - smp_mb(); > > - WRITE_ONCE(lock->tickets.owner, lock->tickets.owner + 1); > > -} > > - > > -static inline int arch_spin_value_unlocked(arch_spinlock_t lock) > > -{ > > - return lock.tickets.owner == lock.tickets.next; > > -} > > - > > -static inline int arch_spin_is_locked(arch_spinlock_t *lock) > > -{ > > - return !arch_spin_value_unlocked(READ_ONCE(*lock)); > > -} > > - > > -static inline int arch_spin_is_contended(arch_spinlock_t *lock) > > -{ > > - struct __raw_tickets tickets = READ_ONCE(lock->tickets); > > - > > - return (tickets.next - tickets.owner) > 1; > > -} > > -#define arch_spin_is_contended arch_spin_is_contended > > - > > +#include <asm/ticket-lock.h> > > #include <asm/qrwlock.h> > > > > #endif /* __ASM_CSKY_SPINLOCK_H */ > > diff --git a/arch/csky/include/asm/spinlock_types.h b/arch/csky/include/asm/spinlock_types.h > > index db87a12c3827..0bb7f6022a3b 100644 > > --- a/arch/csky/include/asm/spinlock_types.h > > +++ b/arch/csky/include/asm/spinlock_types.h > > @@ -3,25 +3,7 @@ > > #ifndef __ASM_CSKY_SPINLOCK_TYPES_H > > #define __ASM_CSKY_SPINLOCK_TYPES_H > > > > -#ifndef __LINUX_SPINLOCK_TYPES_RAW_H > > -# error "please don't include this file directly" > > -#endif > > - > > -#define TICKET_NEXT 16 > > - > > -typedef struct { > > - union { > > - u32 lock; > > - struct __raw_tickets { > > - /* little endian */ > > - u16 owner; > > - u16 next; > > - } tickets; > > - }; > > -} arch_spinlock_t; > > - > > -#define __ARCH_SPIN_LOCK_UNLOCKED { { 0 } } > > - > > +#include <asm/ticket-lock-types.h> > > #include <asm-generic/qrwlock_types.h> > > > > #endif /* __ASM_CSKY_SPINLOCK_TYPES_H */ -- Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/ ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] csky: Move to generic ticket-spinlock 2022-03-19 4:01 ` Guo Ren @ 2022-03-22 17:48 ` Palmer Dabbelt 0 siblings, 0 replies; 6+ messages in thread From: Palmer Dabbelt @ 2022-03-22 17:48 UTC (permalink / raw) To: guoren; +Cc: linux-csky, linux-arch, linux-kernel, guoren On Fri, 18 Mar 2022 21:01:49 PDT (-0700), guoren@kernel.org wrote: > Hi Palmer, > > On Sat, Mar 19, 2022 at 6:48 AM Palmer Dabbelt <palmer@rivosinc.com> wrote: >> >> On Fri, 18 Mar 2022 01:34:21 PDT (-0700), guoren@kernel.org wrote: >> > From: Guo Ren <guoren@linux.alibaba.com> >> > >> > There is no benefit from custom implementation for ticket-spinlock, >> > so move to generic ticket-spinlock for easy maintenance. >> > >> > Signed-off-by: Guo Ren <guoren@linux.alibaba.com> >> > Cc: Palmer Dabbelt <palmer@rivosinc.com> >> >> Thanks, one less port to look at ;) >> >> Looks like there were a few comments on the v1, and I wasn't going to >> target this at the upcoming merge window anyway because I wanted to give > Agree, we needn't so hurry. > >> the various RISC-V vendors time to test stuff. LMK if you want me to >> add this to the others, but I was planning on posting a stable tag >> either way so no big deal on my end. > Yes, I hope csky's could be in the series. And I updated V2 with > Arnd's suggestion, please have a look: > https://lore.kernel.org/linux-arch/20220319035457.2214979-1-guoren@kernel.org/T/#t Thanks, I'll include the csky stuff next time I re-spin this. Looks like there's been some other comments from folks that didn't make your v2, most notably the SOB lines which makes this a bit funny. I'm also not sure I like merging the two RISC-V patches together, as they'd be nice to be able to test on their own. I'll go poke around with this some once I'm a bit father into the merge window. I think we can both keep Arnd's generic header idea and let folks mix/match spin/rw lock flavors, which might also help with some of the other ports. > >> >> > --- >> > arch/csky/include/asm/Kbuild | 2 + >> > arch/csky/include/asm/spinlock.h | 82 +------------------------- >> > arch/csky/include/asm/spinlock_types.h | 20 +------ >> > 3 files changed, 4 insertions(+), 100 deletions(-) >> > >> > diff --git a/arch/csky/include/asm/Kbuild b/arch/csky/include/asm/Kbuild >> > index 904a18a818be..d94434288c31 100644 >> > --- a/arch/csky/include/asm/Kbuild >> > +++ b/arch/csky/include/asm/Kbuild >> > @@ -3,6 +3,8 @@ generic-y += asm-offsets.h >> > generic-y += extable.h >> > generic-y += gpio.h >> > generic-y += kvm_para.h >> > +generic-y += ticket-lock.h >> > +generic-y += ticket-lock-types.h >> > generic-y += qrwlock.h >> > generic-y += user.h >> > generic-y += vmlinux.lds.h >> > diff --git a/arch/csky/include/asm/spinlock.h b/arch/csky/include/asm/spinlock.h >> > index 69f5aa249c5f..8bc179ba0d8d 100644 >> > --- a/arch/csky/include/asm/spinlock.h >> > +++ b/arch/csky/include/asm/spinlock.h >> > @@ -3,87 +3,7 @@ >> > #ifndef __ASM_CSKY_SPINLOCK_H >> > #define __ASM_CSKY_SPINLOCK_H >> > >> > -#include <linux/spinlock_types.h> >> > -#include <asm/barrier.h> >> > - >> > -/* >> > - * Ticket-based spin-locking. >> > - */ >> > -static inline void arch_spin_lock(arch_spinlock_t *lock) >> > -{ >> > - arch_spinlock_t lockval; >> > - u32 ticket_next = 1 << TICKET_NEXT; >> > - u32 *p = &lock->lock; >> > - u32 tmp; >> > - >> > - asm volatile ( >> > - "1: ldex.w %0, (%2) \n" >> > - " mov %1, %0 \n" >> > - " add %0, %3 \n" >> > - " stex.w %0, (%2) \n" >> > - " bez %0, 1b \n" >> > - : "=&r" (tmp), "=&r" (lockval) >> > - : "r"(p), "r"(ticket_next) >> > - : "cc"); >> > - >> > - while (lockval.tickets.next != lockval.tickets.owner) >> > - lockval.tickets.owner = READ_ONCE(lock->tickets.owner); >> > - >> > - smp_mb(); >> > -} >> > - >> > -static inline int arch_spin_trylock(arch_spinlock_t *lock) >> > -{ >> > - u32 tmp, contended, res; >> > - u32 ticket_next = 1 << TICKET_NEXT; >> > - u32 *p = &lock->lock; >> > - >> > - do { >> > - asm volatile ( >> > - " ldex.w %0, (%3) \n" >> > - " movi %2, 1 \n" >> > - " rotli %1, %0, 16 \n" >> > - " cmpne %1, %0 \n" >> > - " bt 1f \n" >> > - " movi %2, 0 \n" >> > - " add %0, %0, %4 \n" >> > - " stex.w %0, (%3) \n" >> > - "1: \n" >> > - : "=&r" (res), "=&r" (tmp), "=&r" (contended) >> > - : "r"(p), "r"(ticket_next) >> > - : "cc"); >> > - } while (!res); >> > - >> > - if (!contended) >> > - smp_mb(); >> > - >> > - return !contended; >> > -} >> > - >> > -static inline void arch_spin_unlock(arch_spinlock_t *lock) >> > -{ >> > - smp_mb(); >> > - WRITE_ONCE(lock->tickets.owner, lock->tickets.owner + 1); >> > -} >> > - >> > -static inline int arch_spin_value_unlocked(arch_spinlock_t lock) >> > -{ >> > - return lock.tickets.owner == lock.tickets.next; >> > -} >> > - >> > -static inline int arch_spin_is_locked(arch_spinlock_t *lock) >> > -{ >> > - return !arch_spin_value_unlocked(READ_ONCE(*lock)); >> > -} >> > - >> > -static inline int arch_spin_is_contended(arch_spinlock_t *lock) >> > -{ >> > - struct __raw_tickets tickets = READ_ONCE(lock->tickets); >> > - >> > - return (tickets.next - tickets.owner) > 1; >> > -} >> > -#define arch_spin_is_contended arch_spin_is_contended >> > - >> > +#include <asm/ticket-lock.h> >> > #include <asm/qrwlock.h> >> > >> > #endif /* __ASM_CSKY_SPINLOCK_H */ >> > diff --git a/arch/csky/include/asm/spinlock_types.h b/arch/csky/include/asm/spinlock_types.h >> > index db87a12c3827..0bb7f6022a3b 100644 >> > --- a/arch/csky/include/asm/spinlock_types.h >> > +++ b/arch/csky/include/asm/spinlock_types.h >> > @@ -3,25 +3,7 @@ >> > #ifndef __ASM_CSKY_SPINLOCK_TYPES_H >> > #define __ASM_CSKY_SPINLOCK_TYPES_H >> > >> > -#ifndef __LINUX_SPINLOCK_TYPES_RAW_H >> > -# error "please don't include this file directly" >> > -#endif >> > - >> > -#define TICKET_NEXT 16 >> > - >> > -typedef struct { >> > - union { >> > - u32 lock; >> > - struct __raw_tickets { >> > - /* little endian */ >> > - u16 owner; >> > - u16 next; >> > - } tickets; >> > - }; >> > -} arch_spinlock_t; >> > - >> > -#define __ARCH_SPIN_LOCK_UNLOCKED { { 0 } } >> > - >> > +#include <asm/ticket-lock-types.h> >> > #include <asm-generic/qrwlock_types.h> >> > >> > #endif /* __ASM_CSKY_SPINLOCK_TYPES_H */ ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-03-22 17:48 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-03-18 8:34 [PATCH] csky: Move to generic ticket-spinlock guoren 2022-03-18 10:57 ` Arnd Bergmann 2022-03-19 3:58 ` Guo Ren 2022-03-18 22:48 ` Palmer Dabbelt 2022-03-19 4:01 ` Guo Ren 2022-03-22 17:48 ` Palmer Dabbelt
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®