From: Tomasz Duszynski <tduszynski@marvell.com>
To: <tduszynski@marvell.com>,
Wathsala Vithanage <wathsala.vithanage@arm.com>
Cc: <Ruifeng.Wang@arm.com>, <bruce.richardson@intel.com>,
<david.marchand@redhat.com>, <dev@dpdk.org>, <jerinj@marvell.com>,
<konstantin.v.ananyev@yandex.ru>, <mattias.ronnblom@ericsson.com>,
<mb@smartsharesystems.com>, <roretzla@linux.microsoft.com>,
<thomas@monjalon.net>, <zhoumin@loongson.cn>
Subject: [PATCH v13 2/4] pmu: support reading ARM PMU events in runtime
Date: Wed, 9 Oct 2024 13:23:06 +0200 [thread overview]
Message-ID: <20241009112308.2973903-3-tduszynski@marvell.com> (raw)
In-Reply-To: <20241009112308.2973903-1-tduszynski@marvell.com>
Add support for reading ARM PMU events in runtime.
Signed-off-by: Tomasz Duszynski <tduszynski@marvell.com>
---
app/test/test_pmu.c | 4 ++
lib/pmu/meson.build | 8 ++++
lib/pmu/pmu_arm64.c | 94 +++++++++++++++++++++++++++++++++++++
lib/pmu/rte_pmu.h | 4 ++
lib/pmu/rte_pmu_pmc_arm64.h | 30 ++++++++++++
5 files changed, 140 insertions(+)
create mode 100644 lib/pmu/pmu_arm64.c
create mode 100644 lib/pmu/rte_pmu_pmc_arm64.h
diff --git a/app/test/test_pmu.c b/app/test/test_pmu.c
index 79376ea2e8..e0809a0f93 100644
--- a/app/test/test_pmu.c
+++ b/app/test/test_pmu.c
@@ -13,6 +13,10 @@ test_pmu_read(void)
int tries = 10, event;
uint64_t val = 0;
+#if defined(RTE_ARCH_ARM64)
+ name = "cpu_cycles";
+#endif
+
if (name == NULL) {
printf("PMU not supported on this arch\n");
return TEST_SKIPPED;
diff --git a/lib/pmu/meson.build b/lib/pmu/meson.build
index 386232e5c7..0d9270eaca 100644
--- a/lib/pmu/meson.build
+++ b/lib/pmu/meson.build
@@ -9,4 +9,12 @@ endif
sources = files('rte_pmu.c')
+indirect_headers += files(
+ 'rte_pmu_pmc_arm64.h',
+)
+
+if dpdk_conf.has('RTE_ARCH_ARM64')
+ sources += files('pmu_arm64.c')
+endif
+
deps += ['log']
diff --git a/lib/pmu/pmu_arm64.c b/lib/pmu/pmu_arm64.c
new file mode 100644
index 0000000000..3b72009cff
--- /dev/null
+++ b/lib/pmu/pmu_arm64.c
@@ -0,0 +1,94 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2024 Marvell International Ltd.
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <rte_bitops.h>
+#include <rte_common.h>
+
+#include "pmu_private.h"
+
+#define PERF_USER_ACCESS_PATH "/proc/sys/kernel/perf_user_access"
+
+static int restore_uaccess;
+
+static int
+read_attr_int(const char *path, int *val)
+{
+ char buf[BUFSIZ];
+ int ret, fd;
+
+ fd = open(path, O_RDONLY);
+ if (fd == -1)
+ return -errno;
+
+ ret = read(fd, buf, sizeof(buf));
+ if (ret == -1) {
+ close(fd);
+
+ return -errno;
+ }
+
+ *val = strtol(buf, NULL, 10);
+ close(fd);
+
+ return 0;
+}
+
+static int
+write_attr_int(const char *path, int val)
+{
+ char buf[BUFSIZ];
+ int num, ret, fd;
+
+ fd = open(path, O_WRONLY);
+ if (fd == -1)
+ return -errno;
+
+ num = snprintf(buf, sizeof(buf), "%d", val);
+ ret = write(fd, buf, num);
+ if (ret == -1) {
+ close(fd);
+
+ return -errno;
+ }
+
+ close(fd);
+
+ return 0;
+}
+
+int
+pmu_arch_init(void)
+{
+ int ret;
+
+ ret = read_attr_int(PERF_USER_ACCESS_PATH, &restore_uaccess);
+ if (ret)
+ return ret;
+
+ /* user access already enabled */
+ if (restore_uaccess == 1)
+ return 0;
+
+ return write_attr_int(PERF_USER_ACCESS_PATH, 1);
+}
+
+void
+pmu_arch_fini(void)
+{
+ write_attr_int(PERF_USER_ACCESS_PATH, restore_uaccess);
+}
+
+void
+pmu_arch_fixup_config(uint64_t config[3])
+{
+ /* select 64 bit counters */
+ config[1] |= RTE_BIT64(0);
+ /* enable userspace access */
+ config[1] |= RTE_BIT64(1);
+}
diff --git a/lib/pmu/rte_pmu.h b/lib/pmu/rte_pmu.h
index 09238ee33d..771fad31d0 100644
--- a/lib/pmu/rte_pmu.h
+++ b/lib/pmu/rte_pmu.h
@@ -31,6 +31,10 @@ extern "C" {
#include <rte_branch_prediction.h>
#include <rte_spinlock.h>
+#if defined(RTE_ARCH_ARM64)
+#include "rte_pmu_pmc_arm64.h"
+#endif
+
/** Maximum number of events in a group */
#define RTE_MAX_NUM_GROUP_EVENTS 8
diff --git a/lib/pmu/rte_pmu_pmc_arm64.h b/lib/pmu/rte_pmu_pmc_arm64.h
new file mode 100644
index 0000000000..39165bbc20
--- /dev/null
+++ b/lib/pmu/rte_pmu_pmc_arm64.h
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2024 Marvell.
+ */
+#ifndef _RTE_PMU_PMC_ARM64_H_
+#define _RTE_PMU_PMC_ARM64_H_
+
+#include <rte_common.h>
+
+static __rte_always_inline uint64_t
+rte_pmu_pmc_read(int index)
+{
+ uint64_t val;
+
+ if (index == 31) {
+ /* CPU Cycles (0x11) must be read via pmccntr_el0 */
+ asm volatile("mrs %0, pmccntr_el0" : "=r" (val));
+ } else {
+ asm volatile(
+ "msr pmselr_el0, %x0\n"
+ "mrs %0, pmxevcntr_el0\n"
+ : "=r" (val)
+ : "rZ" (index)
+ );
+ }
+
+ return val;
+}
+#define rte_pmu_pmc_read rte_pmu_pmc_read
+
+#endif /* _RTE_PMU_PMC_ARM64_H_ */
--
2.34.1
next prev parent reply other threads:[~2024-10-09 11:23 UTC|newest]
Thread overview: 190+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-11 9:43 [PATCH 0/4] add support for self monitoring Tomasz Duszynski
2022-11-11 9:43 ` [PATCH 1/4] eal: add generic support for reading PMU events Tomasz Duszynski
2022-12-15 8:33 ` Mattias Rönnblom
2022-11-11 9:43 ` [PATCH 2/4] eal/arm: support reading ARM PMU events in runtime Tomasz Duszynski
2022-11-11 9:43 ` [PATCH 3/4] eal/x86: support reading Intel " Tomasz Duszynski
2022-11-11 9:43 ` [PATCH 4/4] eal: add PMU support to tracing library Tomasz Duszynski
2022-11-21 12:11 ` [PATCH v2 0/4] add support for self monitoring Tomasz Duszynski
2022-11-21 12:11 ` [PATCH v2 1/4] eal: add generic support for reading PMU events Tomasz Duszynski
2022-11-21 12:11 ` [PATCH v2 2/4] eal/arm: support reading ARM PMU events in runtime Tomasz Duszynski
2022-11-21 12:11 ` [PATCH v2 3/4] eal/x86: support reading Intel " Tomasz Duszynski
2022-11-21 12:11 ` [PATCH v2 4/4] eal: add PMU support to tracing library Tomasz Duszynski
2022-11-29 9:28 ` [PATCH v3 0/4] add support for self monitoring Tomasz Duszynski
2022-11-29 9:28 ` [PATCH v3 1/4] eal: add generic support for reading PMU events Tomasz Duszynski
2022-11-30 8:32 ` zhoumin
2022-12-13 8:05 ` [EXT] " Tomasz Duszynski
2022-11-29 9:28 ` [PATCH v3 2/4] eal/arm: support reading ARM PMU events in runtime Tomasz Duszynski
2022-11-29 9:28 ` [PATCH v3 3/4] eal/x86: support reading Intel " Tomasz Duszynski
2022-11-29 9:28 ` [PATCH v3 4/4] eal: add PMU support to tracing library Tomasz Duszynski
2022-11-29 10:42 ` [PATCH v3 0/4] add support for self monitoring Morten Brørup
2022-12-13 8:23 ` Tomasz Duszynski
2022-12-13 10:43 ` [PATCH v4 " Tomasz Duszynski
2022-12-13 10:43 ` [PATCH v4 1/4] eal: add generic support for reading PMU events Tomasz Duszynski
2022-12-13 11:52 ` Morten Brørup
2022-12-14 9:38 ` Tomasz Duszynski
2022-12-14 10:41 ` Morten Brørup
2022-12-15 8:22 ` Morten Brørup
2022-12-16 7:33 ` Morten Brørup
2023-01-05 21:14 ` Tomasz Duszynski
2023-01-05 22:07 ` Morten Brørup
2023-01-08 15:41 ` Tomasz Duszynski
2023-01-08 16:30 ` Morten Brørup
2022-12-15 8:46 ` Mattias Rönnblom
2023-01-04 15:47 ` Tomasz Duszynski
2023-01-09 7:37 ` Ruifeng Wang
2023-01-09 15:40 ` Tomasz Duszynski
2022-12-13 10:43 ` [PATCH v4 2/4] eal/arm: support reading ARM PMU events in runtime Tomasz Duszynski
2022-12-13 10:43 ` [PATCH v4 3/4] eal/x86: support reading Intel " Tomasz Duszynski
2022-12-13 10:43 ` [PATCH v4 4/4] eal: add PMU support to tracing library Tomasz Duszynski
2023-01-10 23:46 ` [PATCH v5 0/4] add support for self monitoring Tomasz Duszynski
2023-01-10 23:46 ` [PATCH v5 1/4] eal: add generic support for reading PMU events Tomasz Duszynski
2023-01-11 9:05 ` Morten Brørup
2023-01-11 16:20 ` Tomasz Duszynski
2023-01-11 16:54 ` Morten Brørup
2023-01-10 23:46 ` [PATCH v5 2/4] eal/arm: support reading ARM PMU events in runtime Tomasz Duszynski
2023-01-10 23:46 ` [PATCH v5 3/4] eal/x86: support reading Intel " Tomasz Duszynski
2023-01-10 23:46 ` [PATCH v5 4/4] eal: add PMU support to tracing library Tomasz Duszynski
2023-01-11 0:32 ` [PATCH v5 0/4] add support for self monitoring Tyler Retzlaff
2023-01-11 9:31 ` Morten Brørup
2023-01-11 14:24 ` Tomasz Duszynski
2023-01-11 14:32 ` Bruce Richardson
2023-01-11 9:39 ` [EXT] " Tomasz Duszynski
2023-01-11 21:05 ` Tyler Retzlaff
2023-01-13 7:44 ` Tomasz Duszynski
2023-01-13 19:22 ` Tyler Retzlaff
2023-01-14 9:53 ` Morten Brørup
2023-01-19 23:39 ` [PATCH v6 " Tomasz Duszynski
2023-01-19 23:39 ` [PATCH v6 1/4] lib: add generic support for reading PMU events Tomasz Duszynski
2023-01-20 9:46 ` Morten Brørup
2023-01-26 9:40 ` Tomasz Duszynski
2023-01-26 12:29 ` Morten Brørup
2023-01-26 12:59 ` Bruce Richardson
2023-01-26 15:28 ` [EXT] " Tomasz Duszynski
2023-02-02 14:27 ` Morten Brørup
2023-01-26 15:17 ` Tomasz Duszynski
2023-01-20 18:29 ` Tyler Retzlaff
2023-01-26 9:05 ` [EXT] " Tomasz Duszynski
2023-01-19 23:39 ` [PATCH v6 2/4] pmu: support reading ARM PMU events in runtime Tomasz Duszynski
2023-01-19 23:39 ` [PATCH v6 3/4] pmu: support reading Intel x86_64 " Tomasz Duszynski
2023-01-19 23:39 ` [PATCH v6 4/4] eal: add PMU support to tracing library Tomasz Duszynski
2023-02-01 13:17 ` [PATCH v7 0/4] add support for self monitoring Tomasz Duszynski
2023-02-01 13:17 ` [PATCH v7 1/4] lib: add generic support for reading PMU events Tomasz Duszynski
2023-02-01 13:17 ` [PATCH v7 2/4] pmu: support reading ARM PMU events in runtime Tomasz Duszynski
2023-02-01 13:17 ` [PATCH v7 3/4] pmu: support reading Intel x86_64 " Tomasz Duszynski
2023-02-01 13:17 ` [PATCH v7 4/4] eal: add PMU support to tracing library Tomasz Duszynski
2023-02-01 13:51 ` [PATCH v7 0/4] add support for self monitoring Morten Brørup
2023-02-02 7:54 ` Tomasz Duszynski
2023-02-02 9:43 ` [PATCH v8 " Tomasz Duszynski
2023-02-02 9:43 ` [PATCH v8 1/4] lib: add generic support for reading PMU events Tomasz Duszynski
2023-02-02 10:32 ` Ruifeng Wang
2023-02-02 9:43 ` [PATCH v8 2/4] pmu: support reading ARM PMU events in runtime Tomasz Duszynski
2023-02-02 9:43 ` [PATCH v8 3/4] pmu: support reading Intel x86_64 " Tomasz Duszynski
2023-02-02 9:43 ` [PATCH v8 4/4] eal: add PMU support to tracing library Tomasz Duszynski
2023-02-02 12:49 ` [PATCH v9 0/4] add support for self monitoring Tomasz Duszynski
2023-02-02 12:49 ` [PATCH v9 1/4] lib: add generic support for reading PMU events Tomasz Duszynski
2023-02-06 11:02 ` David Marchand
2023-02-09 11:09 ` [EXT] " Tomasz Duszynski
2023-02-02 12:49 ` [PATCH v9 2/4] pmu: support reading ARM PMU events in runtime Tomasz Duszynski
2023-02-02 12:49 ` [PATCH v9 3/4] pmu: support reading Intel x86_64 " Tomasz Duszynski
2023-02-02 12:49 ` [PATCH v9 4/4] eal: add PMU support to tracing library Tomasz Duszynski
2023-02-13 11:31 ` [PATCH v10 0/4] add support for self monitoring Tomasz Duszynski
2023-02-13 11:31 ` [PATCH v10 1/4] lib: add generic support for reading PMU events Tomasz Duszynski
2023-02-16 7:39 ` Ruifeng Wang
2023-02-16 14:44 ` Tomasz Duszynski
2023-02-13 11:31 ` [PATCH v10 2/4] pmu: support reading ARM PMU events in runtime Tomasz Duszynski
2023-02-16 7:41 ` Ruifeng Wang
2023-02-13 11:31 ` [PATCH v10 3/4] pmu: support reading Intel x86_64 " Tomasz Duszynski
2023-02-13 11:31 ` [PATCH v10 4/4] eal: add PMU support to tracing library Tomasz Duszynski
2023-02-16 17:54 ` [PATCH v11 0/4] add support for self monitoring Tomasz Duszynski
2023-02-16 17:54 ` [PATCH v11 1/4] lib: add generic support for reading PMU events Tomasz Duszynski
2023-02-16 23:50 ` Konstantin Ananyev
2023-02-17 8:49 ` [EXT] " Tomasz Duszynski
2023-02-17 10:14 ` Konstantin Ananyev
2023-02-19 14:23 ` Tomasz Duszynski
2023-02-20 14:31 ` Konstantin Ananyev
2023-02-20 16:59 ` Tomasz Duszynski
2023-02-20 17:21 ` Konstantin Ananyev
2023-02-20 20:42 ` Tomasz Duszynski
2023-02-21 0:48 ` Konstantin Ananyev
2023-02-27 8:12 ` Tomasz Duszynski
2023-02-28 11:35 ` Konstantin Ananyev
2023-02-21 12:15 ` Konstantin Ananyev
2023-02-21 2:17 ` Konstantin Ananyev
2023-02-27 9:19 ` [EXT] " Tomasz Duszynski
2023-02-27 20:53 ` Konstantin Ananyev
2023-02-28 8:25 ` Morten Brørup
2023-02-28 12:04 ` Konstantin Ananyev
2023-02-28 13:15 ` Morten Brørup
2023-02-28 16:22 ` Morten Brørup
2023-03-05 16:30 ` Konstantin Ananyev
2023-02-28 9:57 ` Tomasz Duszynski
2023-02-28 11:58 ` Konstantin Ananyev
2023-02-16 17:55 ` [PATCH v11 2/4] pmu: support reading ARM PMU events in runtime Tomasz Duszynski
2023-02-16 17:55 ` [PATCH v11 3/4] pmu: support reading Intel x86_64 " Tomasz Duszynski
2023-02-16 17:55 ` [PATCH v11 4/4] eal: add PMU support to tracing library Tomasz Duszynski
2023-02-16 18:03 ` [PATCH v11 0/4] add support for self monitoring Ruifeng Wang
2023-05-04 8:02 ` David Marchand
2023-07-31 12:33 ` Thomas Monjalon
2023-08-07 8:11 ` [EXT] " Tomasz Duszynski
2023-09-21 8:26 ` David Marchand
2024-09-02 14:48 ` Morten Brørup
2024-09-05 3:49 ` Tomasz Duszynski
2024-09-27 22:06 ` [PATCH v12 " Tomasz Duszynski
2024-09-27 22:06 ` [PATCH v12 1/4] lib: add generic support for reading PMU events Tomasz Duszynski
2024-10-06 14:30 ` Morten Brørup
2024-10-09 9:17 ` Tomasz Duszynski
2024-10-07 6:59 ` Jerin Jacob
2024-10-09 7:50 ` [EXTERNAL] " Tomasz Duszynski
2024-09-27 22:06 ` [PATCH v12 2/4] pmu: support reading ARM PMU events in runtime Tomasz Duszynski
2024-09-27 22:06 ` [PATCH v12 3/4] pmu: support reading Intel x86_64 " Tomasz Duszynski
2024-09-27 22:06 ` [PATCH v12 4/4] eal: add PMU support to tracing library Tomasz Duszynski
2024-10-04 11:00 ` [PATCH v12 0/4] add support for self monitoring David Marchand
2024-10-09 12:45 ` [EXTERNAL] " Tomasz Duszynski
2024-10-09 11:23 ` [PATCH v13 " Tomasz Duszynski
2024-10-09 11:23 ` [PATCH v13 1/4] lib: add generic support for reading PMU events Tomasz Duszynski
2024-10-09 11:23 ` Tomasz Duszynski [this message]
2024-10-09 11:23 ` [PATCH v13 3/4] pmu: support reading Intel x86_64 PMU events in runtime Tomasz Duszynski
2024-10-09 11:23 ` [PATCH v13 4/4] eal: add PMU support to tracing library Tomasz Duszynski
2024-10-09 12:50 ` Morten Brørup
2024-10-09 17:56 ` Stephen Hemminger
2024-10-10 7:24 ` [EXTERNAL] " Tomasz Duszynski
2024-10-10 12:48 ` Morten Brørup
2024-10-11 9:49 ` [PATCH v14 0/4] add support for self monitoring Tomasz Duszynski
2024-10-11 9:49 ` [PATCH v14 1/4] lib: add generic support for reading PMU events Tomasz Duszynski
2024-10-11 11:56 ` Konstantin Ananyev
2024-10-11 14:19 ` Stephen Hemminger
2024-10-15 9:14 ` [EXTERNAL] " Tomasz Duszynski
2024-10-15 9:08 ` Tomasz Duszynski
2024-10-16 8:49 ` Konstantin Ananyev
2024-10-17 7:11 ` Tomasz Duszynski
2024-10-11 9:49 ` [PATCH v14 2/4] pmu: support reading ARM PMU events in runtime Tomasz Duszynski
2024-10-11 9:49 ` [PATCH v14 3/4] pmu: support reading Intel x86_64 " Tomasz Duszynski
2024-10-11 9:49 ` [PATCH v14 4/4] eal: add PMU support to tracing library Tomasz Duszynski
2024-10-11 13:29 ` David Marchand
2024-10-15 9:18 ` [EXTERNAL] " Tomasz Duszynski
2024-10-25 8:54 ` [PATCH v15 0/4] add support for self monitoring Tomasz Duszynski
2024-10-25 8:54 ` [PATCH v15 1/4] lib: add generic support for reading PMU events Tomasz Duszynski
2024-11-05 10:58 ` Konstantin Ananyev
2024-11-15 10:20 ` Tomasz Duszynski
2024-10-25 8:54 ` [PATCH v15 2/4] pmu: support reading ARM PMU events in runtime Tomasz Duszynski
2024-10-25 8:54 ` [PATCH v15 3/4] pmu: support reading Intel x86_64 " Tomasz Duszynski
2024-10-25 8:54 ` [PATCH v15 4/4] eal: add PMU support to tracing library Tomasz Duszynski
2024-10-25 11:02 ` Jerin Jacob
2024-10-28 10:32 ` [EXTERNAL] " Tomasz Duszynski
2024-11-05 7:41 ` Morten Brørup
2024-11-08 10:36 ` Tomasz Duszynski
2024-11-05 11:04 ` Konstantin Ananyev
2024-11-08 11:44 ` Tomasz Duszynski
2024-11-12 23:09 ` Stephen Hemminger
2024-11-15 10:24 ` [EXTERNAL] " Tomasz Duszynski
2024-11-05 4:04 ` [PATCH v15 0/4] add support for self monitoring Tomasz Duszynski
2023-01-25 10:33 ` [PATCH 0/2] add platform bus Tomasz Duszynski
2023-01-25 10:33 ` [PATCH 1/2] lib: add helper to read strings from sysfs files Tomasz Duszynski
2023-01-25 10:39 ` Thomas Monjalon
2023-01-25 16:16 ` Tyler Retzlaff
2023-01-26 8:30 ` [EXT] " Tomasz Duszynski
2023-01-26 17:21 ` Tyler Retzlaff
2023-01-26 8:35 ` Tomasz Duszynski
2023-01-25 10:33 ` [PATCH 2/2] bus: add platform bus Tomasz Duszynski
2023-01-25 10:41 ` [PATCH 0/2] " Tomasz Duszynski
2023-02-16 20:56 ` [PATCH v5 0/4] add support for self monitoring Liang Ma
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241009112308.2973903-3-tduszynski@marvell.com \
--to=tduszynski@marvell.com \
--cc=Ruifeng.Wang@arm.com \
--cc=bruce.richardson@intel.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=jerinj@marvell.com \
--cc=konstantin.v.ananyev@yandex.ru \
--cc=mattias.ronnblom@ericsson.com \
--cc=mb@smartsharesystems.com \
--cc=roretzla@linux.microsoft.com \
--cc=thomas@monjalon.net \
--cc=wathsala.vithanage@arm.com \
--cc=zhoumin@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).