summaryrefslogtreecommitdiffstats
path: root/collectors/ebpf.plugin/ebpf_sync.c
diff options
context:
space:
mode:
Diffstat (limited to 'collectors/ebpf.plugin/ebpf_sync.c')
-rw-r--r--collectors/ebpf.plugin/ebpf_sync.c81
1 files changed, 11 insertions, 70 deletions
diff --git a/collectors/ebpf.plugin/ebpf_sync.c b/collectors/ebpf.plugin/ebpf_sync.c
index 840497533..7c81c1df3 100644
--- a/collectors/ebpf.plugin/ebpf_sync.c
+++ b/collectors/ebpf.plugin/ebpf_sync.c
@@ -10,17 +10,6 @@ static netdata_publish_syscall_t sync_counter_publish_aggregated[NETDATA_SYNC_ID
static netdata_idx_t sync_hash_values[NETDATA_SYNC_IDX_END];
-struct netdata_static_thread sync_threads = {
- .name = "SYNC KERNEL",
- .config_section = NULL,
- .config_name = NULL,
- .env_name = NULL,
- .enabled = 1,
- .thread = NULL,
- .init_routine = NULL,
- .start_routine = NULL
-};
-
static ebpf_local_maps_t sync_maps[] = {{.name = "tbl_sync", .internal_input = NETDATA_SYNC_END,
.user_input = 0, .type = NETDATA_EBPF_MAP_STATIC,
.map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
@@ -77,7 +66,7 @@ static inline void ebpf_sync_disable_probe(struct sync_bpf *obj)
}
/**
- * Disable tramppoline
+ * Disable trampoline
*
* Disable trampoline to use another method.
*
@@ -140,7 +129,7 @@ static void ebpf_sync_set_hash_tables(struct sync_bpf *obj, sync_syscalls_index_
* @param target the syscall that we are attaching a tracer.
* @param idx the index for the main structure
*
- * @return it returns 0 on succes and -1 otherwise
+ * @return it returns 0 on success and -1 otherwise
*/
static inline int ebpf_sync_load_and_attach(struct sync_bpf *obj, ebpf_module_t *em, char *target,
sync_syscalls_index_t idx)
@@ -216,17 +205,12 @@ void ebpf_sync_cleanup_objects()
static void ebpf_sync_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);
#ifdef LIBBPF_MAJOR_VERSION
ebpf_sync_cleanup_objects();
#endif
- freez(sync_threads.thread);
pthread_mutex_lock(&ebpf_exit_cleanup);
em->thread->enabled = NETDATA_THREAD_EBPF_STOPPED;
@@ -243,18 +227,6 @@ static void ebpf_sync_free(ebpf_module_t *em)
static void ebpf_sync_exit(void *ptr)
{
ebpf_module_t *em = (ebpf_module_t *)ptr;
- netdata_thread_cancel(*sync_threads.thread);
- ebpf_sync_free(em);
-}
-
-/**
- * Clean up the main thread.
- *
- * @param ptr thread data.
- */
-static void ebpf_sync_cleanup(void *ptr)
-{
- ebpf_module_t *em = (ebpf_module_t *)ptr;
ebpf_sync_free(em);
}
@@ -350,7 +322,7 @@ static int ebpf_sync_initialize_syscall(ebpf_module_t *em)
*
* Read the table with number of calls for all functions
*/
-static void read_global_table()
+static void ebpf_sync_read_global_table()
{
netdata_idx_t stored;
uint32_t idx = NETDATA_SYNC_CALL;
@@ -366,34 +338,6 @@ static void read_global_table()
}
/**
- * Sync read hash
- *
- * This is the thread callback.
- *
- * @param ptr It is a NULL value for this thread.
- *
- * @return It always returns NULL.
- */
-void *ebpf_sync_read_hash(void *ptr)
-{
- netdata_thread_cleanup_push(ebpf_sync_cleanup, ptr);
- ebpf_module_t *em = (ebpf_module_t *)ptr;
-
- heartbeat_t hb;
- heartbeat_init(&hb);
- usec_t step = NETDATA_EBPF_SYNC_SLEEP_MS * em->update_every;
-
- while (!ebpf_exit_plugin) {
- (void)heartbeat_next(&hb, step);
-
- read_global_table();
- }
-
- netdata_thread_cleanup_pop(1);
- return NULL;
-}
-
-/**
* Create Sync charts
*
* Create charts and dimensions according user input.
@@ -452,20 +396,17 @@ static void sync_send_data()
*/
static void sync_collector(ebpf_module_t *em)
{
- sync_threads.thread = mallocz(sizeof(netdata_thread_t));
- sync_threads.start_routine = ebpf_sync_read_hash;
-
- netdata_thread_create(sync_threads.thread, sync_threads.name, NETDATA_THREAD_OPTION_DEFAULT,
- ebpf_sync_read_hash, em);
-
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;
+ ebpf_sync_read_global_table();
pthread_mutex_lock(&lock);
sync_send_data();