Skip to content

Commit

Permalink
examples/perf/ipc: Use generic hardware events
Browse files Browse the repository at this point in the history
The use of hardcoded raw events breaks compatibility as these are tied
to specific processors. On other processors, it could also be the case
that the raw event codes represent something completely different.

Hence, use the generic events for cycles and instructions as these are
available on most platforms with a core PMU.

Fixes: 59a753d ("Add perf event data collection example for an userspace application")
Signed-off-by: Sandipan Das <[email protected]>
  • Loading branch information
sandip4n authored and yonghong-song committed Aug 20, 2023
1 parent b11d0f2 commit 652bf24
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions examples/perf/ipc.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,22 @@ def print_data(cpu, data, size):

b["output"].open_perf_buffer(print_data)

# Perf Event for Unhalted Cycles, The hex value is
# combination of event, umask and cmask. Read Intel
# Doc to find the event and cmask. Or use
# perf list --details to get event, umask and cmask
# Perf Events for Unhalted Cycles and Retired Instructions are supported on
# most platforms with a PMU and the kernel will attempt to translate these
# into an architecture-specific event code. For architectures that do not have
# these mappings, see perf list --details to find event details.
# NOTE: Events can be multiplexed by kernel in case the
# number of counters is greater than supported by CPU
# performance monitoring unit, which can result in inaccurate
# results. Counter values need to be normalized for a more
# accurate value.
PERF_TYPE_RAW = 4
PERF_TYPE_HARDWARE = 0
PERF_COUNT_HW_CPU_CYCLES = 0
PERF_COUNT_HW_INSTRUCTIONS = 1
# Unhalted Clock Cycles
b["clk"].open_perf_event(PERF_TYPE_RAW, 0x0000003C)
b["clk"].open_perf_event(PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES)
# Instruction Retired
b["inst"].open_perf_event(PERF_TYPE_RAW, 0x000000C0)
b["inst"].open_perf_event(PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS)

while True:
try:
Expand Down

0 comments on commit 652bf24

Please sign in to comment.