From patchwork Mon Jun 24 19:38:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Andreas K. Huettel" X-Patchwork-Id: 1951722 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W7JFH1xX4z1ydW for ; Tue, 25 Jun 2024 05:39:31 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 943ED384AB61 for ; Mon, 24 Jun 2024 19:39:29 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) by sourceware.org (Postfix) with ESMTP id AE893384AB6C for ; Mon, 24 Jun 2024 19:39:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AE893384AB6C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gentoo.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gentoo.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AE893384AB6C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=140.211.166.183 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719257954; cv=none; b=j12A9QdDXCXeowDkBTxQycBQtrfOuqo6v92TO56HJcWQXF+WDGrmq6173PowqGY30hTXndYjsnWev3rrBnfr/2JmT9jAE9deAOx0A6n1YCXQwueMKBF8t/FpEq9NTFLGhtnKQuXM1LPRtiUXRjdrRwSQcuxZSB726e1H9zv1qS4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719257954; c=relaxed/simple; bh=1LN2XbpqRkdc6lSSIFBOQcQwKGsJKjyvjcwsjiHterw=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=M238hjLAC1eecemdXkg7w+t4tm7QcePcOvxMM6JvTOabIqPonsXHbF9ahJs6HwsWOL0YWEreY1qEOqrN7zpotf2JQZfT7rAMenvO+tdWE0LC1o4HC449uhS+X49fnejBiMIQVPomYebPKinvWGinlbra5UpAVBOGdFAoXcg6ECc= ARC-Authentication-Results: i=1; server2.sourceware.org From: =?utf-8?q?Andreas_K=2E_H=C3=BCttel?= To: libc-alpha@sourceware.org Cc: =?utf-8?q?Christoph_M=C3=BCllner?= , Palmer Dabbelt Subject: [COMMITTED] RISC-V: Execute a PAUSE hint in spin loops Date: Mon, 24 Jun 2024 21:38:39 +0200 Message-ID: <20240624193902.22596-1-dilfridge@gentoo.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org From: Christoph Müllner The atomic_spin_nop() macro can be used to run arch-specific code in the body of a spin loop to potentially improve efficiency. RISC-V's Zihintpause extension includes a PAUSE instruction for this use-case, which is encoded as a HINT, which means that it behaves like a NOP on systems that don't implement Zihintpause. Binutils supports Zihintpause since 2.36, so this patch uses the ".insn" directive to keep the code compatible with older toolchains. Signed-off-by: Christoph Müllner Reviewed-by: Palmer Dabbelt Acked-by: Palmer Dabbelt --- sysdeps/unix/sysv/linux/riscv/atomic-machine.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sysdeps/unix/sysv/linux/riscv/atomic-machine.h b/sysdeps/unix/sysv/linux/riscv/atomic-machine.h index c1c9d949a0..90283d9746 100644 --- a/sysdeps/unix/sysv/linux/riscv/atomic-machine.h +++ b/sysdeps/unix/sysv/linux/riscv/atomic-machine.h @@ -178,4 +178,7 @@ # error "ISAs that do not subsume the A extension are not supported" #endif /* !__riscv_atomic */ +/* Execute a PAUSE hint when spinning. */ +#define atomic_spin_nop() __asm(".insn i 0x0f, 0, x0, x0, 0x010") + #endif /* bits/atomic.h */