mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-30 08:02:30 +00:00
6ac22d036f
To prepare for impending deprecation of libbpf's bpf_program__get_prog_info_linear(), pull in the function and associated helpers into the perf codebase and migrate existing uses to the perf copy. Since libbpf's deprecated definitions will still be visible to perf, it is necessary to rename perf's definitions. Signed-off-by: Dave Marchevsky <davemarchevsky@fb.com> Acked-by: Andrii Nakryiko <andrii@kernel.org> Acked-by: Song Liu <songliubraving@fb.com> Cc: Alexei Starovoitov <ast@kernel.org> Cc: Daniel Borkmann <daniel@iogearbox.net> Cc: Ingo Molnar <mingo@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Link: https://lore.kernel.org/r/20211011082031.4148337-4-davemarchevsky@fb.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
76 lines
2.1 KiB
C
76 lines
2.1 KiB
C
/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
|
|
|
|
#ifndef __PERF_BPF_UTILS_H
|
|
#define __PERF_BPF_UTILS_H
|
|
|
|
#define ptr_to_u64(ptr) ((__u64)(unsigned long)(ptr))
|
|
|
|
#ifdef HAVE_LIBBPF_SUPPORT
|
|
|
|
#include <bpf/libbpf.h>
|
|
|
|
/*
|
|
* Get bpf_prog_info in continuous memory
|
|
*
|
|
* struct bpf_prog_info has multiple arrays. The user has option to choose
|
|
* arrays to fetch from kernel. The following APIs provide an uniform way to
|
|
* fetch these data. All arrays in bpf_prog_info are stored in a single
|
|
* continuous memory region. This makes it easy to store the info in a
|
|
* file.
|
|
*
|
|
* Before writing perf_bpil to files, it is necessary to
|
|
* translate pointers in bpf_prog_info to offsets. Helper functions
|
|
* bpil_addr_to_offs() and bpil_offs_to_addr()
|
|
* are introduced to switch between pointers and offsets.
|
|
*
|
|
* Examples:
|
|
* # To fetch map_ids and prog_tags:
|
|
* __u64 arrays = (1UL << PERF_BPIL_MAP_IDS) |
|
|
* (1UL << PERF_BPIL_PROG_TAGS);
|
|
* struct perf_bpil *info_linear =
|
|
* get_bpf_prog_info_linear(fd, arrays);
|
|
*
|
|
* # To save data in file
|
|
* bpil_addr_to_offs(info_linear);
|
|
* write(f, info_linear, sizeof(*info_linear) + info_linear->data_len);
|
|
*
|
|
* # To read data from file
|
|
* read(f, info_linear, <proper_size>);
|
|
* bpil_offs_to_addr(info_linear);
|
|
*/
|
|
enum perf_bpil_array_types {
|
|
PERF_BPIL_FIRST_ARRAY = 0,
|
|
PERF_BPIL_JITED_INSNS = 0,
|
|
PERF_BPIL_XLATED_INSNS,
|
|
PERF_BPIL_MAP_IDS,
|
|
PERF_BPIL_JITED_KSYMS,
|
|
PERF_BPIL_JITED_FUNC_LENS,
|
|
PERF_BPIL_FUNC_INFO,
|
|
PERF_BPIL_LINE_INFO,
|
|
PERF_BPIL_JITED_LINE_INFO,
|
|
PERF_BPIL_PROG_TAGS,
|
|
PERF_BPIL_LAST_ARRAY,
|
|
};
|
|
|
|
struct perf_bpil {
|
|
/* size of struct bpf_prog_info, when the tool is compiled */
|
|
__u32 info_len;
|
|
/* total bytes allocated for data, round up to 8 bytes */
|
|
__u32 data_len;
|
|
/* which arrays are included in data */
|
|
__u64 arrays;
|
|
struct bpf_prog_info info;
|
|
__u8 data[];
|
|
};
|
|
|
|
struct perf_bpil *
|
|
get_bpf_prog_info_linear(int fd, __u64 arrays);
|
|
|
|
void
|
|
bpil_addr_to_offs(struct perf_bpil *info_linear);
|
|
|
|
void
|
|
bpil_offs_to_addr(struct perf_bpil *info_linear);
|
|
|
|
#endif /* HAVE_LIBBPF_SUPPORT */
|
|
#endif /* __PERF_BPF_UTILS_H */
|