[PATCH v10 06/10] lib/pmu: do not try enabling perf counter access on arm64

Wathsala Vithanage wathsala.vithanage at arm.com
Mon Aug 4 19:12:50 CEST 2025


> Subject: [PATCH v10 06/10] lib/pmu: do not try enabling perf counter access on
> arm64
> 
> /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 at marvell.com>

Acked-by: Wathsala Vithanage <wathsala.vithanage at arm.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 8cf2e89c69..97bab80368
> 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



More information about the dev mailing list