Helper function bpf_perf_event_read
This helper reads the value of a perf event counter.
Definition
Copyright (c) 2015 The Libbpf Authors. All rights reserved.
Returns The value of the perf event counter read from the map, or a negative error code in case of failure.
static __u64 (* const bpf_perf_event_read)(void *map, __u64 flags) = (void *) 22;
Usage
This helper relies on a map
of type BPF_MAP_TYPE_PERF_EVENT_ARRAY
. The nature of the perf event counter is selected when map
is updated with perf event file descriptors. The map
is an array whose size is the number of available CPUs, and each cell contains a value relative to one CPU. The value to retrieve is indicated by flags
, that contains the index of the CPU to look up, masked with BPF_F_INDEX_MASK
. Alternatively, flags
can be set to BPF_F_CURRENT_CPU
to indicate that the value for the current CPU should be retrieved.
Note
before Linux 4.13, only hardware perf event can be retrieved.
Also, be aware that the newer helper bpf_perf_event_read_value
is recommended over bpf_perf_event_read
in general. The latter has some ABI quirks where error and counter value are used as a return code (which is wrong to do since ranges may overlap). This issue is fixed with bpf_perf_event_read_value
, which at the same time provides more features over the bpf_perf_event_read
interface. Please refer to the page of bpf_perf_event_read_value
for details.
Program types
This helper call can be used in the following program types:
BPF_PROG_TYPE_KPROBE
BPF_PROG_TYPE_LSM
BPF_PROG_TYPE_PERF_EVENT
BPF_PROG_TYPE_RAW_TRACEPOINT
BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE
BPF_PROG_TYPE_SYSCALL
BPF_PROG_TYPE_TRACEPOINT
BPF_PROG_TYPE_TRACING
Map types
This helper call can be used with the following map types:
Example
Docs could be improved
This part of the docs is incomplete, contributions are very welcome