Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp741998rdg; Thu, 10 Aug 2023 19:41:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGzf9C2n3RE+Wsp8kM4HNRCCKFKB8jXZ4NY7tmzTXomn/GnFtnP62mGFIOIcC+R9FzPjhuv X-Received: by 2002:a17:906:1041:b0:99c:ae35:8cd with SMTP id j1-20020a170906104100b0099cae3508cdmr618963ejj.43.1691721690971; Thu, 10 Aug 2023 19:41:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691721690; cv=none; d=google.com; s=arc-20160816; b=oxiKC+qCHrcm+Vrmc3+OIvyZNXWTx94hRUj3mpUgbGPn76U6dj4cPLG3cgUZ+mRxjx FpYr7N1OBCF7FoZwGTlvBDjUA1uT1XDKZfxrSlGQ0I2CVEhXJRgDOeRW6nU3CHcEdx0V rCWEVTg24ln1U0LcXBcK4cDQfYr22vBz6LlotFt4vyEIJhPV41G+caZv5/mnKUG4KhNu kunIskYmm+C19eBOBwMbx7II7h9mVIORS7gU9HbEgoH9alX7Y0wcc8lhmJuGhknsNnHr VCOiLjNx3mx95aYR1srwu2fnssbJVNUb3oms2iKACfM43eL8GvnXJBFUjNOl60YrVPkd EaZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=U3F3Tgvy0np7hXBBF63s7EBQ8MawxaZQokowbNBHvtk=; fh=TDJI7fP5m4O7MSHiW70GtfN9i9Rz8AVUiTOJcpN7XGY=; b=UXxqs132XcFppUTAlVlAsbanWce1/FGbbkaPYaWtrU8Hv4sXf9xKvkf7FTPKVSLCUG Lsgy92grNH8lf1yy0eZgQdnusVWtCOUS+2PBCZQBLqQoHgCYWoGsIiCObbvTO/SgO8ic ZtzCCKmE1JZGPsdhIlPC1PT8/eJNKQ1GDwPmItQqZXxiwcMDmETYlCrXoIlzxKIybpTe XphU1dQoGgsB4eBHMitgue8/atSYHDdmEYuZklqV/4UK9M7MJUktVVIqs2PZpXZj+58h +socsT3qrpxHuVbg+2T85vhRDyAeHWN+pXlOf4zPMhZnpXco87Ld61+un0X9r5ZmdXDd 161g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ukFP0lPs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f15-20020a170906390f00b0099bc0530efesi2576428eje.453.2023.08.10.19.41.06; Thu, 10 Aug 2023 19:41:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ukFP0lPs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230522AbjHKBkr (ORCPT + 99 others); Thu, 10 Aug 2023 21:40:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229629AbjHKBkq (ORCPT ); Thu, 10 Aug 2023 21:40:46 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8240610D for ; Thu, 10 Aug 2023 18:40:44 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0A5A964A7C for ; Fri, 11 Aug 2023 01:40:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66B65C433C9 for ; Fri, 11 Aug 2023 01:40:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691718043; bh=NJ6p09CbSTr2E2bfl8mxk76nHLwPDnBOE4E31aqoHXc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=ukFP0lPswQW0z8jubmdg1L91dnwv+lqMVFrJFlRmabf/tqe2ZBS+pLaf+7B7okCq7 pLwvSbAmZWAlGO2kO8z8mwmRPq/DSnbc0EAvmbAwSMH51EgN5kb1tfvb2yuqRbZUOG /UxbwuUYqTuHa4gbx/hGYih1MsjDrGgLqyHC3eBsfiv7b3b14438RqKaEFwOhdBnq3 Fdk3dFTPxHINvEoHRV/X12odiNOe0Q63KzqnbcT0C7bhl26agNYwzIDlThBSZbqO2l ZJyTsFwfXxKGnGoDm74tr86kho75GePW262Gn1lJgghk8VuB0O6sPLRpjTQeznP4QG rjkThKeE/9C8g== Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-523225dd110so1954287a12.0 for ; Thu, 10 Aug 2023 18:40:43 -0700 (PDT) X-Gm-Message-State: AOJu0YzADc+Y6824G+5nXFKmhx8XQr2aZyIZTG3MvDQZF7riB4M5ze+O wA16mmwqJlUuwaCrqHmTtNsoYxyot9Y/TgMvadA= X-Received: by 2002:aa7:c30f:0:b0:523:6c47:56f8 with SMTP id l15-20020aa7c30f000000b005236c4756f8mr590466edq.18.1691718041693; Thu, 10 Aug 2023 18:40:41 -0700 (PDT) MIME-Version: 1.0 References: <98f523e515b2adc2aa7bb8d133353bad74e30897.camel@redhat.com> In-Reply-To: From: Guo Ren Date: Fri, 11 Aug 2023 09:40:30 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH v5 5/5] riscv/cmpxchg: Implement xchg for variables of size 1 and 2 To: Palmer Dabbelt Cc: leobras@redhat.com, Arnd Bergmann , Will Deacon , peterz@infradead.org, boqun.feng@gmail.com, Mark Rutland , Paul Walmsley , aou@eecs.berkeley.edu, parri.andrea@gmail.com, andrzej.hajda@intel.com, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 Fri, Aug 11, 2023 at 12:23=E2=80=AFAM Palmer Dabbelt wrote: > > On Thu, 10 Aug 2023 09:04:04 PDT (-0700), leobras@redhat.com wrote: > > On Thu, 2023-08-10 at 08:51 +0200, Arnd Bergmann wrote: > >> On Thu, Aug 10, 2023, at 06:03, Leonardo Bras wrote: > >> > xchg for variables of size 1-byte and 2-bytes is not yet available f= or > >> > riscv, even though its present in other architectures such as arm64 = and > >> > x86. This could lead to not being able to implement some locking mec= hanisms > >> > or requiring some rework to make it work properly. > >> > > >> > Implement 1-byte and 2-bytes xchg in order to achieve parity with ot= her > >> > architectures. > >> > > >> > Signed-off-by: Leonardo Bras > >> > > > > Hello Arnd Bergmann, thanks for reviewing! > > > >> Parity with other architectures by itself is not a reason to do this, > >> in particular the other architectures you listed have the instructions > >> in hardware while riscv does not. > > > > Sure, I understand RISC-V don't have native support for xchg on variabl= es of > > size < 4B. My argument is that it's nice to have even an emulated versi= on for > > this in case any future mechanism wants to use it. > > > > Not having it may mean we won't be able to enable given mechanism in RI= SC-V. > > IIUC the ask is to have a user within the kernel for these functions. > That's the general thing to do, and last time this came up there was no > in-kernel use of it -- the qspinlock stuff would, but we haven't enabled > it yet because we're worried about the performance/fairness stuff that > other ports have seen and nobody's got concrete benchmarks yet (though > there's another patch set out that I haven't had time to look through, > so that may have changed). Conor doesn't agree with using an alternative as a detour mechanism between qspinlock & ticket lock. So I'm preparing V11 with static_key (jump_label) style. Next version, I would separate paravirt_qspinlock & CNA_qspinlock from V10. That would make it easy to review the qspinlock patch series. You can review the next version V11. Now I'm debugging a static_key init problem when load_modules, which is triggered by our combo_qspinlock. The qspinlock is being tested on the riscv platform [1] with 128 cores with 8 NUMA nodes, next, I would update the comparison results of qspinlock & ticket lock. [1]: https://www.sophon.ai/ > > So if something uses these I'm happy to go look closer. > > >> Emulating the small xchg() through cmpxchg() is particularly tricky > >> since it's easy to run into a case where this does not guarantee > >> forward progress. > >> > > > > Didn't get this part: > > By "emulating small xchg() through cmpxchg()", did you mean like emulat= ing an > > xchg (usually 1 instruction) with lr & sc (same used in cmpxchg) ? > > > > If so, yeah, it's a fair point: in some extreme case we could have mult= iple > > threads accessing given cacheline and have sc always failing. On the ot= her hand, > > there are 2 arguments on that: > > > > 1 - Other architectures, (such as powerpc, arm and arm64 without LSE at= omics) > > also seem to rely in this mechanism for every xchg size. Another archs = like csky > > and loongarch use asm that look like mine to handle size < 4B xchg. > > > > > >> This is also something that almost no architecture > >> specific code relies on (generic qspinlock being a notable exception). > >> > > > > 2 - As you mentioned, there should be very little code that will actual= ly make > > use of xchg for vars < 4B, so it should be safe to assume its fine to n= ot > > guarantee forward progress for those rare usages (like some of above me= ntioned > > archs). > > > >> I would recommend just dropping this patch from the series, at least > >> until there is a need for it. > > > > While I agree this is a valid point, I believe its more interesting to = have it > > implemented if any future mechanism wants to make use of this. > > > > > > Thanks! > > Leo --=20 Best Regards Guo Ren