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_swap.c | 79 +++++--------------------------------- 1 file changed, 9 insertions(+), 70 deletions(-) (limited to 'collectors/ebpf.plugin/ebpf_swap.c') diff --git a/collectors/ebpf.plugin/ebpf_swap.c b/collectors/ebpf.plugin/ebpf_swap.c index 8199573a9..059efb63b 100644 --- a/collectors/ebpf.plugin/ebpf_swap.c +++ b/collectors/ebpf.plugin/ebpf_swap.c @@ -34,17 +34,6 @@ static ebpf_local_maps_t swap_maps[] = {{.name = "tbl_pid_swap", .internal_input .map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED}, {.name = NULL, .internal_input = 0, .user_input = 0}}; -struct netdata_static_thread swap_threads = { - .name = "SWAP KERNEL", - .config_section = NULL, - .config_name = NULL, - .env_name = NULL, - .enabled = 1, - .thread = NULL, - .init_routine = NULL, - .start_routine = NULL -}; - netdata_ebpf_targets_t swap_targets[] = { {.name = "swap_readpage", .mode = EBPF_LOAD_TRAMPOLINE}, {.name = "swap_writepage", .mode = EBPF_LOAD_TRAMPOLINE}, {.name = NULL, .mode = EBPF_LOAD_TRAMPOLINE}}; @@ -184,7 +173,7 @@ static void ebpf_swap_disable_release_task(struct swap_bpf *obj) * @param obj is the main structure for bpf objects. * @param em structure with configuration * - * @return it returns 0 on succes and -1 otherwise + * @return it returns 0 on success and -1 otherwise */ static inline int ebpf_swap_load_and_attach(struct swap_bpf *obj, ebpf_module_t *em) { @@ -236,18 +225,13 @@ static inline int ebpf_swap_load_and_attach(struct swap_bpf *obj, ebpf_module_t static void ebpf_swap_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); ebpf_cleanup_publish_syscall(swap_publish_aggregated); freez(swap_vector); freez(swap_values); - freez(swap_threads.thread); #ifdef LIBBPF_MAJOR_VERSION if (bpf_obj) @@ -266,20 +250,6 @@ static void ebpf_swap_free(ebpf_module_t *em) * @param ptr thread data. */ static void ebpf_swap_exit(void *ptr) -{ - ebpf_module_t *em = (ebpf_module_t *)ptr; - netdata_thread_cancel(*swap_threads.thread); - ebpf_swap_free(em); -} - -/** - * Swap cleanup - * - * Clean up allocated memory. - * - * @param ptr thread data. - */ -static void ebpf_swap_cleanup(void *ptr) { ebpf_module_t *em = (ebpf_module_t *)ptr; ebpf_swap_free(em); @@ -412,7 +382,7 @@ static void swap_send_global() * * Read the table with number of calls to all functions */ -static void read_global_table() +static void ebpf_swap_read_global_table() { netdata_idx_t *stored = swap_values; netdata_idx_t *val = swap_hash_values; @@ -432,33 +402,6 @@ static void read_global_table() } } -/** - * Swap read hash - * - * This is the thread callback. - * - * @param ptr It is a NULL value for this thread. - * - * @return It always returns NULL. - */ -void *ebpf_swap_read_hash(void *ptr) -{ - netdata_thread_cleanup_push(ebpf_swap_cleanup, ptr); - heartbeat_t hb; - heartbeat_init(&hb); - - ebpf_module_t *em = (ebpf_module_t *)ptr; - usec_t step = NETDATA_SWAP_SLEEP_MS * em->update_every; - while (!ebpf_exit_plugin) { - (void)heartbeat_next(&hb, step); - - read_global_table(); - } - - netdata_thread_cleanup_pop(1); - return NULL; -} - /** * Sum PIDs * @@ -714,23 +657,19 @@ void ebpf_swap_send_cgroup_data(int update_every) */ static void swap_collector(ebpf_module_t *em) { - swap_threads.thread = mallocz(sizeof(netdata_thread_t)); - swap_threads.start_routine = ebpf_swap_read_hash; - - netdata_thread_create(swap_threads.thread, swap_threads.name, NETDATA_THREAD_OPTION_DEFAULT, - ebpf_swap_read_hash, em); - int cgroup = em->cgroup_charts; int update_every = em->update_every; heartbeat_t hb; heartbeat_init(&hb); - usec_t step = 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; netdata_apps_integration_flags_t apps = em->apps_charts; + ebpf_swap_read_global_table(); pthread_mutex_lock(&collect_data_mutex); if (apps) read_apps_table(); -- cgit v1.2.3