[v7,4/8] lib/pmu: do not try enabling perf counter access on arm64
Checks
Commit Message
/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(-)
@@ -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 {
@@ -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
@@ -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.
*/