Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 758
0x90 Avatar asked Sep 06 '13 17:09

0x90


People also ask

What is kernel profiling?

A Kernel instrumentation profiler uses a subset of the software tools and libraries included in the Linux® kernel, for monitoring the actions made by the kernel to manage the execution of processes running on the SoC hardware.

How does Linux perf work?

Perf overview Perf is a facility comprised of kernel infrastructure for gathering various events and userspace tool to get gathered data from the kernel and analyze it. It is like a gprof, but it is non-invasive, low-overhead and profile the whole stack, including your app, libraries, system calls AND kernel with CPU!

What is Perf_events?

perf_events provides a command line tool, perf, and subcommands for various profiling activities. This is a single interface for the different instrumentation frameworks that provide the various events. The perf command alone will list the subcommands; here is perf version 4.10 (for the Linux 4.10 kernel):

What is Perf_event_open?

A call to perf_event_open() creates a file descriptor that allows measuring performance information. Each file descriptor corresponds to one event that is measured; these can be grouped together to measure multiple events simultaneously.


1 Answers

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.

like image 165
Alfredo Gimenez Avatar answered Sep 19 '22 21:09

Alfredo Gimenez