From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by sourceware.org (Postfix) with ESMTPS id B1C0C3858D33 for ; Fri, 19 Apr 2024 01:03:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B1C0C3858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=dabbelt.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=dabbelt.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B1C0C3858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::629 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713488595; cv=none; b=xlQKc9yWn1Yy94wtGd4TkNEPaEO1G5vEq5jyKqmejtXI23HHClL7TwNA+7hXE2cx1jttWzAm+6PUQ8bBYrcnSUFss6um4iJGOq9Q5jmV9lmEimpGl0TVZ1yVAgCSd16eK8h+EbBF7S9NfqRz7ngXtWR0vfG9QaHv79eqAwCRU3c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713488595; c=relaxed/simple; bh=UIp8Cy1/u7v47QIDiilJHmH3cnG69jMCXVLfx6kcY1Y=; h=DKIM-Signature:Date:Subject:From:To:Message-ID:Mime-Version; b=wEQiEt9g/jR4Ihmygac3lzNsWlRvO7X03rv7IvCgjhvHEhngB9nVhdNO48Uay/EWJP/TPU2QOaeZM4+BE+JgWZpZ8yHgV5kLvM+uueno93xVjbYuWKvBZirFVMDjmdF1qOf6ord/0C9cyG9x4N+1uqk7MPeXQVbyCmEqybKphIg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1e83a2a4f2cso9215755ad.1 for ; Thu, 18 Apr 2024 18:03:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20230601.gappssmtp.com; s=20230601; t=1713488583; x=1714093383; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:to:from:cc :in-reply-to:subject:date:from:to:cc:subject:date:message-id :reply-to; bh=OBFlSDWWtdQR7F1HN8JEJJWo/IvFCbvZrh4HL3PyWUg=; b=ooSOUW8w/vrBjb4qsivn0gEHJtf1fvHGkDj4Sus4VoydqOA+8Ms8AFG7lOeUchwF0C 0wYRcAS0Z/4HnbCZHzIvkPr40NCZy/7y3ZOokuz63jnDSVaYyukQG7Q+FRKpI0BBU5+B DNJKJtD6WQfyVWwmDjO/3ujlKWONKmMOnj5en2dyNOS9C6QWfW6ZNedxuYgAB+4IKLrk ErdT6N6aZ+ZaetD7GON2uAnD/ETeWRiytK4MO1Z18fWehO37G+7+bPpkRw53Vg04UD8I 89PngsD8PEjUkfh5kbdNfkG4evf7Gn6BW87/rdaBUfxmTCNhlh1fBv9jMtqVyDHyFFE/ APAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713488583; x=1714093383; h=content-transfer-encoding:mime-version:message-id:to:from:cc :in-reply-to:subject:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=OBFlSDWWtdQR7F1HN8JEJJWo/IvFCbvZrh4HL3PyWUg=; b=gI8y0aGEAmc6F5Ht/IbkwAlLIplITCODHbAwEYIwORRnhnpclNutkw0A5frkvxVW+s nGycNQgSa+zBWSHpg+VT6W5o98kIbPYzx0e86PEYAwX9i4KLHB8h8s0G3dPAW48pkBm9 4JHM6tk7Q8Qkfgf6LiTvIUwseqfA81DeVFH9cFQsWo8SiPKtBcCNqR8sOKok+/iMVDg0 OFsY2ll+Ho2HuRg8mGWWh/XdHs1wcxb0OzfUYyvfWbUEeBjSUBCfKGyAIK9zYZIkU+4n B+JjVGIZDM6U0O7gX1o9HIqg0iODrhRoPS/RV4bNOlYIRf5V2cpwCp3sCV0WlWYCoMat KJ5A== X-Gm-Message-State: AOJu0Yzmr93mgvQa/ggfD1wMEQcJm22yyhV6J//OmM2r20DklCRgSy8o zORcEWf6ImBE2idwYCfdUAzmluCsV8pjArBkv4AFZ+rwEZS8eABjrexRAlzfULhaI7w/k7vrJya 9 X-Google-Smtp-Source: AGHT+IEWo4MF9eIw6S0KfnDcjkkPodtQ+ELP3ZAiAqhpBlryWdFxB6ReP8tTVyfjfoUdZT02QTP8Qw== X-Received: by 2002:a17:902:f803:b0:1e7:b7ea:2d61 with SMTP id ix3-20020a170902f80300b001e7b7ea2d61mr633176plb.37.1713488582892; Thu, 18 Apr 2024 18:03:02 -0700 (PDT) Received: from localhost ([50.145.13.30]) by smtp.gmail.com with ESMTPSA id mp6-20020a170902fd0600b001e256cb48f7sm2149804plb.197.2024.04.18.18.03.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 18:03:02 -0700 (PDT) Date: Thu, 18 Apr 2024 18:03:02 -0700 (PDT) X-Google-Original-Date: Thu, 18 Apr 2024 18:03:00 PDT (-0700) Subject: Re: [PATCH] RISC-V: Execute a PAUSE hint in spin loops In-Reply-To: <20240418215858.4151969-1-christoph.muellner@vrull.eu> CC: libc-alpha@sourceware.org, adhemerval.zanella@linaro.org, Darius Rad , Andrew Waterman , philipp.tomsich@vrull.eu, Evan Green , kito.cheng@sifive.com, jeffreyalaw@gmail.com, Vineet Gupta , christoph.muellner@vrull.eu From: Palmer Dabbelt To: christoph.muellner@vrull.eu Message-ID: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,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 List-Id: On Thu, 18 Apr 2024 14:58:58 PDT (-0700), christoph.muellner@vrull.eu wrote: > 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 > --- > 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 */ I think this one should be pretty non-controversial: the whole point of PAUSE is for this sort of spin loop, so I don't think we need any benchmarks to justify using it. So Reviewed-by: Palmer Dabbelt Acked-by: Palmer Dabbelt IIRC there's some tunables for spin counts already, so hopefully that's enough to cover us for now. I guess we'll found out when people have hardware... Thanks!