Re: [PATCH] csky: Move to generic ticket-spinlock

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 18 Mar 2022 21:01:49 PDT (-0700), guoren@xxxxxxxxxx wrote:
Hi Palmer,

On Sat, Mar 19, 2022 at 6:48 AM Palmer Dabbelt <palmer@xxxxxxxxxxxx> wrote:

On Fri, 18 Mar 2022 01:34:21 PDT (-0700), guoren@xxxxxxxxxx wrote:
> From: Guo Ren <guoren@xxxxxxxxxxxxxxxxx>
>
> 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@xxxxxxxxxxxxxxxxx>
> Cc: Palmer Dabbelt <palmer@xxxxxxxxxxxx>

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@xxxxxxxxxx/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 */



[Index of Archives]     [Linux Kernel]     [Kernel Newbies]     [x86 Platform Driver]     [Netdev]     [Linux Wireless]     [Netfilter]     [Bugtraq]     [Linux Filesystems]     [Yosemite Discussion]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]

  Powered by Linux