• Daniel Borkmann's avatar
    bpf, libbpf: simplify and cleanup perf ring buffer walk · 3dca2115
    Daniel Borkmann authored
    Simplify bpf_perf_event_read_simple() a bit and fix up some minor
    things along the way: the return code in the header is not of type
    int but enum bpf_perf_event_ret instead. Once callback indicated
    to break the loop walking event data, it also needs to be consumed
    in data_tail since it has been processed already.
    
    Moreover, bpf_perf_event_print_t callback should avoid void * as
    we actually get a pointer to struct perf_event_header and thus
    applications can make use of container_of() to have type checks.
    The walk also doesn't have to use modulo op since the ring size is
    required to be power of two.
    Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
    Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    3dca2115
libbpf.h 11.8 KB