Skip to content

Commit 74925cf

Browse files
Tomasz Duszynskidavid-marchand
authored andcommitted
pmu/arm64: do not enable perf counter user access
/proc/sys/kernel/perf_user_access attribute allow user process to access perf counters. Though in order to change it, a process 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 warns user about that. Signed-off-by: Tomasz Duszynski <[email protected]>
1 parent 8682341 commit 74925cf

File tree

3 files changed

+15
-36
lines changed

3 files changed

+15
-36
lines changed

lib/pmu/pmu.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@
2525
#define FIELD_PREP(m, v) (((uint64_t)(v) << (rte_ffs64(m) - 1)) & (m))
2626

2727
RTE_LOG_REGISTER_DEFAULT(rte_pmu_logtype, INFO)
28-
#define RTE_LOGTYPE_PMU rte_pmu_logtype
29-
30-
#define PMU_LOG(level, ...) \
31-
RTE_LOG_LINE(level, PMU, ## __VA_ARGS__)
3228

3329
/* A structure describing an event */
3430
struct rte_pmu_event {

lib/pmu/pmu_arm64.c

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
#define PERF_USER_ACCESS_PATH "/proc/sys/kernel/perf_user_access"
1616

17-
static int restore_uaccess;
18-
1917
static int
2018
read_attr_int(const char *path, int *val)
2119
{
@@ -39,49 +37,26 @@ read_attr_int(const char *path, int *val)
3937
return 0;
4038
}
4139

42-
static int
43-
write_attr_int(const char *path, int val)
44-
{
45-
char buf[BUFSIZ];
46-
int num, ret, fd;
47-
48-
fd = open(path, O_WRONLY);
49-
if (fd == -1)
50-
return -errno;
51-
52-
num = snprintf(buf, sizeof(buf), "%d", val);
53-
ret = write(fd, buf, num);
54-
if (ret == -1) {
55-
close(fd);
56-
57-
return -errno;
58-
}
59-
60-
close(fd);
61-
62-
return 0;
63-
}
64-
6540
static int
6641
pmu_arm64_init(void)
6742
{
68-
int ret;
43+
int uaccess, ret;
6944

70-
ret = read_attr_int(PERF_USER_ACCESS_PATH, &restore_uaccess);
45+
ret = read_attr_int(PERF_USER_ACCESS_PATH, &uaccess);
7146
if (ret)
7247
return ret;
7348

74-
/* user access already enabled */
75-
if (restore_uaccess == 1)
76-
return 0;
49+
if (uaccess != 1)
50+
PMU_LOG(WARNING, "access to perf counters disabled, "
51+
"run 'echo 1 > %s' to enable",
52+
PERF_USER_ACCESS_PATH);
7753

78-
return write_attr_int(PERF_USER_ACCESS_PATH, 1);
54+
return ret;
7955
}
8056

8157
static void
8258
pmu_arm64_fini(void)
8359
{
84-
write_attr_int(PERF_USER_ACCESS_PATH, restore_uaccess);
8560
}
8661

8762
static void

lib/pmu/pmu_private.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
#ifndef PMU_PRIVATE_H
66
#define PMU_PRIVATE_H
77

8+
#include <rte_log.h>
9+
10+
extern int rte_pmu_logtype;
11+
#define RTE_LOGTYPE_PMU rte_pmu_logtype
12+
13+
#define PMU_LOG(level, ...) \
14+
RTE_LOG_LINE(level, PMU, ## __VA_ARGS__)
15+
816
/**
917
* Structure describing architecture specific PMU operations.
1018
*/

0 commit comments

Comments
 (0)