diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-02-06 16:11:34 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-02-06 16:11:34 +0000 |
commit | d079b656b4719739b2247dcd9d46e9bec793095a (patch) | |
tree | d2c950c70a776bcf697c963151c5bd959f8a9f03 /collectors/ebpf.plugin/ebpf_shm.c | |
parent | Releasing debian version 1.37.1-2. (diff) | |
download | netdata-d079b656b4719739b2247dcd9d46e9bec793095a.tar.xz netdata-d079b656b4719739b2247dcd9d46e9bec793095a.zip |
Merging upstream version 1.38.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | collectors/ebpf.plugin/ebpf_shm.c | 82 |
1 files changed, 11 insertions, 71 deletions
diff --git a/collectors/ebpf.plugin/ebpf_shm.c b/collectors/ebpf.plugin/ebpf_shm.c index f81287d82..4057eff7f 100644 --- a/collectors/ebpf.plugin/ebpf_shm.c +++ b/collectors/ebpf.plugin/ebpf_shm.c @@ -34,17 +34,6 @@ static ebpf_local_maps_t shm_maps[] = {{.name = "tbl_pid_shm", .internal_input = .map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED}, {.name = NULL, .internal_input = 0, .user_input = 0}}; -struct netdata_static_thread shm_threads = { - .name = "SHM KERNEL", - .config_section = NULL, - .config_name = NULL, - .env_name = NULL, - .enabled = 1, - .thread = NULL, - .init_routine = NULL, - .start_routine = NULL -}; - netdata_ebpf_targets_t shm_targets[] = { {.name = "shmget", .mode = EBPF_LOAD_TRAMPOLINE}, {.name = "shmat", .mode = EBPF_LOAD_TRAMPOLINE}, {.name = "shmdt", .mode = EBPF_LOAD_TRAMPOLINE}, @@ -246,7 +235,7 @@ static void ebpf_shm_adjust_map_size(struct shm_bpf *obj, ebpf_module_t *em) * @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_shm_load_and_attach(struct shm_bpf *obj, ebpf_module_t *em) { @@ -299,11 +288,7 @@ static inline int ebpf_shm_load_and_attach(struct shm_bpf *obj, ebpf_module_t *e static void ebpf_shm_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(shm_publish_aggregated); @@ -316,7 +301,9 @@ static void ebpf_shm_free(ebpf_module_t *em) shm_bpf__destroy(bpf_obj); #endif + pthread_mutex_lock(&ebpf_exit_cleanup); em->thread->enabled = NETDATA_THREAD_EBPF_STOPPED; + pthread_mutex_unlock(&ebpf_exit_cleanup); } /** @@ -329,20 +316,6 @@ static void ebpf_shm_free(ebpf_module_t *em) static void ebpf_shm_exit(void *ptr) { ebpf_module_t *em = (ebpf_module_t *)ptr; - netdata_thread_cancel(*shm_threads.thread); - ebpf_shm_free(em); -} - -/** - * SHM Cleanup - * - * Clean up allocated memory. - * - * @param ptr thread data. - */ -static void ebpf_shm_cleanup(void *ptr) -{ - ebpf_module_t *em = (ebpf_module_t *)ptr; ebpf_shm_free(em); } @@ -491,7 +464,7 @@ static void shm_send_global() * * Read the table with number of calls for all functions */ -static void read_global_table() +static void ebpf_shm_read_global_table() { netdata_idx_t *stored = shm_values; netdata_idx_t *val = shm_hash_values; @@ -512,30 +485,6 @@ static void read_global_table() } /** - * Shared memory reader thread. - * - * @param ptr It is a NULL value for this thread. - * @return It always returns NULL. - */ -void *ebpf_shm_read_hash(void *ptr) -{ - netdata_thread_cleanup_push(ebpf_shm_cleanup, ptr); - heartbeat_t hb; - heartbeat_init(&hb); - - ebpf_module_t *em = (ebpf_module_t *)ptr; - usec_t step = NETDATA_SHM_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 values for all targets. */ static void ebpf_shm_sum_pids(netdata_publish_shm_t *shm, struct pid_on_target *root) @@ -894,28 +843,19 @@ void ebpf_shm_send_cgroup_data(int update_every) */ static void shm_collector(ebpf_module_t *em) { - shm_threads.thread = mallocz(sizeof(netdata_thread_t)); - shm_threads.start_routine = ebpf_shm_read_hash; - - netdata_thread_create( - shm_threads.thread, - shm_threads.name, - NETDATA_THREAD_OPTION_DEFAULT, - ebpf_shm_read_hash, - em - ); - int cgroups = 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_shm_read_global_table(); pthread_mutex_lock(&collect_data_mutex); if (apps) { read_apps_table(); |