0x90
0x90

Reputation: 41022

How to profile in the Linux kernel or use the perf_event*.[hc] framework?

I have noticed there are some profiling source code under arch/arm/kernel:

perf_event.c 
perf_event_cpu.c 
perf_event_v6.c 
perf_event_v7.c 
perf_event_xscale.c

I can't understand the hierarchy of those files and how can I use them? can I assume they are always exists and use them in a kernel module? my kernel module runs on Cortex-A7 or Cortex-A15 cores.

There seems to be a lot of very useful things under /arch/arm/kernel/ directory but no documentation about the capabilities ? how comes ?

Upvotes: 5

Views: 2459

Answers (2)

Alfredo Gimenez
Alfredo Gimenez

Reputation: 2224

Perf_event does provide an API that can be used programmatically, but the documentation is sparse at best. Vince Weaver made the best resource for using the perf_event API here: http://web.eece.maine.edu/~vweaver/projects/perf_events/

He also provides some example code for recording counters.

However your best bet is to use an API that wraps perf_event and makes it more accessible, like PAPI (http://icl.cs.utk.edu/papi/)

EDIT: Since you want to do this from a kernel module, PAPI will not be available. The perf_event API still is, however.

Upvotes: 4

Mats Petersson
Mats Petersson

Reputation: 129524

The functionality in the perf_* files is used by/provided for tools like oprofile and perf tools.

And no, they are not ALWAYS available, as there is a config option (CONFIG_PERF_EVENTS) to enable/disable performance measurements.

The functionality is not really meant to be used from another driver. I'm pretty sure that will "upset" any user of oprofile or perf.

Upvotes: 1

Related Questions