@cryptotaxi247 / netdata-1 / commits / 2539cb7ee

Modify eBPF exit (#16159)

thiagoftsm committed Oct 11, 2023 at 08:46 UTC 2539cb7ee65f6c5a1e0ccd041aced7a9608b0369
20 files changed +43 -47
collectors/ebpf.plugin/ebpf.c
+4 -4
@@ -642,6 +642,7 @@ ebpf_plugin_stats_t plugin_statistics = {.core = 0, .legacy = 0, .running = 0, .
642 .probes = 0, .retprobes = 0, .trampolines = 0, .memlock_kern = 0,
643 .hash_tables = 0};
644 netdata_ebpf_judy_pid_t ebpf_judy_pid = {.pid_table = NULL, .index = {.JudyLArray = NULL}};
645 +bool ebpf_plugin_exit = false;
646
647 #ifdef LIBBPF_MAJOR_VERSION
648 struct btf *default_btf = NULL;
@@ -914,7 +915,6 @@ static void ebpf_unload_sync()
915 }
916 }
917
917 -int ebpf_exit_plugin = 0;
918 /**
919 * Close the collector gracefully
920 *
@@ -950,7 +950,7 @@ void ebpf_stop_threads(int sig)
950 #endif
951 pthread_mutex_unlock(&mutex_cgroup_shm);
952
953 - ebpf_exit_plugin = 1;
953 + ebpf_plugin_exit = true;
954
955 ebpf_check_before2go();
956
@@ -4013,7 +4013,7 @@ static void ebpf_kill_previous_process(char *filename, pid_t pid)
4013 */
4014 void ebpf_pid_file(char *filename, size_t length)
4015 {
4016 - snprintfz(filename, length, "%s%s/ebpf.d/ebpf.pid", netdata_configured_host_prefix, ebpf_plugin_dir);
4016 + snprintfz(filename, length, "%s/var/run/ebpf.pid", netdata_configured_host_prefix);
4017 }
4018
4019 /**
@@ -4136,7 +4136,7 @@ int main(int argc, char **argv)
4136 int update_apps_list = update_apps_every - 1;
4137 int process_maps_per_core = ebpf_modules[EBPF_MODULE_PROCESS_IDX].maps_per_core;
4138 //Plugin will be killed when it receives a signal
4139 - for ( ; !ebpf_exit_plugin ; global_iterations_counter++) {
4139 + for ( ; !ebpf_plugin_exit; global_iterations_counter++) {
4140 (void)heartbeat_next(&hb, step);
4141
4142 if (global_iterations_counter % EBPF_DEFAULT_UPDATE_EVERY == 0) {
collectors/ebpf.plugin/ebpf.h
+1 -1
@@ -353,7 +353,7 @@ void ebpf_read_local_addresses_unsafe();
353
354 extern ebpf_filesystem_partitions_t localfs[];
355 extern ebpf_sync_syscalls_t local_syscalls[];
356 -extern int ebpf_exit_plugin;
356 +extern bool ebpf_plugin_exit;
357 void ebpf_stop_threads(int sig);
358 extern netdata_ebpf_judy_pid_t ebpf_judy_pid;
359
collectors/ebpf.plugin/ebpf_cachestat.c
+2 -2
@@ -1288,10 +1288,10 @@ static void cachestat_collector(ebpf_module_t *em)
1288 uint32_t lifetime = em->lifetime;
1289 netdata_idx_t *stats = em->hash_table_stats;
1290 memset(stats, 0, sizeof(em->hash_table_stats));
1291 - while (!ebpf_exit_plugin && running_time < lifetime) {
1291 + while (!ebpf_plugin_exit && running_time < lifetime) {
1292 (void)heartbeat_next(&hb, USEC_PER_SEC);
1293
1294 - if (ebpf_exit_plugin || ++counter != update_every)
1294 + if (ebpf_plugin_exit || ++counter != update_every)
1295 continue;
1296
1297 counter = 0;
collectors/ebpf.plugin/ebpf_cgroup.c
+1 -1
@@ -373,7 +373,7 @@ void *ebpf_cgroup_integration(void *ptr)
373 heartbeat_t hb;
374 heartbeat_init(&hb);
375 //Plugin will be killed when it receives a signal
376 - while (!ebpf_exit_plugin) {
376 + while (!ebpf_plugin_exit) {
377 (void)heartbeat_next(&hb, step);
378
379 // We are using a small heartbeat time to wake up thread,
collectors/ebpf.plugin/ebpf_dcstat.c
+2 -2
@@ -1169,10 +1169,10 @@ static void dcstat_collector(ebpf_module_t *em)
1169 uint32_t lifetime = em->lifetime;
1170 netdata_idx_t *stats = em->hash_table_stats;
1171 memset(stats, 0, sizeof(em->hash_table_stats));
1172 - while (!ebpf_exit_plugin && running_time < lifetime) {
1172 + while (!ebpf_plugin_exit && running_time < lifetime) {
1173 (void)heartbeat_next(&hb, USEC_PER_SEC);
1174
1175 - if (ebpf_exit_plugin || ++counter != update_every)
1175 + if (ebpf_plugin_exit || ++counter != update_every)
1176 continue;
1177
1178 counter = 0;
collectors/ebpf.plugin/ebpf_disk.c
+2 -2
@@ -778,10 +778,10 @@ static void disk_collector(ebpf_module_t *em)
778 int maps_per_core = em->maps_per_core;
779 uint32_t running_time = 0;
780 uint32_t lifetime = em->lifetime;
781 - while (!ebpf_exit_plugin && running_time < lifetime) {
781 + while (!ebpf_plugin_exit && running_time < lifetime) {
782 (void)heartbeat_next(&hb, USEC_PER_SEC);
783
784 - if (ebpf_exit_plugin || ++counter != update_every)
784 + if (ebpf_plugin_exit || ++counter != update_every)
785 continue;
786
787 counter = 0;
collectors/ebpf.plugin/ebpf_fd.c
+2 -2
@@ -1136,10 +1136,10 @@ static void fd_collector(ebpf_module_t *em)
1136 uint32_t lifetime = em->lifetime;
1137 netdata_idx_t *stats = em->hash_table_stats;
1138 memset(stats, 0, sizeof(em->hash_table_stats));
1139 - while (!ebpf_exit_plugin && running_time < lifetime) {
1139 + while (!ebpf_plugin_exit && running_time < lifetime) {
1140 (void)heartbeat_next(&hb, USEC_PER_SEC);
1141
1142 - if (ebpf_exit_plugin || ++counter != update_every)
1142 + if (ebpf_plugin_exit || ++counter != update_every)
1143 continue;
1144
1145 counter = 0;
collectors/ebpf.plugin/ebpf_filesystem.c
+2 -2
@@ -909,10 +909,10 @@ static void filesystem_collector(ebpf_module_t *em)
909 int counter = update_every - 1;
910 uint32_t running_time = 0;
911 uint32_t lifetime = em->lifetime;
912 - while (!ebpf_exit_plugin && running_time < lifetime) {
912 + while (!ebpf_plugin_exit && running_time < lifetime) {
913 (void)heartbeat_next(&hb, USEC_PER_SEC);
914
915 - if (ebpf_exit_plugin || ++counter != update_every)
915 + if (ebpf_plugin_exit || ++counter != update_every)
916 continue;
917
918 counter = 0;
collectors/ebpf.plugin/ebpf_functions.c
+3 -7
@@ -1069,11 +1069,10 @@ void *ebpf_function_thread(void *ptr)
1069 {
1070 (void)ptr;
1071
1072 - bool ebpf_function_plugin_exit = false;
1072 struct functions_evloop_globals *wg = functions_evloop_init(1,
1073 "EBPF",
1074 &lock,
1076 - &ebpf_function_plugin_exit);
1075 + &ebpf_plugin_exit);
1076
1077 functions_evloop_add_function(wg,
1078 "ebpf_socket",
@@ -1082,13 +1081,10 @@ void *ebpf_function_thread(void *ptr)
1081
1082 heartbeat_t hb;
1083 heartbeat_init(&hb);
1085 - while(!ebpf_exit_plugin) {
1084 + while(!ebpf_plugin_exit) {
1085 (void)heartbeat_next(&hb, USEC_PER_SEC);
1086
1088 - if (ebpf_function_plugin_exit) {
1089 - pthread_mutex_lock(&ebpf_exit_cleanup);
1090 - ebpf_stop_threads(0);
1091 - pthread_mutex_unlock(&ebpf_exit_cleanup);
1087 + if (ebpf_plugin_exit) {
1088 break;
1089 }
1090 }
collectors/ebpf.plugin/ebpf_hardirq.c
+2 -2
@@ -580,10 +580,10 @@ static void hardirq_collector(ebpf_module_t *em)
580 //This will be cancelled by its parent
581 uint32_t running_time = 0;
582 uint32_t lifetime = em->lifetime;
583 - while (!ebpf_exit_plugin && running_time < lifetime) {
583 + while (!ebpf_plugin_exit && running_time < lifetime) {
584 (void)heartbeat_next(&hb, USEC_PER_SEC);
585
586 - if (ebpf_exit_plugin || ++counter != update_every)
586 + if (ebpf_plugin_exit || ++counter != update_every)
587 continue;
588
589 counter = 0;
collectors/ebpf.plugin/ebpf_mdflush.c
+2 -2
@@ -345,10 +345,10 @@ static void mdflush_collector(ebpf_module_t *em)
345 int maps_per_core = em->maps_per_core;
346 uint32_t running_time = 0;
347 uint32_t lifetime = em->lifetime;
348 - while (!ebpf_exit_plugin && running_time < lifetime) {
348 + while (!ebpf_plugin_exit && running_time < lifetime) {
349 (void)heartbeat_next(&hb, USEC_PER_SEC);
350
351 - if (ebpf_exit_plugin || ++counter != update_every)
351 + if (ebpf_plugin_exit || ++counter != update_every)
352 continue;
353
354 counter = 0;
collectors/ebpf.plugin/ebpf_mount.c
+2 -2
@@ -367,9 +367,9 @@ static void mount_collector(ebpf_module_t *em)
367 int maps_per_core = em->maps_per_core;
368 uint32_t running_time = 0;
369 uint32_t lifetime = em->lifetime;
370 - while (!ebpf_exit_plugin && running_time < lifetime) {
370 + while (!ebpf_plugin_exit && running_time < lifetime) {
371 (void)heartbeat_next(&hb, USEC_PER_SEC);
372 - if (ebpf_exit_plugin || ++counter != update_every)
372 + if (ebpf_plugin_exit || ++counter != update_every)
373 continue;
374
375 counter = 0;
collectors/ebpf.plugin/ebpf_oomkill.c
+2 -2
@@ -420,9 +420,9 @@ static void oomkill_collector(ebpf_module_t *em)
420 uint32_t running_time = 0;
421 uint32_t lifetime = em->lifetime;
422 netdata_idx_t *stats = em->hash_table_stats;
423 - while (!ebpf_exit_plugin && running_time < lifetime) {
423 + while (!ebpf_plugin_exit && running_time < lifetime) {
424 (void)heartbeat_next(&hb, USEC_PER_SEC);
425 - if (ebpf_exit_plugin || ++counter != update_every)
425 + if (ebpf_plugin_exit || ++counter != update_every)
426 continue;
427
428 counter = 0;
collectors/ebpf.plugin/ebpf_process.c
+2 -2
@@ -1118,10 +1118,10 @@ static void process_collector(ebpf_module_t *em)
1118 uint32_t lifetime = em->lifetime;
1119 netdata_idx_t *stats = em->hash_table_stats;
1120 memset(stats, 0, sizeof(em->hash_table_stats));
1121 - while (!ebpf_exit_plugin && running_time < lifetime) {
1121 + while (!ebpf_plugin_exit && running_time < lifetime) {
1122 usec_t dt = heartbeat_next(&hb, USEC_PER_SEC);
1123 (void)dt;
1124 - if (ebpf_exit_plugin)
1124 + if (ebpf_plugin_exit)
1125 break;
1126
1127 if (++counter == update_every) {
collectors/ebpf.plugin/ebpf_shm.c
+2 -2
@@ -1035,9 +1035,9 @@ static void shm_collector(ebpf_module_t *em)
1035 uint32_t lifetime = em->lifetime;
1036 netdata_idx_t *stats = em->hash_table_stats;
1037 memset(stats, 0, sizeof(em->hash_table_stats));
1038 - while (!ebpf_exit_plugin && running_time < lifetime) {
1038 + while (!ebpf_plugin_exit && running_time < lifetime) {
1039 (void)heartbeat_next(&hb, USEC_PER_SEC);
1040 - if (ebpf_exit_plugin || ++counter != update_every)
1040 + if (ebpf_plugin_exit || ++counter != update_every)
1041 continue;
1042
1043 counter = 0;
collectors/ebpf.plugin/ebpf_socket.c
+4 -4
@@ -1756,9 +1756,9 @@ void *ebpf_read_socket_thread(void *ptr)
1756 uint32_t running_time = 0;
1757 uint32_t lifetime = em->lifetime;
1758 usec_t period = update_every * USEC_PER_SEC;
1759 - while (!ebpf_exit_plugin && running_time < lifetime) {
1759 + while (!ebpf_plugin_exit && running_time < lifetime) {
1760 (void)heartbeat_next(&hb, period);
1761 - if (ebpf_exit_plugin || ++counter != update_every)
1761 + if (ebpf_plugin_exit || ++counter != update_every)
1762 continue;
1763
1764 ebpf_update_array_vectors(em);
@@ -2490,9 +2490,9 @@ static void socket_collector(ebpf_module_t *em)
2490 uint32_t lifetime = em->lifetime;
2491 netdata_idx_t *stats = em->hash_table_stats;
2492 memset(stats, 0, sizeof(em->hash_table_stats));
2493 - while (!ebpf_exit_plugin && running_time < lifetime) {
2493 + while (!ebpf_plugin_exit && running_time < lifetime) {
2494 (void)heartbeat_next(&hb, USEC_PER_SEC);
2495 - if (ebpf_exit_plugin || ++counter != update_every)
2495 + if (ebpf_plugin_exit || ++counter != update_every)
2496 continue;
2497
2498 counter = 0;
collectors/ebpf.plugin/ebpf_softirq.c
+2 -2
@@ -218,9 +218,9 @@ static void softirq_collector(ebpf_module_t *em)
218 //This will be cancelled by its parent
219 uint32_t running_time = 0;
220 uint32_t lifetime = em->lifetime;
221 - while (!ebpf_exit_plugin && running_time < lifetime) {
221 + while (!ebpf_plugin_exit && running_time < lifetime) {
222 (void)heartbeat_next(&hb, USEC_PER_SEC);
223 - if (ebpf_exit_plugin || ++counter != update_every)
223 + if (ebpf_plugin_exit || ++counter != update_every)
224 continue;
225
226 counter = 0;
collectors/ebpf.plugin/ebpf_swap.c
+2 -2
@@ -796,9 +796,9 @@ static void swap_collector(ebpf_module_t *em)
796 uint32_t lifetime = em->lifetime;
797 netdata_idx_t *stats = em->hash_table_stats;
798 memset(stats, 0, sizeof(em->hash_table_stats));
799 - while (!ebpf_exit_plugin && running_time < lifetime) {
799 + while (!ebpf_plugin_exit && running_time < lifetime) {
800 (void)heartbeat_next(&hb, USEC_PER_SEC);
801 - if (ebpf_exit_plugin || ++counter != update_every)
801 + if (ebpf_plugin_exit || ++counter != update_every)
802 continue;
803
804 counter = 0;
collectors/ebpf.plugin/ebpf_sync.c
+2 -2
@@ -560,9 +560,9 @@ static void sync_collector(ebpf_module_t *em)
560 int maps_per_core = em->maps_per_core;
561 uint32_t running_time = 0;
562 uint32_t lifetime = em->lifetime;
563 - while (!ebpf_exit_plugin && running_time < lifetime) {
563 + while (!ebpf_plugin_exit && running_time < lifetime) {
564 (void)heartbeat_next(&hb, USEC_PER_SEC);
565 - if (ebpf_exit_plugin || ++counter != update_every)
565 + if (ebpf_plugin_exit || ++counter != update_every)
566 continue;
567
568 counter = 0;
collectors/ebpf.plugin/ebpf_vfs.c
+2 -2
@@ -1960,9 +1960,9 @@ static void vfs_collector(ebpf_module_t *em)
1960 uint32_t lifetime = em->lifetime;
1961 netdata_idx_t *stats = em->hash_table_stats;
1962 memset(stats, 0, sizeof(em->hash_table_stats));
1963 - while (!ebpf_exit_plugin && running_time < lifetime) {
1963 + while (!ebpf_plugin_exit && running_time < lifetime) {
1964 (void)heartbeat_next(&hb, USEC_PER_SEC);
1965 - if (ebpf_exit_plugin || ++counter != update_every)
1965 + if (ebpf_plugin_exit || ++counter != update_every)
1966 continue;
1967
1968 counter = 0;