From patchwork Mon Jul 29 20:50:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13745784 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 54A30C3DA4A for ; Mon, 29 Jul 2024 20:50:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=SVdIcRdjCyXnJ40fuiniZUWyWC9T4B2CMiCr+IgV+Ho=; b=y8FTqWqTiIvm/N ElRcyQe4BjtSacDZMWdj5GpoMP+1YG7rU/BQ4Q4bnZVNHomfoitlENF6bn9OND8BdX3GY9I+knFkk KGhAdvNjkTs2Be4j0rX8u8bK9RJq57FUYcKiTHTHK+PehUArcDiYKmEMoZ4gYB/8208edzVHEbYe+ 8lb1vaO2GxblL1sYMmxLE23sDur72iZuht5cAY1yaByubdc1N4L/CuOSV1zajOELyyj45r/IOR1KW qs/+0YDATZjpBTNwKe3djf+ioRZqYJ9wlwYtK2ULl3ztnJOgm4xgzuYrdkf/IsgtV+8CF1gUT1f8O VK7eZJlO1E5ft01zaCpQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYXKT-0000000ChRU-2ON5; Mon, 29 Jul 2024 20:50:49 +0000 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYXKP-0000000ChQM-1NQS for linux-riscv@lists.infradead.org; Mon, 29 Jul 2024 20:50:46 +0000 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-70d2d7e692eso2915378b3a.0 for ; Mon, 29 Jul 2024 13:50:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1722286243; x=1722891043; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=DjuJiVps1krVsumKp/stss3kNN6dUsP3Lcn41G8nO8w=; b=XrEs8Sg2o/Sx7KCsYAK2rHH/TCah9wliIHL3l1sJm5/agXT9nk6jM5prH/jD+Pvnpj 8oyWZJMOOp/fSl8vVPFCu1zzqhGFIi4Dr0KpJU1bZ9QC/+VNAFIKEi2GROgAKDluLMXv M1zQxaep+ew3t5NMeeR/UseHE7ljYhXnFNP4gTocWVNjZO/Zy4vyS+AhRToNo6qjdEa1 USgcWOWEAs2LsOcQvcmieUcXtqveJa9mls6O4qbl7mHI+nc72VVSPSoxwe9sXSwcrh/o YcvR7az5BbzM+XKmEuSZbM4dU1mmBQgnlkYnvx2yDTFKQiN47G0LoNOPq4w1ILX1lZLC bE8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722286243; x=1722891043; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DjuJiVps1krVsumKp/stss3kNN6dUsP3Lcn41G8nO8w=; b=FXnOP58MI7+S4Zx9dFRLuG+gZ/68PBvdm6F8oYENswxZYniunW63wNSggeRiVXC874 KpJRavoZH5A/S+ipsWy+8DBJ+BH9JNDk84YHdCqTK0CoVj7eLsVtJyQ3w28y5U4awRG4 7N2EppTSr5rIzi8t+1EH4NHwez5ulB6AEfkO/SoQy3TyH4NS71dSLFFJxpTpC/iUSZ9L vN8QoH23z8wslqg9VcIWt1Cquu+C6rkcLPHyh5HjmZdBfO6FejAjKk1oCiGPKsM3/qRx 04vj2qwl9fgdPGHKQVT1Lx7KPeh6A3Mzh+P1Aza1hALGTAvMBDoxBp728GuL/hIIQIRp UeHQ== X-Forwarded-Encrypted: i=1; AJvYcCWR1W5G86OYd9PZ/HuhplSP+ibW48heQDiAWEwSHEwu0nivylADu6fPhGWrCGCpiyg9iahOxqHtGew4zWPDCovQWY1t8z1kRd+VLM6w2rC1 X-Gm-Message-State: AOJu0YyCooMltXfcVpQdfaWyu1sq1DaXo/QCgCADaKDsdTMdxCFOxty7 CBi7Az65xTAgk6LSZXPjpqxLmq8UpspcczIzs7uX6okgR+PFZuP0ZiwrR6Wb8OsGMAkRRkW3qVO d X-Google-Smtp-Source: AGHT+IEpqSsl++rfk1+CEHWhr8c9oyUyyL6jaX25l669XC3xLwKl86BtTsjs3IN8jI5Bla88QbQ4DA== X-Received: by 2002:a05:6a00:1826:b0:70e:8f30:23e5 with SMTP id d2e1a72fcca58-70ece9fadd2mr7742896b3a.1.1722286243357; Mon, 29 Jul 2024 13:50:43 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70ead72ba2csm7454541b3a.93.2024.07.29.13.50.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 13:50:42 -0700 (PDT) From: Charlie Jenkins Date: Mon, 29 Jul 2024 13:50:35 -0700 Subject: [PATCH 1/2] tools: Add riscv barrier implementation MIME-Version: 1.0 Message-Id: <20240729-optimize_ring_buffer_read_riscv-v1-1-6bbc0f2434ee@rivosinc.com> References: <20240729-optimize_ring_buffer_read_riscv-v1-0-6bbc0f2434ee@rivosinc.com> In-Reply-To: <20240729-optimize_ring_buffer_read_riscv-v1-0-6bbc0f2434ee@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Andrea Parri Cc: linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1722286240; l=2916; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=QKbLeMMF7mDpLciQBgmaXsS7vFL+LO6R6LtddSUAdz0=; b=DmS39ks98S5E4C7fyFQXUee4PXBbUbkym1O5X/y/kETBBNioDUh0xCScGEAxSYNTxY88MmkcI 65hWlx6D9yrBKizG7yXcAyOKvEOsqOzs6Z0GU7bH+EeCeyfTRmJAsHQ X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240729_135045_404345_BBB447F3 X-CRM114-Status: GOOD ( 12.45 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Many of the other architectures use their custom barrier implmentations. Use the barrier code from the kernel sources to optimize barriers in tools. Signed-off-by: Charlie Jenkins --- tools/arch/riscv/include/asm/barrier.h | 39 ++++++++++++++++++++++++++++++++++ tools/arch/riscv/include/asm/fence.h | 13 ++++++++++++ tools/include/asm/barrier.h | 2 ++ 3 files changed, 54 insertions(+) diff --git a/tools/arch/riscv/include/asm/barrier.h b/tools/arch/riscv/include/asm/barrier.h new file mode 100644 index 000000000000..6997f197086d --- /dev/null +++ b/tools/arch/riscv/include/asm/barrier.h @@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copied from the kernel sources to tools/arch/riscv: + * + * Copyright (C) 2012 ARM Ltd. + * Copyright (C) 2013 Regents of the University of California + * Copyright (C) 2017 SiFive + */ + +#ifndef _TOOLS_LINUX_ASM_RISCV_BARRIER_H +#define _TOOLS_LINUX_ASM_RISCV_BARRIER_H + +#include +#include + +/* These barriers need to enforce ordering on both devices and memory. */ +#define mb() RISCV_FENCE(iorw, iorw) +#define rmb() RISCV_FENCE(ir, ir) +#define wmb() RISCV_FENCE(ow, ow) + +/* These barriers do not need to enforce ordering on devices, just memory. */ +#define smp_mb() RISCV_FENCE(rw, rw) +#define smp_rmb() RISCV_FENCE(r, r) +#define smp_wmb() RISCV_FENCE(w, w) + +#define smp_store_release(p, v) \ +do { \ + RISCV_FENCE(rw, w); \ + WRITE_ONCE(*p, v); \ +} while (0) + +#define smp_load_acquire(p) \ +({ \ + typeof(*p) ___p1 = READ_ONCE(*p); \ + RISCV_FENCE(r, rw); \ + ___p1; \ +}) + +#endif /* _TOOLS_LINUX_ASM_RISCV_BARRIER_H */ diff --git a/tools/arch/riscv/include/asm/fence.h b/tools/arch/riscv/include/asm/fence.h new file mode 100644 index 000000000000..37860e86771d --- /dev/null +++ b/tools/arch/riscv/include/asm/fence.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copied from the kernel sources to tools/arch/riscv: + */ + +#ifndef _ASM_RISCV_FENCE_H +#define _ASM_RISCV_FENCE_H + +#define RISCV_FENCE_ASM(p, s) "\tfence " #p "," #s "\n" +#define RISCV_FENCE(p, s) \ + ({ __asm__ __volatile__ (RISCV_FENCE_ASM(p, s) : : : "memory"); }) + +#endif /* _ASM_RISCV_FENCE_H */ diff --git a/tools/include/asm/barrier.h b/tools/include/asm/barrier.h index 8d378c57cb01..0c21678ac5e6 100644 --- a/tools/include/asm/barrier.h +++ b/tools/include/asm/barrier.h @@ -8,6 +8,8 @@ #include "../../arch/arm64/include/asm/barrier.h" #elif defined(__powerpc__) #include "../../arch/powerpc/include/asm/barrier.h" +#elif defined(__riscv) +#include "../../arch/riscv/include/asm/barrier.h" #elif defined(__s390__) #include "../../arch/s390/include/asm/barrier.h" #elif defined(__sh__) From patchwork Mon Jul 29 20:50:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13745783 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 27F01C3DA61 for ; Mon, 29 Jul 2024 20:50:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=wkhAFkY3V2Uzd2vzm7zCu3otL0HoxdZQe0J4szX1pFk=; b=Eo043mvHC3EE9C 6fEyV8uDxRkXjTKQYRjW+KfWoSsZ6gH6gJ64cxh2L7BgECZG3MveGKPbMPt7wbMVXpLlhjM4azkll 7Zd52qOWfMSCJPc2qr3CgzDhrN4STPIOavDt8RN/qtEawiE9NwOeumnZG0k/Or21UuSxuy/DlTh5V RcloVaPtYfP25rWcyRRArOEhjrdNuEicdbcOoLz8dkUBLfJaxfuIeYRmrAzZwxFHBzvrM4KOixVpB /6/CATGBvPv6UB8TDzBOR2Bu/CewtqM+PcWefJAPwaROxpxTwTgJIssJPcwFW+o/IdCWVsdK8eOmT 6WlADMUOE8S7VzK8v2FQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYXKU-0000000ChRm-1Is8; Mon, 29 Jul 2024 20:50:50 +0000 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYXKQ-0000000ChQn-2moy for linux-riscv@lists.infradead.org; Mon, 29 Jul 2024 20:50:47 +0000 Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-7a1be7b7bb5so2760033a12.0 for ; Mon, 29 Jul 2024 13:50:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1722286245; x=1722891045; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=YALcHE45yFBd6B8M2GwV44w9Qj1q3iq9UvV9zldTY8s=; b=chPkduMBKClW5y8KMW7bElB1OQr661Dl5gQqFC+SKTkX9wtj3ikwb6JZJR+e4J4HYv sGsLujSIKlZKxRU7eEP283u+uLbPIprgtBTdm58ycNgt+r5gowxhLuLTMLqu7hj5H9+L mOUJKnUZjoJR4pDlRBG/zF7oTrTvCLMMzJ4/BKPw3U046cgQleEIL2XGBeRivW1dvTyj VWAp6wlaXG1rimujk7lrDHiTAHywEs+Si7I9cyYf1LTqzv0ER3I/uqN1ZOgpA5UzwKO5 mp95utn0xGU4gNVfiAemNi7/LWrmMrItJnehG6LpExGEV3vVQzCknTB4M7K6pkCjXtp+ xh3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722286245; x=1722891045; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YALcHE45yFBd6B8M2GwV44w9Qj1q3iq9UvV9zldTY8s=; b=wInBGpniQL16UnjNFnJcMY2izC2F7yj+V2/OKlgMuW979Q6BrZXbrFEgPWz0dKDHLB dwYuJkjaIYKwWw0gG+bYXMajjOoAxnJpcBZBwdiF2gTVQP+cMe0Wu+hnKj0c+QyzEw0u XgvRG1UGPQkin45RFkTBhzMd3afnaSC6Xm7zTACsO+fGMWu5eEwkGL/bYgVKntu5V2lE L+7+CoMTdy8JSjAyHtYDQaoJ1GECXnsZIC37aEX2ompoMTiakRXLvmJQ0KLxvIRpp0vq HZ2e6ZcudV8juu9KlWMk5YARPBLla7t/VdAfti+DKQXPFgIqy+Z252jmxLrL/u/NmfCX vcmg== X-Forwarded-Encrypted: i=1; AJvYcCW4f4bqQMuaJ8KNgwA9eRv60OPR3v5pfM7buQ2/cD7AworlfGdJBHeAynQZBHYu4h1G6k2FG3i9me/ogmaUkBXBknregVjnCBE988+nupeP X-Gm-Message-State: AOJu0YxCLq72Tv0R7WZ8VPV2Dspr9A7SfXt+LlJVmLLlh/RnWi9vdkSc 0Bj9gV9uzBJMPMaLJoIfvrwLJp2WSdiW+WC6wNVDIxM/3PWYk6pw4kggxXLTQ7aAoQUW8G1NLcX l X-Google-Smtp-Source: AGHT+IEDXOv0oX/69rDFZ/8mFt51Yof+gUeyqD/AVuJdZ/wo3n5UfYRR5ZPswAmeUMRaOEdviGizbA== X-Received: by 2002:a05:6a20:9f89:b0:1c4:d4b2:ffe5 with SMTP id adf61e73a8af0-1c4d4b30374mr3193080637.54.1722286244829; Mon, 29 Jul 2024 13:50:44 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70ead72ba2csm7454541b3a.93.2024.07.29.13.50.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 13:50:43 -0700 (PDT) From: Charlie Jenkins Date: Mon, 29 Jul 2024 13:50:36 -0700 Subject: [PATCH 2/2] tools: Optimize ring buffer for riscv MIME-Version: 1.0 Message-Id: <20240729-optimize_ring_buffer_read_riscv-v1-2-6bbc0f2434ee@rivosinc.com> References: <20240729-optimize_ring_buffer_read_riscv-v1-0-6bbc0f2434ee@rivosinc.com> In-Reply-To: <20240729-optimize_ring_buffer_read_riscv-v1-0-6bbc0f2434ee@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Andrea Parri Cc: linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1722286240; l=920; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=vkgW6uSkTrdq/a10IhVcXIlyy7ZpLz6+wi4VUooJ/G4=; b=6aHzlAFODxv03rehQH+ihSsrMnz7sWZc1A11YVvX3P66jucVnPCsnJUrMqSjNfcAEEr1HsL4F h1j5DqJJcehCOzZfRMxGWt+WNuh5aB190ykVgIfGSl6pAtDILpmMnaI X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240729_135046_744673_1C7711C3 X-CRM114-Status: UNSURE ( 9.12 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Now that riscv supports optimized barriers, use them in the ring buffer. Signed-off-by: Charlie Jenkins --- tools/include/linux/ring_buffer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/include/linux/ring_buffer.h b/tools/include/linux/ring_buffer.h index 6c02617377c2..a74c397359c7 100644 --- a/tools/include/linux/ring_buffer.h +++ b/tools/include/linux/ring_buffer.h @@ -55,7 +55,7 @@ static inline u64 ring_buffer_read_head(struct perf_event_mmap_page *base) * READ_ONCE() + smp_mb() pair. */ #if defined(__x86_64__) || defined(__aarch64__) || defined(__powerpc64__) || \ - defined(__ia64__) || defined(__sparc__) && defined(__arch64__) + defined(__ia64__) || defined(__sparc__) && defined(__arch64__) || defined(__riscv) return smp_load_acquire(&base->data_head); #else u64 head = READ_ONCE(base->data_head);