diff options
-rw-r--r-- | collectors/ebpf.plugin/ebpf.h | 3 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_cachestat.c | 63 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_cachestat.h | 4 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_dcstat.c | 3 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_disk.c | 3 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_fd.c | 68 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_fd.h | 8 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_filesystem.c | 3 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_hardirq.c | 3 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_mdflush.c | 3 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_mount.c | 3 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_process.c | 3 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_shm.c | 3 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_socket.c | 3 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_softirq.c | 3 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_swap.c | 3 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_sync.c | 3 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_vfs.c | 3 | ||||
-rw-r--r-- | libnetdata/ebpf/ebpf.c | 17 |
19 files changed, 147 insertions, 55 deletions
diff --git a/collectors/ebpf.plugin/ebpf.h b/collectors/ebpf.plugin/ebpf.h index 28b04ce480..16e62498c4 100644 --- a/collectors/ebpf.plugin/ebpf.h +++ b/collectors/ebpf.plugin/ebpf.h @@ -123,6 +123,9 @@ enum ebpf_threads_status { #endif #endif +// Messages +#define NETDATA_EBPF_DEFAULT_FNT_NOT_FOUND "Cannot find the necessary functions to monitor" + // Chart definitions #define NETDATA_EBPF_FAMILY "ebpf" #define NETDATA_EBPF_IP_FAMILY "ip" diff --git a/collectors/ebpf.plugin/ebpf_cachestat.c b/collectors/ebpf.plugin/ebpf_cachestat.c index 4c410647d3..6914d141ad 100644 --- a/collectors/ebpf.plugin/ebpf_cachestat.c +++ b/collectors/ebpf.plugin/ebpf_cachestat.c @@ -51,6 +51,9 @@ netdata_ebpf_targets_t cachestat_targets[] = { {.name = "add_to_page_cache_lru", {.name = "mark_buffer_dirty", .mode = EBPF_LOAD_TRAMPOLINE}, {.name = NULL, .mode = EBPF_LOAD_TRAMPOLINE}}; +static char *account_page[NETDATA_CACHESTAT_ACCOUNT_DIRTY_END] ={ "account_page_dirtied", + "__set_page_dirty", "__folio_mark_dirty" }; + #ifdef LIBBPF_MAJOR_VERSION #include "includes/cachestat.skel.h" // BTF code @@ -83,10 +86,12 @@ static void ebpf_cachestat_disable_probe(struct cachestat_bpf *obj) */ static void ebpf_cachestat_disable_specific_probe(struct cachestat_bpf *obj) { - if (running_on_kernel >= NETDATA_EBPF_KERNEL_5_16) { + if (!strcmp(cachestat_targets[NETDATA_KEY_CALLS_ACCOUNT_PAGE_DIRTIED].name, + account_page[NETDATA_CACHESTAT_FOLIO_DIRTY])) { bpf_program__set_autoload(obj->progs.netdata_account_page_dirtied_kprobe, false); bpf_program__set_autoload(obj->progs.netdata_set_page_dirty_kprobe, false); - } else if (running_on_kernel >= NETDATA_EBPF_KERNEL_5_15) { + } else if (!strcmp(cachestat_targets[NETDATA_KEY_CALLS_ACCOUNT_PAGE_DIRTIED].name, + account_page[NETDATA_CACHESTAT_SET_PAGE_DIRTY])) { bpf_program__set_autoload(obj->progs.netdata_folio_mark_dirty_kprobe, false); bpf_program__set_autoload(obj->progs.netdata_account_page_dirtied_kprobe, false); } else { @@ -122,10 +127,12 @@ static void ebpf_cachestat_disable_trampoline(struct cachestat_bpf *obj) */ static void ebpf_cachestat_disable_specific_trampoline(struct cachestat_bpf *obj) { - if (running_on_kernel >= NETDATA_EBPF_KERNEL_5_16) { + if (!strcmp(cachestat_targets[NETDATA_KEY_CALLS_ACCOUNT_PAGE_DIRTIED].name, + account_page[NETDATA_CACHESTAT_FOLIO_DIRTY])) { bpf_program__set_autoload(obj->progs.netdata_account_page_dirtied_fentry, false); bpf_program__set_autoload(obj->progs.netdata_set_page_dirty_fentry, false); - } else if (running_on_kernel >= NETDATA_EBPF_KERNEL_5_15) { + } else if (!strcmp(cachestat_targets[NETDATA_KEY_CALLS_ACCOUNT_PAGE_DIRTIED].name, + account_page[NETDATA_CACHESTAT_SET_PAGE_DIRTY])) { bpf_program__set_autoload(obj->progs.netdata_folio_mark_dirty_fentry, false); bpf_program__set_autoload(obj->progs.netdata_account_page_dirtied_fentry, false); } else { @@ -149,10 +156,12 @@ static inline void netdata_set_trampoline_target(struct cachestat_bpf *obj) bpf_program__set_attach_target(obj->progs.netdata_mark_page_accessed_fentry, 0, cachestat_targets[NETDATA_KEY_CALLS_MARK_PAGE_ACCESSED].name); - if (running_on_kernel >= NETDATA_EBPF_KERNEL_5_16) { + if (!strcmp(cachestat_targets[NETDATA_KEY_CALLS_ACCOUNT_PAGE_DIRTIED].name, + account_page[NETDATA_CACHESTAT_FOLIO_DIRTY])) { bpf_program__set_attach_target(obj->progs.netdata_folio_mark_dirty_fentry, 0, cachestat_targets[NETDATA_KEY_CALLS_ACCOUNT_PAGE_DIRTIED].name); - } else if (running_on_kernel >= NETDATA_EBPF_KERNEL_5_15) { + } else if (!strcmp(cachestat_targets[NETDATA_KEY_CALLS_ACCOUNT_PAGE_DIRTIED].name, + account_page[NETDATA_CACHESTAT_SET_PAGE_DIRTY])) { bpf_program__set_attach_target(obj->progs.netdata_set_page_dirty_fentry, 0, cachestat_targets[NETDATA_KEY_CALLS_ACCOUNT_PAGE_DIRTIED].name); } else { @@ -192,12 +201,14 @@ static int ebpf_cachestat_attach_probe(struct cachestat_bpf *obj) if (ret) return -1; - if (running_on_kernel >= NETDATA_EBPF_KERNEL_5_16) { + if (!strcmp(cachestat_targets[NETDATA_KEY_CALLS_ACCOUNT_PAGE_DIRTIED].name, + account_page[NETDATA_CACHESTAT_FOLIO_DIRTY])) { obj->links.netdata_folio_mark_dirty_kprobe = bpf_program__attach_kprobe(obj->progs.netdata_folio_mark_dirty_kprobe, false, cachestat_targets[NETDATA_KEY_CALLS_ACCOUNT_PAGE_DIRTIED].name); ret = libbpf_get_error(obj->links.netdata_folio_mark_dirty_kprobe); - } else if (running_on_kernel >= NETDATA_EBPF_KERNEL_5_15) { + } else if (!strcmp(cachestat_targets[NETDATA_KEY_CALLS_ACCOUNT_PAGE_DIRTIED].name, + account_page[NETDATA_CACHESTAT_SET_PAGE_DIRTY])) { obj->links.netdata_set_page_dirty_kprobe = bpf_program__attach_kprobe(obj->progs.netdata_set_page_dirty_kprobe, false, cachestat_targets[NETDATA_KEY_CALLS_ACCOUNT_PAGE_DIRTIED].name); @@ -363,7 +374,8 @@ static void ebpf_cachestat_free(ebpf_module_t *em) static void ebpf_cachestat_exit(void *ptr) { ebpf_module_t *em = (ebpf_module_t *)ptr; - netdata_thread_cancel(*cachestat_threads.thread); + if (cachestat_threads.thread) + netdata_thread_cancel(*cachestat_threads.thread); ebpf_cachestat_free(em); } @@ -1237,16 +1249,28 @@ static void ebpf_cachestat_allocate_global_vectors(int apps) * Update Internal value * * Update values used during runtime. + * + * @return It returns 0 when one of the functions is present and -1 otherwise. */ -static void ebpf_cachestat_set_internal_value() +static int ebpf_cachestat_set_internal_value() { - static char *account_page[] = { "account_page_dirtied", "__set_page_dirty", "__folio_mark_dirty" }; - if (running_on_kernel >= NETDATA_EBPF_KERNEL_5_16) - cachestat_targets[NETDATA_KEY_CALLS_ACCOUNT_PAGE_DIRTIED].name = account_page[NETDATA_CACHESTAT_FOLIO_DIRTY]; - else if (running_on_kernel >= NETDATA_EBPF_KERNEL_5_15) - cachestat_targets[NETDATA_KEY_CALLS_ACCOUNT_PAGE_DIRTIED].name = account_page[NETDATA_CACHESTAT_SET_PAGE_DIRTY]; - else - cachestat_targets[NETDATA_KEY_CALLS_ACCOUNT_PAGE_DIRTIED].name = account_page[NETDATA_CACHESTAT_ACCOUNT_PAGE_DIRTY]; + ebpf_addresses_t address = {.function = NULL, .hash = 0, .addr = 0}; + int i; + for (i = 0; i < NETDATA_CACHESTAT_ACCOUNT_DIRTY_END ; i++) { + address.function = account_page[i]; + ebpf_load_addresses(&address, -1); + if (address.addr) + break; + } + + if (!address.addr) { + error("%s cachestat.", NETDATA_EBPF_DEFAULT_FNT_NOT_FOUND); + return -1; + } + + cachestat_targets[NETDATA_KEY_CALLS_ACCOUNT_PAGE_DIRTIED].name = address.function; + + return 0; } /* @@ -1300,7 +1324,10 @@ void *ebpf_cachestat_thread(void *ptr) ebpf_update_pid_table(&cachestat_maps[NETDATA_CACHESTAT_PID_STATS], em); - ebpf_cachestat_set_internal_value(); + if (ebpf_cachestat_set_internal_value()) { + em->thread->enabled = NETDATA_THREAD_EBPF_STOPPED; + goto endcachestat; + } #ifdef LIBBPF_MAJOR_VERSION ebpf_adjust_thread_load(em, default_btf); diff --git a/collectors/ebpf.plugin/ebpf_cachestat.h b/collectors/ebpf.plugin/ebpf_cachestat.h index 07f0745d42..fba2772293 100644 --- a/collectors/ebpf.plugin/ebpf_cachestat.h +++ b/collectors/ebpf.plugin/ebpf_cachestat.h @@ -48,7 +48,9 @@ enum cachestat_counters { enum cachestat_account_dirty_pages { NETDATA_CACHESTAT_ACCOUNT_PAGE_DIRTY, NETDATA_CACHESTAT_SET_PAGE_DIRTY, - NETDATA_CACHESTAT_FOLIO_DIRTY + NETDATA_CACHESTAT_FOLIO_DIRTY, + + NETDATA_CACHESTAT_ACCOUNT_DIRTY_END }; enum cachestat_indexes { diff --git a/collectors/ebpf.plugin/ebpf_dcstat.c b/collectors/ebpf.plugin/ebpf_dcstat.c index 71169e1535..4591e987db 100644 --- a/collectors/ebpf.plugin/ebpf_dcstat.c +++ b/collectors/ebpf.plugin/ebpf_dcstat.c @@ -338,7 +338,8 @@ static void ebpf_dcstat_free(ebpf_module_t *em ) static void ebpf_dcstat_exit(void *ptr) { ebpf_module_t *em = (ebpf_module_t *)ptr; - netdata_thread_cancel(*dcstat_threads.thread); + if (dcstat_threads.thread) + netdata_thread_cancel(*dcstat_threads.thread); ebpf_dcstat_free(em); } diff --git a/collectors/ebpf.plugin/ebpf_disk.c b/collectors/ebpf.plugin/ebpf_disk.c index a27bd81e38..1c9bb0ede9 100644 --- a/collectors/ebpf.plugin/ebpf_disk.c +++ b/collectors/ebpf.plugin/ebpf_disk.c @@ -473,7 +473,8 @@ static void ebpf_disk_free(ebpf_module_t *em) static void ebpf_disk_exit(void *ptr) { ebpf_module_t *em = (ebpf_module_t *)ptr; - netdata_thread_cancel(*disk_threads.thread); + if (disk_threads.thread) + netdata_thread_cancel(*disk_threads.thread); ebpf_disk_free(em); } diff --git a/collectors/ebpf.plugin/ebpf_fd.c b/collectors/ebpf.plugin/ebpf_fd.c index 30b7f22cee..1f9498eaff 100644 --- a/collectors/ebpf.plugin/ebpf_fd.c +++ b/collectors/ebpf.plugin/ebpf_fd.c @@ -6,6 +6,9 @@ static char *fd_dimension_names[NETDATA_FD_SYSCALL_END] = { "open", "close" }; static char *fd_id_names[NETDATA_FD_SYSCALL_END] = { "do_sys_open", "__close_fd" }; +static char *close_targets[NETDATA_EBPF_MAX_FD_TARGETS] = {"close_fd", "__close_fd"}; +static char *open_targets[NETDATA_EBPF_MAX_FD_TARGETS] = {"do_sys_openat2", "do_sys_open"}; + static netdata_syscall_stat_t fd_aggregated_data[NETDATA_FD_SYSCALL_END]; static netdata_publish_syscall_t fd_publish_aggregated[NETDATA_FD_SYSCALL_END]; @@ -65,7 +68,7 @@ static inline void ebpf_fd_disable_probes(struct fd_bpf *obj) bpf_program__set_autoload(obj->progs.netdata_sys_open_kprobe, false); bpf_program__set_autoload(obj->progs.netdata_sys_open_kretprobe, false); bpf_program__set_autoload(obj->progs.netdata_release_task_fd_kprobe, false); - if (running_on_kernel >= NETDATA_EBPF_KERNEL_5_11) { + if (!strcmp(fd_targets[NETDATA_FD_SYSCALL_CLOSE].name, close_targets[NETDATA_FD_CLOSE_FD])) { bpf_program__set_autoload(obj->progs.netdata___close_fd_kretprobe, false); bpf_program__set_autoload(obj->progs.netdata___close_fd_kprobe, false); bpf_program__set_autoload(obj->progs.netdata_close_fd_kprobe, false); @@ -85,7 +88,7 @@ static inline void ebpf_fd_disable_probes(struct fd_bpf *obj) */ static inline void ebpf_disable_specific_probes(struct fd_bpf *obj) { - if (running_on_kernel >= NETDATA_EBPF_KERNEL_5_11) { + if (!strcmp(fd_targets[NETDATA_FD_SYSCALL_CLOSE].name, close_targets[NETDATA_FD_CLOSE_FD])) { bpf_program__set_autoload(obj->progs.netdata___close_fd_kretprobe, false); bpf_program__set_autoload(obj->progs.netdata___close_fd_kprobe, false); } else { @@ -121,7 +124,7 @@ static inline void ebpf_disable_trampoline(struct fd_bpf *obj) */ static inline void ebpf_disable_specific_trampoline(struct fd_bpf *obj) { - if (running_on_kernel >= NETDATA_EBPF_KERNEL_5_11) { + if (!strcmp(fd_targets[NETDATA_FD_SYSCALL_CLOSE].name, close_targets[NETDATA_FD_CLOSE_FD])) { bpf_program__set_autoload(obj->progs.netdata___close_fd_fentry, false); bpf_program__set_autoload(obj->progs.netdata___close_fd_fexit, false); } else { @@ -143,7 +146,7 @@ static void ebpf_set_trampoline_target(struct fd_bpf *obj) bpf_program__set_attach_target(obj->progs.netdata_sys_open_fexit, 0, fd_targets[NETDATA_FD_SYSCALL_OPEN].name); bpf_program__set_attach_target(obj->progs.netdata_release_task_fd_fentry, 0, EBPF_COMMON_FNCT_CLEAN_UP); - if (running_on_kernel >= NETDATA_EBPF_KERNEL_5_11) { + if (!strcmp(fd_targets[NETDATA_FD_SYSCALL_CLOSE].name, close_targets[NETDATA_FD_CLOSE_FD])) { bpf_program__set_attach_target( obj->progs.netdata_close_fd_fentry, 0, fd_targets[NETDATA_FD_SYSCALL_CLOSE].name); bpf_program__set_attach_target(obj->progs.netdata_close_fd_fexit, 0, fd_targets[NETDATA_FD_SYSCALL_CLOSE].name); @@ -185,7 +188,7 @@ static int ebpf_fd_attach_probe(struct fd_bpf *obj) if (ret) return -1; - if (running_on_kernel >= NETDATA_EBPF_KERNEL_5_11) { + if (!strcmp(fd_targets[NETDATA_FD_SYSCALL_CLOSE].name, close_targets[NETDATA_FD_CLOSE_FD])) { obj->links.netdata_close_fd_kretprobe = bpf_program__attach_kprobe(obj->progs.netdata_close_fd_kretprobe, true, fd_targets[NETDATA_FD_SYSCALL_CLOSE].name); ret = libbpf_get_error(obj->links.netdata_close_fd_kretprobe); @@ -217,21 +220,47 @@ static int ebpf_fd_attach_probe(struct fd_bpf *obj) } /** + * FD Fill Address + * + * Fill address value used to load probes/trampoline. + */ +static inline void ebpf_fd_fill_address(ebpf_addresses_t *address, char **targets) +{ + int i; + for (i = 0; i < NETDATA_EBPF_MAX_FD_TARGETS; i++) { + address->function = targets[i]; + ebpf_load_addresses(address, -1); + if (address->addr) + break; + } +} + +/** * Set target values * * Set pointers used to laod data. + * + * @return It returns 0 on success and -1 otherwise. */ -static void ebpf_fd_set_target_values() +static int ebpf_fd_set_target_values() { - static char *close_targets[] = {"close_fd", "__close_fd"}; - static char *open_targets[] = {"do_sys_openat2", "do_sys_open"}; - if (running_on_kernel >= NETDATA_EBPF_KERNEL_5_11) { - fd_targets[NETDATA_FD_SYSCALL_OPEN].name = open_targets[0]; - fd_targets[NETDATA_FD_SYSCALL_CLOSE].name = close_targets[0]; - } else { - fd_targets[NETDATA_FD_SYSCALL_OPEN].name = open_targets[1]; - fd_targets[NETDATA_FD_SYSCALL_CLOSE].name = close_targets[1]; - } + ebpf_addresses_t address = {.function = NULL, .hash = 0, .addr = 0}; + ebpf_fd_fill_address(&address, close_targets); + + if (!address.addr) + return -1; + + fd_targets[NETDATA_FD_SYSCALL_CLOSE].name = address.function; + + address.addr = 0; + ebpf_fd_fill_address(&address, open_targets); + + if (!address.addr) + return -1; + + fd_targets[NETDATA_FD_SYSCALL_OPEN].name = address.function; + + return 0; } /** @@ -290,7 +319,11 @@ static inline int ebpf_fd_load_and_attach(struct fd_bpf *obj, ebpf_module_t *em) netdata_ebpf_targets_t *mt = em->targets; netdata_ebpf_program_loaded_t test = mt[NETDATA_FD_SYSCALL_OPEN].mode; - ebpf_fd_set_target_values(); + if (ebpf_fd_set_target_values()) { + error("%s file descriptor.", NETDATA_EBPF_DEFAULT_FNT_NOT_FOUND); + return -1; + } + if (test == EBPF_LOAD_TRAMPOLINE) { ebpf_fd_disable_probes(obj); ebpf_disable_specific_trampoline(obj); @@ -372,7 +405,8 @@ static void ebpf_fd_free(ebpf_module_t *em) static void ebpf_fd_exit(void *ptr) { ebpf_module_t *em = (ebpf_module_t *)ptr; - netdata_thread_cancel(*fd_thread.thread); + if (fd_thread.thread) + netdata_thread_cancel(*fd_thread.thread); ebpf_fd_free(em); } diff --git a/collectors/ebpf.plugin/ebpf_fd.h b/collectors/ebpf.plugin/ebpf_fd.h index 914a34b989..ead822f4f8 100644 --- a/collectors/ebpf.plugin/ebpf_fd.h +++ b/collectors/ebpf.plugin/ebpf_fd.h @@ -74,6 +74,14 @@ enum fd_syscalls { NETDATA_FD_SYSCALL_END }; +enum fd_close_syscall { + NETDATA_FD_CLOSE_FD, + NETDATA_FD___CLOSE_FD, + + NETDATA_FD_CLOSE_END +}; + +#define NETDATA_EBPF_MAX_FD_TARGETS 2 void *ebpf_fd_thread(void *ptr); void ebpf_fd_create_apps_charts(struct ebpf_module *em, void *ptr); diff --git a/collectors/ebpf.plugin/ebpf_filesystem.c b/collectors/ebpf.plugin/ebpf_filesystem.c index 7dbec7410e..3027197299 100644 --- a/collectors/ebpf.plugin/ebpf_filesystem.c +++ b/collectors/ebpf.plugin/ebpf_filesystem.c @@ -367,7 +367,8 @@ static void ebpf_filesystem_free(ebpf_module_t *em) static void ebpf_filesystem_exit(void *ptr) { ebpf_module_t *em = (ebpf_module_t *)ptr; - netdata_thread_cancel(*filesystem_threads.thread); + if (filesystem_threads.thread) + netdata_thread_cancel(*filesystem_threads.thread); ebpf_filesystem_free(em); } diff --git a/collectors/ebpf.plugin/ebpf_hardirq.c b/collectors/ebpf.plugin/ebpf_hardirq.c index b07dd24cae..6408cba1f7 100644 --- a/collectors/ebpf.plugin/ebpf_hardirq.c +++ b/collectors/ebpf.plugin/ebpf_hardirq.c @@ -183,7 +183,8 @@ static void ebpf_hardirq_free(ebpf_module_t *em) static void hardirq_exit(void *ptr) { ebpf_module_t *em = (ebpf_module_t *)ptr; - netdata_thread_cancel(*hardirq_threads.thread); + if (hardirq_threads.thread) + netdata_thread_cancel(*hardirq_threads.thread); ebpf_hardirq_free(em); } diff --git a/collectors/ebpf.plugin/ebpf_mdflush.c b/collectors/ebpf.plugin/ebpf_mdflush.c index dc805da23f..45911e5bf5 100644 --- a/collectors/ebpf.plugin/ebpf_mdflush.c +++ b/collectors/ebpf.plugin/ebpf_mdflush.c @@ -92,7 +92,8 @@ static void mdflush_exit(void *ptr) static void mdflush_cleanup(void *ptr) { ebpf_module_t *em = (ebpf_module_t *)ptr; - netdata_thread_cancel(*mdflush_threads.thread); + if (mdflush_threads.thread) + netdata_thread_cancel(*mdflush_threads.thread); ebpf_mdflush_free(em); } diff --git a/collectors/ebpf.plugin/ebpf_mount.c b/collectors/ebpf.plugin/ebpf_mount.c index ec1f07a659..3dd92659a7 100644 --- a/collectors/ebpf.plugin/ebpf_mount.c +++ b/collectors/ebpf.plugin/ebpf_mount.c @@ -269,7 +269,8 @@ static void ebpf_mount_free(ebpf_module_t *em) static void ebpf_mount_exit(void *ptr) { ebpf_module_t *em = (ebpf_module_t *)ptr; - netdata_thread_cancel(*mount_thread.thread); + if (mount_thread.thread) + netdata_thread_cancel(*mount_thread.thread); ebpf_mount_free(em); } diff --git a/collectors/ebpf.plugin/ebpf_process.c b/collectors/ebpf.plugin/ebpf_process.c index 682577da74..5d1d4b46cd 100644 --- a/collectors/ebpf.plugin/ebpf_process.c +++ b/collectors/ebpf.plugin/ebpf_process.c @@ -745,7 +745,8 @@ static void ebpf_process_exit(void *ptr) pthread_mutex_lock(&ebpf_exit_cleanup); em->thread->enabled = NETDATA_THREAD_EBPF_STOPPED; pthread_mutex_unlock(&ebpf_exit_cleanup); - pthread_cancel(*cgroup_thread.thread); + if (cgroup_thread.thread) + pthread_cancel(*cgroup_thread.thread); } /***************************************************************** diff --git a/collectors/ebpf.plugin/ebpf_shm.c b/collectors/ebpf.plugin/ebpf_shm.c index f81287d826..0892406e96 100644 --- a/collectors/ebpf.plugin/ebpf_shm.c +++ b/collectors/ebpf.plugin/ebpf_shm.c @@ -329,7 +329,8 @@ static void ebpf_shm_free(ebpf_module_t *em) static void ebpf_shm_exit(void *ptr) { ebpf_module_t *em = (ebpf_module_t *)ptr; - netdata_thread_cancel(*shm_threads.thread); + if (shm_threads.thread) + netdata_thread_cancel(*shm_threads.thread); ebpf_shm_free(em); } diff --git a/collectors/ebpf.plugin/ebpf_socket.c b/collectors/ebpf.plugin/ebpf_socket.c index 3a023e4a47..303301a2e8 100644 --- a/collectors/ebpf.plugin/ebpf_socket.c +++ b/collectors/ebpf.plugin/ebpf_socket.c @@ -647,7 +647,8 @@ static void ebpf_socket_free(ebpf_module_t *em ) static void ebpf_socket_exit(void *ptr) { ebpf_module_t *em = (ebpf_module_t *)ptr; - netdata_thread_cancel(*socket_threads.thread); + if (socket_threads.thread) + netdata_thread_cancel(*socket_threads.thread); ebpf_socket_free(em); } diff --git a/collectors/ebpf.plugin/ebpf_softirq.c b/collectors/ebpf.plugin/ebpf_softirq.c index 3b5d15921b..2e92a1495c 100644 --- a/collectors/ebpf.plugin/ebpf_softirq.c +++ b/collectors/ebpf.plugin/ebpf_softirq.c @@ -104,7 +104,8 @@ static void ebpf_softirq_free(ebpf_module_t *em) static void softirq_exit(void *ptr) { ebpf_module_t *em = (ebpf_module_t *)ptr; - netdata_thread_cancel(*softirq_threads.thread); + if (softirq_threads.thread) + netdata_thread_cancel(*softirq_threads.thread); ebpf_softirq_free(em); } diff --git a/collectors/ebpf.plugin/ebpf_swap.c b/collectors/ebpf.plugin/ebpf_swap.c index 8199573a9f..f2d74f6821 100644 --- a/collectors/ebpf.plugin/ebpf_swap.c +++ b/collectors/ebpf.plugin/ebpf_swap.c @@ -268,7 +268,8 @@ static void ebpf_swap_free(ebpf_module_t *em) static void ebpf_swap_exit(void *ptr) { ebpf_module_t *em = (ebpf_module_t *)ptr; - netdata_thread_cancel(*swap_threads.thread); + if (swap_threads.thread) + netdata_thread_cancel(*swap_threads.thread); ebpf_swap_free(em); } diff --git a/collectors/ebpf.plugin/ebpf_sync.c b/collectors/ebpf.plugin/ebpf_sync.c index 8404975337..0c74684e7f 100644 --- a/collectors/ebpf.plugin/ebpf_sync.c +++ b/collectors/ebpf.plugin/ebpf_sync.c @@ -243,7 +243,8 @@ static void ebpf_sync_free(ebpf_module_t *em) static void ebpf_sync_exit(void *ptr) { ebpf_module_t *em = (ebpf_module_t *)ptr; - netdata_thread_cancel(*sync_threads.thread); + if (sync_threads.thread) + netdata_thread_cancel(*sync_threads.thread); ebpf_sync_free(em); } diff --git a/collectors/ebpf.plugin/ebpf_vfs.c b/collectors/ebpf.plugin/ebpf_vfs.c index ad6de4a07d..eae5d32868 100644 --- a/collectors/ebpf.plugin/ebpf_vfs.c +++ b/collectors/ebpf.plugin/ebpf_vfs.c @@ -440,7 +440,8 @@ static void ebpf_vfs_free(ebpf_module_t *em) static void ebpf_vfs_exit(void *ptr) { ebpf_module_t *em = (ebpf_module_t *)ptr; - netdata_thread_cancel(*vfs_threads.thread); + if (vfs_threads.thread) + netdata_thread_cancel(*vfs_threads.thread); ebpf_vfs_free(em); } diff --git a/libnetdata/ebpf/ebpf.c b/libnetdata/ebpf/ebpf.c index 382485e5f3..2c16a80902 100644 --- a/libnetdata/ebpf/ebpf.c +++ b/libnetdata/ebpf/ebpf.c @@ -1160,7 +1160,8 @@ void ebpf_adjust_apps_cgroup(ebpf_module_t *em, netdata_ebpf_program_loaded_t mo * Helper used to get address from /proc/kallsym * * @param fa address structure - * @param fd file descriptor loaded inside kernel. + * @param fd file descriptor loaded inside kernel. If a negative value is given + * the function will load address and it won't update hash table. */ void ebpf_load_addresses(ebpf_addresses_t *fa, int fd) { @@ -1182,11 +1183,15 @@ void ebpf_load_addresses(ebpf_addresses_t *fa, int fd) char *fcnt = procfile_lineword(ff, l, 2); uint32_t hash = simple_hash(fcnt); if (fa->hash == hash && !strcmp(fcnt, fa->function)) { - char addr[128]; - snprintf(addr, 127, "0x%s", procfile_lineword(ff, l, 0)); - fa->addr = (unsigned long) strtoul(addr, NULL, 16); - uint32_t key = 0; - bpf_map_update_elem(fd, &key, &fa->addr, BPF_ANY); + if (fd > 0) { + char addr[128]; + snprintf(addr, 127, "0x%s", procfile_lineword(ff, l, 0)); + fa->addr = (unsigned long) strtoul(addr, NULL, 16); + uint32_t key = 0; + bpf_map_update_elem(fd, &key, &fa->addr, BPF_ANY); + } else + fa->addr = 1; + break; } } |