Performance counters

group Perf

This API gives access to the core performance counters. Each core has a few performance counters which can be configured to count one event out of several available. An event is a cycle, an instruction, a cache miss and so on. The number of counters limits the number of events which can be monitored at the same time and depends on the platform. Real chips have only 1 counter while other platforms have one per event.

In addition, this API uses a few other HW mechanisms useful for monitoring performance such as timers.

Functions

static inline void pi_perf_conf(uint32_t events)

Configure performance counters.

The set of events which can be activated at the same time depends on the platform. On real chips (rather than with the simulator), there is always only one counter. It is advisable to always use only one to be compatible with simulator and chip. At least PI_PERF_CYCLES and another event can be monitored at the same time as the first one is using the timer. This API can be called both from fabric-controller or cluster side.

Parameters:
  • events – A mask containing the events to activate. Bit positions in the mas are defined by pi_perf_event_e. For example, to activate “cycles” event counter, add (1 << PI_PERF_CYCLES) to the mask.

static inline void pi_perf_reset()

Reset all hardware performance counters.

All hardware performance counters are set to 0, except the time, as it is a shared resource within the cluster. This API can be called both from fabric-controller or cluster side.

static inline void pi_perf_start()

Start monitoring configured events.

This function is useful for finely controlling the point where performance events start being monitored. The counter retains its value between stop and start so it is possible to easily sum events for several portions of code. This API can be called both from fabric-controller or cluster side.

static inline void pi_perf_stop()

Stop monitoring configured events.

This API can be called both from fabric-controller or cluster side.

static inline uint32_t pi_perf_read(pi_perf_event_e id)

Read a performance counter.

This does a direct read of the specified performance counter. Calling this function is useful for getting the performance counter with very low overhead (just few instructions). This API can be called both from fabric-controller or cluster side.

Parameters:
  • id – The performance event identifier to read (see pi_perf_event_e).

Returns:

The performance counter value.