diff options
author | thiagoftsm <thiagoftsm@gmail.com> | 2022-01-10 13:11:59 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-10 13:11:59 +0000 |
commit | c2c0b688726fdf6ce4cd77449cb58b87e23769b7 (patch) | |
tree | f4e07b66eadef4f94143bfd4adb84d27186571bd /libnetdata/ebpf | |
parent | eebcb8520c526523a0a471887783ba63392d7e24 (diff) |
Fix cachestat on kernel 5.15.x (eBPF) (#11833)
Diffstat (limited to 'libnetdata/ebpf')
-rw-r--r-- | libnetdata/ebpf/ebpf.c | 29 | ||||
-rw-r--r-- | libnetdata/ebpf/ebpf.h | 8 |
2 files changed, 25 insertions, 12 deletions
diff --git a/libnetdata/ebpf/ebpf.c b/libnetdata/ebpf/ebpf.c index 1ccaa7b417..3aef243a47 100644 --- a/libnetdata/ebpf/ebpf.c +++ b/libnetdata/ebpf/ebpf.c @@ -257,7 +257,9 @@ char *ebpf_kernel_suffix(int version, int isrh) else return "3.10"; } else { - if (version >= NETDATA_EBPF_KERNEL_5_11) + if (version >= NETDATA_EBPF_KERNEL_5_15) + return "5.15"; + else if (version >= NETDATA_EBPF_KERNEL_5_11) return "5.11"; else if (version >= NETDATA_EBPF_KERNEL_5_10) return "5.10"; @@ -375,18 +377,21 @@ static struct bpf_link **ebpf_attach_programs(struct bpf_object *obj, size_t len struct bpf_link **links = callocz(length , sizeof(struct bpf_link *)); size_t i = 0; struct bpf_program *prog; + ebpf_specify_name_t *w; bpf_object__for_each_program(prog, obj) { - links[i] = bpf_program__attach(prog); - if (libbpf_get_error(links[i]) && names) { + if (names) { const char *name = bpf_program__name(prog); - ebpf_specify_name_t *w = ebpf_find_names(names, name); - if (w) { - enum bpf_prog_type type = bpf_program__get_type(prog); - if (type == BPF_PROG_TYPE_KPROBE) - links[i] = bpf_program__attach_kprobe(prog, w->retprobe, w->optional); - } - } + w = ebpf_find_names(names, name); + } else + w = NULL; + + if (w) { + enum bpf_prog_type type = bpf_program__get_type(prog); + if (type == BPF_PROG_TYPE_KPROBE) + links[i] = bpf_program__attach_kprobe(prog, w->retprobe, w->optional); + } else + links[i] = bpf_program__attach(prog); if (libbpf_get_error(links[i])) { links[i] = NULL; @@ -483,7 +488,7 @@ struct bpf_link **ebpf_load_program(char *plugins_dir, ebpf_module_t *em, char * return ebpf_attach_programs(*obj, count_programs, em->names); } -static char *ebpf_update_name(char *search) +char *ebpf_find_symbol(char *search) { char filename[FILENAME_MAX + 1]; char *ret = NULL; @@ -521,7 +526,7 @@ void ebpf_update_names(ebpf_specify_name_t *opt, ebpf_module_t *em) size_t i = 0; while (opt[i].program_name) { opt[i].retprobe = (mode == MODE_RETURN); - opt[i].optional = ebpf_update_name(opt[i].function_to_attach); + opt[i].optional = ebpf_find_symbol(opt[i].function_to_attach); i++; } diff --git a/libnetdata/ebpf/ebpf.h b/libnetdata/ebpf/ebpf.h index 73128f529b..1da28d4cb3 100644 --- a/libnetdata/ebpf/ebpf.h +++ b/libnetdata/ebpf/ebpf.h @@ -46,6 +46,13 @@ #define NETDATA_RH_8 2048 /** + * Kernel 5.15 + * + * 331520 = 5*65536 + 15*256 + */ +#define NETDATA_EBPF_KERNEL_5_15 331520 + +/** * Kernel 5.11 * * 330240 = 5*65536 + 11*256 @@ -182,6 +189,7 @@ extern void ebpf_mount_config_name(char *filename, size_t length, char *path, co extern int ebpf_load_config(struct config *config, char *filename); extern void ebpf_update_module(ebpf_module_t *em); extern void ebpf_update_names(ebpf_specify_name_t *opt, ebpf_module_t *em); +extern char *ebpf_find_symbol(char *search); extern void ebpf_load_addresses(ebpf_addresses_t *fa, int fd); extern void ebpf_fill_algorithms(int *algorithms, size_t length, int algorithm); extern char **ebpf_fill_histogram_dimension(size_t maximum); |