summaryrefslogtreecommitdiffstats
path: root/collectors/ebpf.plugin/ebpf_mdflush.c
diff options
context:
space:
mode:
Diffstat (limited to 'collectors/ebpf.plugin/ebpf_mdflush.c')
-rw-r--r--collectors/ebpf.plugin/ebpf_mdflush.c84
1 files changed, 11 insertions, 73 deletions
diff --git a/collectors/ebpf.plugin/ebpf_mdflush.c b/collectors/ebpf.plugin/ebpf_mdflush.c
index dc805da23..1a5a7731e 100644
--- a/collectors/ebpf.plugin/ebpf_mdflush.c
+++ b/collectors/ebpf.plugin/ebpf_mdflush.c
@@ -35,17 +35,6 @@ static avl_tree_lock mdflush_pub;
// tmp store for mdflush values we get from a per-CPU eBPF map.
static mdflush_ebpf_val_t *mdflush_ebpf_vals = NULL;
-static struct netdata_static_thread mdflush_threads = {
- .name = "MDFLUSH KERNEL",
- .config_section = NULL,
- .config_name = NULL,
- .env_name = NULL,
- .enabled = 1,
- .thread = NULL,
- .init_routine = NULL,
- .start_routine = NULL
-};
-
/**
* MDflush Free
*
@@ -55,18 +44,10 @@ static struct netdata_static_thread mdflush_threads = {
*/
static void ebpf_mdflush_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;
- }
- pthread_mutex_unlock(&ebpf_exit_cleanup);
-
freez(mdflush_ebpf_vals);
- freez(mdflush_threads.thread);
-
+ pthread_mutex_lock(&ebpf_exit_cleanup);
em->thread->enabled = NETDATA_THREAD_EBPF_STOPPED;
+ pthread_mutex_unlock(&ebpf_exit_cleanup);
}
/**
@@ -83,20 +64,6 @@ static void mdflush_exit(void *ptr)
}
/**
- * CLeanup
- *
- * Clean allocated memory.
- *
- * @param ptr thread data.
- */
-static void mdflush_cleanup(void *ptr)
-{
- ebpf_module_t *em = (ebpf_module_t *)ptr;
- netdata_thread_cancel(*mdflush_threads.thread);
- ebpf_mdflush_free(em);
-}
-
-/**
* Compare mdflush values.
*
* @param a `netdata_mdflush_t *`.
@@ -188,28 +155,6 @@ static void mdflush_read_count_map()
}
}
-/**
- * Read eBPF maps for mdflush.
- */
-static void *mdflush_reader(void *ptr)
-{
- netdata_thread_cleanup_push(mdflush_cleanup, ptr);
- heartbeat_t hb;
- heartbeat_init(&hb);
-
- ebpf_module_t *em = (ebpf_module_t *)ptr;
-
- usec_t step = NETDATA_MDFLUSH_SLEEP_MS * em->update_every;
- while (!ebpf_exit_plugin) {
- (void)heartbeat_next(&hb, step);
-
- mdflush_read_count_map();
- }
-
- netdata_thread_cleanup_pop(1);
- return NULL;
-}
-
static void mdflush_create_charts(int update_every)
{
ebpf_create_chart(
@@ -256,34 +201,27 @@ static void mdflush_collector(ebpf_module_t *em)
{
mdflush_ebpf_vals = callocz(ebpf_nprocs, sizeof(mdflush_ebpf_val_t));
+ int update_every = em->update_every;
avl_init_lock(&mdflush_pub, mdflush_val_cmp);
- // create reader thread.
- mdflush_threads.thread = mallocz(sizeof(netdata_thread_t));
- mdflush_threads.start_routine = mdflush_reader;
- netdata_thread_create(
- mdflush_threads.thread,
- mdflush_threads.name,
- NETDATA_THREAD_OPTION_DEFAULT,
- mdflush_reader,
- em
- );
-
// create chart and static dims.
pthread_mutex_lock(&lock);
- mdflush_create_charts(em->update_every);
+ mdflush_create_charts(update_every);
ebpf_update_stats(&plugin_statistics, em);
pthread_mutex_unlock(&lock);
// loop and read from published data until ebpf plugin is closed.
heartbeat_t hb;
heartbeat_init(&hb);
- usec_t step = em->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;
+ mdflush_read_count_map();
// write dims now for all hitherto discovered devices.
write_begin_chart("mdstat", "mdstat_flush");
avl_traverse_lock(&mdflush_pub, mdflush_write_dims, NULL);