wcohen / libpfm4

This is a mirror of the official libpfm4 git repository, https://sourceforge.net/p/perfmon2/libpfm4/ci/master/tree/ with some local branch for developing patches.
Other
55 stars 18 forks source link

Invalid event attribute for cpu_clk_unhalted.thread #6

Open anson304 opened 1 year ago

anson304 commented 1 year ago

Hello, I am getting the error: invalid event attribute for cpu_clk_unhalted.thread. However, I do get counter values which are in the expected range even though an error message is printed out. However, there is no error when I try cpu_clk_unhalted.thread_p instead.

The error occurs when calling this line: ret = pfm_get_os_event_encoding(event, PFM_PLM3, PFM_OS_PERF_EVENT, &arg)) != PFM_SUCCESS

I use the following config:


    // clear all fields
    memset(&config, 0, sizeof(config));
    // common options across counters
    apply_default_options(&config);
    apply_required_options(&config);
wcohen commented 1 year ago

Please subscribe to the libpfm development mailing list (https://sourceforge.net/projects/perfmon2/lists/perfmon2-devel) post questions there. This git repo is a fork of the upstream and on it about section says:

This is a mirror of the official libpfm4 git repository, https://sourceforge.net/p/perfmon2/libpfm4/ci/master/tree/ with some local branch for developing patches.

Note that there is some crucial information missing from your question. What specific microarchitecture/specific process type is this being run on? libpfm is very sensitive to that as different events are used for different procesosrs. Also what is the setting of /proc/sys/kernel/perf_event_paranoid? When trying an event that the kernel doesn't allow because of the setting perf which uses the same kernel infrastructure prints out the following message:

$ perf stat --e cycles:k ls
Error:
Access to performance monitoring and observability operations is limited.
Enforced MAC policy settings (SELinux) can limit access to performance
monitoring and observability operations. Inspect system audit records for
more perf_event access control information and adjusting the policy.
Consider adjusting /proc/sys/kernel/perf_event_paranoid setting to open
access to performance monitoring and observability operations for processes
without CAP_PERFMON, CAP_SYS_PTRACE or CAP_SYS_ADMIN Linux capability.
More information can be found at 'Perf events and tool security' document:
https://www.kernel.org/doc/html/latest/admin-guide/perf-security.html
perf_event_paranoid setting is 2:
  -1: Allow use of (almost) all events by all users
      Ignore mlock limit after perf_event_mlock_kb without CAP_IPC_LOCK
>= 0: Disallow raw and ftrace function tracepoint access
>= 1: Disallow CPU event access
>= 2: Disallow kernel profiling
To make the adjusted perf_event_paranoid setting permanent preserve it
in /etc/sysctl.conf (e.g. kernel.perf_event_paranoid = <setting>)
anson304 commented 1 year ago

Thank you, I've posted to the mailing list. Just in case it is lost, I'll post my question here too:

It works when I run the following from the command line, and it appears when I use perf list: perf stat --e cpu_clk_unhalted.thread ls

/proc/sys/kernel/perf_event_paranoid is set to 0

I'm using Intel(R) Xeon(R) Gold 6252N CPU @ 2.30GHz

It works perfectly fine for other counters such as: "uops_issued.any", "uops_retired.retire_slots", "idq_uops_not_delivered.core","int_misc.recovery_cycles", "cycle_activity.stalls_l3_miss", "cycle_activity.stalls_mem_any", "resource_stalls.sb"