Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1637490pxp; Thu, 17 Mar 2022 13:17:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyny7iuUzSwdgzCgDOf2zUdBltfleM+rrOLbvJ5nst1yPlGUF3mPcm4bzPVSqdmN233sk6s X-Received: by 2002:a17:90b:4d05:b0:1bf:7d65:f1f7 with SMTP id mw5-20020a17090b4d0500b001bf7d65f1f7mr7379867pjb.108.1647548252682; Thu, 17 Mar 2022 13:17:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647548252; cv=none; d=google.com; s=arc-20160816; b=Ah4vk+OTkcEysLpjdROelFxBUaEP4eqturzzubZI//+yb6V/KrpGhqQnQmFJk7SyRD y7VcAxwbIx6sHrwHmhb0rNH2F99+6XdSZ4xY+lXNkINyj2UAKwOQxcXLHR1ct7MxeWN+ U+ff/TbPw9B7j8kEPmi1raq6BG3sPMcvbT3oynvz6ecRQXbDmDeWMRwpzVmZ0DqaSCma nWl7380109gnwvd09hOUTqo0S2mSeA90lPTtcnR6edb//LttFtUtHOuZji//L0RNgZbE euEcJbriQqjaNqcDNeG1KgkDyVeb0VFpnURyBdfAac/5+8H3m+FGu5OU5Lqm6QWiNhnO wA+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=aa1jAvfCIcTnLm2lUoV2mmz4eiiaEOLiyUm5zpRdIXk=; b=MFYJfizA6WwTuEZ1n3qXGoiL8FSgUcH+9e+weFN7iG3uaxeI6rmdTgm1iZnWpyfV3u xqDJvRNnCF3Y5Fawq13Nd0lSHzFpNMtxX6jFqqdFWxgjBkiMsiYh7kHLjL7xRyvut0hQ ZOTLoXaFX1PZW8RyE7vu/WJM4EUoCqEgWEjfZ6Eh0yXtAPlGLOnjw6tHDWbLi8hAcTxt jVQMRWbUG+4EbrnmcNdF8wYC80Dn5SGu23gxHd4Z2aUAwVcEZBxddrk+6txSO9OltQLv D9C1TKMkGb3TIIG833pRpQ+xjpB/guu4hse7Tg2l2BonNmcj4ffAsKWTiXZFp/eSzkVA 2+mA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RRSYGFXy; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id g7-20020a056a001a0700b004f71b5c047csi6183821pfv.85.2022.03.17.13.17.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 13:17:32 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RRSYGFXy; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 27B561427DB; Thu, 17 Mar 2022 12:59:25 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235471AbiCQPFE (ORCPT + 99 others); Thu, 17 Mar 2022 11:05:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231290AbiCQPFC (ORCPT ); Thu, 17 Mar 2022 11:05:02 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 701F3F1AF8 for ; Thu, 17 Mar 2022 08:03:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647529424; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aa1jAvfCIcTnLm2lUoV2mmz4eiiaEOLiyUm5zpRdIXk=; b=RRSYGFXysvlLOQrsC8WcdVp7xVWcncxpKH1Lbn2KfpOgiuLxKA2iGbOZOMNhu6ekZk+aF9 GW+8BjFLNwVXnN7N8AfCX14MYd/0ckhzSqJtLADX1xBdRUjKcBL0hk6fHtgiZXCRKuLorI dQT110SIDGIltWbG4YPvMymSndwc/NI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-144-1uKE53VaO8eu6i448SukJw-1; Thu, 17 Mar 2022 11:03:43 -0400 X-MC-Unique: 1uKE53VaO8eu6i448SukJw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0AF02805A30; Thu, 17 Mar 2022 15:03:42 +0000 (UTC) Received: from [10.22.33.180] (unknown [10.22.33.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 98BEC401E6F; Thu, 17 Mar 2022 15:03:40 +0000 (UTC) Message-ID: <364c72a9-64ca-592a-510b-d48a963121aa@redhat.com> Date: Thu, 17 Mar 2022 11:03:40 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH 2/5] asm-generic: ticket-lock: New generic ticket-based spinlock Content-Language: en-US To: Boqun Feng , Palmer Dabbelt Cc: linux-riscv@lists.infradead.org, peterz@infradead.org, jonas@southpole.se, stefan.kristiansson@saunalahti.fi, shorne@gmail.com, mingo@redhat.com, Will Deacon , Paul Walmsley , Palmer Dabbelt , aou@eecs.berkeley.edu, Arnd Bergmann , jszhang@kernel.org, wangkefeng.wang@huawei.com, openrisc@lists.librecores.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org References: <20220316232600.20419-1-palmer@rivosinc.com> <20220316232600.20419-3-palmer@rivosinc.com> From: Waiman Long In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/17/22 09:57, Boqun Feng wrote: > On Wed, Mar 16, 2022 at 04:25:57PM -0700, Palmer Dabbelt wrote: >> From: Peter Zijlstra >> >> This is a simple, fair spinlock. Specifically it doesn't have all the >> subtle memory model dependencies that qspinlock has, which makes it more >> suitable for simple systems as it is more likely to be correct. >> >> [Palmer: commit text] >> Signed-off-by: Palmer Dabbelt >> >> -- >> >> I have specifically not included Peter's SOB on this, as he sent his >> original patch >> >> without one. >> --- >> include/asm-generic/ticket-lock-types.h | 11 ++++ >> include/asm-generic/ticket-lock.h | 86 +++++++++++++++++++++++++ >> 2 files changed, 97 insertions(+) >> create mode 100644 include/asm-generic/ticket-lock-types.h >> create mode 100644 include/asm-generic/ticket-lock.h >> >> diff --git a/include/asm-generic/ticket-lock-types.h b/include/asm-generic/ticket-lock-types.h >> new file mode 100644 >> index 000000000000..829759aedda8 >> --- /dev/null >> +++ b/include/asm-generic/ticket-lock-types.h >> @@ -0,0 +1,11 @@ >> +/* SPDX-License-Identifier: GPL-2.0 */ >> + >> +#ifndef __ASM_GENERIC_TICKET_LOCK_TYPES_H >> +#define __ASM_GENERIC_TICKET_LOCK_TYPES_H >> + >> +#include >> +typedef atomic_t arch_spinlock_t; >> + >> +#define __ARCH_SPIN_LOCK_UNLOCKED ATOMIC_INIT(0) >> + >> +#endif /* __ASM_GENERIC_TICKET_LOCK_TYPES_H */ >> diff --git a/include/asm-generic/ticket-lock.h b/include/asm-generic/ticket-lock.h >> new file mode 100644 >> index 000000000000..3f0d53e21a37 >> --- /dev/null >> +++ b/include/asm-generic/ticket-lock.h >> @@ -0,0 +1,86 @@ >> +/* SPDX-License-Identifier: GPL-2.0 */ >> + >> +/* >> + * 'Generic' ticket-lock implementation. >> + * >> + * It relies on atomic_fetch_add() having well defined forward progress >> + * guarantees under contention. If your architecture cannot provide this, stick >> + * to a test-and-set lock. >> + * >> + * It also relies on atomic_fetch_add() being safe vs smp_store_release() on a >> + * sub-word of the value. This is generally true for anything LL/SC although >> + * you'd be hard pressed to find anything useful in architecture specifications >> + * about this. If your architecture cannot do this you might be better off with >> + * a test-and-set. >> + * >> + * It further assumes atomic_*_release() + atomic_*_acquire() is RCpc and hence >> + * uses atomic_fetch_add() which is SC to create an RCsc lock. >> + * > Probably it's better to use "fully-ordered" instead of "SC", because our > atomic documents never use "SC" or "Sequential Consisteny" to describe > the semantics, further I'm not sure our "fully-ordered" is equivalent to > SC, better not cause misunderstanding in the future here. The terms RCpc, RCsc comes from academia. I believe we can keep this but add more comment to elaborate what they are and what do they mean for the average kernel engineer. Cheers, Longman