@cryptotaxi247 / netdata-1 / commits / b20911cbd

Remove sync warning (#12831)

thiagoftsm committed May 6, 2022 at 13:43 UTC b20911cbda25a265ac492bbed1bd44ab9d8a7526
5 files changed +121 -34
collectors/ebpf.plugin/ebpf.c
+2 -19
@@ -1172,23 +1172,6 @@ static inline void epbf_update_load_mode(char *str)
1172 ebpf_set_load_mode(load);
1173 }
1174
1175 -#ifdef LIBBPF_MAJOR_VERSION
1176 -/**
1177 - * Set default btf file
1178 - *
1179 - * Load the default BTF file on environment.
1180 - */
1181 -static void ebpf_set_default_btf_file()
1182 -{
1183 - char path[PATH_MAX + 1];
1184 - snprintfz(path, PATH_MAX, "%s/vmlinux", btf_path);
1185 - default_btf = ebpf_parse_btf_file(path);
1186 - if (!default_btf)
1187 - info("Your environment does not have BTF file %s/vmlinux. The plugin will work with 'legacy' code.",
1188 - btf_path);
1189 -}
1190 -#endif
1191 -
1175 /**
1176 * Read collector values
1177 *
@@ -1210,10 +1193,10 @@ static void read_collector_values(int *disable_apps, int *disable_cgroups, int u
1193 how_to_load(value);
1194
1195 btf_path = appconfig_get(&collector_config, EBPF_GLOBAL_SECTION, EBPF_CFG_PROGRAM_PATH,
1213 - EBPF_DEFAULT_BTF_FILE);
1196 + EBPF_DEFAULT_BTF_PATH);
1197
1198 #ifdef LIBBPF_MAJOR_VERSION
1216 - ebpf_set_default_btf_file();
1199 + default_btf = ebpf_load_btf_file(btf_path, EBPF_DEFAULT_BTF_FILE);
1200 #endif
1201
1202 value = appconfig_get(&collector_config, EBPF_GLOBAL_SECTION, EBPF_CFG_TYPE_FORMAT, EBPF_CFG_DEFAULT_PROGRAM);
collectors/ebpf.plugin/ebpf.d.conf
+1
@@ -21,6 +21,7 @@
21 cgroups = no
22 update every = 5
23 pid table size = 32768
24 + btf path = /sys/kernel/btf/
25
26 #
27 # eBPF Programs
collectors/ebpf.plugin/ebpf_sync.c
+43 -12
@@ -44,13 +44,41 @@ struct config sync_config = { .first_section = NULL,
44 .rwlock = AVL_LOCK_INITIALIZER } };
45
46 ebpf_sync_syscalls_t local_syscalls[] = {
47 - {.syscall = NETDATA_SYSCALLS_SYNC, .enabled = CONFIG_BOOLEAN_YES, .objects = NULL, .probe_links = NULL},
48 - {.syscall = NETDATA_SYSCALLS_SYNCFS, .enabled = CONFIG_BOOLEAN_YES, .objects = NULL, .probe_links = NULL},
49 - {.syscall = NETDATA_SYSCALLS_MSYNC, .enabled = CONFIG_BOOLEAN_YES, .objects = NULL, .probe_links = NULL},
50 - {.syscall = NETDATA_SYSCALLS_FSYNC, .enabled = CONFIG_BOOLEAN_YES, .objects = NULL, .probe_links = NULL},
51 - {.syscall = NETDATA_SYSCALLS_FDATASYNC, .enabled = CONFIG_BOOLEAN_YES, .objects = NULL, .probe_links = NULL},
52 - {.syscall = NETDATA_SYSCALLS_SYNC_FILE_RANGE, .enabled = CONFIG_BOOLEAN_YES, .objects = NULL, .probe_links = NULL},
53 - {.syscall = NULL, .enabled = CONFIG_BOOLEAN_NO, .objects = NULL, .probe_links = NULL}
47 + {.syscall = NETDATA_SYSCALLS_SYNC, .enabled = CONFIG_BOOLEAN_YES, .objects = NULL, .probe_links = NULL,
48 +#ifdef LIBBPF_MAJOR_VERSION
49 + .sync_obj = NULL
50 +#endif
51 + },
52 + {.syscall = NETDATA_SYSCALLS_SYNCFS, .enabled = CONFIG_BOOLEAN_YES, .objects = NULL, .probe_links = NULL,
53 +#ifdef LIBBPF_MAJOR_VERSION
54 + .sync_obj = NULL
55 +#endif
56 + },
57 + {.syscall = NETDATA_SYSCALLS_MSYNC, .enabled = CONFIG_BOOLEAN_YES, .objects = NULL, .probe_links = NULL,
58 +#ifdef LIBBPF_MAJOR_VERSION
59 + .sync_obj = NULL
60 +#endif
61 + },
62 + {.syscall = NETDATA_SYSCALLS_FSYNC, .enabled = CONFIG_BOOLEAN_YES, .objects = NULL, .probe_links = NULL,
63 +#ifdef LIBBPF_MAJOR_VERSION
64 + .sync_obj = NULL
65 +#endif
66 + },
67 + {.syscall = NETDATA_SYSCALLS_FDATASYNC, .enabled = CONFIG_BOOLEAN_YES, .objects = NULL, .probe_links = NULL,
68 +#ifdef LIBBPF_MAJOR_VERSION
69 + .sync_obj = NULL
70 +#endif
71 + },
72 + {.syscall = NETDATA_SYSCALLS_SYNC_FILE_RANGE, .enabled = CONFIG_BOOLEAN_YES, .objects = NULL, .probe_links = NULL,
73 +#ifdef LIBBPF_MAJOR_VERSION
74 + .sync_obj = NULL
75 +#endif
76 + },
77 + {.syscall = NULL, .enabled = CONFIG_BOOLEAN_NO, .objects = NULL, .probe_links = NULL,
78 +#ifdef LIBBPF_MAJOR_VERSION
79 + .sync_obj = NULL
80 +#endif
81 + }
82 };
83
84 netdata_ebpf_targets_t sync_targets[] = { {.name = NETDATA_SYSCALLS_SYNC, .mode = EBPF_LOAD_TRAMPOLINE},
@@ -228,7 +256,7 @@ static int ebpf_sync_initialize_syscall(ebpf_module_t *em)
256 {
257 int i;
258 const char *saved_name = em->thread_name;
231 - sync_syscalls_index_t errors = 0;
259 + int errors = 0;
260 for (i = 0; local_syscalls[i].syscall; i++) {
261 ebpf_sync_syscalls_t *w = &local_syscalls[i];
262 if (w->enabled) {
@@ -246,12 +274,15 @@ static int ebpf_sync_initialize_syscall(ebpf_module_t *em)
274 if (!w->sync_obj) {
275 errors++;
276 } else {
249 - if (ebpf_sync_load_and_attach(w->sync_obj, em, syscall, i)) {
277 + if (ebpf_is_function_inside_btf(default_btf, syscall)) {
278 + if (ebpf_sync_load_and_attach(w->sync_obj, em, syscall, i)) {
279 + errors++;
280 + }
281 + } else {
282 if (ebpf_sync_load_legacy(w, em))
283 errors++;
252 -
253 - em->thread_name = saved_name;
284 }
285 + em->thread_name = saved_name;
286 }
287 }
288 #endif
@@ -263,7 +294,7 @@ static int ebpf_sync_initialize_syscall(ebpf_module_t *em)
294 memset(sync_counter_publish_aggregated, 0 , NETDATA_SYNC_IDX_END * sizeof(netdata_publish_syscall_t));
295 memset(sync_hash_values, 0 , NETDATA_SYNC_IDX_END * sizeof(netdata_idx_t));
296
266 - return 0;
297 + return (errors) ? -1 : 0;
298 }
299
300 /*****************************************************************
libnetdata/ebpf/ebpf.c
+71 -2
@@ -843,9 +843,13 @@ void ebpf_adjust_thread_load(ebpf_module_t *mod, struct btf *file)
843 }
844
845 /**
846 + * Parse BTF file
847 *
847 - * @param filename
848 - * @return
848 + * Parse a specific BTF file present on filesystem
849 + *
850 + * @param filename the file that will be parsed.
851 + *
852 + * @return It returns a pointer for the file on success and NULL otherwise.
853 */
854 struct btf *ebpf_parse_btf_file(const char *filename)
855 {
@@ -858,6 +862,71 @@ struct btf *ebpf_parse_btf_file(const char *filename)
862
863 return bf;
864 }
865 +
866 +/**
867 + * Load default btf file
868 + *
869 + * Load the default BTF file on environment.
870 + *
871 + * @param path is the fullpath
872 + * @param filename is the file inside BTF path.
873 + */
874 +struct btf *ebpf_load_btf_file(char *path, char *filename)
875 +{
876 + char fullpath[PATH_MAX + 1];
877 + snprintfz(fullpath, PATH_MAX, "%s/%s", path, filename);
878 + struct btf *ret = ebpf_parse_btf_file(fullpath);
879 + if (!ret)
880 + info("Your environment does not have BTF file %s/%s. The plugin will work with 'legacy' code.",
881 + path, filename);
882 +
883 + return ret;
884 +}
885 +
886 +/**
887 + * Find BTF attach type
888 + *
889 + * Search type fr current btf file.
890 + *
891 + * @param file is the structure for the btf file already parsed.
892 + */
893 +static inline const struct btf_type *ebpf_find_btf_attach_type(struct btf *file)
894 +{
895 + int id = btf__find_by_name_kind(file, "bpf_attach_type", BTF_KIND_ENUM);
896 + if (id < 0) {
897 + fprintf(stderr, "Cannot find 'bpf_attach_type'");
898 +
899 + return NULL;
900 + }
901 +
902 + return btf__type_by_id(file, id);
903 +}
904 +
905 +/**
906 + * Is function inside BTF
907 + *
908 + * Look for a specific function inside the given BTF file.
909 + *
910 + * @param file is the structure for the btf file already parsed.
911 + * @param function is the function that we want to find.
912 + */
913 +int ebpf_is_function_inside_btf(struct btf *file, char *function)
914 +{
915 + const struct btf_type *type = ebpf_find_btf_attach_type(file);
916 + if (!type)
917 + return -1;
918 +
919 + const struct btf_enum *e = btf_enum(type);
920 + int i, id;
921 + for (id = -1, i = 0; i < btf_vlen(type); i++, e++) {
922 + if (!strcmp(btf__name_by_offset(file, e->name_off), "BPF_TRACE_FENTRY")) {
923 + id = btf__find_by_name_kind(file, function, BTF_KIND_FUNC);
924 + break;
925 + }
926 + }
927 +
928 + return (id > 0) ? 1 : 0;
929 +}
930 #endif
931
932 /**
libnetdata/ebpf/ebpf.h
+4 -1
@@ -275,7 +275,8 @@ extern int ebpf_enable_tracing_values(char *subsys, char *eventname);
275 extern int ebpf_disable_tracing_values(char *subsys, char *eventname);
276
277 // BTF Section
278 -#define EBPF_DEFAULT_BTF_FILE "/sys/kernel/btf"
278 +#define EBPF_DEFAULT_BTF_FILE "vmlinux"
279 +#define EBPF_DEFAULT_BTF_PATH "/sys/kernel/btf"
280 #define EBPF_DEFAULT_ERROR_MSG "Cannot open or load BPF file for thread"
281
282 // BTF helpers
@@ -287,6 +288,8 @@ extern void ebpf_select_host_prefix(char *output, size_t length, char *syscall,
288 #ifdef LIBBPF_MAJOR_VERSION
289 extern void ebpf_adjust_thread_load(ebpf_module_t *mod, struct btf *file);
290 extern struct btf *ebpf_parse_btf_file(const char *filename);
291 +extern struct btf *ebpf_load_btf_file(char *path, char *filename);
292 +extern int ebpf_is_function_inside_btf(struct btf *file, char *function);
293 #endif
294
295 #endif /* NETDATA_EBPF_H */