Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp1081857lqh; Sun, 5 May 2024 15:46:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW5jxXxvWOgttqueLq3qeSGACiWBKIWDMyvjDvoLXoJ+aZwESnX43B+6l9iW3E9FjCIHkp9y0OGoiPmqDbab6YgyD9aVGVId1BXsB03Xw== X-Google-Smtp-Source: AGHT+IEaUnMkSw/qN0vXYXtDBBkk+WnJ68zgYweHD/8wh1f3NjuwbK694rL9ZzmJEmm71SwiEWgL X-Received: by 2002:a05:6871:813:b0:22e:8868:af8a with SMTP id q19-20020a056871081300b0022e8868af8amr10402279oap.31.1714949173093; Sun, 05 May 2024 15:46:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714949173; cv=pass; d=google.com; s=arc-20160816; b=vRMXbaVipjLbqHN/jBL5+0dhT+b30IkHn+HiZ/wcaBXfAHr4NGR++UM4ELLpZ+e5lC 0/HnaAipKuQKwdjr3WPM3LcmWcDufh/vSrT+P2sresratVFcurWLCx7fmFv1pUXVUxrF EbZpKx5FiA4xoErdXYEaeFWSZzAR8g+witAwi6naAwgHHyTMf4OM1g0c+suMRrtF1Lyj bOZepSdBTrRyl0SF5AmW5tvaiGBzvxRs/gPy3sA7cpOD6VKhw1GSRkvnRT/5aAKpJgq6 YThFCciAx5IjCb/p6JACEAnqgZ6mAzpXkGBiw5rS9N/iZVtY6LhSpzWjl614ondCU3AS 6JzA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=er8OR4CkvYPSBm1vxvC1YRmn3HecSea62NIpaFm00EE=; fh=LQeaBfR8iomaLUZJ4Kv1ADbKnMm+VEPo/UzI649f/AA=; b=zxh7FA3uhxeLUsFE7dkqReahkhAJtmHK3ze0BqUIVNuTs25FfruOCYLitzG2IsDZxL /ViVW5xGTf7SA1F0CaFvC/ZKEjTAIUk9RvE5WaUowZpMY5L3hCbWUgUWVwwLmEvaHBGw E40hOC2qC2yKYCg0ta8nKeTY28+k7dcgG4o7sZ/VlZFkpLqxWu+TEiCLj4T8G0pHfgNm 67+QnEc0jHLNyZBfsAkV6T5ByvUpDfhR49XM14CScN19oWpjsEqiS7EVuc71wwX3KOoC Ib/Sq1W3LDtavd0JOSWo1fzVxF9Tc6ryzO5+jUueXSPOfC+N1jfW04Oq+cPni9cmq/kL hyoA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hvADrHwT; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-169191-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169191-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 26-20020a63175a000000b0061af77aaff4si6940757pgx.405.2024.05.05.15.46.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 May 2024 15:46:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-169191-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hvADrHwT; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-169191-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169191-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id B7AE428163C for ; Sun, 5 May 2024 22:46:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D122913FD8D; Sun, 5 May 2024 22:46:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hvADrHwT" Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (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 770FC26AC5 for ; Sun, 5 May 2024 22:46:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714949167; cv=none; b=BOUNdvgLYwf+G7UymYCk8S9zyO+a0V6WKmCNZMfwK7slipihlODpnMAHpp1jQvsk5fWMYDo2mFjUhhgKCrm/ue2+h5NQRrl6jw35GZIknlm0XAzCSnYAUQhTK/NPIh5ls3oJeQXl5hYjsa/D6P3DYzJ2MiPmLySeSA0SfSz5wxk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714949167; c=relaxed/simple; bh=zhlB7Fq0o6YOVJ07sy+Af1SHLPehmXkTm9uPn2j7VSc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HVzrE52dnpQ6t9iJsYjSgnPexCvAmyw9GIYagv3ZgbP/qbTB8ERFssocQIPPCtzk8HFTNvfQT3a81SLDNAEnHPaGRFZhI26+H71ICFfgRba0RwYAcMLkrizcaxIr4bQbjiANtTImuXKTVW0vpeK6MPNovBmPzZ9MIDbM9V6qjHA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hvADrHwT; arc=none smtp.client-ip=209.85.218.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a59cc765c29so89830266b.3 for ; Sun, 05 May 2024 15:46:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714949164; x=1715553964; darn=vger.kernel.org; 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=er8OR4CkvYPSBm1vxvC1YRmn3HecSea62NIpaFm00EE=; b=hvADrHwTRimcIzPCf5DSLKPwasf7lyK9iA8G15r9kyTHhOlZgrHAhFz66x1CGuTROC vs3jPXTSnHQKkGZ7BtIYILHQoB/fErs2sShzCpGtO7SbPch5GX35RvyfwvNwR3Vy33xg OHlOy3F+meAe6wx2/JVZBetc3bnJE6aVye8mYY+wdmMXpacwtjPLbVjerNTrRYzfqfpi KAbCl5NZRO5th1PJpRmNLjHQiI9mITrPDxsn/BZE5DqYGnixAG/nEOEP5fy/JWE578Wo fif6yBxWxPlzbTI0UqSbWK5vRbw3yPbtzxnF9Csvg8Xb0oQtLJxeTBrRTGHSoQVo/rbZ mUqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714949164; x=1715553964; 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=er8OR4CkvYPSBm1vxvC1YRmn3HecSea62NIpaFm00EE=; b=EZeDPNTiF0mKB5W8T0G7e6f8nEDQRo18pX5pJcT2nXjuvc+J8FDwUoEgYe46NFBR7M 0dJs5OZgDLL0ra7KEtQ3sMUzB5/vSzpeI+Sv6ficqfaEpNBetBNZLDKXJMObz5ncNPUm DM4DOwPjUGYh9r50N3kZqRv1bfCNqIyeogpIG+m/XBP1MsYQ0xbmrzeCBEmAZuFRAKYb VKUxQZlew/gn66EFMge/ltVVAPm5okj3NsnThOderk7DdjA4wWt9/n55bwfzzNbveOVY peiJTdva64/FWZAoao9eAWzf9oqY2lZmAJn01xzea/A/oVD0HUFyI5fCNEcFk0mplU4S K0YA== X-Forwarded-Encrypted: i=1; AJvYcCV6I0IoibX4sT6MlcUO/1xy4bxvwJ6RTIgzM944BHdruENbKNF/vnGPpIZBO9KFnnY/4t6z8tP80Mjs84JoVX/2oZ+MEP7UgjJ8yEha X-Gm-Message-State: AOJu0YyRt4R26+SFMwGKXdhvUXc0vbrajaEdr1VWjoaN9XrmFMOoNbGb rdYDaprfys9sCVOR4BgMfYWTH96Y8dGhbZZ3wpzqGX+4h9AGmCYJ X-Received: by 2002:a17:906:b806:b0:a59:ba18:2fb2 with SMTP id dv6-20020a170906b80600b00a59ba182fb2mr2137235ejb.35.1714949163495; Sun, 05 May 2024 15:46:03 -0700 (PDT) Received: from andrea ([31.189.114.81]) by smtp.gmail.com with ESMTPSA id a25-20020a1709064a5900b00a59a9949ec9sm2188379ejv.118.2024.05.05.15.46.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 May 2024 15:46:02 -0700 (PDT) Date: Mon, 6 May 2024 00:45:58 +0200 From: Andrea Parri To: Puranjay Mohan Cc: Will Deacon , Peter Zijlstra , Boqun Feng , Mark Rutland , Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, puranjay12@gmail.com Subject: Re: [PATCH] riscv/atomic.h: optimize ops with acquire/release ordering Message-ID: References: <20240505123340.38495-1-puranjay@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240505123340.38495-1-puranjay@kernel.org> Hi Puranjay, On Sun, May 05, 2024 at 12:33:40PM +0000, Puranjay Mohan wrote: > Currently, atomic ops with acquire or release ordering are implemented > as atomic ops with relaxed ordering followed by or preceded by an > acquire fence or a release fence. > > Section 8.1 of the "The RISC-V Instruction Set Manual Volume I: > Unprivileged ISA", titled, "Specifying Ordering of Atomic Instructions" > says: > > | To provide more efficient support for release consistency [5], each > | atomic instruction has two bits, aq and rl, used to specify additional > | memory ordering constraints as viewed by other RISC-V harts. > > and > > | If only the aq bit is set, the atomic memory operation is treated as > | an acquire access. > | If only the rl bit is set, the atomic memory operation is treated as a > | release access. > > So, rather than using two instructions (relaxed atomic op + fence), use > a single atomic op instruction with acquire/release ordering. > > Example program: > > atomic_t cnt = ATOMIC_INIT(0); > atomic_fetch_add_acquire(1, &cnt); > atomic_fetch_add_release(1, &cnt); > > Before: > > amoadd.w a4,a5,(a4) // Atomic add with relaxed ordering > fence r,rw // Fence to force Acquire ordering > > fence rw,w // Fence to force Release ordering > amoadd.w a4,a5,(a4) // Atomic add with relaxed ordering > > After: > > amoadd.w.aq a4,a5,(a4) // Atomic add with Acquire ordering > > amoadd.w.rl a4,a5,(a4) // Atomic add with Release ordering > > Signed-off-by: Puranjay Mohan Your changes are effectively partially reverting: 5ce6c1f3535fa ("riscv/atomic: Strengthen implementations with fences") Can you please provide (and possibly include in the changelog of v2) a more thoughtful explanation for the correctness of such revert? (Anticipating a somewhat non-trivial analysis...) Have you tried your changes on some actual hardware? How did they perform? Anything worth mentioning (besides the mere instruction count)? Andrea