From nobody Mon Jun 22 19:20:49 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59608C433F5 for ; Fri, 18 Mar 2022 08:34:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233819AbiCRIgH (ORCPT ); Fri, 18 Mar 2022 04:36:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233764AbiCRIgE (ORCPT ); Fri, 18 Mar 2022 04:36:04 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 234621FCD31; Fri, 18 Mar 2022 01:34:44 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 68391B80B2E; Fri, 18 Mar 2022 08:34:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9BC57C340E8; Fri, 18 Mar 2022 08:34:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647592482; bh=8LsQHARc36osfxHPIM0ZbutdnqRcT4bVoo5JOGzezRk=; h=From:To:Cc:Subject:Date:From; b=BLhLgHS0EsguLvExFj1WKJgZJe69d7yOXU0MW77sz3Wpo0D2njetetnc+r68yufwx HzhdbwKLDTNu3LN4GVsqj3tgVj9qTTvDYvh3CdB8dDEZsdxKRnnkPzrugRir/rjSkI yfuPMPEUzyW8Ezs/Otxf8UIqgE6HwPW2BtUF63LutIKG3O23gxy4rziVRStC5QzB98 bCsbmOO+FWR7i7xmQxeOAqMvF3RdFluFfosDA6lfSbK1wwDj5jiwqLsu58gcBO7aVo j++lcHX7ePMNPFcOWceUzTzy35ihmNTQr3vl5HQnsFWwgjJKIuA+pi1p3g5LYwaioh q37i3dB/6CYvw== From: guoren@kernel.org To: palmer@rivosinc.com Cc: linux-csky@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, Guo Ren Subject: [PATCH] csky: Move to generic ticket-spinlock Date: Fri, 18 Mar 2022 16:34:21 +0800 Message-Id: <20220318083421.2062259-1-guoren@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Guo Ren There is no benefit from custom implementation for ticket-spinlock, so move to generic ticket-spinlock for easy maintenance. Signed-off-by: Guo Ren Cc: Palmer Dabbelt --- 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 +=3D asm-offsets.h generic-y +=3D extable.h generic-y +=3D gpio.h generic-y +=3D kvm_para.h +generic-y +=3D ticket-lock.h +generic-y +=3D ticket-lock-types.h generic-y +=3D qrwlock.h generic-y +=3D user.h generic-y +=3D vmlinux.lds.h diff --git a/arch/csky/include/asm/spinlock.h b/arch/csky/include/asm/spinl= ock.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 =20 -#include -#include - -/* - * Ticket-based spin-locking. - */ -static inline void arch_spin_lock(arch_spinlock_t *lock) -{ - arch_spinlock_t lockval; - u32 ticket_next =3D 1 << TICKET_NEXT; - u32 *p =3D &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" - : "=3D&r" (tmp), "=3D&r" (lockval) - : "r"(p), "r"(ticket_next) - : "cc"); - - while (lockval.tickets.next !=3D lockval.tickets.owner) - lockval.tickets.owner =3D READ_ONCE(lock->tickets.owner); - - smp_mb(); -} - -static inline int arch_spin_trylock(arch_spinlock_t *lock) -{ - u32 tmp, contended, res; - u32 ticket_next =3D 1 << TICKET_NEXT; - u32 *p =3D &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" - : "=3D&r" (res), "=3D&r" (tmp), "=3D&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 =3D=3D 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 =3D READ_ONCE(lock->tickets); - - return (tickets.next - tickets.owner) > 1; -} -#define arch_spin_is_contended arch_spin_is_contended - +#include #include =20 #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 =20 -#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 #include =20 #endif /* __ASM_CSKY_SPINLOCK_TYPES_H */ --=20 2.25.1