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_vfs.c | 81 +++++---------------------------------- 1 file changed, 10 insertions(+), 71 deletions(-) (limited to 'collectors/ebpf.plugin/ebpf_vfs.c') diff --git a/collectors/ebpf.plugin/ebpf_vfs.c b/collectors/ebpf.plugin/ebpf_vfs.c index ad6de4a07..b3c0ba45d 100644 --- a/collectors/ebpf.plugin/ebpf_vfs.c +++ b/collectors/ebpf.plugin/ebpf_vfs.c @@ -34,17 +34,6 @@ struct config vfs_config = { .first_section = NULL, .index = { .avl_tree = { .root = NULL, .compar = appconfig_section_compare }, .rwlock = AVL_LOCK_INITIALIZER } }; -struct netdata_static_thread vfs_threads = { - .name = "VFS KERNEL", - .config_section = NULL, - .config_name = NULL, - .env_name = NULL, - .enabled = 1, - .thread = NULL, - .init_routine = NULL, - .start_routine = NULL -}; - netdata_ebpf_targets_t vfs_targets[] = { {.name = "vfs_write", .mode = EBPF_LOAD_TRAMPOLINE}, {.name = "vfs_writev", .mode = EBPF_LOAD_TRAMPOLINE}, {.name = "vfs_read", .mode = EBPF_LOAD_TRAMPOLINE}, @@ -357,7 +346,7 @@ static void ebpf_vfs_disable_release_task(struct vfs_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_vfs_load_and_attach(struct vfs_bpf *obj, ebpf_module_t *em) { @@ -409,16 +398,11 @@ static inline int ebpf_vfs_load_and_attach(struct vfs_bpf *obj, ebpf_module_t *e static void ebpf_vfs_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(vfs_hash_values); freez(vfs_vector); - freez(vfs_threads.thread); #ifdef LIBBPF_MAJOR_VERSION if (bpf_obj) @@ -438,18 +422,6 @@ static void ebpf_vfs_free(ebpf_module_t *em) * @param ptr thread data. **/ static void ebpf_vfs_exit(void *ptr) -{ - ebpf_module_t *em = (ebpf_module_t *)ptr; - netdata_thread_cancel(*vfs_threads.thread); - ebpf_vfs_free(em); -} - -/** -* Clean up the main thread. -* -* @param ptr thread data. -**/ -static void ebpf_vfs_cleanup(void *ptr) { ebpf_module_t *em = (ebpf_module_t *)ptr; ebpf_vfs_free(em); @@ -518,7 +490,7 @@ static void ebpf_vfs_send_data(ebpf_module_t *em) /** * Read the hash table and store data to allocated vectors. */ -static void read_global_table() +static void ebpf_vfs_read_global_table() { uint64_t idx; netdata_idx_t res[NETDATA_VFS_COUNTER]; @@ -873,36 +845,6 @@ static void read_update_vfs_cgroup() pthread_mutex_unlock(&mutex_cgroup_shm); } -/** - * VFS read hash - * - * This is the thread callback. - * This thread is necessary, because we cannot freeze the whole plugin to read the data. - * - * @param ptr It is a NULL value for this thread. - * - * @return It always returns NULL. - */ -void *ebpf_vfs_read_hash(void *ptr) -{ - netdata_thread_cleanup_push(ebpf_vfs_cleanup, ptr); - heartbeat_t hb; - heartbeat_init(&hb); - - ebpf_module_t *em = (ebpf_module_t *)ptr; - - usec_t step = NETDATA_LATENCY_VFS_SLEEP_MS * em->update_every; - //This will be cancelled by its parent - while (!ebpf_exit_plugin) { - (void)heartbeat_next(&hb, step); - - read_global_table(); - } - - netdata_thread_cleanup_pop(1); - return NULL; -} - /** * Sum PIDs * @@ -1525,22 +1467,19 @@ static void ebpf_vfs_send_cgroup_data(ebpf_module_t *em) */ static void vfs_collector(ebpf_module_t *em) { - vfs_threads.thread = mallocz(sizeof(netdata_thread_t)); - vfs_threads.start_routine = ebpf_vfs_read_hash; - - netdata_thread_create(vfs_threads.thread, vfs_threads.name, NETDATA_THREAD_OPTION_DEFAULT, - ebpf_vfs_read_hash, em); - int cgroups = em->cgroup_charts; 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; 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_vfs_read_global_table(); pthread_mutex_lock(&collect_data_mutex); if (apps) ebpf_vfs_read_apps(); -- cgit v1.2.3