diff options
Diffstat (limited to 'collectors/ebpf.plugin/ebpf_swap.c')
-rw-r--r-- | collectors/ebpf.plugin/ebpf_swap.c | 69 |
1 files changed, 3 insertions, 66 deletions
diff --git a/collectors/ebpf.plugin/ebpf_swap.c b/collectors/ebpf.plugin/ebpf_swap.c index f83e4643e3..1608f4c26e 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}}; @@ -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) @@ -268,21 +252,6 @@ static void ebpf_swap_free(ebpf_module_t *em) static void ebpf_swap_exit(void *ptr) { ebpf_module_t *em = (ebpf_module_t *)ptr; - if (swap_threads.thread) - 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); } @@ -413,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; @@ -434,33 +403,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 * * Sum values for all targets. @@ -715,12 +657,6 @@ 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; @@ -732,6 +668,7 @@ static void swap_collector(ebpf_module_t *em) break; 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(); |