@cryptotaxi247 / netdata-1 / commits / 49bcf61f6

Speed up eBPF exit before to bring functions (#15187)

thiagoftsm committed Jun 19, 2023 at 13:08 UTC 49bcf61f6d9d997d30359772497fb26fd1305019
13 files changed +168 -298
collectors/ebpf.plugin/ebpf.c
+57 -80
@@ -539,6 +539,31 @@ ARAL *ebpf_allocate_pid_aral(char *name, size_t size)
539 *
540 *****************************************************************/
541
542 +/**
543 + * Wait to avoid possible coredumps while process is closing.
544 + */
545 +static inline void ebpf_check_before2go()
546 +{
547 + int i = EBPF_OPTION_ALL_CHARTS;
548 + usec_t max = USEC_PER_SEC, step = 200000;
549 + while (i && max) {
550 + max -= step;
551 + sleep_usec(step);
552 + i = 0;
553 + int j;
554 + pthread_mutex_lock(&ebpf_exit_cleanup);
555 + for (j = 0; ebpf_modules[j].thread_name != NULL; j++) {
556 + if (ebpf_modules[j].enabled == NETDATA_THREAD_EBPF_RUNNING)
557 + i++;
558 + }
559 + pthread_mutex_unlock(&ebpf_exit_cleanup);
560 + }
561 +
562 + if (i) {
563 + error("eBPF cannot unload all threads on time, but it will go away");
564 + }
565 +}
566 +
567 /**
568 * Close the collector gracefully
569 */
@@ -561,8 +586,10 @@ static void ebpf_exit()
586 #ifdef NETDATA_INTERNAL_CHECKS
587 error("Good bye world! I was PID %d", main_thread_id);
588 #endif
564 - printf("DISABLE\n");
589 + fprintf(stdout, "EXIT\n");
590 + fflush(stdout);
591
592 + ebpf_check_before2go();
593 pthread_mutex_lock(&mutex_cgroup_shm);
594 if (shm_ebpf_cgroup.header) {
595 ebpf_unmap_cgroup_shared_memory();
@@ -604,6 +631,10 @@ static void ebpf_unload_unique_maps()
631 {
632 int i;
633 for (i = 0; ebpf_modules[i].thread_name; i++) {
634 + // These threads are cleaned with other functions
635 + if (i > EBPF_MODULE_SOCKET_IDX)
636 + continue;
637 +
638 if (ebpf_modules[i].enabled != NETDATA_THREAD_EBPF_STOPPED) {
639 if (ebpf_modules[i].enabled != NETDATA_THREAD_EBPF_NOT_RUNNING)
640 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()
642 continue;
643 }
644
614 - ebpf_unload_legacy_code(ebpf_modules[i].objects, ebpf_modules[i].probe_links);
615 - switch (i) {
616 - case EBPF_MODULE_CACHESTAT_IDX: {
617 -#ifdef LIBBPF_MAJOR_VERSION
618 - if (cachestat_bpf_obj)
619 - cachestat_bpf__destroy(cachestat_bpf_obj);
620 -#endif
621 - break;
622 - }
623 - case EBPF_MODULE_DCSTAT_IDX: {
624 -#ifdef LIBBPF_MAJOR_VERSION
625 - if (dc_bpf_obj)
626 - dc_bpf__destroy(dc_bpf_obj);
627 -#endif
628 - break;
629 - }
630 - case EBPF_MODULE_FD_IDX: {
631 -#ifdef LIBBPF_MAJOR_VERSION
632 - if (fd_bpf_obj)
633 - fd_bpf__destroy(fd_bpf_obj);
634 -#endif
635 - break;
636 - }
637 - case EBPF_MODULE_MOUNT_IDX: {
638 -#ifdef LIBBPF_MAJOR_VERSION
639 - if (mount_bpf_obj)
640 - mount_bpf__destroy(mount_bpf_obj);
641 -#endif
642 - break;
643 - }
644 - case EBPF_MODULE_SHM_IDX: {
645 -#ifdef LIBBPF_MAJOR_VERSION
646 - if (shm_bpf_obj)
647 - shm_bpf__destroy(shm_bpf_obj);
648 -#endif
649 - break;
650 - }
651 - case EBPF_MODULE_SOCKET_IDX: {
652 -#ifdef LIBBPF_MAJOR_VERSION
653 - if (socket_bpf_obj)
654 - socket_bpf__destroy(socket_bpf_obj);
655 -#endif
656 - break;
657 - }
658 - case EBPF_MODULE_SWAP_IDX: {
659 -#ifdef LIBBPF_MAJOR_VERSION
660 - if (bpf_obj)
661 - swap_bpf__destroy(bpf_obj);
662 -#endif
663 - break;
664 - }
665 - case EBPF_MODULE_VFS_IDX: {
645 + if (ebpf_modules[i].load == EBPF_LOAD_LEGACY) {
646 + ebpf_unload_legacy_code(ebpf_modules[i].objects, ebpf_modules[i].probe_links);
647 + continue;
648 + }
649 +
650 + if (i == EBPF_MODULE_SOCKET_IDX) {
651 #ifdef LIBBPF_MAJOR_VERSION
667 - if (vfs_bpf_obj)
668 - vfs_bpf__destroy(vfs_bpf_obj);
652 + if (socket_bpf_obj)
653 + socket_bpf__destroy(socket_bpf_obj);
654 #endif
670 - break;
671 - }
672 - case EBPF_MODULE_PROCESS_IDX:
673 - case EBPF_MODULE_DISK_IDX:
674 - case EBPF_MODULE_HARDIRQ_IDX:
675 - case EBPF_MODULE_SOFTIRQ_IDX:
676 - case EBPF_MODULE_OOMKILL_IDX:
677 - case EBPF_MODULE_MDFLUSH_IDX:
678 - default:
679 - continue;
655 }
656 +
657 }
658 }
659
@@ -689,11 +665,15 @@ static void ebpf_unload_unique_maps()
665 static void ebpf_unload_filesystems()
666 {
667 if (ebpf_modules[EBPF_MODULE_FILESYSTEM_IDX].enabled == NETDATA_THREAD_EBPF_NOT_RUNNING ||
692 - ebpf_modules[EBPF_MODULE_SYNC_IDX].enabled == NETDATA_THREAD_EBPF_RUNNING)
668 + ebpf_modules[EBPF_MODULE_FILESYSTEM_IDX].enabled == NETDATA_THREAD_EBPF_RUNNING ||
669 + ebpf_modules[EBPF_MODULE_FILESYSTEM_IDX].load != EBPF_LOAD_LEGACY)
670 return;
671
672 int i;
673 for (i = 0; localfs[i].filesystem != NULL; i++) {
674 + if (!localfs[i].objects)
675 + continue;
676 +
677 ebpf_unload_legacy_code(localfs[i].objects, localfs[i].probe_links);
678 }
679 }
@@ -711,6 +691,15 @@ static void ebpf_unload_sync()
691
692 int i;
693 for (i = 0; local_syscalls[i].syscall != NULL; i++) {
694 + if (!local_syscalls[i].enabled)
695 + continue;
696 +
697 +#ifdef LIBBPF_MAJOR_VERSION
698 + if (local_syscalls[i].sync_obj) {
699 + sync_bpf__destroy(local_syscalls[i].sync_obj);
700 + continue;
701 + }
702 +#endif
703 ebpf_unload_legacy_code(local_syscalls[i].objects, local_syscalls[i].probe_links);
704 }
705 }
@@ -753,19 +742,7 @@ static void ebpf_stop_threads(int sig)
742
743 ebpf_exit_plugin = 1;
744
756 - usec_t max = USEC_PER_SEC, step = 100000;
757 - while (i && max) {
758 - max -= step;
759 - sleep_usec(step);
760 - i = 0;
761 - int j;
762 - pthread_mutex_lock(&ebpf_exit_cleanup);
763 - for (j = 0; ebpf_modules[j].thread_name != NULL; j++) {
764 - if (ebpf_modules[j].enabled == NETDATA_THREAD_EBPF_RUNNING)
765 - i++;
766 - }
767 - pthread_mutex_unlock(&ebpf_exit_cleanup);
768 - }
745 + ebpf_check_before2go();
746
747 pthread_mutex_lock(&ebpf_exit_cleanup);
748 ebpf_unload_unique_maps();
@@ -2650,7 +2627,7 @@ int main(int argc, char **argv)
2627 (void)heartbeat_next(&hb, step);
2628
2629 pthread_mutex_lock(&ebpf_exit_cleanup);
2653 - if (ebpf_modules[i].enabled == NETDATA_THREAD_EBPF_RUNNING && process_pid_fd != -1) {
2630 + if (process_pid_fd != -1) {
2631 pthread_mutex_lock(&collect_data_mutex);
2632 if (++update_apps_list == update_apps_every) {
2633 update_apps_list = 0;
collectors/ebpf.plugin/ebpf_cachestat.c
+12 -22
@@ -336,27 +336,6 @@ static inline int ebpf_cachestat_load_and_attach(struct cachestat_bpf *obj, ebpf
336 *
337 *****************************************************************/
338
339 -/**
340 - * Cachestat Free
341 - *
342 - * Cleanup variables after child threads to stop
343 - *
344 - * @param ptr thread data.
345 - */
346 -static void ebpf_cachestat_free(ebpf_module_t *em)
347 -{
348 - pthread_mutex_lock(&ebpf_exit_cleanup);
349 - em->enabled = NETDATA_THREAD_EBPF_STOPPING;
350 - pthread_mutex_unlock(&ebpf_exit_cleanup);
351 -
352 - freez(cachestat_vector);
353 - freez(cachestat_values);
354 -
355 - pthread_mutex_lock(&ebpf_exit_cleanup);
356 - em->enabled = NETDATA_THREAD_EBPF_STOPPED;
357 - pthread_mutex_unlock(&ebpf_exit_cleanup);
358 -}
359 -
339 /**
340 * Cachestat exit.
341 *
@@ -368,7 +347,18 @@ static void ebpf_cachestat_exit(void *ptr)
347 {
348 ebpf_module_t *em = (ebpf_module_t *)ptr;
349
371 - ebpf_cachestat_free(em);
350 +#ifdef LIBBPF_MAJOR_VERSION
351 + if (cachestat_bpf_obj)
352 + cachestat_bpf__destroy(cachestat_bpf_obj);
353 +#endif
354 +
355 + if (em->objects) {
356 + ebpf_unload_legacy_code(em->objects, em->probe_links);
357 + }
358 +
359 + pthread_mutex_lock(&ebpf_exit_cleanup);
360 + em->enabled = NETDATA_THREAD_EBPF_STOPPED;
361 + pthread_mutex_unlock(&ebpf_exit_cleanup);
362 }
363
364 /*****************************************************************
collectors/ebpf.plugin/ebpf_dcstat.c
+10 -36
@@ -286,55 +286,29 @@ void dcstat_update_publish(netdata_publish_dcstat_t *out, uint64_t cache_access,
286 *****************************************************************/
287
288 /**
289 - * Clean names
290 - *
291 - * Clean the optional names allocated during startup.
292 - */
293 -void ebpf_dcstat_clean_names()
294 -{
295 - size_t i = 0;
296 - while (dc_optional_name[i].program_name) {
297 - freez(dc_optional_name[i].optional);
298 - i++;
299 - }
300 -}
301 -
302 -/**
303 - * DCstat Free
289 + * DCstat exit
290 *
305 - * Cleanup variables after child threads to stop
291 + * Cancel child and exit.
292 *
293 * @param ptr thread data.
294 */
309 -static void ebpf_dcstat_free(ebpf_module_t *em )
295 +static void ebpf_dcstat_exit(void *ptr)
296 {
311 - pthread_mutex_lock(&ebpf_exit_cleanup);
312 - em->enabled = NETDATA_THREAD_EBPF_STOPPING;
313 - pthread_mutex_unlock(&ebpf_exit_cleanup);
297 + ebpf_module_t *em = (ebpf_module_t *)ptr;
298
315 - freez(dcstat_vector);
316 - freez(dcstat_values);
299 +#ifdef LIBBPF_MAJOR_VERSION
300 + if (dc_bpf_obj)
301 + dc_bpf__destroy(dc_bpf_obj);
302 +#endif
303
318 - ebpf_dcstat_clean_names();
304 + if (em->objects)
305 + ebpf_unload_legacy_code(em->objects, em->probe_links);
306
307 pthread_mutex_lock(&ebpf_exit_cleanup);
308 em->enabled = NETDATA_THREAD_EBPF_STOPPED;
309 pthread_mutex_unlock(&ebpf_exit_cleanup);
310 }
311
325 -/**
326 - * DCstat exit
327 - *
328 - * Cancel child and exit.
329 - *
330 - * @param ptr thread data.
331 - */
332 -static void ebpf_dcstat_exit(void *ptr)
333 -{
334 - ebpf_module_t *em = (ebpf_module_t *)ptr;
335 - ebpf_dcstat_free(em);
336 -}
337 -
312 /*****************************************************************
313 *
314 * APPS
collectors/ebpf.plugin/ebpf_disk.c
+7 -19
@@ -435,17 +435,18 @@ static void ebpf_cleanup_disk_list()
435 }
436
437 /**
438 - * DISK Free
438 + * Disk exit.
439 *
440 - * Cleanup variables after child threads to stop
440 + * Cancel child and exit.
441 *
442 * @param ptr thread data.
443 */
444 -static void ebpf_disk_free(ebpf_module_t *em)
444 +static void ebpf_disk_exit(void *ptr)
445 {
446 - pthread_mutex_lock(&ebpf_exit_cleanup);
447 - em->enabled = NETDATA_THREAD_EBPF_STOPPING;
448 - pthread_mutex_unlock(&ebpf_exit_cleanup);
446 + ebpf_module_t *em = (ebpf_module_t *)ptr;
447 +
448 + if (em->objects)
449 + ebpf_unload_legacy_code(em->objects, em->probe_links);
450
451 ebpf_disk_disable_tracepoints();
452
@@ -463,19 +464,6 @@ static void ebpf_disk_free(ebpf_module_t *em)
464 pthread_mutex_unlock(&ebpf_exit_cleanup);
465 }
466
466 -/**
467 - * Disk exit.
468 - *
469 - * Cancel child and exit.
470 - *
471 - * @param ptr thread data.
472 - */
473 -static void ebpf_disk_exit(void *ptr)
474 -{
475 - ebpf_module_t *em = (ebpf_module_t *)ptr;
476 - ebpf_disk_free(em);
477 -}
478 -
467 /*****************************************************************
468 *
469 * MAIN LOOP
collectors/ebpf.plugin/ebpf_fd.c
+10 -21
@@ -370,39 +370,28 @@ static inline int ebpf_fd_load_and_attach(struct fd_bpf *obj, ebpf_module_t *em)
370 *****************************************************************/
371
372 /**
373 - * FD Free
373 + * FD Exit
374 *
375 - * Cleanup variables after child threads to stop
375 + * Cancel child thread and exit.
376 *
377 * @param ptr thread data.
378 */
379 -static void ebpf_fd_free(ebpf_module_t *em)
379 +static void ebpf_fd_exit(void *ptr)
380 {
381 - pthread_mutex_lock(&ebpf_exit_cleanup);
382 - em->enabled = NETDATA_THREAD_EBPF_STOPPING;
383 - pthread_mutex_unlock(&ebpf_exit_cleanup);
381 + ebpf_module_t *em = (ebpf_module_t *)ptr;
382
385 - freez(fd_values);
386 - freez(fd_vector);
383 +#ifdef LIBBPF_MAJOR_VERSION
384 + if (fd_bpf_obj)
385 + fd_bpf__destroy(fd_bpf_obj);
386 +#endif
387 + if (em->objects)
388 + ebpf_unload_legacy_code(em->objects, em->probe_links);
389
390 pthread_mutex_lock(&ebpf_exit_cleanup);
391 em->enabled = NETDATA_THREAD_EBPF_STOPPED;
392 pthread_mutex_unlock(&ebpf_exit_cleanup);
393 }
394
393 -/**
394 - * FD Exit
395 - *
396 - * Cancel child thread and exit.
397 - *
398 - * @param ptr thread data.
399 - */
400 -static void ebpf_fd_exit(void *ptr)
401 -{
402 - ebpf_module_t *em = (ebpf_module_t *)ptr;
403 - ebpf_fd_free(em);
404 -}
405 -
395 /*****************************************************************
396 *
397 * MAIN LOOP
collectors/ebpf.plugin/ebpf_hardirq.c
+9 -16
@@ -188,35 +188,28 @@ void ebpf_hardirq_release(hardirq_val_t *stat)
188 *****************************************************************/
189
190 /**
191 - * Hardirq Free
191 + * Hardirq Exit
192 *
193 - * Cleanup variables after child threads to stop
193 + * Cancel child and exit.
194 *
195 * @param ptr thread data.
196 */
197 -static void ebpf_hardirq_free(ebpf_module_t *em)
197 +static void hardirq_exit(void *ptr)
198 {
199 + ebpf_module_t *em = (ebpf_module_t *)ptr;
200 +
201 + if (em->objects)
202 + ebpf_unload_legacy_code(em->objects, em->probe_links);
203 +
204 for (int i = 0; hardirq_tracepoints[i].class != NULL; i++) {
205 ebpf_disable_tracepoint(&hardirq_tracepoints[i]);
206 }
207 +
208 pthread_mutex_lock(&ebpf_exit_cleanup);
209 em->enabled = NETDATA_THREAD_EBPF_STOPPED;
210 pthread_mutex_unlock(&ebpf_exit_cleanup);
211 }
212
207 -/**
208 - * Hardirq Exit
209 - *
210 - * Cancel child and exit.
211 - *
212 - * @param ptr thread data.
213 - */
214 -static void hardirq_exit(void *ptr)
215 -{
216 - ebpf_module_t *em = (ebpf_module_t *)ptr;
217 - ebpf_hardirq_free(em);
218 -}
219 -
213 /*****************************************************************
214 * MAIN LOOP
215 *****************************************************************/
collectors/ebpf.plugin/ebpf_mdflush.c
+7 -16
@@ -38,21 +38,6 @@ static avl_tree_lock mdflush_pub;
38 // tmp store for mdflush values we get from a per-CPU eBPF map.
39 static mdflush_ebpf_val_t *mdflush_ebpf_vals = NULL;
40
41 -/**
42 - * MDflush Free
43 - *
44 - * Cleanup variables after child threads to stop
45 - *
46 - * @param ptr thread data.
47 - */
48 -static void ebpf_mdflush_free(ebpf_module_t *em)
49 -{
50 - freez(mdflush_ebpf_vals);
51 - pthread_mutex_lock(&ebpf_exit_cleanup);
52 - em->enabled = NETDATA_THREAD_EBPF_STOPPED;
53 - pthread_mutex_unlock(&ebpf_exit_cleanup);
54 -}
55 -
41 /**
42 * MDflush exit
43 *
@@ -63,7 +48,13 @@ static void ebpf_mdflush_free(ebpf_module_t *em)
48 static void mdflush_exit(void *ptr)
49 {
50 ebpf_module_t *em = (ebpf_module_t *)ptr;
66 - ebpf_mdflush_free(em);
51 +
52 + if (em->objects)
53 + ebpf_unload_legacy_code(em->objects, em->probe_links);
54 +
55 + pthread_mutex_lock(&ebpf_exit_cleanup);
56 + em->enabled = NETDATA_THREAD_EBPF_STOPPED;
57 + pthread_mutex_unlock(&ebpf_exit_cleanup);
58 }
59
60 /**
collectors/ebpf.plugin/ebpf_mount.c
+11 -15
@@ -222,20 +222,6 @@ static inline int ebpf_mount_load_and_attach(struct mount_bpf *obj, ebpf_module_
222 *
223 *****************************************************************/
224
225 -/**
226 - * Mount Free
227 - *
228 - * Cleanup variables after child threads to stop
229 - *
230 - * @param ptr thread data.
231 - */
232 -static void ebpf_mount_free(ebpf_module_t *em)
233 -{
234 - pthread_mutex_lock(&ebpf_exit_cleanup);
235 - em->enabled = NETDATA_THREAD_EBPF_STOPPED;
236 - pthread_mutex_unlock(&ebpf_exit_cleanup);
237 -}
238 -
225 /**
226 * Mount Exit
227 *
@@ -246,7 +232,17 @@ static void ebpf_mount_free(ebpf_module_t *em)
232 static void ebpf_mount_exit(void *ptr)
233 {
234 ebpf_module_t *em = (ebpf_module_t *)ptr;
249 - ebpf_mount_free(em);
235 +
236 +#ifdef LIBBPF_MAJOR_VERSION
237 + if (mount_bpf_obj)
238 + mount_bpf__destroy(mount_bpf_obj);
239 +#endif
240 + if (em->objects)
241 + ebpf_unload_legacy_code(em->objects, em->probe_links);
242 +
243 + pthread_mutex_lock(&ebpf_exit_cleanup);
244 + em->enabled = NETDATA_THREAD_EBPF_STOPPED;
245 + pthread_mutex_unlock(&ebpf_exit_cleanup);
246 }
247
248 /*****************************************************************
collectors/ebpf.plugin/ebpf_oomkill.c
+4
@@ -52,6 +52,10 @@ static netdata_publish_syscall_t oomkill_publish_aggregated = {.name = "oomkill"
52 static void oomkill_cleanup(void *ptr)
53 {
54 ebpf_module_t *em = (ebpf_module_t *)ptr;
55 +
56 + if (em->objects)
57 + ebpf_unload_legacy_code(em->objects, em->probe_links);
58 +
59 pthread_mutex_lock(&ebpf_exit_cleanup);
60 em->enabled = NETDATA_THREAD_EBPF_STOPPED;
61 pthread_mutex_unlock(&ebpf_exit_cleanup);
collectors/ebpf.plugin/ebpf_shm.c
+12 -18
@@ -288,23 +288,6 @@ static inline int ebpf_shm_load_and_attach(struct shm_bpf *obj, ebpf_module_t *e
288 * FUNCTIONS TO CLOSE THE THREAD
289 *****************************************************************/
290
291 -/**
292 - * SHM Free
293 - *
294 - * Cleanup variables after child threads to stop
295 - *
296 - * @param ptr thread data.
297 - */
298 -static void ebpf_shm_free(ebpf_module_t *em)
299 -{
300 - freez(shm_vector);
301 - freez(shm_values);
302 -
303 - pthread_mutex_lock(&ebpf_exit_cleanup);
304 - em->enabled = NETDATA_THREAD_EBPF_STOPPED;
305 - pthread_mutex_unlock(&ebpf_exit_cleanup);
306 -}
307 -
291 /**
292 * SHM Exit
293 *
@@ -315,7 +298,18 @@ static void ebpf_shm_free(ebpf_module_t *em)
298 static void ebpf_shm_exit(void *ptr)
299 {
300 ebpf_module_t *em = (ebpf_module_t *)ptr;
318 - ebpf_shm_free(em);
301 +
302 +#ifdef LIBBPF_MAJOR_VERSION
303 + if (shm_bpf_obj)
304 + shm_bpf__destroy(shm_bpf_obj);
305 +#endif
306 +
307 + if (em->objects)
308 + ebpf_unload_legacy_code(em->objects, em->probe_links);
309 +
310 + pthread_mutex_lock(&ebpf_exit_cleanup);
311 + em->enabled = NETDATA_THREAD_EBPF_STOPPED;
312 + pthread_mutex_unlock(&ebpf_exit_cleanup);
313 }
314
315 /*****************************************************************
collectors/ebpf.plugin/ebpf_softirq.c
+7 -19
@@ -61,17 +61,18 @@ static softirq_val_t softirq_vals[] = {
61 static softirq_ebpf_val_t *softirq_ebpf_vals = NULL;
62
63 /**
64 - * Cachestat Free
64 + * Cleanup
65 *
66 - * Cleanup variables after child threads to stop
66 + * Clean up allocated memory.
67 *
68 * @param ptr thread data.
69 */
70 -static void ebpf_softirq_free(ebpf_module_t *em)
70 +static void softirq_cleanup(void *ptr)
71 {
72 - pthread_mutex_lock(&ebpf_exit_cleanup);
73 - em->enabled = NETDATA_THREAD_EBPF_STOPPING;
74 - pthread_mutex_unlock(&ebpf_exit_cleanup);
72 + ebpf_module_t *em = (ebpf_module_t *)ptr;
73 +
74 + if (em->objects)
75 + ebpf_unload_legacy_code(em->objects, em->probe_links);
76
77 for (int i = 0; softirq_tracepoints[i].class != NULL; i++) {
78 ebpf_disable_tracepoint(&softirq_tracepoints[i]);
@@ -83,19 +84,6 @@ static void ebpf_softirq_free(ebpf_module_t *em)
84 pthread_mutex_unlock(&ebpf_exit_cleanup);
85 }
86
86 -/**
87 - * Cleanup
88 - *
89 - * Clean up allocated memory.
90 - *
91 - * @param ptr thread data.
92 - */
93 -static void softirq_cleanup(void *ptr)
94 -{
95 - ebpf_module_t *em = (ebpf_module_t *)ptr;
96 - ebpf_softirq_free(em);
97 -}
98 -
87 /*****************************************************************
88 * MAIN LOOP
89 *****************************************************************/
collectors/ebpf.plugin/ebpf_swap.c
+11 -18
@@ -229,23 +229,6 @@ static inline int ebpf_swap_load_and_attach(struct swap_bpf *obj, ebpf_module_t
229 *
230 *****************************************************************/
231
232 -/**
233 - * Cachestat Free
234 - *
235 - * Cleanup variables after child threads to stop
236 - *
237 - * @param ptr thread data.
238 - */
239 -static void ebpf_swap_free(ebpf_module_t *em)
240 -{
241 - freez(swap_vector);
242 - freez(swap_values);
243 -
244 - pthread_mutex_lock(&ebpf_exit_cleanup);
245 - em->enabled = NETDATA_THREAD_EBPF_STOPPED;
246 - pthread_mutex_unlock(&ebpf_exit_cleanup);
247 -}
248 -
232 /**
233 * Swap exit
234 *
@@ -256,7 +239,17 @@ static void ebpf_swap_free(ebpf_module_t *em)
239 static void ebpf_swap_exit(void *ptr)
240 {
241 ebpf_module_t *em = (ebpf_module_t *)ptr;
259 - ebpf_swap_free(em);
242 +
243 +#ifdef LIBBPF_MAJOR_VERSION
244 + if (bpf_obj)
245 + swap_bpf__destroy(bpf_obj);
246 +#endif
247 + if (em->objects)
248 + ebpf_unload_legacy_code(em->objects, em->probe_links);
249 +
250 + pthread_mutex_lock(&ebpf_exit_cleanup);
251 + em->enabled = NETDATA_THREAD_EBPF_STOPPED;
252 + pthread_mutex_unlock(&ebpf_exit_cleanup);
253 }
254
255 /*****************************************************************
collectors/ebpf.plugin/ebpf_vfs.c
+11 -18
@@ -403,23 +403,6 @@ static inline int ebpf_vfs_load_and_attach(struct vfs_bpf *obj, ebpf_module_t *e
403 *
404 *****************************************************************/
405
406 -/**
407 - * Cachestat Free
408 - *
409 - * Cleanup variables after child threads to stop
410 - *
411 - * @param ptr thread data.
412 - */
413 -static void ebpf_vfs_free(ebpf_module_t *em)
414 -{
415 - freez(vfs_hash_values);
416 - freez(vfs_vector);
417 -
418 - pthread_mutex_lock(&ebpf_exit_cleanup);
419 - em->enabled = NETDATA_THREAD_EBPF_STOPPED;
420 - pthread_mutex_unlock(&ebpf_exit_cleanup);
421 -}
422 -
406 /**
407 * Exit
408 *
@@ -430,7 +413,17 @@ static void ebpf_vfs_free(ebpf_module_t *em)
413 static void ebpf_vfs_exit(void *ptr)
414 {
415 ebpf_module_t *em = (ebpf_module_t *)ptr;
433 - ebpf_vfs_free(em);
416 +
417 +#ifdef LIBBPF_MAJOR_VERSION
418 + if (vfs_bpf_obj)
419 + vfs_bpf__destroy(vfs_bpf_obj);
420 +#endif
421 + if (em->objects)
422 + ebpf_unload_legacy_code(em->objects, em->probe_links);
423 +
424 + pthread_mutex_lock(&ebpf_exit_cleanup);
425 + em->enabled = NETDATA_THREAD_EBPF_STOPPED;
426 + pthread_mutex_unlock(&ebpf_exit_cleanup);
427 }
428
429 /*****************************************************************