Zephyr API Documentation 4.5.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
Performance counters

Data Structures

struct  perf_counter_config
 Performance counter configuration entry. More...

Functions

int perf_counter_init (void)
 Initialize the PMU for the current logical CPU.
uint32_t perf_counter_num_counters (void)
void perf_counter_get_info (perf_counter_info_t *info)
 Fill info with PMU identification for the current logical CPU.
int perf_counter_config (uint32_t counter, perf_counter_evt_t event)
 Map hardware event counter counter to architectural event event.
void perf_counter_enable (uint32_t counter)
 Enable counting on hardware event counter counter.
void perf_counter_disable (uint32_t counter)
 Disable counting on hardware event counter counter.
void perf_counter_enable_all (void)
 Enable all implemented event counters (and the cycle counter where applicable).
void perf_counter_disable_all (void)
 Disable all event counters (and the cycle counter where applicable).
uint64_t perf_counter_read (uint32_t counter)
 Read the current value of hardware event counter counter.
void perf_counter_reset (uint32_t counter)
 Reset hardware event counter counter to zero.
void perf_counter_reset_all (void)
 Reset all hardware event counters to zero (implementation-defined; may include cycle counter policies).
uint64_t perf_counter_cycle_count (void)
 Read the architectural cycle count register (if implemented).
void perf_counter_cycle_reset (void)
 Reset the cycle count register to zero (implementation-defined).
void perf_counter_start (void)
 Start counting: enable the PMU globally (implementation-defined).
void perf_counter_stop (void)
 Stop counting: disable the PMU globally (implementation-defined).
bool perf_counter_overflow (uint32_t counter)
 Return whether hardware event counter counter has overflowed since the flag was cleared.
void perf_counter_clear_overflow (uint32_t counter)
 Clear the overflow flag for hardware event counter counter.

Detailed Description

Function Documentation

◆ perf_counter_clear_overflow()

void perf_counter_clear_overflow ( uint32_t counter)

#include <zephyr/arch/perf_counter.h>

Clear the overflow flag for hardware event counter counter.

Parameters
counterEvent counter index [0, perf_counter_num_counters()).

◆ perf_counter_config()

int perf_counter_config ( uint32_t counter,
perf_counter_evt_t event )

#include <zephyr/arch/perf_counter.h>

Map hardware event counter counter to architectural event event.

Parameters
counterEvent counter index in the range [0, perf_counter_num_counters()).
eventEvent selector (perf_counter_evt_t from the architecture supplement when present).
Returns
0 on success, negative errno on failure

◆ perf_counter_cycle_count()

uint64_t perf_counter_cycle_count ( void )

#include <zephyr/arch/perf_counter.h>

Read the architectural cycle count register (if implemented).

Returns
Cycle count, or 0 if unavailable

◆ perf_counter_cycle_reset()

void perf_counter_cycle_reset ( void )

#include <zephyr/arch/perf_counter.h>

Reset the cycle count register to zero (implementation-defined).

◆ perf_counter_disable()

void perf_counter_disable ( uint32_t counter)

#include <zephyr/arch/perf_counter.h>

Disable counting on hardware event counter counter.

Parameters
counterEvent counter index [0, perf_counter_num_counters()).

◆ perf_counter_disable_all()

void perf_counter_disable_all ( void )

#include <zephyr/arch/perf_counter.h>

Disable all event counters (and the cycle counter where applicable).

◆ perf_counter_enable()

void perf_counter_enable ( uint32_t counter)

#include <zephyr/arch/perf_counter.h>

Enable counting on hardware event counter counter.

Parameters
counterEvent counter index [0, perf_counter_num_counters()).

◆ perf_counter_enable_all()

void perf_counter_enable_all ( void )

#include <zephyr/arch/perf_counter.h>

Enable all implemented event counters (and the cycle counter where applicable).

◆ perf_counter_get_info()

void perf_counter_get_info ( perf_counter_info_t * info)

#include <zephyr/arch/perf_counter.h>

Fill info with PMU identification for the current logical CPU.

info must not be NULL. Fields are only meaningful after a successful perf_counter_init on this CPU; contents are backend-defined (see arch perf_counter_info_t).

◆ perf_counter_init()

int perf_counter_init ( void )

#include <zephyr/arch/perf_counter.h>

Initialize the PMU for the current logical CPU.

Architecture-neutral interface for hardware performance counters. Backends implement these functions for each supported architecture (for example ARMv8-A PMUv3 on AArch64, future ARMv8-R / Cortex-R52, RISC-V HPM CSRs, etc.).

Architectural event codes are defined by the architecture supplement (for example perf_counter_evt_t in <zephyr/arch/arm64/pmuv3.h> when CONFIG_ARM64 is enabled).

PMU is not initialized during kernel startup. Call perf_counter_init() before other perf_counter_*() functions on this CPU.

Call once per logical CPU that will use counters, before any other perf_counter_*() API on that CPU. Idempotent on success: later calls return 0 if this CPU already initialized successfully, or -ENOTSUP if this CPU recorded that no PMU is available.

PMU control and counters are per-CPU. On SMP, use the PMU only while running on the intended CPU — for example pin the thread with k_thread_cpu_pin() (requires CONFIG_SCHED_CPU_MASK), or constrain its CPU affinity with k_thread_cpu_mask_enable() / k_thread_cpu_mask_disable(), so it does not migrate during a measurement.

There is no SYS_INIT hook; callers choose when to probe (for example at the start of a benchmark).

Return values
0Success
-ENOTSUPNo PMU or not usable at this exception level on this CPU

◆ perf_counter_num_counters()

uint32_t perf_counter_num_counters ( void )

#include <zephyr/arch/perf_counter.h>

Returns
Number of event counters on this CPU, or 0 if PMU unavailable

◆ perf_counter_overflow()

bool perf_counter_overflow ( uint32_t counter)

#include <zephyr/arch/perf_counter.h>

Return whether hardware event counter counter has overflowed since the flag was cleared.

Parameters
counterEvent counter index [0, perf_counter_num_counters()).
Returns
true if overflow is pending, false otherwise or if PMU is unavailable

◆ perf_counter_read()

uint64_t perf_counter_read ( uint32_t counter)

#include <zephyr/arch/perf_counter.h>

Read the current value of hardware event counter counter.

Parameters
counterEvent counter index [0, perf_counter_num_counters()).
Returns
Counter value, or 0 if PMU is unavailable or counter is out of range

◆ perf_counter_reset()

void perf_counter_reset ( uint32_t counter)

#include <zephyr/arch/perf_counter.h>

Reset hardware event counter counter to zero.

Parameters
counterEvent counter index [0, perf_counter_num_counters()).

◆ perf_counter_reset_all()

void perf_counter_reset_all ( void )

#include <zephyr/arch/perf_counter.h>

Reset all hardware event counters to zero (implementation-defined; may include cycle counter policies).

◆ perf_counter_start()

void perf_counter_start ( void )

#include <zephyr/arch/perf_counter.h>

Start counting: enable the PMU globally (implementation-defined).

◆ perf_counter_stop()

void perf_counter_stop ( void )

#include <zephyr/arch/perf_counter.h>

Stop counting: disable the PMU globally (implementation-defined).