Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp39879lqb; Tue, 28 May 2024 08:17:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUT7rWPYe6yUK0M046k0/+ey0r2LvlEpjZ/aD04A3I3uFma/XYpWQ32RdoN76quJenMwl/vIiFqWsnoafjnvekyFDdnhVBYY9fUu/Q35g== X-Google-Smtp-Source: AGHT+IFSU58D1F6elrIMt8ql2nEHrBs6mqsHTlq4S/U9/BiEZOQu4RfYCsakCl4WJ/H9SQCvoThp X-Received: by 2002:a54:4801:0:b0:3c9:96d2:fcea with SMTP id 5614622812f47-3d1a66d4b5amr11687002b6e.17.1716909447259; Tue, 28 May 2024 08:17:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716909447; cv=pass; d=google.com; s=arc-20160816; b=AgciBqX1R3bcLSVuKEM9VwUHZ38URbCZKicJTsIRm6wV9t4t9wCr2IxTS7P2n1N4jF nbh2q8SZVwX8lEP7YBKYkRf8do2QcBtlQjQMqPyBoSddBecHScyfrCZDyIL56kjwmNWp up1j8gne8QGOdh3A2xlGY77AtWwTnY9ArFSEZxjJvBjMsZWbmKg1XJ+fWCMM5/nHTnQc Ea7BFTJZQZ57MEfXck2qVSJ7BHTH+We945D+8BWfAp0TXdewVkCEQylLTBMiTeXjO5NF SyOOPCuXeB0Dm6tMfHdTmDBNXqFy5P5HadAmy9irBXv5d45ChkzWlXHnUIcKGrQ8FpMI EBLw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=heAbIXv1oMx4SoDoWG1mJ8ALiEwmwn+mI3czPDKQjFY=; fh=kThhk/q0e1zSH7NRTlJdM8ncR88a+9r3yU9jlZdbZR8=; b=ywqZWdsfU/U8o5MQsiZvJ295A7TgAbqBQ78qMQ10nI/BMDRggL8D7EHHya42Cq0uoI JICrtXqoDGlmdilJu/y86N++RcVuDkNbzief6RJlFbTDXXGL79P8BPljhgtuZXS219k4 Rz2n/ebC2iA1Z4LkujZZWa4tKGpJyxQMbSzgK9oP4lZAUtYp40vRP+TGhpx+BkR2qaQY GwM8I3BFkF0vWd5QjCIwuXLGhnlU+q3y+8mY8Zv3SixKEIKXY4lg2jqaVuAz+20bM6TD xYx160KY60MRK8lk8JT6Vc++g46wZfufk82ima/Gn7TFFnnsAqZtuCHQUij/30dpTaZX xQug==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="B/2cJVLe"; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-192646-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192646-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 71dfb90a1353d-4e4f072ab63si2035921e0c.28.2024.05.28.08.17.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 08:17:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-192646-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="B/2cJVLe"; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-192646-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192646-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B98421C22D00 for ; Tue, 28 May 2024 15:17:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C0BE4171E7C; Tue, 28 May 2024 15:16:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="B/2cJVLe" Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 110D6282FA for ; Tue, 28 May 2024 15:16:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716909363; cv=none; b=Q6KDnSktW4FcPZq5u+mAYJg31++68LQDiGh71dw5qocILA4QOXLis1/CPMGdwMkHb3Q2yHsfUOZ4lvRG0Z1/zgzjM4QnoEp2mF6b3YKawECsm0fjwE0qdby8R6P8y0vTbtAzRvw6V73EGxQUsdQvluiAZP25gUAI47QrIXwSgaw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716909363; c=relaxed/simple; bh=zIctHSF8s4ycH2M1Xuee5DajFIDyCPEPGL7Vxs9tOR4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TDETqNBATFR+vhY/Vt3x6xBU6UzmMIIb0/d5ixk4dDSaJQ9nFP9XGb2aQ71Ya5RobHfp2IZ72QwLRlt3FTU+IsqMkw03sFksgI1Nqw7NEVc0JgEeLSmCvfoezL0dGYUBBw8F6gmwFc93haMhUsZCYNDnZkX9HZmXHDjpYzDfq1Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=B/2cJVLe; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-42121d27861so248885e9.0 for ; Tue, 28 May 2024 08:16:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1716909360; x=1717514160; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=heAbIXv1oMx4SoDoWG1mJ8ALiEwmwn+mI3czPDKQjFY=; b=B/2cJVLeRvjhR6DtdsavZO5f1aH9SugqzUFIN6bfi7wqkO7BbNkCgyuud9c/WcgcFB DNo6vfe3CsksekPdbp+cp00dihZqdQgf0fSLPkKpEJ3su1vbVGAxMtMzsJIGJNWFU7ww zSCw0uMIltcXh/TtfIk+becgE2awNSoxLPMpn5pTJnEsLQod1RIsyuknJPprOsEF1W4X Kt2xWSWD3iTXsS5ORWV3QEEM2/X3/jAGisD+6p2TR1rmyzSxzqrF1kf5ealpxywFmkEK N3mDi5rqgucKvpUu0PNNkZGFM+JC0dKv2V9W3++exx18BTHiwg2a4syRW4GI7R6iUvdr 7zzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716909360; x=1717514160; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=heAbIXv1oMx4SoDoWG1mJ8ALiEwmwn+mI3czPDKQjFY=; b=VMwNx/XeNo/iOTOqr7UAi/hVT8xTZykXJiBxkmB3sgRcmL4/zWyx7NNuy4BQYcOYSc EkIYSWYrlYtbfzPgYHuX7IRF/AqDwUnDP1f6uy8Hpj69fUuAcXz9jbomHzhKgilqKmNB DL8nTe2ZdOZt1cfjLG11Y/KuAfMvoRH+/mlsfa4wkKVynhmuw+Ci9N7Tu2t1b1Wx6zbZ sbfF4EZUgszvUHhTCXVXLXZ2LsmSPFVA+TmPhgCf9RUm5U2tkQgwDY1m8r/XEVeNlSDW 0vdJ6gAwLORc+91BvTMOWsxMRpc89vdJ/6CjiCNGJehgZReADnIhfYGftx9kpiy3x8uE 2LWg== X-Forwarded-Encrypted: i=1; AJvYcCViQQoPiMH3UXfor65XG9GebkxbJxGHnVW8IVB/GDWly9JWfpZgwNxQWuXsjnIIxdkhEsa/DMpckle7K09GG1jvzs2oogh4Vmlzzxc0 X-Gm-Message-State: AOJu0Yw4PJBpOjv9nbKI9oUw7cE2NL/+sCqWR3Dm1J2DVkkangEatwLq pGkVrN8FWOK6biqWTfZu9g2egAq+mGlLHmJhdXlQQlBpt9HLcKqbNWrPK1ElRR4= X-Received: by 2002:a05:600c:45cd:b0:420:29dd:84db with SMTP id 5b1f17b1804b1-42108a26c56mr116889895e9.35.1716909360501; Tue, 28 May 2024 08:16:00 -0700 (PDT) Received: from alex-rivos.home (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42108970b4esm146682755e9.14.2024.05.28.08.15.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 08:16:00 -0700 (PDT) From: Alexandre Ghiti To: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , Boqun Feng , Arnd Bergmann , Leonardo Bras , Guo Ren , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-arch@vger.kernel.org Cc: Guo Ren Subject: [PATCH 5/7] asm-generic: ticket-lock: Reuse arch_spinlock_t of qspinlock Date: Tue, 28 May 2024 17:10:50 +0200 Message-Id: <20240528151052.313031-6-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240528151052.313031-1-alexghiti@rivosinc.com> References: <20240528151052.313031-1-alexghiti@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Guo Ren The arch_spinlock_t of qspinlock has contained the atomic_t val, which satisfies the ticket-lock requirement. Thus, unify the arch_spinlock_t into qspinlock_types.h. This is the preparation for the next combo spinlock. Reviewed-by: Leonardo Bras Suggested-by: Arnd Bergmann Link: https://lore.kernel.org/linux-riscv/CAK8P3a2rnz9mQqhN6-e0CGUUv9rntRELFdxt_weiD7FxH7fkfQ@mail.gmail.com/ Signed-off-by: Guo Ren Signed-off-by: Guo Ren --- include/asm-generic/spinlock.h | 14 +++++++------- include/asm-generic/spinlock_types.h | 12 ++---------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/include/asm-generic/spinlock.h b/include/asm-generic/spinlock.h index 90803a826ba0..4773334ee638 100644 --- a/include/asm-generic/spinlock.h +++ b/include/asm-generic/spinlock.h @@ -32,7 +32,7 @@ static __always_inline void arch_spin_lock(arch_spinlock_t *lock) { - u32 val = atomic_fetch_add(1<<16, lock); + u32 val = atomic_fetch_add(1<<16, &lock->val); u16 ticket = val >> 16; if (ticket == (u16)val) @@ -46,31 +46,31 @@ static __always_inline void arch_spin_lock(arch_spinlock_t *lock) * have no outstanding writes due to the atomic_fetch_add() the extra * orderings are free. */ - atomic_cond_read_acquire(lock, ticket == (u16)VAL); + atomic_cond_read_acquire(&lock->val, ticket == (u16)VAL); smp_mb(); } static __always_inline bool arch_spin_trylock(arch_spinlock_t *lock) { - u32 old = atomic_read(lock); + u32 old = atomic_read(&lock->val); if ((old >> 16) != (old & 0xffff)) return false; - return atomic_try_cmpxchg(lock, &old, old + (1<<16)); /* SC, for RCsc */ + return atomic_try_cmpxchg(&lock->val, &old, old + (1<<16)); /* SC, for RCsc */ } static __always_inline void arch_spin_unlock(arch_spinlock_t *lock) { u16 *ptr = (u16 *)lock + IS_ENABLED(CONFIG_CPU_BIG_ENDIAN); - u32 val = atomic_read(lock); + u32 val = atomic_read(&lock->val); smp_store_release(ptr, (u16)val + 1); } static __always_inline int arch_spin_value_unlocked(arch_spinlock_t lock) { - u32 val = lock.counter; + u32 val = lock.val.counter; return ((val >> 16) == (val & 0xffff)); } @@ -84,7 +84,7 @@ static __always_inline int arch_spin_is_locked(arch_spinlock_t *lock) static __always_inline int arch_spin_is_contended(arch_spinlock_t *lock) { - u32 val = atomic_read(lock); + u32 val = atomic_read(&lock->val); return (s16)((val >> 16) - (val & 0xffff)) > 1; } diff --git a/include/asm-generic/spinlock_types.h b/include/asm-generic/spinlock_types.h index 8962bb730945..f534aa5de394 100644 --- a/include/asm-generic/spinlock_types.h +++ b/include/asm-generic/spinlock_types.h @@ -3,15 +3,7 @@ #ifndef __ASM_GENERIC_SPINLOCK_TYPES_H #define __ASM_GENERIC_SPINLOCK_TYPES_H -#include -typedef atomic_t arch_spinlock_t; - -/* - * qrwlock_types depends on arch_spinlock_t, so we must typedef that before the - * include. - */ -#include - -#define __ARCH_SPIN_LOCK_UNLOCKED ATOMIC_INIT(0) +#include +#include #endif /* __ASM_GENERIC_SPINLOCK_TYPES_H */ -- 2.39.2