@cryptotaxi247 / netdata-1 / commits / be615262a

Improve ebpf exit (#14270)

thiagoftsm committed Jan 27, 2023 at 16:31 UTC be615262a2a933d1c51aa927c83629f9c1e8a713
30 files changed +110 -975
collectors/ebpf.plugin/ebpf.c
+41 -25
@@ -483,7 +483,7 @@ static void ebpf_exit()
483 if (unlink(filename))
484 error("Cannot remove PID file %s", filename);
485
486 - exit(0);
486 + ebpf_exit_plugin = 2;
487 }
488
489 /**
@@ -534,7 +534,7 @@ static void ebpf_stop_threads(int sig)
534 pthread_mutex_unlock(&ebpf_exit_cleanup);
535
536 ebpf_exit_plugin = 1;
537 - usec_t max = 3 * USEC_PER_SEC, step = 100000;
537 + usec_t max = USEC_PER_SEC, step = 100000;
538 while (i && max) {
539 max -= step;
540 sleep_usec(step);
@@ -548,32 +548,35 @@ static void ebpf_stop_threads(int sig)
548 pthread_mutex_unlock(&ebpf_exit_cleanup);
549 }
550
551 - //Unload threads(except sync and filesystem)
552 - pthread_mutex_lock(&ebpf_exit_cleanup);
553 - for (i = 0; ebpf_threads[i].name != NULL; i++) {
554 - if (ebpf_threads[i].enabled == NETDATA_THREAD_EBPF_STOPPED && i != EBPF_MODULE_FILESYSTEM_IDX &&
555 - i != EBPF_MODULE_SYNC_IDX)
556 - ebpf_unload_legacy_code(ebpf_modules[i].objects, ebpf_modules[i].probe_links);
557 - }
558 - pthread_mutex_unlock(&ebpf_exit_cleanup);
551 + if (!i) {
552 + //Unload threads(except sync and filesystem)
553 + pthread_mutex_lock(&ebpf_exit_cleanup);
554 + for (i = 0; ebpf_threads[i].name != NULL; i++) {
555 + if (ebpf_threads[i].enabled == NETDATA_THREAD_EBPF_STOPPED && i != EBPF_MODULE_FILESYSTEM_IDX &&
556 + i != EBPF_MODULE_SYNC_IDX)
557 + ebpf_unload_legacy_code(ebpf_modules[i].objects, ebpf_modules[i].probe_links);
558 + }
559 + pthread_mutex_unlock(&ebpf_exit_cleanup);
560
560 - //Unload filesystem
561 - pthread_mutex_lock(&ebpf_exit_cleanup);
562 - if (ebpf_threads[EBPF_MODULE_FILESYSTEM_IDX].enabled == NETDATA_THREAD_EBPF_STOPPED) {
563 - for (i = 0; localfs[i].filesystem != NULL; i++) {
564 - ebpf_unload_legacy_code(localfs[i].objects, localfs[i].probe_links);
561 + //Unload filesystem
562 + pthread_mutex_lock(&ebpf_exit_cleanup);
563 + if (ebpf_threads[EBPF_MODULE_FILESYSTEM_IDX].enabled == NETDATA_THREAD_EBPF_STOPPED) {
564 + for (i = 0; localfs[i].filesystem != NULL; i++) {
565 + ebpf_unload_legacy_code(localfs[i].objects, localfs[i].probe_links);
566 + }
567 }
566 - }
567 - pthread_mutex_unlock(&ebpf_exit_cleanup);
568 + pthread_mutex_unlock(&ebpf_exit_cleanup);
569
569 - //Unload Sync
570 - pthread_mutex_lock(&ebpf_exit_cleanup);
571 - if (ebpf_threads[EBPF_MODULE_SYNC_IDX].enabled == NETDATA_THREAD_EBPF_STOPPED) {
572 - for (i = 0; local_syscalls[i].syscall != NULL; i++) {
573 - ebpf_unload_legacy_code(local_syscalls[i].objects, local_syscalls[i].probe_links);
570 + //Unload Sync
571 + pthread_mutex_lock(&ebpf_exit_cleanup);
572 + if (ebpf_threads[EBPF_MODULE_SYNC_IDX].enabled == NETDATA_THREAD_EBPF_STOPPED) {
573 + for (i = 0; local_syscalls[i].syscall != NULL; i++) {
574 + ebpf_unload_legacy_code(local_syscalls[i].objects, local_syscalls[i].probe_links);
575 + }
576 }
577 + pthread_mutex_unlock(&ebpf_exit_cleanup);
578 +
579 }
576 - pthread_mutex_unlock(&ebpf_exit_cleanup);
580
581 ebpf_exit();
582 }
@@ -2245,12 +2248,25 @@ int main(int argc, char **argv)
2248 }
2249 }
2250
2248 - usec_t step = EBPF_DEFAULT_UPDATE_EVERY * USEC_PER_SEC;
2251 + usec_t step = USEC_PER_SEC;
2252 + int counter = NETDATA_EBPF_CGROUP_UPDATE - 1;
2253 heartbeat_t hb;
2254 heartbeat_init(&hb);
2255 //Plugin will be killed when it receives a signal
2252 - while (!ebpf_exit_plugin) {
2256 + while (ebpf_exit_plugin != 2) {
2257 (void)heartbeat_next(&hb, step);
2258 + if (ebpf_exit_plugin == 2)
2259 + break;
2260 +
2261 + // We are using a small heartbeat time to wake up thread,
2262 + // but we should not update so frequently the shared memory data
2263 + if (++counter >= NETDATA_EBPF_CGROUP_UPDATE) {
2264 + counter = 0;
2265 + if (!shm_ebpf_cgroup.header)
2266 + ebpf_map_cgroup_shared_memory();
2267 +
2268 + ebpf_parse_cgroup_shm_data();
2269 + }
2270 }
2271
2272 return 0;
collectors/ebpf.plugin/ebpf_cachestat.c
+3 -65
@@ -15,15 +15,6 @@ netdata_cachestat_pid_t *cachestat_vector = NULL;
15 static netdata_idx_t cachestat_hash_values[NETDATA_CACHESTAT_END];
16 static netdata_idx_t *cachestat_values = NULL;
17
18 -struct netdata_static_thread cachestat_threads = {.name = "CACHESTAT KERNEL",
19 - .config_section = NULL,
20 - .config_name = NULL,
21 - .env_name = NULL,
22 - .enabled = 1,
23 - .thread = NULL,
24 - .init_routine = NULL,
25 - .start_routine = NULL};
26 -
18 ebpf_local_maps_t cachestat_maps[] = {{.name = "cstat_global", .internal_input = NETDATA_CACHESTAT_END,
19 .user_input = 0, .type = NETDATA_EBPF_MAP_STATIC,
20 .map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
@@ -342,18 +333,13 @@ static inline int ebpf_cachestat_load_and_attach(struct cachestat_bpf *obj, ebpf
333 static void ebpf_cachestat_free(ebpf_module_t *em)
334 {
335 pthread_mutex_lock(&ebpf_exit_cleanup);
345 - if (em->thread->enabled == NETDATA_THREAD_EBPF_RUNNING) {
346 - em->thread->enabled = NETDATA_THREAD_EBPF_STOPPING;
347 - pthread_mutex_unlock(&ebpf_exit_cleanup);
348 - return;
349 - }
336 + em->thread->enabled = NETDATA_THREAD_EBPF_STOPPING;
337 pthread_mutex_unlock(&ebpf_exit_cleanup);
338
339 ebpf_cleanup_publish_syscall(cachestat_counter_publish_aggregated);
340
341 freez(cachestat_vector);
342 freez(cachestat_values);
356 - freez(cachestat_threads.thread);
343
344 #ifdef LIBBPF_MAJOR_VERSION
345 if (bpf_obj)
@@ -374,21 +360,7 @@ static void ebpf_cachestat_free(ebpf_module_t *em)
360 static void ebpf_cachestat_exit(void *ptr)
361 {
362 ebpf_module_t *em = (ebpf_module_t *)ptr;
377 - if (cachestat_threads.thread)
378 - netdata_thread_cancel(*cachestat_threads.thread);
379 - ebpf_cachestat_free(em);
380 -}
363
382 -/**
383 - * Cachestat cleanup
384 - *
385 - * Clean up allocated addresses.
386 - *
387 - * @param ptr thread data.
388 - */
389 -static void ebpf_cachestat_cleanup(void *ptr)
390 -{
391 - ebpf_module_t *em = (ebpf_module_t *)ptr;
364 ebpf_cachestat_free(em);
365 }
366
@@ -668,7 +640,7 @@ void ebpf_cachestat_create_apps_charts(struct ebpf_module *em, void *ptr)
640 *
641 * Read the table with number of calls for all functions
642 */
671 -static void read_global_table()
643 +static void ebpf_cachestat_read_global_table()
644 {
645 uint32_t idx;
646 netdata_idx_t *val = cachestat_hash_values;
@@ -688,35 +660,6 @@ static void read_global_table()
660 }
661 }
662
691 -/**
692 - * Socket read hash
693 - *
694 - * This is the thread callback.
695 - * This thread is necessary, because we cannot freeze the whole plugin to read the data on very busy socket.
696 - *
697 - * @param ptr It is a NULL value for this thread.
698 - *
699 - * @return It always returns NULL.
700 - */
701 -void *ebpf_cachestat_read_hash(void *ptr)
702 -{
703 - netdata_thread_cleanup_push(ebpf_cachestat_cleanup, ptr);
704 - heartbeat_t hb;
705 - heartbeat_init(&hb);
706 -
707 - ebpf_module_t *em = (ebpf_module_t *)ptr;
708 -
709 - usec_t step = NETDATA_LATENCY_CACHESTAT_SLEEP_MS * em->update_every;
710 - while (!ebpf_exit_plugin) {
711 - (void)heartbeat_next(&hb, step);
712 -
713 - read_global_table();
714 - }
715 -
716 - netdata_thread_cleanup_pop(1);
717 - return NULL;
718 -}
719 -
663 /**
664 * Send global
665 *
@@ -1118,12 +1061,6 @@ void ebpf_cachestat_send_cgroup_data(int update_every)
1061 */
1062 static void cachestat_collector(ebpf_module_t *em)
1063 {
1121 - cachestat_threads.thread = callocz(1, sizeof(netdata_thread_t));
1122 - cachestat_threads.start_routine = ebpf_cachestat_read_hash;
1123 -
1124 - netdata_thread_create(cachestat_threads.thread, cachestat_threads.name, NETDATA_THREAD_OPTION_DEFAULT,
1125 - ebpf_cachestat_read_hash, em);
1126 -
1064 netdata_publish_cachestat_t publish;
1065 memset(&publish, 0, sizeof(publish));
1066 int cgroups = em->cgroup_charts;
@@ -1138,6 +1075,7 @@ static void cachestat_collector(ebpf_module_t *em)
1075 break;
1076
1077 netdata_apps_integration_flags_t apps = em->apps_charts;
1078 + ebpf_cachestat_read_global_table();
1079 pthread_mutex_lock(&collect_data_mutex);
1080 if (apps)
1081 read_apps_table();
collectors/ebpf.plugin/ebpf_cachestat.h
-2
@@ -19,8 +19,6 @@
19 #define EBPF_CACHESTAT_DIMENSION_HITS "hits/s"
20 #define EBPF_CACHESTAT_DIMENSION_MISSES "misses/s"
21
22 -#define NETDATA_LATENCY_CACHESTAT_SLEEP_MS 600000ULL
23 -
22 // configuration file
23 #define NETDATA_CACHESTAT_CONFIG_FILE "cachestat.conf"
24
collectors/ebpf.plugin/ebpf_dcstat.c
+3 -64
@@ -19,15 +19,6 @@ struct config dcstat_config = { .first_section = NULL,
19 .index = { .avl_tree = { .root = NULL, .compar = appconfig_section_compare },
20 .rwlock = AVL_LOCK_INITIALIZER } };
21
22 -struct netdata_static_thread dcstat_threads = {"DCSTAT KERNEL",
23 - .config_section = NULL,
24 - .config_name = NULL,
25 - .env_name = NULL,
26 - .enabled = 1,
27 - .thread = NULL,
28 - .init_routine = NULL,
29 - .start_routine = NULL};
30 -
22 ebpf_local_maps_t dcstat_maps[] = {{.name = "dcstat_global", .internal_input = NETDATA_DIRECTORY_CACHE_END,
23 .user_input = 0, .type = NETDATA_EBPF_MAP_STATIC,
24 .map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
@@ -303,16 +294,11 @@ void ebpf_dcstat_clean_names()
294 static void ebpf_dcstat_free(ebpf_module_t *em )
295 {
296 pthread_mutex_lock(&ebpf_exit_cleanup);
306 - if (em->thread->enabled == NETDATA_THREAD_EBPF_RUNNING) {
307 - em->thread->enabled = NETDATA_THREAD_EBPF_STOPPING;
308 - pthread_mutex_unlock(&ebpf_exit_cleanup);
309 - return;
310 - }
297 + em->thread->enabled = NETDATA_THREAD_EBPF_STOPPING;
298 pthread_mutex_unlock(&ebpf_exit_cleanup);
299
300 freez(dcstat_vector);
301 freez(dcstat_values);
315 - freez(dcstat_threads.thread);
302
303 ebpf_cleanup_publish_syscall(dcstat_counter_publish_aggregated);
304
@@ -336,19 +322,6 @@ static void ebpf_dcstat_free(ebpf_module_t *em )
322 * @param ptr thread data.
323 */
324 static void ebpf_dcstat_exit(void *ptr)
339 -{
340 - ebpf_module_t *em = (ebpf_module_t *)ptr;
341 - if (dcstat_threads.thread)
342 - netdata_thread_cancel(*dcstat_threads.thread);
343 - ebpf_dcstat_free(em);
344 -}
345 -
346 -/**
347 - * Clean up the main thread.
348 - *
349 - * @param ptr thread data.
350 - */
351 -static void ebpf_dcstat_cleanup(void *ptr)
325 {
326 ebpf_module_t *em = (ebpf_module_t *)ptr;
327 ebpf_dcstat_free(em);
@@ -539,7 +512,7 @@ static void ebpf_update_dc_cgroup()
512 *
513 * Read the table with number of calls for all functions
514 */
542 -static void read_global_table()
515 +static void ebpf_dc_read_global_table()
516 {
517 uint32_t idx;
518 netdata_idx_t *val = dcstat_hash_values;
@@ -559,35 +532,6 @@ static void read_global_table()
532 }
533 }
534
562 -/**
563 - * DCstat read hash
564 - *
565 - * This is the thread callback.
566 - * This thread is necessary, because we cannot freeze the whole plugin to read the data.
567 - *
568 - * @param ptr It is a NULL value for this thread.
569 - *
570 - * @return It always returns NULL.
571 - */
572 -void *ebpf_dcstat_read_hash(void *ptr)
573 -{
574 - netdata_thread_cleanup_push(ebpf_dcstat_cleanup, ptr);
575 - heartbeat_t hb;
576 - heartbeat_init(&hb);
577 -
578 - ebpf_module_t *em = (ebpf_module_t *)ptr;
579 -
580 - usec_t step = NETDATA_LATENCY_DCSTAT_SLEEP_MS * em->update_every;
581 - while (!ebpf_exit_plugin) {
582 - (void)heartbeat_next(&hb, step);
583 -
584 - read_global_table();
585 - }
586 -
587 - netdata_thread_cleanup_pop(1);
588 - return NULL;
589 -}
590 -
535 /**
536 * Cachestat sum PIDs
537 *
@@ -1035,12 +979,6 @@ void ebpf_dc_send_cgroup_data(int update_every)
979 */
980 static void dcstat_collector(ebpf_module_t *em)
981 {
1038 - dcstat_threads.thread = mallocz(sizeof(netdata_thread_t));
1039 - dcstat_threads.start_routine = ebpf_dcstat_read_hash;
1040 -
1041 - netdata_thread_create(dcstat_threads.thread, dcstat_threads.name, NETDATA_THREAD_OPTION_DEFAULT,
1042 - ebpf_dcstat_read_hash, em);
1043 -
982 netdata_publish_dcstat_t publish;
983 memset(&publish, 0, sizeof(publish));
984 int cgroups = em->cgroup_charts;
@@ -1054,6 +992,7 @@ static void dcstat_collector(ebpf_module_t *em)
992 break;
993
994 netdata_apps_integration_flags_t apps = em->apps_charts;
995 + ebpf_dc_read_global_table();
996 pthread_mutex_lock(&collect_data_mutex);
997 if (apps)
998 read_apps_table();
collectors/ebpf.plugin/ebpf_dcstat.h
-2
@@ -28,8 +28,6 @@
28 #define NETDATA_SYSTEMD_DC_NOT_CACHE_CONTEXT "services.dc_not_cache"
29 #define NETDATA_SYSTEMD_DC_NOT_FOUND_CONTEXT "services.dc_not_found"
30
31 -#define NETDATA_LATENCY_DCSTAT_SLEEP_MS 700000ULL
32 -
31 enum directory_cache_indexes {
32 NETDATA_DCSTAT_IDX_RATIO,
33 NETDATA_DCSTAT_IDX_REFERENCE,
collectors/ebpf.plugin/ebpf_disk.c
+2 -65
@@ -33,16 +33,6 @@ static netdata_syscall_stat_t disk_aggregated_data[NETDATA_EBPF_HIST_MAX_BINS];
33 static netdata_publish_syscall_t disk_publish_aggregated[NETDATA_EBPF_HIST_MAX_BINS];
34
35 static netdata_idx_t *disk_hash_values = NULL;
36 -static struct netdata_static_thread disk_threads = {
37 - .name = "DISK KERNEL",
38 - .config_section = NULL,
39 - .config_name = NULL,
40 - .env_name = NULL,
41 - .enabled = 1,
42 - .thread = NULL,
43 - .init_routine = NULL,
44 - .start_routine = NULL
45 -};
36
37 ebpf_publish_disk_t *plot_disks = NULL;
38 pthread_mutex_t plot_mutex;
@@ -439,11 +429,7 @@ static void ebpf_cleanup_disk_list()
429 static void ebpf_disk_free(ebpf_module_t *em)
430 {
431 pthread_mutex_lock(&ebpf_exit_cleanup);
442 - if (em->thread->enabled == NETDATA_THREAD_EBPF_RUNNING) {
443 - em->thread->enabled = NETDATA_THREAD_EBPF_STOPPING;
444 - pthread_mutex_unlock(&ebpf_exit_cleanup);
445 - return;
446 - }
432 + em->thread->enabled = NETDATA_THREAD_EBPF_STOPPING;
433 pthread_mutex_unlock(&ebpf_exit_cleanup);
434
435 ebpf_disk_disable_tracepoints();
@@ -452,7 +438,6 @@ static void ebpf_disk_free(ebpf_module_t *em)
438 ebpf_histogram_dimension_cleanup(dimensions, NETDATA_EBPF_HIST_MAX_BINS);
439
440 freez(disk_hash_values);
455 - freez(disk_threads.thread);
441 pthread_mutex_destroy(&plot_mutex);
442
443 ebpf_cleanup_plot_disks();
@@ -471,21 +456,6 @@ static void ebpf_disk_free(ebpf_module_t *em)
456 * @param ptr thread data.
457 */
458 static void ebpf_disk_exit(void *ptr)
474 -{
475 - ebpf_module_t *em = (ebpf_module_t *)ptr;
476 - if (disk_threads.thread)
477 - netdata_thread_cancel(*disk_threads.thread);
478 - ebpf_disk_free(em);
479 -}
480 -
481 -/**
482 - * Disk Cleanup
483 - *
484 - * Clean up allocated memory.
485 - *
486 - * @param ptr thread data.
487 - */
488 -static void ebpf_disk_cleanup(void *ptr)
459 {
460 ebpf_module_t *em = (ebpf_module_t *)ptr;
461 ebpf_disk_free(em);
@@ -592,35 +562,6 @@ static void read_hard_disk_tables(int table)
562 }
563 }
564
595 -/**
596 - * Disk read hash
597 - *
598 - * This is the thread callback.
599 - * This thread is necessary, because we cannot freeze the whole plugin to read the data on very busy socket.
600 - *
601 - * @param ptr It is a NULL value for this thread.
602 - *
603 - * @return It always returns NULL.
604 - */
605 -void *ebpf_disk_read_hash(void *ptr)
606 -{
607 - netdata_thread_cleanup_push(ebpf_disk_cleanup, ptr);
608 - heartbeat_t hb;
609 - heartbeat_init(&hb);
610 -
611 - ebpf_module_t *em = (ebpf_module_t *)ptr;
612 -
613 - usec_t step = NETDATA_LATENCY_DISK_SLEEP_MS * em->update_every;
614 - while (!ebpf_exit_plugin) {
615 - (void)heartbeat_next(&hb, step);
616 -
617 - read_hard_disk_tables(disk_maps[NETDATA_DISK_READ].map_fd);
618 - }
619 -
620 - netdata_thread_cleanup_pop(1);
621 - return NULL;
622 -}
623 -
565 /**
566 * Obsolete Hard Disk charts
567 *
@@ -744,11 +685,6 @@ static void ebpf_latency_send_hd_data(int update_every)
685 static void disk_collector(ebpf_module_t *em)
686 {
687 disk_hash_values = callocz(ebpf_nprocs, sizeof(netdata_idx_t));
747 - disk_threads.thread = mallocz(sizeof(netdata_thread_t));
748 - disk_threads.start_routine = ebpf_disk_read_hash;
749 -
750 - netdata_thread_create(disk_threads.thread, disk_threads.name, NETDATA_THREAD_OPTION_DEFAULT,
751 - ebpf_disk_read_hash, em);
688
689 int update_every = em->update_every;
690 heartbeat_t hb;
@@ -759,6 +695,7 @@ static void disk_collector(ebpf_module_t *em)
695 if (ebpf_exit_plugin)
696 break;
697
698 + read_hard_disk_tables(disk_maps[NETDATA_DISK_READ].map_fd);
699 pthread_mutex_lock(&lock);
700 ebpf_remove_pointer_from_plot_disk(em);
701 ebpf_latency_send_hd_data(update_every);
collectors/ebpf.plugin/ebpf_disk.h
-2
@@ -11,8 +11,6 @@
11
12 #define NETDATA_EBPF_PROC_PARTITIONS "/proc/partitions"
13
14 -#define NETDATA_LATENCY_DISK_SLEEP_MS 650000ULL
15 -
14 // Process configuration name
15 #define NETDATA_DISK_CONFIG_FILE "disk.conf"
16
collectors/ebpf.plugin/ebpf_fd.c
+3 -63
@@ -32,15 +32,6 @@ struct config fd_config = { .first_section = NULL, .last_section = NULL, .mutex
32 .index = {.avl_tree = { .root = NULL, .compar = appconfig_section_compare },
33 .rwlock = AVL_LOCK_INITIALIZER } };
34
35 -struct netdata_static_thread fd_thread = {"FD KERNEL",
36 - .config_section = NULL,
37 - .config_name = NULL,
38 - .env_name = NULL,
39 - .enabled = 1,
40 - .thread = NULL,
41 - .init_routine = NULL,
42 - .start_routine = NULL};
43 -
35 static netdata_idx_t fd_hash_values[NETDATA_FD_COUNTER];
36 static netdata_idx_t *fd_values = NULL;
37
@@ -373,15 +364,10 @@ static inline int ebpf_fd_load_and_attach(struct fd_bpf *obj, ebpf_module_t *em)
364 static void ebpf_fd_free(ebpf_module_t *em)
365 {
366 pthread_mutex_lock(&ebpf_exit_cleanup);
376 - if (em->thread->enabled == NETDATA_THREAD_EBPF_RUNNING) {
377 - em->thread->enabled = NETDATA_THREAD_EBPF_STOPPING;
378 - pthread_mutex_unlock(&ebpf_exit_cleanup);
379 - return;
380 - }
367 + em->thread->enabled = NETDATA_THREAD_EBPF_STOPPING;
368 pthread_mutex_unlock(&ebpf_exit_cleanup);
369
370 ebpf_cleanup_publish_syscall(fd_publish_aggregated);
384 - freez(fd_thread.thread);
371 freez(fd_values);
372 freez(fd_vector);
373
@@ -403,19 +389,6 @@ static void ebpf_fd_free(ebpf_module_t *em)
389 * @param ptr thread data.
390 */
391 static void ebpf_fd_exit(void *ptr)
406 -{
407 - ebpf_module_t *em = (ebpf_module_t *)ptr;
408 - if (fd_thread.thread)
409 - netdata_thread_cancel(*fd_thread.thread);
410 - ebpf_fd_free(em);
411 -}
412 -
413 -/**
414 - * Clean up the main thread.
415 - *
416 - * @param ptr thread data.
417 - */
418 -static void ebpf_fd_cleanup(void *ptr)
392 {
393 ebpf_module_t *em = (ebpf_module_t *)ptr;
394 ebpf_fd_free(em);
@@ -454,7 +427,7 @@ static void ebpf_fd_send_data(ebpf_module_t *em)
427 *
428 * Read the table with number of calls for all functions
429 */
457 -static void read_global_table()
430 +static void ebpf_fd_read_global_table()
431 {
432 uint32_t idx;
433 netdata_idx_t *val = fd_hash_values;
@@ -474,34 +447,6 @@ static void read_global_table()
447 }
448 }
449
477 -/**
478 - * File descriptor read hash
479 - *
480 - * This is the thread callback.
481 - * This thread is necessary, because we cannot freeze the whole plugin to read the data.
482 - *
483 - * @param ptr It is a NULL value for this thread.
484 - *
485 - * @return It always returns NULL.
486 - */
487 -void *ebpf_fd_read_hash(void *ptr)
488 -{
489 - netdata_thread_cleanup_push(ebpf_fd_cleanup, ptr);
490 - heartbeat_t hb;
491 - heartbeat_init(&hb);
492 -
493 - ebpf_module_t *em = (ebpf_module_t *)ptr;
494 - usec_t step = NETDATA_FD_SLEEP_MS * em->update_every;
495 - while (!ebpf_exit_plugin) {
496 - (void)heartbeat_next(&hb, step);
497 -
498 - read_global_table();
499 - }
500 -
501 - netdata_thread_cleanup_pop(1);
502 - return NULL;
503 -}
504 -
450 /**
451 * Apps Accumulator
452 *
@@ -976,12 +921,6 @@ static void ebpf_fd_send_cgroup_data(ebpf_module_t *em)
921 */
922 static void fd_collector(ebpf_module_t *em)
923 {
979 - fd_thread.thread = mallocz(sizeof(netdata_thread_t));
980 - fd_thread.start_routine = ebpf_fd_read_hash;
981 -
982 - netdata_thread_create(fd_thread.thread, fd_thread.name, NETDATA_THREAD_OPTION_DEFAULT,
983 - ebpf_fd_read_hash, em);
984 -
924 int cgroups = em->cgroup_charts;
925 heartbeat_t hb;
926 heartbeat_init(&hb);
@@ -992,6 +931,7 @@ static void fd_collector(ebpf_module_t *em)
931 break;
932
933 netdata_apps_integration_flags_t apps = em->apps_charts;
934 + ebpf_fd_read_global_table();
935 pthread_mutex_lock(&collect_data_mutex);
936 if (apps)
937 read_apps_table();
collectors/ebpf.plugin/ebpf_fd.h
-2
@@ -6,8 +6,6 @@
6 // Module name
7 #define NETDATA_EBPF_MODULE_NAME_FD "filedescriptor"
8
9 -#define NETDATA_FD_SLEEP_MS 850000ULL
10 -
9 // Menu group
10 #define NETDATA_FILE_GROUP "file_access"
11
collectors/ebpf.plugin/ebpf_filesystem.c
+8 -58
@@ -30,17 +30,6 @@ static ebpf_local_maps_t fs_maps[] = {{.name = "tbl_ext4", .internal_input = NET
30 .type = NETDATA_EBPF_MAP_CONTROLLER,
31 .map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED}};
32
33 -struct netdata_static_thread filesystem_threads = {
34 - .name = "EBPF FS READ",
35 - .config_section = NULL,
36 - .config_name = NULL,
37 - .env_name = NULL,
38 - .enabled = 1,
39 - .thread = NULL,
40 - .init_routine = NULL,
41 - .start_routine = NULL
42 -};
43 -
33 static netdata_syscall_stat_t filesystem_aggregated_data[NETDATA_EBPF_HIST_MAX_BINS];
34 static netdata_publish_syscall_t filesystem_publish_aggregated[NETDATA_EBPF_HIST_MAX_BINS];
35
@@ -337,14 +326,9 @@ void ebpf_filesystem_cleanup_ebpf_data()
326 static void ebpf_filesystem_free(ebpf_module_t *em)
327 {
328 pthread_mutex_lock(&ebpf_exit_cleanup);
340 - if (em->thread->enabled == NETDATA_THREAD_EBPF_RUNNING) {
341 - em->thread->enabled = NETDATA_THREAD_EBPF_STOPPING;
342 - pthread_mutex_unlock(&ebpf_exit_cleanup);
343 - return;
344 - }
329 + em->thread->enabled = NETDATA_THREAD_EBPF_STOPPING;
330 pthread_mutex_unlock(&ebpf_exit_cleanup);
331
347 - freez(filesystem_threads.thread);
332 ebpf_cleanup_publish_syscall(filesystem_publish_aggregated);
333
334 ebpf_filesystem_cleanup_ebpf_data();
@@ -365,21 +349,6 @@ static void ebpf_filesystem_free(ebpf_module_t *em)
349 * @param ptr thread data.
350 */
351 static void ebpf_filesystem_exit(void *ptr)
368 -{
369 - ebpf_module_t *em = (ebpf_module_t *)ptr;
370 - if (filesystem_threads.thread)
371 - netdata_thread_cancel(*filesystem_threads.thread);
372 - ebpf_filesystem_free(em);
373 -}
374 -
375 -/**
376 - * File system cleanup
377 - *
378 - * Clean up allocated thread.
379 - *
380 - * @param ptr thread data.
381 - */
382 -static void ebpf_filesystem_cleanup(void *ptr)
352 {
353 ebpf_module_t *em = (ebpf_module_t *)ptr;
354 ebpf_filesystem_free(em);
@@ -484,30 +453,16 @@ static void read_filesystem_tables()
453 *
454 * @return It always returns NULL.
455 */
487 -void *ebpf_filesystem_read_hash(void *ptr)
456 +void ebpf_filesystem_read_hash(ebpf_module_t *em)
457 {
489 - netdata_thread_cleanup_push(ebpf_filesystem_cleanup, ptr);
490 - ebpf_module_t *em = (ebpf_module_t *)ptr;
458 + ebpf_obsolete_fs_charts(em->update_every);
459
492 - heartbeat_t hb;
493 - heartbeat_init(&hb);
494 - usec_t step = NETDATA_FILESYSTEM_READ_SLEEP_MS * em->update_every;
495 - int update_every = em->update_every;
496 - while (!ebpf_exit_plugin) {
497 - (void)heartbeat_next(&hb, step);
498 -
499 - (void) ebpf_update_partitions(em);
500 - ebpf_obsolete_fs_charts(update_every);
501 -
502 - // No more partitions, it is not necessary to read tables
503 - if (em->optional)
504 - continue;
460 + (void) ebpf_update_partitions(em);
461
506 - read_filesystem_tables();
507 - }
462 + if (em->optional)
463 + return;
464
509 - netdata_thread_cleanup_pop(1);
510 - return NULL;
465 + read_filesystem_tables();
466 }
467
468 /**
@@ -544,12 +499,6 @@ static void ebpf_histogram_send_data()
499 */
500 static void filesystem_collector(ebpf_module_t *em)
501 {
547 - filesystem_threads.thread = mallocz(sizeof(netdata_thread_t));
548 - filesystem_threads.start_routine = ebpf_filesystem_read_hash;
549 -
550 - netdata_thread_create(filesystem_threads.thread, filesystem_threads.name,
551 - NETDATA_THREAD_OPTION_DEFAULT, ebpf_filesystem_read_hash, em);
552 -
502 int update_every = em->update_every;
503 heartbeat_t hb;
504 heartbeat_init(&hb);
@@ -559,6 +508,7 @@ static void filesystem_collector(ebpf_module_t *em)
508 if (ebpf_exit_plugin)
509 break;
510
511 + ebpf_filesystem_read_hash(em);
512 pthread_mutex_lock(&lock);
513
514 ebpf_create_fs_charts(update_every);
collectors/ebpf.plugin/ebpf_filesystem.h
-1
@@ -11,7 +11,6 @@
11 #define NETDATA_FS_MAX_DIST_NAME 64UL
12
13 #define NETDATA_FILESYSTEM_CONFIG_NAME "filesystem"
14 -#define NETDATA_FILESYSTEM_READ_SLEEP_MS 600000ULL
14
15 // Process configuration name
16 #define NETDATA_FILESYSTEM_CONFIG_FILE "filesystem.conf"
collectors/ebpf.plugin/ebpf_hardirq.c
+7 -60
@@ -135,17 +135,6 @@ static hardirq_ebpf_val_t *hardirq_ebpf_vals = NULL;
135 // tmp store for static hard IRQ values we get from a per-CPU eBPF map.
136 static hardirq_ebpf_static_val_t *hardirq_ebpf_static_vals = NULL;
137
138 -static struct netdata_static_thread hardirq_threads = {
139 - .name = "HARDIRQ KERNEL",
140 - .config_section = NULL,
141 - .config_name = NULL,
142 - .env_name = NULL,
143 - .enabled = 1,
144 - .thread = NULL,
145 - .init_routine = NULL,
146 - .start_routine = NULL
147 -};
148 -
138 /**
139 * Hardirq Free
140 *
@@ -156,21 +145,18 @@ static struct netdata_static_thread hardirq_threads = {
145 static void ebpf_hardirq_free(ebpf_module_t *em)
146 {
147 pthread_mutex_lock(&ebpf_exit_cleanup);
159 - if (em->thread->enabled == NETDATA_THREAD_EBPF_RUNNING) {
160 - em->thread->enabled = NETDATA_THREAD_EBPF_STOPPING;
161 - pthread_mutex_unlock(&ebpf_exit_cleanup);
162 - return;
163 - }
148 + em->thread->enabled = NETDATA_THREAD_EBPF_STOPPING;
149 pthread_mutex_unlock(&ebpf_exit_cleanup);
150
166 - freez(hardirq_threads.thread);
151 for (int i = 0; hardirq_tracepoints[i].class != NULL; i++) {
152 ebpf_disable_tracepoint(&hardirq_tracepoints[i]);
153 }
154 freez(hardirq_ebpf_vals);
155 freez(hardirq_ebpf_static_vals);
156
157 + pthread_mutex_lock(&ebpf_exit_cleanup);
158 em->thread->enabled = NETDATA_THREAD_EBPF_STOPPED;
159 + pthread_mutex_unlock(&ebpf_exit_cleanup);
160 }
161
162 /**
@@ -181,21 +167,6 @@ static void ebpf_hardirq_free(ebpf_module_t *em)
167 * @param ptr thread data.
168 */
169 static void hardirq_exit(void *ptr)
184 -{
185 - ebpf_module_t *em = (ebpf_module_t *)ptr;
186 - if (hardirq_threads.thread)
187 - netdata_thread_cancel(*hardirq_threads.thread);
188 - ebpf_hardirq_free(em);
189 -}
190 -
191 -/**
192 - * Hardirq clean up
193 - *
194 - * Clean up allocated memory.
195 - *
196 - * @param ptr thread data.
197 - */
198 -static void hardirq_cleanup(void *ptr)
170 {
171 ebpf_module_t *em = (ebpf_module_t *)ptr;
172 ebpf_hardirq_free(em);
@@ -332,24 +303,10 @@ static void hardirq_read_latency_static_map(int mapfd)
303 /**
304 * Read eBPF maps for hard IRQ.
305 */
335 -static void *hardirq_reader(void *ptr)
306 +static void hardirq_reader()
307 {
337 - netdata_thread_cleanup_push(hardirq_cleanup, ptr);
338 - heartbeat_t hb;
339 - heartbeat_init(&hb);
340 -
341 - ebpf_module_t *em = (ebpf_module_t *)ptr;
342 -
343 - usec_t step = NETDATA_HARDIRQ_SLEEP_MS * em->update_every;
344 - while (!ebpf_exit_plugin) {
345 - (void)heartbeat_next(&hb, step);
346 -
347 - hardirq_read_latency_map(hardirq_maps[HARDIRQ_MAP_LATENCY].map_fd);
348 - hardirq_read_latency_static_map(hardirq_maps[HARDIRQ_MAP_LATENCY_STATIC].map_fd);
349 - }
350 -
351 - netdata_thread_cleanup_pop(1);
352 - return NULL;
308 + hardirq_read_latency_map(hardirq_maps[HARDIRQ_MAP_LATENCY].map_fd);
309 + hardirq_read_latency_static_map(hardirq_maps[HARDIRQ_MAP_LATENCY_STATIC].map_fd);
310 }
311
312 static void hardirq_create_charts(int update_every)
@@ -429,17 +386,6 @@ static void hardirq_collector(ebpf_module_t *em)
386
387 avl_init_lock(&hardirq_pub, hardirq_val_cmp);
388
432 - // create reader thread.
433 - hardirq_threads.thread = mallocz(sizeof(netdata_thread_t));
434 - hardirq_threads.start_routine = hardirq_reader;
435 - netdata_thread_create(
436 - hardirq_threads.thread,
437 - hardirq_threads.name,
438 - NETDATA_THREAD_OPTION_DEFAULT,
439 - hardirq_reader,
440 - em
441 - );
442 -
389 // create chart and static dims.
390 pthread_mutex_lock(&lock);
391 hardirq_create_charts(em->update_every);
@@ -457,6 +403,7 @@ static void hardirq_collector(ebpf_module_t *em)
403 if (ebpf_exit_plugin)
404 break;
405
406 + hardirq_reader();
407 pthread_mutex_lock(&lock);
408
409 // write dims now for all hitherto discovered IRQs.
collectors/ebpf.plugin/ebpf_hardirq.h
-1
@@ -47,7 +47,6 @@ typedef struct hardirq_ebpf_static_val {
47 *****************************************************************/
48
49 #define NETDATA_EBPF_MODULE_NAME_HARDIRQ "hardirq"
50 -#define NETDATA_HARDIRQ_SLEEP_MS 650000ULL
50 #define NETDATA_HARDIRQ_CONFIG_FILE "hardirq.conf"
51
52 typedef struct hardirq_val {
collectors/ebpf.plugin/ebpf_mdflush.c
+3 -69
@@ -35,17 +35,6 @@ static avl_tree_lock mdflush_pub;
35 // tmp store for mdflush values we get from a per-CPU eBPF map.
36 static mdflush_ebpf_val_t *mdflush_ebpf_vals = NULL;
37
38 -static struct netdata_static_thread mdflush_threads = {
39 - .name = "MDFLUSH KERNEL",
40 - .config_section = NULL,
41 - .config_name = NULL,
42 - .env_name = NULL,
43 - .enabled = 1,
44 - .thread = NULL,
45 - .init_routine = NULL,
46 - .start_routine = NULL
47 -};
48 -
38 /**
39 * MDflush Free
40 *
@@ -55,18 +44,10 @@ static struct netdata_static_thread mdflush_threads = {
44 */
45 static void ebpf_mdflush_free(ebpf_module_t *em)
46 {
58 - pthread_mutex_lock(&ebpf_exit_cleanup);
59 - if (em->thread->enabled == NETDATA_THREAD_EBPF_RUNNING) {
60 - em->thread->enabled = NETDATA_THREAD_EBPF_STOPPING;
61 - pthread_mutex_unlock(&ebpf_exit_cleanup);
62 - return;
63 - }
64 - pthread_mutex_unlock(&ebpf_exit_cleanup);
65 -
47 freez(mdflush_ebpf_vals);
67 - freez(mdflush_threads.thread);
68 -
48 + pthread_mutex_lock(&ebpf_exit_cleanup);
49 em->thread->enabled = NETDATA_THREAD_EBPF_STOPPED;
50 + pthread_mutex_unlock(&ebpf_exit_cleanup);
51 }
52
53 /**
@@ -82,21 +63,6 @@ static void mdflush_exit(void *ptr)
63 ebpf_mdflush_free(em);
64 }
65
85 -/**
86 - * CLeanup
87 - *
88 - * Clean allocated memory.
89 - *
90 - * @param ptr thread data.
91 - */
92 -static void mdflush_cleanup(void *ptr)
93 -{
94 - ebpf_module_t *em = (ebpf_module_t *)ptr;
95 - if (mdflush_threads.thread)
96 - netdata_thread_cancel(*mdflush_threads.thread);
97 - ebpf_mdflush_free(em);
98 -}
99 -
66 /**
67 * Compare mdflush values.
68 *
@@ -189,28 +155,6 @@ static void mdflush_read_count_map()
155 }
156 }
157
192 -/**
193 - * Read eBPF maps for mdflush.
194 - */
195 -static void *mdflush_reader(void *ptr)
196 -{
197 - netdata_thread_cleanup_push(mdflush_cleanup, ptr);
198 - heartbeat_t hb;
199 - heartbeat_init(&hb);
200 -
201 - ebpf_module_t *em = (ebpf_module_t *)ptr;
202 -
203 - usec_t step = NETDATA_MDFLUSH_SLEEP_MS * em->update_every;
204 - while (!ebpf_exit_plugin) {
205 - (void)heartbeat_next(&hb, step);
206 -
207 - mdflush_read_count_map();
208 - }
209 -
210 - netdata_thread_cleanup_pop(1);
211 - return NULL;
212 -}
213 -
158 static void mdflush_create_charts(int update_every)
159 {
160 ebpf_create_chart(
@@ -259,17 +203,6 @@ static void mdflush_collector(ebpf_module_t *em)
203
204 avl_init_lock(&mdflush_pub, mdflush_val_cmp);
205
262 - // create reader thread.
263 - mdflush_threads.thread = mallocz(sizeof(netdata_thread_t));
264 - mdflush_threads.start_routine = mdflush_reader;
265 - netdata_thread_create(
266 - mdflush_threads.thread,
267 - mdflush_threads.name,
268 - NETDATA_THREAD_OPTION_DEFAULT,
269 - mdflush_reader,
270 - em
271 - );
272 -
206 // create chart and static dims.
207 pthread_mutex_lock(&lock);
208 mdflush_create_charts(em->update_every);
@@ -285,6 +218,7 @@ static void mdflush_collector(ebpf_module_t *em)
218 if (ebpf_exit_plugin)
219 break;
220
221 + mdflush_read_count_map();
222 // write dims now for all hitherto discovered devices.
223 write_begin_chart("mdstat", "mdstat_flush");
224 avl_traverse_lock(&mdflush_pub, mdflush_write_dims, NULL);
collectors/ebpf.plugin/ebpf_mdflush.h
-2
@@ -6,8 +6,6 @@
6 // Module name
7 #define NETDATA_EBPF_MODULE_NAME_MDFLUSH "mdflush"
8
9 -#define NETDATA_MDFLUSH_SLEEP_MS 850000ULL
10 -
9 // charts
10 #define NETDATA_MDFLUSH_GLOBAL_CHART "mdflush"
11
collectors/ebpf.plugin/ebpf_mount.c
+4 -70
@@ -22,17 +22,6 @@ static netdata_idx_t *mount_values = NULL;
22
23 static netdata_idx_t mount_hash_values[NETDATA_MOUNT_END];
24
25 -struct netdata_static_thread mount_thread = {
26 - .name = "MOUNT KERNEL",
27 - .config_section = NULL,
28 - .config_name = NULL,
29 - .env_name = NULL,
30 - .enabled = 1,
31 - .thread = NULL,
32 - .init_routine = NULL,
33 - .start_routine = NULL
34 -};
35 -
25 netdata_ebpf_targets_t mount_targets[] = { {.name = "mount", .mode = EBPF_LOAD_TRAMPOLINE},
26 {.name = "umount", .mode = EBPF_LOAD_TRAMPOLINE},
27 {.name = NULL, .mode = EBPF_LOAD_TRAMPOLINE}};
@@ -239,14 +228,9 @@ static inline int ebpf_mount_load_and_attach(struct mount_bpf *obj, ebpf_module_
228 static void ebpf_mount_free(ebpf_module_t *em)
229 {
230 pthread_mutex_lock(&ebpf_exit_cleanup);
242 - if (em->thread->enabled == NETDATA_THREAD_EBPF_RUNNING) {
243 - em->thread->enabled = NETDATA_THREAD_EBPF_STOPPING;
244 - pthread_mutex_unlock(&ebpf_exit_cleanup);
245 - return;
246 - }
231 + em->thread->enabled = NETDATA_THREAD_EBPF_STOPPING;
232 pthread_mutex_unlock(&ebpf_exit_cleanup);
233
249 - freez(mount_thread.thread);
234 freez(mount_values);
235
236 #ifdef LIBBPF_MAJOR_VERSION
@@ -267,21 +251,6 @@ static void ebpf_mount_free(ebpf_module_t *em)
251 * @param ptr thread data.
252 */
253 static void ebpf_mount_exit(void *ptr)
270 -{
271 - ebpf_module_t *em = (ebpf_module_t *)ptr;
272 - if (mount_thread.thread)
273 - netdata_thread_cancel(*mount_thread.thread);
274 - ebpf_mount_free(em);
275 -}
276 -
277 -/**
278 - * Mount cleanup
279 - *
280 - * Clean up allocated memory.
281 - *
282 - * @param ptr thread data.
283 - */
284 -static void ebpf_mount_cleanup(void *ptr)
254 {
255 ebpf_module_t *em = (ebpf_module_t *)ptr;
256 ebpf_mount_free(em);
@@ -298,7 +267,7 @@ static void ebpf_mount_cleanup(void *ptr)
267 *
268 * Read the table with number of calls for all functions
269 */
301 -static void read_global_table()
270 +static void ebpf_mount_read_global_table()
271 {
272 uint32_t idx;
273 netdata_idx_t *val = mount_hash_values;
@@ -318,36 +287,6 @@ static void read_global_table()
287 }
288 }
289
321 -/**
322 - * Mount read hash
323 - *
324 - * This is the thread callback.
325 - * This thread is necessary, because we cannot freeze the whole plugin to read the data.
326 - *
327 - * @param ptr It is a NULL value for this thread.
328 - *
329 - * @return It always returns NULL.
330 - */
331 -void *ebpf_mount_read_hash(void *ptr)
332 -{
333 - netdata_thread_cleanup_push(ebpf_mount_cleanup, ptr);
334 - heartbeat_t hb;
335 - heartbeat_init(&hb);
336 -
337 - ebpf_module_t *em = (ebpf_module_t *)ptr;
338 -
339 - usec_t step = NETDATA_LATENCY_MOUNT_SLEEP_MS * em->update_every;
340 - //This will be cancelled by its parent
341 - while (!ebpf_exit_plugin) {
342 - (void)heartbeat_next(&hb, step);
343 -
344 - read_global_table();
345 - }
346 -
347 - netdata_thread_cleanup_pop(1);
348 - return NULL;
349 -}
350 -
290 /**
291 * Send data to Netdata calling auxiliary functions.
292 */
@@ -372,14 +311,8 @@ static void ebpf_mount_send_data()
311 */
312 static void mount_collector(ebpf_module_t *em)
313 {
375 - mount_thread.thread = mallocz(sizeof(netdata_thread_t));
376 - mount_thread.start_routine = ebpf_mount_read_hash;
377 - memset(mount_hash_values, 0, sizeof(mount_hash_values));
378 -
314 mount_values = callocz((size_t)ebpf_nprocs, sizeof(netdata_idx_t));
380 -
381 - netdata_thread_create(mount_thread.thread, mount_thread.name, NETDATA_THREAD_OPTION_DEFAULT,
382 - ebpf_mount_read_hash, em);
315 + memset(mount_hash_values, 0, sizeof(mount_hash_values));
316
317 heartbeat_t hb;
318 heartbeat_init(&hb);
@@ -389,6 +322,7 @@ static void mount_collector(ebpf_module_t *em)
322 if (ebpf_exit_plugin)
323 break;
324
325 + ebpf_mount_read_global_table();
326 pthread_mutex_lock(&lock);
327
328 ebpf_mount_send_data();
collectors/ebpf.plugin/ebpf_mount.h
-2
@@ -8,8 +8,6 @@
8
9 #define NETDATA_EBPF_MOUNT_SYSCALL 2
10
11 -#define NETDATA_LATENCY_MOUNT_SLEEP_MS 700000ULL
12 -
11 #define NETDATA_EBPF_MOUNT_CALLS "call"
12 #define NETDATA_EBPF_MOUNT_ERRORS "error"
13 #define NETDATA_EBPF_MOUNT_FAMILY "mount (eBPF)"
collectors/ebpf.plugin/ebpf_oomkill.c
+2
@@ -46,7 +46,9 @@ static netdata_publish_syscall_t oomkill_publish_aggregated = {.name = "oomkill"
46 static void oomkill_cleanup(void *ptr)
47 {
48 ebpf_module_t *em = (ebpf_module_t *)ptr;
49 + pthread_mutex_lock(&ebpf_exit_cleanup);
50 em->thread->enabled = NETDATA_THREAD_EBPF_STOPPED;
51 + pthread_mutex_unlock(&ebpf_exit_cleanup);
52 }
53
54 static void oomkill_write_data(int32_t *keys, uint32_t total)
collectors/ebpf.plugin/ebpf_oomkill.h
-1
@@ -17,7 +17,6 @@ typedef uint8_t oomkill_ebpf_val_t;
17 *****************************************************************/
18
19 #define NETDATA_EBPF_MODULE_NAME_OOMKILL "oomkill"
20 -#define NETDATA_OOMKILL_SLEEP_MS 650000ULL
20 #define NETDATA_OOMKILL_CONFIG_FILE "oomkill.conf"
21
22 #define NETDATA_OOMKILL_CHART "oomkills"
collectors/ebpf.plugin/ebpf_process.c
+2 -71
@@ -57,17 +57,6 @@ struct config process_config = { .first_section = NULL,
57 static char *threads_stat[NETDATA_EBPF_THREAD_STAT_END] = {"total", "running"};
58 static char *load_event_stat[NETDATA_EBPF_LOAD_STAT_END] = {"legacy", "co-re"};
59
60 -static struct netdata_static_thread cgroup_thread = {
61 - .name = "EBPF CGROUP",
62 - .config_section = NULL,
63 - .config_name = NULL,
64 - .env_name = NULL,
65 - .enabled = 1,
66 - .thread = NULL,
67 - .init_routine = NULL,
68 - .start_routine = NULL
69 -};
70 -
60 /*****************************************************************
61 *
62 * PROCESS DATA AND SEND TO NETDATA
@@ -326,55 +315,6 @@ static void ebpf_process_update_apps_data()
315 }
316 }
317
329 -/**
330 - * Cgroup Exit
331 - *
332 - * Function used with netdata_thread_clean_push
333 - *
334 - * @param ptr unused argument
335 - */
336 -static void ebpf_cgroup_exit(void *ptr)
337 -{
338 - UNUSED(ptr);
339 -}
340 -
341 -/**
342 - * Cgroup update shm
343 - *
344 - * This is the thread callback.
345 - * This thread is necessary, because we cannot freeze the whole plugin to read the data from shared memory.
346 - *
347 - * @param ptr It is a NULL value for this thread.
348 - *
349 - * @return It always returns NULL.
350 - */
351 -void *ebpf_cgroup_update_shm(void *ptr)
352 -{
353 - netdata_thread_cleanup_push(ebpf_cgroup_exit, ptr);
354 - heartbeat_t hb;
355 - heartbeat_init(&hb);
356 -
357 - usec_t step = 3 * USEC_PER_SEC;
358 - int counter = NETDATA_EBPF_CGROUP_UPDATE - 1;
359 - //This will be cancelled by its parent
360 - while (!ebpf_exit_plugin) {
361 - (void)heartbeat_next(&hb, step);
362 -
363 - // We are using a small heartbeat time to wake up thread,
364 - // but we should not update so frequently the shared memory data
365 - if (++counter >= NETDATA_EBPF_CGROUP_UPDATE) {
366 - counter = 0;
367 - if (!shm_ebpf_cgroup.header)
368 - ebpf_map_cgroup_shared_memory();
369 -
370 - ebpf_parse_cgroup_shm_data();
371 - }
372 - }
373 -
374 - netdata_thread_cleanup_pop(1);
375 - return NULL;
376 -}
377 -
318 /**
319 * Update cgroup
320 *
@@ -745,8 +685,6 @@ static void ebpf_process_exit(void *ptr)
685 pthread_mutex_lock(&ebpf_exit_cleanup);
686 em->thread->enabled = NETDATA_THREAD_EBPF_STOPPED;
687 pthread_mutex_unlock(&ebpf_exit_cleanup);
748 - if (cgroup_thread.thread)
749 - pthread_cancel(*cgroup_thread.thread);
688 }
689
690 /*****************************************************************
@@ -1105,13 +1043,6 @@ void ebpf_send_statistic_data()
1043 */
1044 static void process_collector(ebpf_module_t *em)
1045 {
1108 - // Start cgroup integration before other threads
1109 - cgroup_thread.thread = mallocz(sizeof(netdata_thread_t));
1110 - cgroup_thread.start_routine = ebpf_cgroup_update_shm;
1111 -
1112 - netdata_thread_create(cgroup_thread.thread, cgroup_thread.name, NETDATA_THREAD_OPTION_DEFAULT,
1113 - ebpf_cgroup_update_shm, NULL);
1114 -
1046 heartbeat_t hb;
1047 heartbeat_init(&hb);
1048 int publish_global = em->global_charts;
@@ -1153,7 +1084,7 @@ static void process_collector(ebpf_module_t *em)
1084 ebpf_process_update_apps_data();
1085 }
1086
1156 - if (cgroups) {
1087 + if (cgroups && shm_ebpf_cgroup.header) {
1088 ebpf_update_process_cgroup();
1089 }
1090 }
@@ -1170,7 +1101,7 @@ static void process_collector(ebpf_module_t *em)
1101 ebpf_process_send_apps_data(apps_groups_root_target, em);
1102 }
1103
1173 - if (cgroups) {
1104 + if (cgroups && shm_ebpf_cgroup.header) {
1105 ebpf_process_send_cgroup_data(em);
1106 }
1107 }
collectors/ebpf.plugin/ebpf_process.h
+1 -1
@@ -39,7 +39,7 @@
39 #define NETDATA_SYSTEMD_PROCESS_EXIT_CONTEXT "services.task_exit"
40 #define NETDATA_SYSTEMD_PROCESS_ERROR_CONTEXT "services.task_error"
41
42 -#define NETDATA_EBPF_CGROUP_UPDATE 10
42 +#define NETDATA_EBPF_CGROUP_UPDATE 30
43
44 // Statistical information
45 enum netdata_ebpf_thread_stats{
collectors/ebpf.plugin/ebpf_shm.c
+5 -67
@@ -34,17 +34,6 @@ static ebpf_local_maps_t shm_maps[] = {{.name = "tbl_pid_shm", .internal_input =
34 .map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
35 {.name = NULL, .internal_input = 0, .user_input = 0}};
36
37 -struct netdata_static_thread shm_threads = {
38 - .name = "SHM KERNEL",
39 - .config_section = NULL,
40 - .config_name = NULL,
41 - .env_name = NULL,
42 - .enabled = 1,
43 - .thread = NULL,
44 - .init_routine = NULL,
45 - .start_routine = NULL
46 -};
47 -
37 netdata_ebpf_targets_t shm_targets[] = { {.name = "shmget", .mode = EBPF_LOAD_TRAMPOLINE},
38 {.name = "shmat", .mode = EBPF_LOAD_TRAMPOLINE},
39 {.name = "shmdt", .mode = EBPF_LOAD_TRAMPOLINE},
@@ -299,11 +288,7 @@ static inline int ebpf_shm_load_and_attach(struct shm_bpf *obj, ebpf_module_t *e
288 static void ebpf_shm_free(ebpf_module_t *em)
289 {
290 pthread_mutex_lock(&ebpf_exit_cleanup);
302 - if (em->thread->enabled == NETDATA_THREAD_EBPF_RUNNING) {
303 - em->thread->enabled = NETDATA_THREAD_EBPF_STOPPING;
304 - pthread_mutex_unlock(&ebpf_exit_cleanup);
305 - return;
306 - }
291 + em->thread->enabled = NETDATA_THREAD_EBPF_STOPPING;
292 pthread_mutex_unlock(&ebpf_exit_cleanup);
293
294 ebpf_cleanup_publish_syscall(shm_publish_aggregated);
@@ -316,7 +301,9 @@ static void ebpf_shm_free(ebpf_module_t *em)
301 shm_bpf__destroy(bpf_obj);
302 #endif
303
304 + pthread_mutex_lock(&ebpf_exit_cleanup);
305 em->thread->enabled = NETDATA_THREAD_EBPF_STOPPED;
306 + pthread_mutex_unlock(&ebpf_exit_cleanup);
307 }
308
309 /**
@@ -327,21 +314,6 @@ static void ebpf_shm_free(ebpf_module_t *em)
314 * @param ptr thread data.
315 */
316 static void ebpf_shm_exit(void *ptr)
330 -{
331 - ebpf_module_t *em = (ebpf_module_t *)ptr;
332 - if (shm_threads.thread)
333 - netdata_thread_cancel(*shm_threads.thread);
334 - ebpf_shm_free(em);
335 -}
336 -
337 -/**
338 - * SHM Cleanup
339 - *
340 - * Clean up allocated memory.
341 - *
342 - * @param ptr thread data.
343 - */
344 -static void ebpf_shm_cleanup(void *ptr)
317 {
318 ebpf_module_t *em = (ebpf_module_t *)ptr;
319 ebpf_shm_free(em);
@@ -492,7 +464,7 @@ static void shm_send_global()
464 *
465 * Read the table with number of calls for all functions
466 */
495 -static void read_global_table()
467 +static void ebpf_shm_read_global_table()
468 {
469 netdata_idx_t *stored = shm_values;
470 netdata_idx_t *val = shm_hash_values;
@@ -512,30 +484,6 @@ static void read_global_table()
484 }
485 }
486
515 -/**
516 - * Shared memory reader thread.
517 - *
518 - * @param ptr It is a NULL value for this thread.
519 - * @return It always returns NULL.
520 - */
521 -void *ebpf_shm_read_hash(void *ptr)
522 -{
523 - netdata_thread_cleanup_push(ebpf_shm_cleanup, ptr);
524 - heartbeat_t hb;
525 - heartbeat_init(&hb);
526 -
527 - ebpf_module_t *em = (ebpf_module_t *)ptr;
528 - usec_t step = NETDATA_SHM_SLEEP_MS * em->update_every;
529 - while (!ebpf_exit_plugin) {
530 - (void)heartbeat_next(&hb, step);
531 -
532 - read_global_table();
533 - }
534 -
535 - netdata_thread_cleanup_pop(1);
536 - return NULL;
537 -}
538 -
487 /**
488 * Sum values for all targets.
489 */
@@ -895,17 +843,6 @@ void ebpf_shm_send_cgroup_data(int update_every)
843 */
844 static void shm_collector(ebpf_module_t *em)
845 {
898 - shm_threads.thread = mallocz(sizeof(netdata_thread_t));
899 - shm_threads.start_routine = ebpf_shm_read_hash;
900 -
901 - netdata_thread_create(
902 - shm_threads.thread,
903 - shm_threads.name,
904 - NETDATA_THREAD_OPTION_DEFAULT,
905 - ebpf_shm_read_hash,
906 - em
907 - );
908 -
846 int cgroups = em->cgroup_charts;
847 int update_every = em->update_every;
848 heartbeat_t hb;
@@ -917,6 +854,7 @@ static void shm_collector(ebpf_module_t *em)
854 break;
855
856 netdata_apps_integration_flags_t apps = em->apps_charts;
857 + ebpf_shm_read_global_table();
858 pthread_mutex_lock(&collect_data_mutex);
859 if (apps) {
860 read_apps_table();
collectors/ebpf.plugin/ebpf_shm.h
-2
@@ -6,8 +6,6 @@
6 // Module name
7 #define NETDATA_EBPF_MODULE_NAME_SHM "shm"
8
9 -#define NETDATA_SHM_SLEEP_MS 850000ULL
10 -
9 // charts
10 #define NETDATA_SHM_GLOBAL_CHART "shared_memory_calls"
11 #define NETDATA_SHMGET_CHART "shmget_call"
collectors/ebpf.plugin/ebpf_socket.c
+14 -12
@@ -2158,16 +2158,14 @@ void *ebpf_socket_read_hash(void *ptr)
2158 usec_t step = NETDATA_SOCKET_READ_SLEEP_MS * em->update_every;
2159 int fd_ipv4 = socket_maps[NETDATA_SOCKET_TABLE_IPV4].map_fd;
2160 int fd_ipv6 = socket_maps[NETDATA_SOCKET_TABLE_IPV6].map_fd;
2161 - uint32_t network_connection = network_viewer_opt.enabled;
2161 while (!ebpf_exit_plugin) {
2162 (void)heartbeat_next(&hb, step);
2163 + if (ebpf_exit_plugin)
2164 + break;
2165
2166 pthread_mutex_lock(&nv_mutex);
2166 - read_listen_table();
2167 - if (network_connection) {
2168 - ebpf_read_socket_hash_table(fd_ipv4, AF_INET);
2169 - ebpf_read_socket_hash_table(fd_ipv6, AF_INET6);
2170 - }
2167 + ebpf_read_socket_hash_table(fd_ipv4, AF_INET);
2168 + ebpf_read_socket_hash_table(fd_ipv6, AF_INET6);
2169 pthread_mutex_unlock(&nv_mutex);
2170 }
2171
@@ -2863,19 +2861,21 @@ static void socket_collector(usec_t step, ebpf_module_t *em)
2861 {
2862 heartbeat_t hb;
2863 heartbeat_init(&hb);
2864 + uint32_t network_connection = network_viewer_opt.enabled;
2865
2867 - socket_threads.thread = mallocz(sizeof(netdata_thread_t));
2868 - socket_threads.start_routine = ebpf_socket_read_hash;
2866 + if (network_connection) {
2867 + socket_threads.thread = mallocz(sizeof(netdata_thread_t));
2868 + socket_threads.start_routine = ebpf_socket_read_hash;
2869
2870 - netdata_thread_create(socket_threads.thread, socket_threads.name,
2871 - NETDATA_THREAD_OPTION_DEFAULT, ebpf_socket_read_hash, em);
2870 + netdata_thread_create(socket_threads.thread, socket_threads.name,
2871 + NETDATA_THREAD_OPTION_DEFAULT, ebpf_socket_read_hash, em);
2872 + }
2873
2874 int cgroups = em->cgroup_charts;
2875 if (cgroups)
2876 ebpf_socket_update_cgroup_algorithm();
2877
2878 int socket_global_enabled = em->global_charts;
2878 - uint32_t network_connection = network_viewer_opt.enabled;
2879 int update_every = em->update_every;
2880 while (!ebpf_exit_plugin) {
2881 (void)heartbeat_next(&hb, step);
@@ -2884,8 +2884,10 @@ static void socket_collector(usec_t step, ebpf_module_t *em)
2884
2885 netdata_apps_integration_flags_t socket_apps_enabled = em->apps_charts;
2886 pthread_mutex_lock(&collect_data_mutex);
2887 - if (socket_global_enabled)
2887 + if (socket_global_enabled) {
2888 + read_listen_table();
2889 read_hash_global_tables();
2890 + }
2891
2892 if (socket_apps_enabled)
2893 ebpf_socket_update_apps_data();
collectors/ebpf.plugin/ebpf_softirq.c
+3 -67
@@ -54,17 +54,6 @@ static softirq_val_t softirq_vals[] = {
54 // tmp store for soft IRQ values we get from a per-CPU eBPF map.
55 static softirq_ebpf_val_t *softirq_ebpf_vals = NULL;
56
57 -static struct netdata_static_thread softirq_threads = {
58 - .name = "SOFTIRQ KERNEL",
59 - .config_section = NULL,
60 - .config_name = NULL,
61 - .env_name = NULL,
62 - .enabled = 1,
63 - .thread = NULL,
64 - .init_routine = NULL,
65 - .start_routine = NULL
66 -};
67 -
57 /**
58 * Cachestat Free
59 *
@@ -75,40 +64,19 @@ static struct netdata_static_thread softirq_threads = {
64 static void ebpf_softirq_free(ebpf_module_t *em)
65 {
66 pthread_mutex_lock(&ebpf_exit_cleanup);
78 - if (em->thread->enabled == NETDATA_THREAD_EBPF_RUNNING) {
79 - em->thread->enabled = NETDATA_THREAD_EBPF_STOPPING;
80 - pthread_mutex_unlock(&ebpf_exit_cleanup);
81 - return;
82 - }
67 + em->thread->enabled = NETDATA_THREAD_EBPF_STOPPING;
68 pthread_mutex_unlock(&ebpf_exit_cleanup);
69
85 - freez(softirq_threads.thread);
86 -
70 for (int i = 0; softirq_tracepoints[i].class != NULL; i++) {
71 ebpf_disable_tracepoint(&softirq_tracepoints[i]);
72 }
73 freez(softirq_ebpf_vals);
74
75 pthread_mutex_lock(&ebpf_exit_cleanup);
93 - em->thread->enabled = NETDATA_MAIN_THREAD_EXITED;
76 + em->thread->enabled = NETDATA_THREAD_EBPF_STOPPED;
77 pthread_mutex_unlock(&ebpf_exit_cleanup);
78 }
79
97 -/**
98 - * Exit
99 - *
100 - * Cancel thread.
101 - *
102 - * @param ptr thread data.
103 - */
104 -static void softirq_exit(void *ptr)
105 -{
106 - ebpf_module_t *em = (ebpf_module_t *)ptr;
107 - if (softirq_threads.thread)
108 - netdata_thread_cancel(*softirq_threads.thread);
109 - ebpf_softirq_free(em);
110 -}
111 -
80 /**
81 * Cleanup
82 *
@@ -147,28 +115,6 @@ static void softirq_read_latency_map()
115 }
116 }
117
150 -/**
151 - * Read eBPF maps for soft IRQ.
152 - */
153 -static void *softirq_reader(void *ptr)
154 -{
155 - netdata_thread_cleanup_push(softirq_exit, ptr);
156 - heartbeat_t hb;
157 - heartbeat_init(&hb);
158 -
159 - ebpf_module_t *em = (ebpf_module_t *)ptr;
160 -
161 - usec_t step = NETDATA_SOFTIRQ_SLEEP_MS * em->update_every;
162 - while (!ebpf_exit_plugin) {
163 - (void)heartbeat_next(&hb, step);
164 -
165 - softirq_read_latency_map();
166 - }
167 -
168 - netdata_thread_cleanup_pop(1);
169 - return NULL;
170 -}
171 -
118 static void softirq_create_charts(int update_every)
119 {
120 ebpf_create_chart(
@@ -213,17 +159,6 @@ static void softirq_collector(ebpf_module_t *em)
159 {
160 softirq_ebpf_vals = callocz(ebpf_nprocs, sizeof(softirq_ebpf_val_t));
161
216 - // create reader thread.
217 - softirq_threads.thread = mallocz(sizeof(netdata_thread_t));
218 - softirq_threads.start_routine = softirq_reader;
219 - netdata_thread_create(
220 - softirq_threads.thread,
221 - softirq_threads.name,
222 - NETDATA_THREAD_OPTION_DEFAULT,
223 - softirq_reader,
224 - em
225 - );
226 -
162 // create chart and static dims.
163 pthread_mutex_lock(&lock);
164 softirq_create_charts(em->update_every);
@@ -241,6 +176,7 @@ static void softirq_collector(ebpf_module_t *em)
176 if (ebpf_exit_plugin)
177 break;
178
179 + softirq_read_latency_map();
180 pthread_mutex_lock(&lock);
181
182 // write dims now for all hitherto discovered IRQs.
collectors/ebpf.plugin/ebpf_softirq.h
-1
@@ -20,7 +20,6 @@ typedef struct softirq_ebpf_val {
20 *****************************************************************/
21
22 #define NETDATA_EBPF_MODULE_NAME_SOFTIRQ "softirq"
23 -#define NETDATA_SOFTIRQ_SLEEP_MS 650000ULL
23 #define NETDATA_SOFTIRQ_CONFIG_FILE "softirq.conf"
24
25 typedef struct sofirq_val {
collectors/ebpf.plugin/ebpf_swap.c
+3 -66
@@ -34,17 +34,6 @@ static ebpf_local_maps_t swap_maps[] = {{.name = "tbl_pid_swap", .internal_input
34 .map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
35 {.name = NULL, .internal_input = 0, .user_input = 0}};
36
37 -struct netdata_static_thread swap_threads = {
38 - .name = "SWAP KERNEL",
39 - .config_section = NULL,
40 - .config_name = NULL,
41 - .env_name = NULL,
42 - .enabled = 1,
43 - .thread = NULL,
44 - .init_routine = NULL,
45 - .start_routine = NULL
46 -};
47 -
37 netdata_ebpf_targets_t swap_targets[] = { {.name = "swap_readpage", .mode = EBPF_LOAD_TRAMPOLINE},
38 {.name = "swap_writepage", .mode = EBPF_LOAD_TRAMPOLINE},
39 {.name = NULL, .mode = EBPF_LOAD_TRAMPOLINE}};
@@ -236,18 +225,13 @@ static inline int ebpf_swap_load_and_attach(struct swap_bpf *obj, ebpf_module_t
225 static void ebpf_swap_free(ebpf_module_t *em)
226 {
227 pthread_mutex_lock(&ebpf_exit_cleanup);
239 - if (em->thread->enabled == NETDATA_THREAD_EBPF_RUNNING) {
240 - em->thread->enabled = NETDATA_THREAD_EBPF_STOPPING;
241 - pthread_mutex_unlock(&ebpf_exit_cleanup);
242 - return;
243 - }
228 + em->thread->enabled = NETDATA_THREAD_EBPF_STOPPING;
229 pthread_mutex_unlock(&ebpf_exit_cleanup);
230
231 ebpf_cleanup_publish_syscall(swap_publish_aggregated);
232
233 freez(swap_vector);
234 freez(swap_values);
250 - freez(swap_threads.thread);
235
236 #ifdef LIBBPF_MAJOR_VERSION
237 if (bpf_obj)
@@ -266,21 +250,6 @@ static void ebpf_swap_free(ebpf_module_t *em)
250 * @param ptr thread data.
251 */
252 static void ebpf_swap_exit(void *ptr)
269 -{
270 - ebpf_module_t *em = (ebpf_module_t *)ptr;
271 - if (swap_threads.thread)
272 - netdata_thread_cancel(*swap_threads.thread);
273 - ebpf_swap_free(em);
274 -}
275 -
276 -/**
277 - * Swap cleanup
278 - *
279 - * Clean up allocated memory.
280 - *
281 - * @param ptr thread data.
282 - */
283 -static void ebpf_swap_cleanup(void *ptr)
253 {
254 ebpf_module_t *em = (ebpf_module_t *)ptr;
255 ebpf_swap_free(em);
@@ -413,7 +382,7 @@ static void swap_send_global()
382 *
383 * Read the table with number of calls to all functions
384 */
416 -static void read_global_table()
385 +static void ebpf_swap_read_global_table()
386 {
387 netdata_idx_t *stored = swap_values;
388 netdata_idx_t *val = swap_hash_values;
@@ -433,33 +402,6 @@ static void read_global_table()
402 }
403 }
404
436 -/**
437 - * Swap read hash
438 - *
439 - * This is the thread callback.
440 - *
441 - * @param ptr It is a NULL value for this thread.
442 - *
443 - * @return It always returns NULL.
444 - */
445 -void *ebpf_swap_read_hash(void *ptr)
446 -{
447 - netdata_thread_cleanup_push(ebpf_swap_cleanup, ptr);
448 - heartbeat_t hb;
449 - heartbeat_init(&hb);
450 -
451 - ebpf_module_t *em = (ebpf_module_t *)ptr;
452 - usec_t step = NETDATA_SWAP_SLEEP_MS * em->update_every;
453 - while (!ebpf_exit_plugin) {
454 - (void)heartbeat_next(&hb, step);
455 -
456 - read_global_table();
457 - }
458 -
459 - netdata_thread_cleanup_pop(1);
460 - return NULL;
461 -}
462 -
405 /**
406 * Sum PIDs
407 *
@@ -715,12 +657,6 @@ void ebpf_swap_send_cgroup_data(int update_every)
657 */
658 static void swap_collector(ebpf_module_t *em)
659 {
718 - swap_threads.thread = mallocz(sizeof(netdata_thread_t));
719 - swap_threads.start_routine = ebpf_swap_read_hash;
720 -
721 - netdata_thread_create(swap_threads.thread, swap_threads.name, NETDATA_THREAD_OPTION_DEFAULT,
722 - ebpf_swap_read_hash, em);
723 -
660 int cgroup = em->cgroup_charts;
661 int update_every = em->update_every;
662 heartbeat_t hb;
@@ -732,6 +668,7 @@ static void swap_collector(ebpf_module_t *em)
668 break;
669
670 netdata_apps_integration_flags_t apps = em->apps_charts;
671 + ebpf_swap_read_global_table();
672 pthread_mutex_lock(&collect_data_mutex);
673 if (apps)
674 read_apps_table();
collectors/ebpf.plugin/ebpf_sync.c
+3 -65
@@ -10,17 +10,6 @@ static netdata_publish_syscall_t sync_counter_publish_aggregated[NETDATA_SYNC_ID
10
11 static netdata_idx_t sync_hash_values[NETDATA_SYNC_IDX_END];
12
13 -struct netdata_static_thread sync_threads = {
14 - .name = "SYNC KERNEL",
15 - .config_section = NULL,
16 - .config_name = NULL,
17 - .env_name = NULL,
18 - .enabled = 1,
19 - .thread = NULL,
20 - .init_routine = NULL,
21 - .start_routine = NULL
22 -};
23 -
13 static ebpf_local_maps_t sync_maps[] = {{.name = "tbl_sync", .internal_input = NETDATA_SYNC_END,
14 .user_input = 0, .type = NETDATA_EBPF_MAP_STATIC,
15 .map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
@@ -216,17 +205,12 @@ void ebpf_sync_cleanup_objects()
205 static void ebpf_sync_free(ebpf_module_t *em)
206 {
207 pthread_mutex_lock(&ebpf_exit_cleanup);
219 - if (em->thread->enabled == NETDATA_THREAD_EBPF_RUNNING) {
220 - em->thread->enabled = NETDATA_THREAD_EBPF_STOPPING;
221 - pthread_mutex_unlock(&ebpf_exit_cleanup);
222 - return;
223 - }
208 + em->thread->enabled = NETDATA_THREAD_EBPF_STOPPING;
209 pthread_mutex_unlock(&ebpf_exit_cleanup);
210
211 #ifdef LIBBPF_MAJOR_VERSION
212 ebpf_sync_cleanup_objects();
213 #endif
229 - freez(sync_threads.thread);
214
215 pthread_mutex_lock(&ebpf_exit_cleanup);
216 em->thread->enabled = NETDATA_THREAD_EBPF_STOPPED;
@@ -241,19 +225,6 @@ static void ebpf_sync_free(ebpf_module_t *em)
225 * @param ptr thread data.
226 */
227 static void ebpf_sync_exit(void *ptr)
244 -{
245 - ebpf_module_t *em = (ebpf_module_t *)ptr;
246 - if (sync_threads.thread)
247 - netdata_thread_cancel(*sync_threads.thread);
248 - ebpf_sync_free(em);
249 -}
250 -
251 -/**
252 - * Clean up the main thread.
253 - *
254 - * @param ptr thread data.
255 - */
256 -static void ebpf_sync_cleanup(void *ptr)
228 {
229 ebpf_module_t *em = (ebpf_module_t *)ptr;
230 ebpf_sync_free(em);
@@ -351,7 +322,7 @@ static int ebpf_sync_initialize_syscall(ebpf_module_t *em)
322 *
323 * Read the table with number of calls for all functions
324 */
354 -static void read_global_table()
325 +static void ebpf_sync_read_global_table()
326 {
327 netdata_idx_t stored;
328 uint32_t idx = NETDATA_SYNC_CALL;
@@ -366,34 +337,6 @@ static void read_global_table()
337 }
338 }
339
369 -/**
370 - * Sync read hash
371 - *
372 - * This is the thread callback.
373 - *
374 - * @param ptr It is a NULL value for this thread.
375 - *
376 - * @return It always returns NULL.
377 - */
378 -void *ebpf_sync_read_hash(void *ptr)
379 -{
380 - netdata_thread_cleanup_push(ebpf_sync_cleanup, ptr);
381 - ebpf_module_t *em = (ebpf_module_t *)ptr;
382 -
383 - heartbeat_t hb;
384 - heartbeat_init(&hb);
385 - usec_t step = NETDATA_EBPF_SYNC_SLEEP_MS * em->update_every;
386 -
387 - while (!ebpf_exit_plugin) {
388 - (void)heartbeat_next(&hb, step);
389 -
390 - read_global_table();
391 - }
392 -
393 - netdata_thread_cleanup_pop(1);
394 - return NULL;
395 -}
396 -
340 /**
341 * Create Sync charts
342 *
@@ -453,12 +396,6 @@ static void sync_send_data()
396 */
397 static void sync_collector(ebpf_module_t *em)
398 {
456 - sync_threads.thread = mallocz(sizeof(netdata_thread_t));
457 - sync_threads.start_routine = ebpf_sync_read_hash;
458 -
459 - netdata_thread_create(sync_threads.thread, sync_threads.name, NETDATA_THREAD_OPTION_DEFAULT,
460 - ebpf_sync_read_hash, em);
461 -
399 heartbeat_t hb;
400 heartbeat_init(&hb);
401 usec_t step = em->update_every * USEC_PER_SEC;
@@ -467,6 +404,7 @@ static void sync_collector(ebpf_module_t *em)
404 if (ebpf_exit_plugin)
405 break;
406
407 + ebpf_sync_read_global_table();
408 pthread_mutex_lock(&lock);
409
410 sync_send_data();
collectors/ebpf.plugin/ebpf_vfs.c
+3 -67
@@ -34,17 +34,6 @@ struct config vfs_config = { .first_section = NULL,
34 .index = { .avl_tree = { .root = NULL, .compar = appconfig_section_compare },
35 .rwlock = AVL_LOCK_INITIALIZER } };
36
37 -struct netdata_static_thread vfs_threads = {
38 - .name = "VFS KERNEL",
39 - .config_section = NULL,
40 - .config_name = NULL,
41 - .env_name = NULL,
42 - .enabled = 1,
43 - .thread = NULL,
44 - .init_routine = NULL,
45 - .start_routine = NULL
46 -};
47 -
37 netdata_ebpf_targets_t vfs_targets[] = { {.name = "vfs_write", .mode = EBPF_LOAD_TRAMPOLINE},
38 {.name = "vfs_writev", .mode = EBPF_LOAD_TRAMPOLINE},
39 {.name = "vfs_read", .mode = EBPF_LOAD_TRAMPOLINE},
@@ -409,16 +398,11 @@ static inline int ebpf_vfs_load_and_attach(struct vfs_bpf *obj, ebpf_module_t *e
398 static void ebpf_vfs_free(ebpf_module_t *em)
399 {
400 pthread_mutex_lock(&ebpf_exit_cleanup);
412 - if (em->thread->enabled == NETDATA_THREAD_EBPF_RUNNING) {
413 - em->thread->enabled = NETDATA_THREAD_EBPF_STOPPING;
414 - pthread_mutex_unlock(&ebpf_exit_cleanup);
415 - return;
416 - }
401 + em->thread->enabled = NETDATA_THREAD_EBPF_STOPPING;
402 pthread_mutex_unlock(&ebpf_exit_cleanup);
403
404 freez(vfs_hash_values);
405 freez(vfs_vector);
421 - freez(vfs_threads.thread);
406
407 #ifdef LIBBPF_MAJOR_VERSION
408 if (bpf_obj)
@@ -438,19 +422,6 @@ static void ebpf_vfs_free(ebpf_module_t *em)
422 * @param ptr thread data.
423 **/
424 static void ebpf_vfs_exit(void *ptr)
441 -{
442 - ebpf_module_t *em = (ebpf_module_t *)ptr;
443 - if (vfs_threads.thread)
444 - netdata_thread_cancel(*vfs_threads.thread);
445 - ebpf_vfs_free(em);
446 -}
447 -
448 -/**
449 -* Clean up the main thread.
450 -*
451 -* @param ptr thread data.
452 -**/
453 -static void ebpf_vfs_cleanup(void *ptr)
425 {
426 ebpf_module_t *em = (ebpf_module_t *)ptr;
427 ebpf_vfs_free(em);
@@ -519,7 +490,7 @@ static void ebpf_vfs_send_data(ebpf_module_t *em)
490 /**
491 * Read the hash table and store data to allocated vectors.
492 */
522 -static void read_global_table()
493 +static void ebpf_vfs_read_global_table()
494 {
495 uint64_t idx;
496 netdata_idx_t res[NETDATA_VFS_COUNTER];
@@ -874,36 +845,6 @@ static void read_update_vfs_cgroup()
845 pthread_mutex_unlock(&mutex_cgroup_shm);
846 }
847
877 -/**
878 - * VFS read hash
879 - *
880 - * This is the thread callback.
881 - * This thread is necessary, because we cannot freeze the whole plugin to read the data.
882 - *
883 - * @param ptr It is a NULL value for this thread.
884 - *
885 - * @return It always returns NULL.
886 - */
887 -void *ebpf_vfs_read_hash(void *ptr)
888 -{
889 - netdata_thread_cleanup_push(ebpf_vfs_cleanup, ptr);
890 - heartbeat_t hb;
891 - heartbeat_init(&hb);
892 -
893 - ebpf_module_t *em = (ebpf_module_t *)ptr;
894 -
895 - usec_t step = NETDATA_LATENCY_VFS_SLEEP_MS * em->update_every;
896 - //This will be cancelled by its parent
897 - while (!ebpf_exit_plugin) {
898 - (void)heartbeat_next(&hb, step);
899 -
900 - read_global_table();
901 - }
902 -
903 - netdata_thread_cleanup_pop(1);
904 - return NULL;
905 -}
906 -
848 /**
849 * Sum PIDs
850 *
@@ -1526,12 +1467,6 @@ static void ebpf_vfs_send_cgroup_data(ebpf_module_t *em)
1467 */
1468 static void vfs_collector(ebpf_module_t *em)
1469 {
1529 - vfs_threads.thread = mallocz(sizeof(netdata_thread_t));
1530 - vfs_threads.start_routine = ebpf_vfs_read_hash;
1531 -
1532 - netdata_thread_create(vfs_threads.thread, vfs_threads.name, NETDATA_THREAD_OPTION_DEFAULT,
1533 - ebpf_vfs_read_hash, em);
1534 -
1470 int cgroups = em->cgroup_charts;
1471 heartbeat_t hb;
1472 heartbeat_init(&hb);
@@ -1542,6 +1477,7 @@ static void vfs_collector(ebpf_module_t *em)
1477 break;
1478
1479 netdata_apps_integration_flags_t apps = em->apps_charts;
1480 + ebpf_vfs_read_global_table();
1481 pthread_mutex_lock(&collect_data_mutex);
1482 if (apps)
1483 ebpf_vfs_read_apps();
collectors/ebpf.plugin/ebpf_vfs.h
-2
@@ -8,8 +8,6 @@
8
9 #define NETDATA_DIRECTORY_VFS_CONFIG_FILE "vfs.conf"
10
11 -#define NETDATA_LATENCY_VFS_SLEEP_MS 750000ULL
12 -
11 // Global chart name
12 #define NETDATA_VFS_FILE_CLEAN_COUNT "vfs_deleted_objects"
13 #define NETDATA_VFS_FILE_IO_COUNT "vfs_io"