From mboxrd@z Thu Jan 1 00:00:00 1970 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 B84FFC77B73 for ; Tue, 30 May 2023 18:45:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231635AbjE3Spp (ORCPT ); Tue, 30 May 2023 14:45:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229971AbjE3Spg (ORCPT ); Tue, 30 May 2023 14:45:36 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E36F9C9 for ; Tue, 30 May 2023 11:45:35 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-51478f6106cso7901068a12.1 for ; Tue, 30 May 2023 11:45:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685472334; x=1688064334; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=uToXJ+fOWkpnn5Y/56EQgrrTUY3apSu6OqRigzUlyIc=; b=Bx1VXp1lL1lr/7Wg4nAZ/8axfexaAsOa5wdsT0oRkjQoSAlr/s2ZxkRzDYWGF5JzY0 jgZC646MNyQRsm7TAkynXNGDr7V04SO4B0NwGP2V3vPF1vhSesCmL3/mEnMJTQw3Ujdk /REcVYg+ph1BCux4hWvJFck0XFyK9F2a2yr9unJoLygRbFoT3c9bguF4D/hDysaxF7a5 7kNhXL6FfSL6x15DosMBfLRZsS3njv/j7lchGd540xy5yJok7PXaQyS5sEBQIRWD5MK2 V7/uC3cHqK8r1oRZSTuGH4dZ/3a5iq+VEkvHfuxPigsc9H3qbtoz84wxK5yO/myq+lQN Bcog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685472334; x=1688064334; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=uToXJ+fOWkpnn5Y/56EQgrrTUY3apSu6OqRigzUlyIc=; b=hIb3hkI6C9NVknNDki6zTqvoE66fM4RUL6Ev7+V8JYVaMH5d4wn9mgBVdowApVu+xu br98Ul90QY324KYMOjY5HaQboi2RtuVxfcBvTQFAIsyGELEBFZ9dc/SJ2SWjJazJ5D7/ bvMachqzmpr/OvpfuKKcO1FFo/p6L//kRq8GgjVfYemqq6h0QpL+mY13AVJ3yGvqJV8Y KvR55aJaerTPRpdy5jRRk6fHc6sGh7wdY9NhHxjnLJHrTEOF/LUbQSuB+h+vtvxPOa/S 4i76VpJafkM8sfE7Un3FKGrmG8HKV2hQbr6YumxpiunyNdGYrvtJJrkSkcJxAexyem8/ cSdw== X-Gm-Message-State: AC+VfDzNUzPgOfyho6ryRVjhbwbFaOu/rMY9qYDiw4kLAoRuRluNfCkM UDpljPtkrTraqs3DP8z5oYYH9QeJGvXkeQ== X-Google-Smtp-Source: ACHHUZ7iBBEKE+toubaVfH5MLKrEnuzzySKWPjZ7fHNs67mYDXW5fh0fbYrECQwxAPCIA3fJeHK3YA== X-Received: by 2002:a17:907:9609:b0:947:335f:5a0d with SMTP id gb9-20020a170907960900b00947335f5a0dmr3678436ejc.62.1685472334056; Tue, 30 May 2023 11:45:34 -0700 (PDT) Received: from andrea (host-95-247-65-76.retail.telecomitalia.it. [95.247.65.76]) by smtp.gmail.com with ESMTPSA id f6-20020a1709064dc600b0094f4d2d81d9sm7726268ejw.94.2023.05.30.11.45.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 11:45:33 -0700 (PDT) Date: Tue, 30 May 2023 20:45:28 +0200 From: Andrea Parri To: Palmer Dabbelt Cc: ajones@ventanamicro.com, heiko@sntech.de, linux-riscv@lists.infradead.org, Paul Walmsley , linux-kernel@vger.kernel.org, christoph.muellner@vrull.eu, David.Laight@aculab.com, heiko.stuebner@vrull.eu Subject: Re: [PATCH v3 2/2] riscv: Add Zawrs support for spinlocks Message-ID: References: <20230524-35efcabbbfd6a1ef83865fb4@orel> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 24, 2023 at 04:00:43PM -0700, Palmer Dabbelt wrote: > On Wed, 24 May 2023 10:05:52 PDT (-0700), ajones@ventanamicro.com wrote: > > I guess this peeling off of the first iteration is because it's expected > > that the load generated by READ_ONCE() is more efficient than lr.w/d? If > > we're worried about unnecessary use of lr.w/d, then shouldn't we look > > for a solution that doesn't issue those instructions when we don't have > > the Zawrs extension? > > It's actually just a consequence of how the Linux hooks are described: > they're macros that take a C expression to test in the loop, and we can't > handle C expressions in LR/SC loops as that'd require compiler support and > nobody's figured out how to do that correctly yet (there were some patches, > but they had issues). So we need to do this awkward bit of checking without > the reservation and then waiting with the reservation. I believe Andrew was really just hinting to something like (from arch/arm64/): #define smp_cond_load_relaxed(ptr, cond_expr) \ ({ \ typeof(ptr) __PTR = (ptr); \ __unqual_scalar_typeof(*ptr) VAL; \ for (;;) { \ VAL = READ_ONCE(*__PTR); \ if (cond_expr) \ break; \ __cmpwait_relaxed(__PTR, VAL); \ } \ (typeof(*ptr))VAL; \ }) where the __cmpwait_relaxed() would issue NOPs without Zawrs, a sequence "lr.* ; beq ; wrs.sto" otherwise. (with the "dangling reservation" when we branch, similarly to CMPXCHG)? Andrea