@cryptotaxi247 / netdata-1 / commits / c2c0b6887

Fix cachestat on kernel 5.15.x (eBPF) (#11833)

thiagoftsm committed Jan 10, 2022 at 13:11 UTC c2c0b688726fdf6ce4cd77449cb58b87e23769b7
5 files changed +36 -16
collectors/ebpf.plugin/ebpf_mdflush.c
+7
@@ -294,6 +294,13 @@ void *ebpf_mdflush_thread(void *ptr)
294 ebpf_module_t *em = (ebpf_module_t *)ptr;
295 em->maps = mdflush_maps;
296
297 + char *md_flush_request = ebpf_find_symbol("md_flush_request");
298 + if (!md_flush_request) {
299 + em->enabled = CONFIG_BOOLEAN_NO;
300 + error("Cannot monitor MD devices, because md is not loaded.");
301 + }
302 + freez(md_flush_request);
303 +
304 if (!em->enabled) {
305 goto endmdflush;
306 }
libnetdata/ebpf/ebpf.c
+17 -12
@@ -257,7 +257,9 @@ char *ebpf_kernel_suffix(int version, int isrh)
257 else
258 return "3.10";
259 } else {
260 - if (version >= NETDATA_EBPF_KERNEL_5_11)
260 + if (version >= NETDATA_EBPF_KERNEL_5_15)
261 + return "5.15";
262 + else if (version >= NETDATA_EBPF_KERNEL_5_11)
263 return "5.11";
264 else if (version >= NETDATA_EBPF_KERNEL_5_10)
265 return "5.10";
@@ -375,18 +377,21 @@ static struct bpf_link **ebpf_attach_programs(struct bpf_object *obj, size_t len
377 struct bpf_link **links = callocz(length , sizeof(struct bpf_link *));
378 size_t i = 0;
379 struct bpf_program *prog;
380 + ebpf_specify_name_t *w;
381 bpf_object__for_each_program(prog, obj)
382 {
380 - links[i] = bpf_program__attach(prog);
381 - if (libbpf_get_error(links[i]) && names) {
383 + if (names) {
384 const char *name = bpf_program__name(prog);
383 - ebpf_specify_name_t *w = ebpf_find_names(names, name);
384 - if (w) {
385 - enum bpf_prog_type type = bpf_program__get_type(prog);
386 - if (type == BPF_PROG_TYPE_KPROBE)
387 - links[i] = bpf_program__attach_kprobe(prog, w->retprobe, w->optional);
388 - }
389 - }
385 + w = ebpf_find_names(names, name);
386 + } else
387 + w = NULL;
388 +
389 + if (w) {
390 + enum bpf_prog_type type = bpf_program__get_type(prog);
391 + if (type == BPF_PROG_TYPE_KPROBE)
392 + links[i] = bpf_program__attach_kprobe(prog, w->retprobe, w->optional);
393 + } else
394 + links[i] = bpf_program__attach(prog);
395
396 if (libbpf_get_error(links[i])) {
397 links[i] = NULL;
@@ -483,7 +488,7 @@ struct bpf_link **ebpf_load_program(char *plugins_dir, ebpf_module_t *em, char *
488 return ebpf_attach_programs(*obj, count_programs, em->names);
489 }
490
486 -static char *ebpf_update_name(char *search)
491 +char *ebpf_find_symbol(char *search)
492 {
493 char filename[FILENAME_MAX + 1];
494 char *ret = NULL;
@@ -521,7 +526,7 @@ void ebpf_update_names(ebpf_specify_name_t *opt, ebpf_module_t *em)
526 size_t i = 0;
527 while (opt[i].program_name) {
528 opt[i].retprobe = (mode == MODE_RETURN);
524 - opt[i].optional = ebpf_update_name(opt[i].function_to_attach);
529 + opt[i].optional = ebpf_find_symbol(opt[i].function_to_attach);
530
531 i++;
532 }
libnetdata/ebpf/ebpf.h
+8
@@ -45,6 +45,13 @@
45 */
46 #define NETDATA_RH_8 2048
47
48 +/**
49 + * Kernel 5.15
50 + *
51 + * 331520 = 5*65536 + 15*256
52 + */
53 +#define NETDATA_EBPF_KERNEL_5_15 331520
54 +
55 /**
56 * Kernel 5.11
57 *
@@ -182,6 +189,7 @@ extern void ebpf_mount_config_name(char *filename, size_t length, char *path, co
189 extern int ebpf_load_config(struct config *config, char *filename);
190 extern void ebpf_update_module(ebpf_module_t *em);
191 extern void ebpf_update_names(ebpf_specify_name_t *opt, ebpf_module_t *em);
192 +extern char *ebpf_find_symbol(char *search);
193 extern void ebpf_load_addresses(ebpf_addresses_t *fa, int fd);
194 extern void ebpf_fill_algorithms(int *algorithms, size_t length, int algorithm);
195 extern char **ebpf_fill_histogram_dimension(size_t maximum);
packaging/ebpf.checksums
+3 -3
@@ -1,3 +1,3 @@
1 -7ffd13d0f32df93bc7868a7cf040e75c40a9e041f6bb7f4a591cc6ce71b1cf72 netdata-kernel-collector-glibc-v0.8.6.tar.xz
2 -05c10d57252941b7f6dbb8a726a243416942c58738015014dd764b4bcb0c2f9c netdata-kernel-collector-musl-v0.8.6.tar.xz
3 -2a607729a9093538624a94dfdbf2a3660eb4eb199f86962d38806d8e1e420a71 netdata-kernel-collector-static-v0.8.6.tar.xz
1 +44f21082c348b81f73034a986904207ee050379d51d6a6733a71323f2d36c8dd netdata-kernel-collector-glibc-v0.9.0.tar.xz
2 +9589070de6b7fe29fb0ea8f23394625c2887ddf3007bca9e65cfdb11ce41a7f7 netdata-kernel-collector-musl-v0.9.0.tar.xz
3 +f39c5c97f10d08ce72551a64aef8f9264346608e7d215afc910a5fe2158db868 netdata-kernel-collector-static-v0.9.0.tar.xz
packaging/ebpf.version
+1 -1
@@ -1 +1 @@
1 -v0.8.6
1 +v0.9.0