Using the kernel's performance counters
Hardware performance counters are perfect for code optimization, especially in embedded systems with a single workload. They are actively used by a wide range of tracing and profiling tools. This recipe will introduce the Linux performance counters subsystem and show how to use it.
Getting ready
The Linux Kernel Performance Counters Subsystem (LPC), commonly known as linux_perf
, is an abstraction interface for different CPU-specific performance measurements. The perf_events
subsystem not only exposes hardware performance counters from the CPU, but also kernel software events using the same API. It also allows the mapping of events to processes, although this has a performance overhead. Furthermore, it provides generalized events that are common across architectures.
Events can be categorized into three main groups:
- Software events: Based on kernel counters, these events are used for things such as context switches and minor faults tracking.
- Hardware events...