From aa2fe8ccbfcb117efa207d10229eeeac5d0f97c7 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 6 Feb 2023 17:11:30 +0100 Subject: Adding upstream version 1.38.0. Signed-off-by: Daniel Baumann --- collectors/ebpf.plugin/ebpf_mdflush.c | 84 +++++------------------------------ 1 file changed, 11 insertions(+), 73 deletions(-) (limited to 'collectors/ebpf.plugin/ebpf_mdflush.c') diff --git a/collectors/ebpf.plugin/ebpf_mdflush.c b/collectors/ebpf.plugin/ebpf_mdflush.c index dc805da23..1a5a7731e 100644 --- a/collectors/ebpf.plugin/ebpf_mdflush.c +++ b/collectors/ebpf.plugin/ebpf_mdflush.c @@ -35,17 +35,6 @@ static avl_tree_lock mdflush_pub; // tmp store for mdflush values we get from a per-CPU eBPF map. static mdflush_ebpf_val_t *mdflush_ebpf_vals = NULL; -static struct netdata_static_thread mdflush_threads = { - .name = "MDFLUSH KERNEL", - .config_section = NULL, - .config_name = NULL, - .env_name = NULL, - .enabled = 1, - .thread = NULL, - .init_routine = NULL, - .start_routine = NULL -}; - /** * MDflush Free * @@ -55,18 +44,10 @@ static struct netdata_static_thread mdflush_threads = { */ static void ebpf_mdflush_free(ebpf_module_t *em) { - pthread_mutex_lock(&ebpf_exit_cleanup); - if (em->thread->enabled == NETDATA_THREAD_EBPF_RUNNING) { - em->thread->enabled = NETDATA_THREAD_EBPF_STOPPING; - pthread_mutex_unlock(&ebpf_exit_cleanup); - return; - } - pthread_mutex_unlock(&ebpf_exit_cleanup); - freez(mdflush_ebpf_vals); - freez(mdflush_threads.thread); - + pthread_mutex_lock(&ebpf_exit_cleanup); em->thread->enabled = NETDATA_THREAD_EBPF_STOPPED; + pthread_mutex_unlock(&ebpf_exit_cleanup); } /** @@ -82,20 +63,6 @@ static void mdflush_exit(void *ptr) ebpf_mdflush_free(em); } -/** - * CLeanup - * - * Clean allocated memory. - * - * @param ptr thread data. - */ -static void mdflush_cleanup(void *ptr) -{ - ebpf_module_t *em = (ebpf_module_t *)ptr; - netdata_thread_cancel(*mdflush_threads.thread); - ebpf_mdflush_free(em); -} - /** * Compare mdflush values. * @@ -188,28 +155,6 @@ static void mdflush_read_count_map() } } -/** - * Read eBPF maps for mdflush. - */ -static void *mdflush_reader(void *ptr) -{ - netdata_thread_cleanup_push(mdflush_cleanup, ptr); - heartbeat_t hb; - heartbeat_init(&hb); - - ebpf_module_t *em = (ebpf_module_t *)ptr; - - usec_t step = NETDATA_MDFLUSH_SLEEP_MS * em->update_every; - while (!ebpf_exit_plugin) { - (void)heartbeat_next(&hb, step); - - mdflush_read_count_map(); - } - - netdata_thread_cleanup_pop(1); - return NULL; -} - static void mdflush_create_charts(int update_every) { ebpf_create_chart( @@ -256,34 +201,27 @@ static void mdflush_collector(ebpf_module_t *em) { mdflush_ebpf_vals = callocz(ebpf_nprocs, sizeof(mdflush_ebpf_val_t)); + int update_every = em->update_every; avl_init_lock(&mdflush_pub, mdflush_val_cmp); - // create reader thread. - mdflush_threads.thread = mallocz(sizeof(netdata_thread_t)); - mdflush_threads.start_routine = mdflush_reader; - netdata_thread_create( - mdflush_threads.thread, - mdflush_threads.name, - NETDATA_THREAD_OPTION_DEFAULT, - mdflush_reader, - em - ); - // create chart and static dims. pthread_mutex_lock(&lock); - mdflush_create_charts(em->update_every); + mdflush_create_charts(update_every); ebpf_update_stats(&plugin_statistics, em); pthread_mutex_unlock(&lock); // loop and read from published data until ebpf plugin is closed. heartbeat_t hb; heartbeat_init(&hb); - usec_t step = em->update_every * USEC_PER_SEC; + int counter = update_every - 1; while (!ebpf_exit_plugin) { - (void)heartbeat_next(&hb, step); - if (ebpf_exit_plugin) - break; + (void)heartbeat_next(&hb, USEC_PER_SEC); + if (ebpf_exit_plugin || ++counter != update_every) + continue; + + counter = 0; + mdflush_read_count_map(); // write dims now for all hitherto discovered devices. write_begin_chart("mdstat", "mdstat_flush"); avl_traverse_lock(&mdflush_pub, mdflush_write_dims, NULL); -- cgit v1.2.3