![]() |
|
|||
0001 /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 0002 0003 #ifndef __PERF_BPF_UTILS_H 0004 #define __PERF_BPF_UTILS_H 0005 0006 #define ptr_to_u64(ptr) ((__u64)(unsigned long)(ptr)) 0007 0008 #ifdef HAVE_LIBBPF_SUPPORT 0009 0010 #include <bpf/libbpf.h> 0011 0012 /* 0013 * Get bpf_prog_info in continuous memory 0014 * 0015 * struct bpf_prog_info has multiple arrays. The user has option to choose 0016 * arrays to fetch from kernel. The following APIs provide an uniform way to 0017 * fetch these data. All arrays in bpf_prog_info are stored in a single 0018 * continuous memory region. This makes it easy to store the info in a 0019 * file. 0020 * 0021 * Before writing perf_bpil to files, it is necessary to 0022 * translate pointers in bpf_prog_info to offsets. Helper functions 0023 * bpil_addr_to_offs() and bpil_offs_to_addr() 0024 * are introduced to switch between pointers and offsets. 0025 * 0026 * Examples: 0027 * # To fetch map_ids and prog_tags: 0028 * __u64 arrays = (1UL << PERF_BPIL_MAP_IDS) | 0029 * (1UL << PERF_BPIL_PROG_TAGS); 0030 * struct perf_bpil *info_linear = 0031 * get_bpf_prog_info_linear(fd, arrays); 0032 * 0033 * # To save data in file 0034 * bpil_addr_to_offs(info_linear); 0035 * write(f, info_linear, sizeof(*info_linear) + info_linear->data_len); 0036 * 0037 * # To read data from file 0038 * read(f, info_linear, <proper_size>); 0039 * bpil_offs_to_addr(info_linear); 0040 */ 0041 enum perf_bpil_array_types { 0042 PERF_BPIL_FIRST_ARRAY = 0, 0043 PERF_BPIL_JITED_INSNS = 0, 0044 PERF_BPIL_XLATED_INSNS, 0045 PERF_BPIL_MAP_IDS, 0046 PERF_BPIL_JITED_KSYMS, 0047 PERF_BPIL_JITED_FUNC_LENS, 0048 PERF_BPIL_FUNC_INFO, 0049 PERF_BPIL_LINE_INFO, 0050 PERF_BPIL_JITED_LINE_INFO, 0051 PERF_BPIL_PROG_TAGS, 0052 PERF_BPIL_LAST_ARRAY, 0053 }; 0054 0055 struct perf_bpil { 0056 /* size of struct bpf_prog_info, when the tool is compiled */ 0057 __u32 info_len; 0058 /* total bytes allocated for data, round up to 8 bytes */ 0059 __u32 data_len; 0060 /* which arrays are included in data */ 0061 __u64 arrays; 0062 struct bpf_prog_info info; 0063 __u8 data[]; 0064 }; 0065 0066 struct perf_bpil * 0067 get_bpf_prog_info_linear(int fd, __u64 arrays); 0068 0069 void 0070 bpil_addr_to_offs(struct perf_bpil *info_linear); 0071 0072 void 0073 bpil_offs_to_addr(struct perf_bpil *info_linear); 0074 0075 #endif /* HAVE_LIBBPF_SUPPORT */ 0076 #endif /* __PERF_BPF_UTILS_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |