简体   繁体   中英

Reading raw perf counter from kernel module

My goal is to read the intel rapl counter ( perf_event_intel_rapl.c ) introduced in kernel 3.14 ( lwn-link ) from within another kernel module. Reading "general" counters is easy using perf_event_create_kernel_counter . I have found an excellent example for that: http://wadeatwork.com/?p=1SW_CPU_CLOCK

The perf manpage ( link ) says, for "non-generalized" events PERF_TYPE_RAW should be used as perf_event_attr->type together with an implementation specific config field.

My question is how I should configure the perf_event_attr struct in order to access the rapl counters. I haven't found any documentation on how to achieve this from a kernel module.

The perf_event support for RAPL includes generalized events that are accessible as system wide, requiring root access (sudo).

You should try the command:

sudo perf list

and see if the event power/energy-cores/ is there, if not, either your CPU has no RAPL support or perf_event does not enable the RAPL features on your CPU. If your CPU support RAPL but it's not enabled in perf_event, you can enable it by adding RAPL support for your CPU to perf_event as described in this link .

Once your CPU is supported, you can use the perf tool to do profiling with the command:

sudo perf stat -e power/energy-cores

For further details, this is a guide with steps to sample RAPL events using perf tool that describes the above with detail and provides some code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM