From d079b656b4719739b2247dcd9d46e9bec793095a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 6 Feb 2023 17:11:34 +0100 Subject: Merging upstream version 1.38.0. Signed-off-by: Daniel Baumann --- collectors/ebpf.plugin/ebpf_hardirq.c | 77 +++++++---------------------------- 1 file changed, 14 insertions(+), 63 deletions(-) (limited to 'collectors/ebpf.plugin/ebpf_hardirq.c') diff --git a/collectors/ebpf.plugin/ebpf_hardirq.c b/collectors/ebpf.plugin/ebpf_hardirq.c index b07dd24ca..20c4b9d05 100644 --- a/collectors/ebpf.plugin/ebpf_hardirq.c +++ b/collectors/ebpf.plugin/ebpf_hardirq.c @@ -135,17 +135,6 @@ static hardirq_ebpf_val_t *hardirq_ebpf_vals = NULL; // tmp store for static hard IRQ values we get from a per-CPU eBPF map. static hardirq_ebpf_static_val_t *hardirq_ebpf_static_vals = NULL; -static struct netdata_static_thread hardirq_threads = { - .name = "HARDIRQ KERNEL", - .config_section = NULL, - .config_name = NULL, - .env_name = NULL, - .enabled = 1, - .thread = NULL, - .init_routine = NULL, - .start_routine = NULL -}; - /** * Hardirq Free * @@ -156,21 +145,18 @@ static struct netdata_static_thread hardirq_threads = { static void ebpf_hardirq_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; - } + em->thread->enabled = NETDATA_THREAD_EBPF_STOPPING; pthread_mutex_unlock(&ebpf_exit_cleanup); - freez(hardirq_threads.thread); for (int i = 0; hardirq_tracepoints[i].class != NULL; i++) { ebpf_disable_tracepoint(&hardirq_tracepoints[i]); } freez(hardirq_ebpf_vals); freez(hardirq_ebpf_static_vals); + pthread_mutex_lock(&ebpf_exit_cleanup); em->thread->enabled = NETDATA_THREAD_EBPF_STOPPED; + pthread_mutex_unlock(&ebpf_exit_cleanup); } /** @@ -181,20 +167,6 @@ static void ebpf_hardirq_free(ebpf_module_t *em) * @param ptr thread data. */ static void hardirq_exit(void *ptr) -{ - ebpf_module_t *em = (ebpf_module_t *)ptr; - netdata_thread_cancel(*hardirq_threads.thread); - ebpf_hardirq_free(em); -} - -/** - * Hardirq clean up - * - * Clean up allocated memory. - * - * @param ptr thread data. - */ -static void hardirq_cleanup(void *ptr) { ebpf_module_t *em = (ebpf_module_t *)ptr; ebpf_hardirq_free(em); @@ -331,24 +303,10 @@ static void hardirq_read_latency_static_map(int mapfd) /** * Read eBPF maps for hard IRQ. */ -static void *hardirq_reader(void *ptr) +static void hardirq_reader() { - netdata_thread_cleanup_push(hardirq_cleanup, ptr); - heartbeat_t hb; - heartbeat_init(&hb); - - ebpf_module_t *em = (ebpf_module_t *)ptr; - - usec_t step = NETDATA_HARDIRQ_SLEEP_MS * em->update_every; - while (!ebpf_exit_plugin) { - (void)heartbeat_next(&hb, step); - - hardirq_read_latency_map(hardirq_maps[HARDIRQ_MAP_LATENCY].map_fd); - hardirq_read_latency_static_map(hardirq_maps[HARDIRQ_MAP_LATENCY_STATIC].map_fd); - } - - netdata_thread_cleanup_pop(1); - return NULL; + hardirq_read_latency_map(hardirq_maps[HARDIRQ_MAP_LATENCY].map_fd); + hardirq_read_latency_static_map(hardirq_maps[HARDIRQ_MAP_LATENCY_STATIC].map_fd); } static void hardirq_create_charts(int update_every) @@ -428,17 +386,6 @@ static void hardirq_collector(ebpf_module_t *em) avl_init_lock(&hardirq_pub, hardirq_val_cmp); - // create reader thread. - hardirq_threads.thread = mallocz(sizeof(netdata_thread_t)); - hardirq_threads.start_routine = hardirq_reader; - netdata_thread_create( - hardirq_threads.thread, - hardirq_threads.name, - NETDATA_THREAD_OPTION_DEFAULT, - hardirq_reader, - em - ); - // create chart and static dims. pthread_mutex_lock(&lock); hardirq_create_charts(em->update_every); @@ -449,13 +396,17 @@ static void hardirq_collector(ebpf_module_t *em) // 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 update_every = em->update_every; + int counter = update_every - 1; //This will be cancelled by its parent 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; + hardirq_reader(); pthread_mutex_lock(&lock); // write dims now for all hitherto discovered IRQs. -- cgit v1.2.3