DPDK patches and discussions
 help / color / mirror / Atom feed
From: Tomasz Duszynski <tduszynski@marvell.com>
To: <tduszynski@marvell.com>
Cc: <bruce.richardson@intel.com>, <dev@dpdk.org>,
	<jerinj@marvell.com>, <mb@smartsharesystems.com>,
	<thomas@monjalon.net>, <david.marchand@redhat.com>
Subject: [PATCH v5 4/8] lib/pmu: do not try enabling perf counter access on arm64
Date: Wed, 25 Jun 2025 06:47:26 +0200	[thread overview]
Message-ID: <20250625044730.2435526-5-tduszynski@marvell.com> (raw)
In-Reply-To: <20250625044730.2435526-1-tduszynski@marvell.com>

/proc/sys/kernel/perf_user_access attribute allow user process to access
perf counters. Though in order to change it binary requires elevated
capabilities or must be run as root. If that's not the case counter
access remains disabled. Hence to avoid confusion log message that
that warns user about that.

Signed-off-by: Tomasz Duszynski <tduszynski@marvell.com>
---
 lib/pmu/pmu.c         |  4 ----
 lib/pmu/pmu_arm64.c   | 39 +++++++--------------------------------
 lib/pmu/pmu_private.h |  8 ++++++++
 3 files changed, 15 insertions(+), 36 deletions(-)

diff --git a/lib/pmu/pmu.c b/lib/pmu/pmu.c
index 0709f5e58c..3cae29891c 100644
--- a/lib/pmu/pmu.c
+++ b/lib/pmu/pmu.c
@@ -25,10 +25,6 @@
 #define FIELD_PREP(m, v) (((uint64_t)(v) << (rte_ffs64(m) - 1)) & (m))
 
 RTE_LOG_REGISTER_DEFAULT(rte_pmu_logtype, INFO)
-#define RTE_LOGTYPE_PMU rte_pmu_logtype
-
-#define PMU_LOG(level, ...) \
-	RTE_LOG_LINE(level, PMU, ## __VA_ARGS__)
 
 /* A structure describing an event */
 struct rte_pmu_event {
diff --git a/lib/pmu/pmu_arm64.c b/lib/pmu/pmu_arm64.c
index 3f4f5fa297..2c40b5f702 100644
--- a/lib/pmu/pmu_arm64.c
+++ b/lib/pmu/pmu_arm64.c
@@ -14,8 +14,6 @@
 
 #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)
 {
@@ -39,49 +37,26 @@ read_attr_int(const char *path, int *val)
 	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;
-}
-
 static int
 pmu_arm64_init(void)
 {
-	int ret;
+	int uaccess, ret;
 
-	ret = read_attr_int(PERF_USER_ACCESS_PATH, &restore_uaccess);
+	ret = read_attr_int(PERF_USER_ACCESS_PATH, &uaccess);
 	if (ret)
 		return ret;
 
-	/* user access already enabled */
-	if (restore_uaccess == 1)
-		return 0;
+	if (uaccess != 1)
+		PMU_LOG(WARNING, "access to perf counters disabled, "
+			"run 'echo 1 > %s' to enable",
+			PERF_USER_ACCESS_PATH);
 
-	return write_attr_int(PERF_USER_ACCESS_PATH, 1);
+	return ret;
 }
 
 static void
 pmu_arm64_fini(void)
 {
-	write_attr_int(PERF_USER_ACCESS_PATH, restore_uaccess);
 }
 
 static void
diff --git a/lib/pmu/pmu_private.h b/lib/pmu/pmu_private.h
index d74f7f4092..82118df8b3 100644
--- a/lib/pmu/pmu_private.h
+++ b/lib/pmu/pmu_private.h
@@ -5,6 +5,14 @@
 #ifndef PMU_PRIVATE_H
 #define PMU_PRIVATE_H
 
+#include <rte_log.h>
+
+extern int rte_pmu_logtype;
+#define RTE_LOGTYPE_PMU rte_pmu_logtype
+
+#define PMU_LOG(level, ...) \
+	RTE_LOG_LINE(level, PMU, ## __VA_ARGS__)
+
 /**
  * Structure describing architecture specific PMU operations.
  */
-- 
2.34.1


  parent reply	other threads:[~2025-06-25  4:48 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-16  6:53 [PATCH 0/6] lib/pmu: cleanups and trace integration Tomasz Duszynski
2025-06-16  6:53 ` [PATCH 1/6] lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs Tomasz Duszynski
2025-06-16  6:53 ` [PATCH 2/6] lib/pmu: export only necessary arch headers Tomasz Duszynski
2025-06-16  6:53 ` [PATCH 3/6] lib/pmu: reimplement per-arch ops as callbacks Tomasz Duszynski
2025-06-16  7:03   ` Thomas Monjalon
2025-06-16  9:54     ` Tomasz Duszynski
2025-06-16  6:53 ` [PATCH 4/6] lib/pmu: use build system defined RTE_LIB_PMU macro Tomasz Duszynski
2025-06-16  7:08   ` Thomas Monjalon
2025-06-16 10:53     ` Tomasz Duszynski
2025-06-16  6:53 ` [PATCH 5/6] test/pmu: enable fast test Tomasz Duszynski
2025-06-16  6:53 ` [PATCH 6/6] trace: add PMU Tomasz Duszynski
2025-06-16  7:13   ` Thomas Monjalon
2025-06-16  9:49     ` Tomasz Duszynski
2025-06-16 10:32       ` Bruce Richardson
2025-06-16 13:18       ` Morten Brørup
2025-06-18  6:56 ` [PATCH v2 0/6] lib/pmu: cleanups and trace integration Tomasz Duszynski
2025-06-18  6:56   ` [PATCH v2 1/6] lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs Tomasz Duszynski
2025-06-18  6:56   ` [PATCH v2 2/6] lib/pmu: export only necessary arch headers Tomasz Duszynski
2025-06-18  6:56   ` [PATCH v2 3/6] lib/pmu: reimplement per-arch ops as callbacks Tomasz Duszynski
2025-06-18  6:56   ` [PATCH v2 4/6] lib/pmu: use build system defined RTE_LIB_PMU macro Tomasz Duszynski
2025-06-18  6:56   ` [PATCH v2 5/6] test/pmu: enable fast test Tomasz Duszynski
2025-06-18  6:56   ` [PATCH v2 6/6] trace: add PMU Tomasz Duszynski
2025-06-18  7:16     ` Morten Brørup
2025-06-18  9:47       ` Thomas Monjalon
2025-06-18 10:28         ` Bruce Richardson
2025-06-18 11:30           ` Morten Brørup
2025-06-18 10:23       ` Tomasz Duszynski
2025-06-18 10:37         ` Morten Brørup
2025-06-20 12:05   ` [PATCH v3 0/7] lib/pmu: cleanups and trace integration Tomasz Duszynski
2025-06-20 12:05     ` [PATCH v3 1/7] lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs Tomasz Duszynski
2025-06-20 12:05     ` [PATCH v3 2/7] lib/pmu: export only necessary arch headers Tomasz Duszynski
2025-06-20 12:05     ` [PATCH v3 3/7] lib/pmu: reimplement per-arch ops as callbacks Tomasz Duszynski
2025-06-20 12:05     ` [PATCH v3 4/7] lib/pmu: use build system defined RTE_LIB_PMU macro Tomasz Duszynski
2025-06-20 12:05     ` [PATCH v3 5/7] test/pmu: enable fast test Tomasz Duszynski
2025-06-20 12:05     ` [PATCH v3 6/7] trace: add PMU Tomasz Duszynski
2025-06-20 12:05     ` [PATCH v3 7/7] lib/pmu: fix out-of-bound access Tomasz Duszynski
2025-06-24 12:29     ` [PATCH v4 0/7] lib/pmu: cleanups and trace integration Tomasz Duszynski
2025-06-24 12:29       ` [PATCH v4 1/7] lib/pmu: export only necessary arch headers Tomasz Duszynski
2025-06-24 12:29       ` [PATCH v4 2/7] lib/pmu: reimplement per-arch ops as callbacks Tomasz Duszynski
2025-06-24 12:29       ` [PATCH v4 3/7] lib/pmu: do not try enabling perf counter access on arm64 Tomasz Duszynski
2025-06-24 12:29       ` [PATCH v4 4/7] lib/pmu: use build system defined RTE_LIB_PMU macro Tomasz Duszynski
2025-06-24 12:29       ` [PATCH v4 5/7] test/pmu: enable fast test Tomasz Duszynski
2025-06-24 12:29       ` [PATCH v4 6/7] trace: add PMU Tomasz Duszynski
2025-06-24 12:29       ` [PATCH v4 7/7] lib/pmu: fix out-of-bound access Tomasz Duszynski
2025-06-25  4:47       ` [PATCH v5 0/8] lib/pmu: cleanups and trace integration Tomasz Duszynski
2025-06-25  4:47         ` [PATCH v5 1/8] lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs Tomasz Duszynski
2025-06-25  4:47         ` [PATCH v5 2/8] lib/pmu: export only necessary arch headers Tomasz Duszynski
2025-06-25  4:47         ` [PATCH v5 3/8] lib/pmu: reimplement per-arch ops as callbacks Tomasz Duszynski
2025-06-25  4:47         ` Tomasz Duszynski [this message]
2025-06-25  4:47         ` [PATCH v5 5/8] lib/pmu: use build system defined RTE_LIB_PMU macro Tomasz Duszynski
2025-06-25  4:47         ` [PATCH v5 6/8] test/pmu: enable fast test Tomasz Duszynski
2025-06-25  4:47         ` [PATCH v5 7/8] trace: add PMU Tomasz Duszynski
2025-06-25  4:47         ` [PATCH v5 8/8] lib/pmu: fix out-of-bound access Tomasz Duszynski

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=20250625044730.2435526-5-tduszynski@marvell.com \
    --to=tduszynski@marvell.com \
    --cc=bruce.richardson@intel.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=jerinj@marvell.com \
    --cc=mb@smartsharesystems.com \
    --cc=thomas@monjalon.net \
    /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).