diff options
author | thiagoftsm <thiagoftsm@gmail.com> | 2023-06-19 13:08:42 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-19 13:08:42 +0000 |
commit | 49bcf61f6d9d997d30359772497fb26fd1305019 (patch) | |
tree | aabe7baa368e41b1d2b53f181f9076b978d402d6 | |
parent | c76538e2f0ef4450e7c5f12b44f620d74fdcde47 (diff) |
Speed up eBPF exit before to bring functions (#15187)
-rw-r--r-- | collectors/ebpf.plugin/ebpf.c | 137 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_cachestat.c | 34 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_dcstat.c | 46 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_disk.c | 26 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_fd.c | 31 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_hardirq.c | 25 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_mdflush.c | 23 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_mount.c | 26 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_oomkill.c | 4 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_shm.c | 30 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_softirq.c | 26 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_swap.c | 29 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_vfs.c | 29 |
13 files changed, 168 insertions, 298 deletions
diff --git a/collectors/ebpf.plugin/ebpf.c b/collectors/ebpf.plugin/ebpf.c index 45303574fa..ffab37de32 100644 --- a/collectors/ebpf.plugin/ebpf.c +++ b/collectors/ebpf.plugin/ebpf.c @@ -540,6 +540,31 @@ ARAL *ebpf_allocate_pid_aral(char *name, size_t size) *****************************************************************/ /** + * Wait to avoid possible coredumps while process is closing. + */ +static inline void ebpf_check_before2go() +{ + int i = EBPF_OPTION_ALL_CHARTS; + usec_t max = USEC_PER_SEC, step = 200000; + while (i && max) { + max -= step; + sleep_usec(step); + i = 0; + int j; + pthread_mutex_lock(&ebpf_exit_cleanup); + for (j = 0; ebpf_modules[j].thread_name != NULL; j++) { + if (ebpf_modules[j].enabled == NETDATA_THREAD_EBPF_RUNNING) + i++; + } + pthread_mutex_unlock(&ebpf_exit_cleanup); + } + + if (i) { + error("eBPF cannot unload all threads on time, but it will go away"); + } +} + +/** * Close the collector gracefully */ static void ebpf_exit() @@ -561,8 +586,10 @@ static void ebpf_exit() #ifdef NETDATA_INTERNAL_CHECKS error("Good bye world! I was PID %d", main_thread_id); #endif - printf("DISABLE\n"); + fprintf(stdout, "EXIT\n"); + fflush(stdout); + ebpf_check_before2go(); pthread_mutex_lock(&mutex_cgroup_shm); if (shm_ebpf_cgroup.header) { ebpf_unmap_cgroup_shared_memory(); @@ -604,6 +631,10 @@ static void ebpf_unload_unique_maps() { int i; for (i = 0; ebpf_modules[i].thread_name; i++) { + // These threads are cleaned with other functions + if (i > EBPF_MODULE_SOCKET_IDX) + continue; + if (ebpf_modules[i].enabled != NETDATA_THREAD_EBPF_STOPPED) { if (ebpf_modules[i].enabled != NETDATA_THREAD_EBPF_NOT_RUNNING) error("Cannot unload maps for thread %s, because it is not stopped.", ebpf_modules[i].thread_name); @@ -611,73 +642,18 @@ static void ebpf_unload_unique_maps() continue; } - ebpf_unload_legacy_code(ebpf_modules[i].objects, ebpf_modules[i].probe_links); - switch (i) { - case EBPF_MODULE_CACHESTAT_IDX: { -#ifdef LIBBPF_MAJOR_VERSION - if (cachestat_bpf_obj) - cachestat_bpf__destroy(cachestat_bpf_obj); -#endif - break; - } - case EBPF_MODULE_DCSTAT_IDX: { -#ifdef LIBBPF_MAJOR_VERSION - if (dc_bpf_obj) - dc_bpf__destroy(dc_bpf_obj); -#endif - break; - } - case EBPF_MODULE_FD_IDX: { -#ifdef LIBBPF_MAJOR_VERSION - if (fd_bpf_obj) - fd_bpf__destroy(fd_bpf_obj); -#endif - break; - } - case EBPF_MODULE_MOUNT_IDX: { -#ifdef LIBBPF_MAJOR_VERSION - if (mount_bpf_obj) - mount_bpf__destroy(mount_bpf_obj); -#endif - break; - } - case EBPF_MODULE_SHM_IDX: { -#ifdef LIBBPF_MAJOR_VERSION - if (shm_bpf_obj) - shm_bpf__destroy(shm_bpf_obj); -#endif - break; - } - case EBPF_MODULE_SOCKET_IDX: { -#ifdef LIBBPF_MAJOR_VERSION - if (socket_bpf_obj) - socket_bpf__destroy(socket_bpf_obj); -#endif - break; - } - case EBPF_MODULE_SWAP_IDX: { -#ifdef LIBBPF_MAJOR_VERSION - if (bpf_obj) - swap_bpf__destroy(bpf_obj); -#endif - break; - } - case EBPF_MODULE_VFS_IDX: { + if (ebpf_modules[i].load == EBPF_LOAD_LEGACY) { + ebpf_unload_legacy_code(ebpf_modules[i].objects, ebpf_modules[i].probe_links); + continue; + } + + if (i == EBPF_MODULE_SOCKET_IDX) { #ifdef LIBBPF_MAJOR_VERSION - if (vfs_bpf_obj) - vfs_bpf__destroy(vfs_bpf_obj); + if (socket_bpf_obj) + socket_bpf__destroy(socket_bpf_obj); #endif - break; - } - case EBPF_MODULE_PROCESS_IDX: - case EBPF_MODULE_DISK_IDX: - case EBPF_MODULE_HARDIRQ_IDX: - case EBPF_MODULE_SOFTIRQ_IDX: - case EBPF_MODULE_OOMKILL_IDX: - case EBPF_MODULE_MDFLUSH_IDX: - default: - continue; } + } } @@ -689,11 +665,15 @@ static void ebpf_unload_unique_maps() static void ebpf_unload_filesystems() { if (ebpf_modules[EBPF_MODULE_FILESYSTEM_IDX].enabled == NETDATA_THREAD_EBPF_NOT_RUNNING || - ebpf_modules[EBPF_MODULE_SYNC_IDX].enabled == NETDATA_THREAD_EBPF_RUNNING) + ebpf_modules[EBPF_MODULE_FILESYSTEM_IDX].enabled == NETDATA_THREAD_EBPF_RUNNING || + ebpf_modules[EBPF_MODULE_FILESYSTEM_IDX].load != EBPF_LOAD_LEGACY) return; int i; for (i = 0; localfs[i].filesystem != NULL; i++) { + if (!localfs[i].objects) + continue; + ebpf_unload_legacy_code(localfs[i].objects, localfs[i].probe_links); } } @@ -711,6 +691,15 @@ static void ebpf_unload_sync() int i; for (i = 0; local_syscalls[i].syscall != NULL; i++) { + if (!local_syscalls[i].enabled) + continue; + +#ifdef LIBBPF_MAJOR_VERSION + if (local_syscalls[i].sync_obj) { + sync_bpf__destroy(local_syscalls[i].sync_obj); + continue; + } +#endif ebpf_unload_legacy_code(local_syscalls[i].objects, local_syscalls[i].probe_links); } } @@ -753,19 +742,7 @@ static void ebpf_stop_threads(int sig) ebpf_exit_plugin = 1; - usec_t max = USEC_PER_SEC, step = 100000; - while (i && max) { - max -= step; - sleep_usec(step); - i = 0; - int j; - pthread_mutex_lock(&ebpf_exit_cleanup); - for (j = 0; ebpf_modules[j].thread_name != NULL; j++) { - if (ebpf_modules[j].enabled == NETDATA_THREAD_EBPF_RUNNING) - i++; - } - pthread_mutex_unlock(&ebpf_exit_cleanup); - } + ebpf_check_before2go(); pthread_mutex_lock(&ebpf_exit_cleanup); ebpf_unload_unique_maps(); @@ -2650,7 +2627,7 @@ int main(int argc, char **argv) (void)heartbeat_next(&hb, step); pthread_mutex_lock(&ebpf_exit_cleanup); - if (ebpf_modules[i].enabled == NETDATA_THREAD_EBPF_RUNNING && process_pid_fd != -1) { + if (process_pid_fd != -1) { pthread_mutex_lock(&collect_data_mutex); if (++update_apps_list == update_apps_every) { update_apps_list = 0; diff --git a/collectors/ebpf.plugin/ebpf_cachestat.c b/collectors/ebpf.plugin/ebpf_cachestat.c index 5bbbe1f43b..c287136cfd 100644 --- a/collectors/ebpf.plugin/ebpf_cachestat.c +++ b/collectors/ebpf.plugin/ebpf_cachestat.c @@ -337,27 +337,6 @@ static inline int ebpf_cachestat_load_and_attach(struct cachestat_bpf *obj, ebpf *****************************************************************/ /** - * Cachestat Free - * - * Cleanup variables after child threads to stop - * - * @param ptr thread data. - */ -static void ebpf_cachestat_free(ebpf_module_t *em) -{ - pthread_mutex_lock(&ebpf_exit_cleanup); - em->enabled = NETDATA_THREAD_EBPF_STOPPING; - pthread_mutex_unlock(&ebpf_exit_cleanup); - - freez(cachestat_vector); - freez(cachestat_values); - - pthread_mutex_lock(&ebpf_exit_cleanup); - em->enabled = NETDATA_THREAD_EBPF_STOPPED; - pthread_mutex_unlock(&ebpf_exit_cleanup); -} - -/** * Cachestat exit. * * Cancel child and exit. @@ -368,7 +347,18 @@ static void ebpf_cachestat_exit(void *ptr) { ebpf_module_t *em = (ebpf_module_t *)ptr; - ebpf_cachestat_free(em); +#ifdef LIBBPF_MAJOR_VERSION + if (cachestat_bpf_obj) + cachestat_bpf__destroy(cachestat_bpf_obj); +#endif + + if (em->objects) { + ebpf_unload_legacy_code(em->objects, em->probe_links); + } + + pthread_mutex_lock(&ebpf_exit_cleanup); + em->enabled = NETDATA_THREAD_EBPF_STOPPED; + pthread_mutex_unlock(&ebpf_exit_cleanup); } /***************************************************************** diff --git a/collectors/ebpf.plugin/ebpf_dcstat.c b/collectors/ebpf.plugin/ebpf_dcstat.c index 5a07e4619b..4157f0c875 100644 --- a/collectors/ebpf.plugin/ebpf_dcstat.c +++ b/collectors/ebpf.plugin/ebpf_dcstat.c @@ -286,55 +286,29 @@ void dcstat_update_publish(netdata_publish_dcstat_t *out, uint64_t cache_access, *****************************************************************/ /** - * Clean names - * - * Clean the optional names allocated during startup. - */ -void ebpf_dcstat_clean_names() -{ - size_t i = 0; - while (dc_optional_name[i].program_name) { - freez(dc_optional_name[i].optional); - i++; - } -} - -/** - * DCstat Free + * DCstat exit * - * Cleanup variables after child threads to stop + * Cancel child and exit. * * @param ptr thread data. */ -static void ebpf_dcstat_free(ebpf_module_t *em ) +static void ebpf_dcstat_exit(void *ptr) { - pthread_mutex_lock(&ebpf_exit_cleanup); - em->enabled = NETDATA_THREAD_EBPF_STOPPING; - pthread_mutex_unlock(&ebpf_exit_cleanup); + ebpf_module_t *em = (ebpf_module_t *)ptr; - freez(dcstat_vector); - freez(dcstat_values); +#ifdef LIBBPF_MAJOR_VERSION + if (dc_bpf_obj) + dc_bpf__destroy(dc_bpf_obj); +#endif - ebpf_dcstat_clean_names(); + if (em->objects) + ebpf_unload_legacy_code(em->objects, em->probe_links); pthread_mutex_lock(&ebpf_exit_cleanup); em->enabled = NETDATA_THREAD_EBPF_STOPPED; pthread_mutex_unlock(&ebpf_exit_cleanup); } -/** - * DCstat exit - * - * Cancel child and exit. - * - * @param ptr thread data. - */ -static void ebpf_dcstat_exit(void *ptr) -{ - ebpf_module_t *em = (ebpf_module_t *)ptr; - ebpf_dcstat_free(em); -} - /***************************************************************** * * APPS diff --git a/collectors/ebpf.plugin/ebpf_disk.c b/collectors/ebpf.plugin/ebpf_disk.c index 71c9727779..231186b841 100644 --- a/collectors/ebpf.plugin/ebpf_disk.c +++ b/collectors/ebpf.plugin/ebpf_disk.c @@ -435,17 +435,18 @@ static void ebpf_cleanup_disk_list() } /** - * DISK Free + * Disk exit. * - * Cleanup variables after child threads to stop + * Cancel child and exit. * * @param ptr thread data. */ -static void ebpf_disk_free(ebpf_module_t *em) +static void ebpf_disk_exit(void *ptr) { - pthread_mutex_lock(&ebpf_exit_cleanup); - em->enabled = NETDATA_THREAD_EBPF_STOPPING; - pthread_mutex_unlock(&ebpf_exit_cleanup); + ebpf_module_t *em = (ebpf_module_t *)ptr; + + if (em->objects) + ebpf_unload_legacy_code(em->objects, em->probe_links); ebpf_disk_disable_tracepoints(); @@ -463,19 +464,6 @@ static void ebpf_disk_free(ebpf_module_t *em) pthread_mutex_unlock(&ebpf_exit_cleanup); } -/** - * Disk exit. - * - * Cancel child and exit. - * - * @param ptr thread data. - */ -static void ebpf_disk_exit(void *ptr) -{ - ebpf_module_t *em = (ebpf_module_t *)ptr; - ebpf_disk_free(em); -} - /***************************************************************** * * MAIN LOOP diff --git a/collectors/ebpf.plugin/ebpf_fd.c b/collectors/ebpf.plugin/ebpf_fd.c index 6d3868952d..d39e6ae20d 100644 --- a/collectors/ebpf.plugin/ebpf_fd.c +++ b/collectors/ebpf.plugin/ebpf_fd.c @@ -370,39 +370,28 @@ static inline int ebpf_fd_load_and_attach(struct fd_bpf *obj, ebpf_module_t *em) *****************************************************************/ /** - * FD Free + * FD Exit * - * Cleanup variables after child threads to stop + * Cancel child thread and exit. * * @param ptr thread data. */ -static void ebpf_fd_free(ebpf_module_t *em) +static void ebpf_fd_exit(void *ptr) { - pthread_mutex_lock(&ebpf_exit_cleanup); - em->enabled = NETDATA_THREAD_EBPF_STOPPING; - pthread_mutex_unlock(&ebpf_exit_cleanup); + ebpf_module_t *em = (ebpf_module_t *)ptr; - freez(fd_values); - freez(fd_vector); +#ifdef LIBBPF_MAJOR_VERSION + if (fd_bpf_obj) + fd_bpf__destroy(fd_bpf_obj); +#endif + if (em->objects) + ebpf_unload_legacy_code(em->objects, em->probe_links); pthread_mutex_lock(&ebpf_exit_cleanup); em->enabled = NETDATA_THREAD_EBPF_STOPPED; pthread_mutex_unlock(&ebpf_exit_cleanup); } -/** - * FD Exit - * - * Cancel child thread and exit. - * - * @param ptr thread data. - */ -static void ebpf_fd_exit(void *ptr) -{ - ebpf_module_t *em = (ebpf_module_t *)ptr; - ebpf_fd_free(em); -} - /***************************************************************** * * MAIN LOOP diff --git a/collectors/ebpf.plugin/ebpf_hardirq.c b/collectors/ebpf.plugin/ebpf_hardirq.c index 113648ec97..f714c261c0 100644 --- a/collectors/ebpf.plugin/ebpf_hardirq.c +++ b/collectors/ebpf.plugin/ebpf_hardirq.c @@ -188,35 +188,28 @@ void ebpf_hardirq_release(hardirq_val_t *stat) *****************************************************************/ /** - * Hardirq Free + * Hardirq Exit * - * Cleanup variables after child threads to stop + * Cancel child and exit. * * @param ptr thread data. */ -static void ebpf_hardirq_free(ebpf_module_t *em) +static void hardirq_exit(void *ptr) { + ebpf_module_t *em = (ebpf_module_t *)ptr; + + if (em->objects) + ebpf_unload_legacy_code(em->objects, em->probe_links); + for (int i = 0; hardirq_tracepoints[i].class != NULL; i++) { ebpf_disable_tracepoint(&hardirq_tracepoints[i]); } + pthread_mutex_lock(&ebpf_exit_cleanup); em->enabled = NETDATA_THREAD_EBPF_STOPPED; pthread_mutex_unlock(&ebpf_exit_cleanup); } -/** - * Hardirq Exit - * - * Cancel child and exit. - * - * @param ptr thread data. - */ -static void hardirq_exit(void *ptr) -{ - ebpf_module_t *em = (ebpf_module_t *)ptr; - ebpf_hardirq_free(em); -} - /***************************************************************** * MAIN LOOP *****************************************************************/ diff --git a/collectors/ebpf.plugin/ebpf_mdflush.c b/collectors/ebpf.plugin/ebpf_mdflush.c index 321bd97ee2..65ed860a46 100644 --- a/collectors/ebpf.plugin/ebpf_mdflush.c +++ b/collectors/ebpf.plugin/ebpf_mdflush.c @@ -39,21 +39,6 @@ static avl_tree_lock mdflush_pub; static mdflush_ebpf_val_t *mdflush_ebpf_vals = NULL; /** - * MDflush Free - * - * Cleanup variables after child threads to stop - * - * @param ptr thread data. - */ -static void ebpf_mdflush_free(ebpf_module_t *em) -{ - freez(mdflush_ebpf_vals); - pthread_mutex_lock(&ebpf_exit_cleanup); - em->enabled = NETDATA_THREAD_EBPF_STOPPED; - pthread_mutex_unlock(&ebpf_exit_cleanup); -} - -/** * MDflush exit * * Cancel thread and exit. @@ -63,7 +48,13 @@ static void ebpf_mdflush_free(ebpf_module_t *em) static void mdflush_exit(void *ptr) { ebpf_module_t *em = (ebpf_module_t *)ptr; - ebpf_mdflush_free(em); + + if (em->objects) + ebpf_unload_legacy_code(em->objects, em->probe_links); + + pthread_mutex_lock(&ebpf_exit_cleanup); + em->enabled = NETDATA_THREAD_EBPF_STOPPED; + pthread_mutex_unlock(&ebpf_exit_cleanup); } /** diff --git a/collectors/ebpf.plugin/ebpf_mount.c b/collectors/ebpf.plugin/ebpf_mount.c index e0951f8c42..e48c892276 100644 --- a/collectors/ebpf.plugin/ebpf_mount.c +++ b/collectors/ebpf.plugin/ebpf_mount.c @@ -223,20 +223,6 @@ static inline int ebpf_mount_load_and_attach(struct mount_bpf *obj, ebpf_module_ *****************************************************************/ /** - * Mount Free - * - * Cleanup variables after child threads to stop - * - * @param ptr thread data. - */ -static void ebpf_mount_free(ebpf_module_t *em) -{ - pthread_mutex_lock(&ebpf_exit_cleanup); - em->enabled = NETDATA_THREAD_EBPF_STOPPED; - pthread_mutex_unlock(&ebpf_exit_cleanup); -} - -/** * Mount Exit * * Cancel child thread. @@ -246,7 +232,17 @@ static void ebpf_mount_free(ebpf_module_t *em) static void ebpf_mount_exit(void *ptr) { ebpf_module_t *em = (ebpf_module_t *)ptr; - ebpf_mount_free(em); + +#ifdef LIBBPF_MAJOR_VERSION + if (mount_bpf_obj) + mount_bpf__destroy(mount_bpf_obj); +#endif + if (em->objects) + ebpf_unload_legacy_code(em->objects, em->probe_links); + + pthread_mutex_lock(&ebpf_exit_cleanup); + em->enabled = NETDATA_THREAD_EBPF_STOPPED; + pthread_mutex_unlock(&ebpf_exit_cleanup); } /***************************************************************** diff --git a/collectors/ebpf.plugin/ebpf_oomkill.c b/collectors/ebpf.plugin/ebpf_oomkill.c index 0948752920..c80f44873a 100644 --- a/collectors/ebpf.plugin/ebpf_oomkill.c +++ b/collectors/ebpf.plugin/ebpf_oomkill.c @@ -52,6 +52,10 @@ static netdata_publish_syscall_t oomkill_publish_aggregated = {.name = "oomkill" static void oomkill_cleanup(void *ptr) { ebpf_module_t *em = (ebpf_module_t *)ptr; + + if (em->objects) + ebpf_unload_legacy_code(em->objects, em->probe_links); + pthread_mutex_lock(&ebpf_exit_cleanup); em->enabled = NETDATA_THREAD_EBPF_STOPPED; pthread_mutex_unlock(&ebpf_exit_cleanup); diff --git a/collectors/ebpf.plugin/ebpf_shm.c b/collectors/ebpf.plugin/ebpf_shm.c index 093d65b602..94ac624b30 100644 --- a/collectors/ebpf.plugin/ebpf_shm.c +++ b/collectors/ebpf.plugin/ebpf_shm.c @@ -289,23 +289,6 @@ static inline int ebpf_shm_load_and_attach(struct shm_bpf *obj, ebpf_module_t *e *****************************************************************/ /** - * SHM Free - * - * Cleanup variables after child threads to stop - * - * @param ptr thread data. - */ -static void ebpf_shm_free(ebpf_module_t *em) -{ - freez(shm_vector); - freez(shm_values); - - pthread_mutex_lock(&ebpf_exit_cleanup); - em->enabled = NETDATA_THREAD_EBPF_STOPPED; - pthread_mutex_unlock(&ebpf_exit_cleanup); -} - -/** * SHM Exit * * Cancel child thread. @@ -315,7 +298,18 @@ static void ebpf_shm_free(ebpf_module_t *em) static void ebpf_shm_exit(void *ptr) { ebpf_module_t *em = (ebpf_module_t *)ptr; - ebpf_shm_free(em); + +#ifdef LIBBPF_MAJOR_VERSION + if (shm_bpf_obj) + shm_bpf__destroy(shm_bpf_obj); +#endif + + if (em->objects) + ebpf_unload_legacy_code(em->objects, em->probe_links); + + pthread_mutex_lock(&ebpf_exit_cleanup); + em->enabled = NETDATA_THREAD_EBPF_STOPPED; + pthread_mutex_unlock(&ebpf_exit_cleanup); } /***************************************************************** diff --git a/collectors/ebpf.plugin/ebpf_softirq.c b/collectors/ebpf.plugin/ebpf_softirq.c index 01e2d0a528..b5c77bf06d 100644 --- a/collectors/ebpf.plugin/ebpf_softirq.c +++ b/collectors/ebpf.plugin/ebpf_softirq.c @@ -61,17 +61,18 @@ static softirq_val_t softirq_vals[] = { static softirq_ebpf_val_t *softirq_ebpf_vals = NULL; /** - * Cachestat Free + * Cleanup * - * Cleanup variables after child threads to stop + * Clean up allocated memory. * * @param ptr thread data. */ -static void ebpf_softirq_free(ebpf_module_t *em) +static void softirq_cleanup(void *ptr) { - pthread_mutex_lock(&ebpf_exit_cleanup); - em->enabled = NETDATA_THREAD_EBPF_STOPPING; - pthread_mutex_unlock(&ebpf_exit_cleanup); + ebpf_module_t *em = (ebpf_module_t *)ptr; + + if (em->objects) + ebpf_unload_legacy_code(em->objects, em->probe_links); for (int i = 0; softirq_tracepoints[i].class != NULL; i++) { ebpf_disable_tracepoint(&softirq_tracepoints[i]); @@ -83,19 +84,6 @@ static void ebpf_softirq_free(ebpf_module_t *em) pthread_mutex_unlock(&ebpf_exit_cleanup); } -/** - * Cleanup - * - * Clean up allocated memory. - * - * @param ptr thread data. - */ -static void softirq_cleanup(void *ptr) -{ - ebpf_module_t *em = (ebpf_module_t *)ptr; - ebpf_softirq_free(em); -} - /***************************************************************** * MAIN LOOP *****************************************************************/ diff --git a/collectors/ebpf.plugin/ebpf_swap.c b/collectors/ebpf.plugin/ebpf_swap.c index c9129a3fae..492b596782 100644 --- a/collectors/ebpf.plugin/ebpf_swap.c +++ b/collectors/ebpf.plugin/ebpf_swap.c @@ -230,23 +230,6 @@ static inline int ebpf_swap_load_and_attach(struct swap_bpf *obj, ebpf_module_t *****************************************************************/ /** - * Cachestat Free - * - * Cleanup variables after child threads to stop - * - * @param ptr thread data. - */ -static void ebpf_swap_free(ebpf_module_t *em) -{ - freez(swap_vector); - freez(swap_values); - - pthread_mutex_lock(&ebpf_exit_cleanup); - em->enabled = NETDATA_THREAD_EBPF_STOPPED; - pthread_mutex_unlock(&ebpf_exit_cleanup); -} - -/** * Swap exit * * Cancel thread and exit. @@ -256,7 +239,17 @@ static void ebpf_swap_free(ebpf_module_t *em) static void ebpf_swap_exit(void *ptr) { ebpf_module_t *em = (ebpf_module_t *)ptr; - ebpf_swap_free(em); + +#ifdef LIBBPF_MAJOR_VERSION + if (bpf_obj) + swap_bpf__destroy(bpf_obj); +#endif + if (em->objects) + ebpf_unload_legacy_code(em->objects, em->probe_links); + + pthread_mutex_lock(&ebpf_exit_cleanup); + em->enabled = NETDATA_THREAD_EBPF_STOPPED; + pthread_mutex_unlock(&ebpf_exit_cleanup); } /***************************************************************** diff --git a/collectors/ebpf.plugin/ebpf_vfs.c b/collectors/ebpf.plugin/ebpf_vfs.c index bfc7ee8f71..6cafafc385 100644 --- a/collectors/ebpf.plugin/ebpf_vfs.c +++ b/collectors/ebpf.plugin/ebpf_vfs.c @@ -404,23 +404,6 @@ static inline int ebpf_vfs_load_and_attach(struct vfs_bpf *obj, ebpf_module_t *e *****************************************************************/ /** - * Cachestat Free - * - * Cleanup variables after child threads to stop - * - * @param ptr thread data. - */ -static void ebpf_vfs_free(ebpf_module_t *em) -{ - freez(vfs_hash_values); - freez(vfs_vector); - - pthread_mutex_lock(&ebpf_exit_cleanup); - em->enabled = NETDATA_THREAD_EBPF_STOPPED; - pthread_mutex_unlock(&ebpf_exit_cleanup); -} - -/** * Exit * * Cancel thread and exit. @@ -430,7 +413,17 @@ static void ebpf_vfs_free(ebpf_module_t *em) static void ebpf_vfs_exit(void *ptr) { ebpf_module_t *em = (ebpf_module_t *)ptr; - ebpf_vfs_free(em); + +#ifdef LIBBPF_MAJOR_VERSION + if (vfs_bpf_obj) + vfs_bpf__destroy(vfs_bpf_obj); +#endif + if (em->objects) + ebpf_unload_legacy_code(em->objects, em->probe_links); + + pthread_mutex_lock(&ebpf_exit_cleanup); + em->enabled = NETDATA_THREAD_EBPF_STOPPED; + pthread_mutex_unlock(&ebpf_exit_cleanup); } /***************************************************************** |