summaryrefslogtreecommitdiffstats
path: root/collectors/ebpf.plugin/ebpf_dcstat.c
diff options
context:
space:
mode:
authorthiagoftsm <thiagoftsm@gmail.com>2023-01-27 16:31:52 +0000
committerGitHub <noreply@github.com>2023-01-27 16:31:52 +0000
commitbe615262a2a933d1c51aa927c83629f9c1e8a713 (patch)
tree0f035b93bc3c92c6fef1420b5dcdd85fe29abd46 /collectors/ebpf.plugin/ebpf_dcstat.c
parent081dbc6cedbc7c035d8e3bc7bcb1845db656bacf (diff)
Improve ebpf exit (#14270)
Diffstat (limited to 'collectors/ebpf.plugin/ebpf_dcstat.c')
-rw-r--r--collectors/ebpf.plugin/ebpf_dcstat.c67
1 files changed, 3 insertions, 64 deletions
diff --git a/collectors/ebpf.plugin/ebpf_dcstat.c b/collectors/ebpf.plugin/ebpf_dcstat.c
index e8dacb4b84..d1e189d1ad 100644
--- a/collectors/ebpf.plugin/ebpf_dcstat.c
+++ b/collectors/ebpf.plugin/ebpf_dcstat.c
@@ -19,15 +19,6 @@ struct config dcstat_config = { .first_section = NULL,
.index = { .avl_tree = { .root = NULL, .compar = appconfig_section_compare },
.rwlock = AVL_LOCK_INITIALIZER } };
-struct netdata_static_thread dcstat_threads = {"DCSTAT KERNEL",
- .config_section = NULL,
- .config_name = NULL,
- .env_name = NULL,
- .enabled = 1,
- .thread = NULL,
- .init_routine = NULL,
- .start_routine = NULL};
-
ebpf_local_maps_t dcstat_maps[] = {{.name = "dcstat_global", .internal_input = NETDATA_DIRECTORY_CACHE_END,
.user_input = 0, .type = NETDATA_EBPF_MAP_STATIC,
.map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
@@ -303,16 +294,11 @@ void ebpf_dcstat_clean_names()
static void ebpf_dcstat_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(dcstat_vector);
freez(dcstat_values);
- freez(dcstat_threads.thread);
ebpf_cleanup_publish_syscall(dcstat_counter_publish_aggregated);
@@ -338,19 +324,6 @@ static void ebpf_dcstat_free(ebpf_module_t *em )
static void ebpf_dcstat_exit(void *ptr)
{
ebpf_module_t *em = (ebpf_module_t *)ptr;
- if (dcstat_threads.thread)
- netdata_thread_cancel(*dcstat_threads.thread);
- ebpf_dcstat_free(em);
-}
-
-/**
- * Clean up the main thread.
- *
- * @param ptr thread data.
- */
-static void ebpf_dcstat_cleanup(void *ptr)
-{
- ebpf_module_t *em = (ebpf_module_t *)ptr;
ebpf_dcstat_free(em);
}
@@ -539,7 +512,7 @@ static void ebpf_update_dc_cgroup()
*
* Read the table with number of calls for all functions
*/
-static void read_global_table()
+static void ebpf_dc_read_global_table()
{
uint32_t idx;
netdata_idx_t *val = dcstat_hash_values;
@@ -560,35 +533,6 @@ static void read_global_table()
}
/**
- * DCstat 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_dcstat_read_hash(void *ptr)
-{
- netdata_thread_cleanup_push(ebpf_dcstat_cleanup, ptr);
- heartbeat_t hb;
- heartbeat_init(&hb);
-
- ebpf_module_t *em = (ebpf_module_t *)ptr;
-
- usec_t step = NETDATA_LATENCY_DCSTAT_SLEEP_MS * em->update_every;
- while (!ebpf_exit_plugin) {
- (void)heartbeat_next(&hb, step);
-
- read_global_table();
- }
-
- netdata_thread_cleanup_pop(1);
- return NULL;
-}
-
-/**
* Cachestat sum PIDs
*
* Sum values for all PIDs associated to a group
@@ -1035,12 +979,6 @@ void ebpf_dc_send_cgroup_data(int update_every)
*/
static void dcstat_collector(ebpf_module_t *em)
{
- dcstat_threads.thread = mallocz(sizeof(netdata_thread_t));
- dcstat_threads.start_routine = ebpf_dcstat_read_hash;
-
- netdata_thread_create(dcstat_threads.thread, dcstat_threads.name, NETDATA_THREAD_OPTION_DEFAULT,
- ebpf_dcstat_read_hash, em);
-
netdata_publish_dcstat_t publish;
memset(&publish, 0, sizeof(publish));
int cgroups = em->cgroup_charts;
@@ -1054,6 +992,7 @@ static void dcstat_collector(ebpf_module_t *em)
break;
netdata_apps_integration_flags_t apps = em->apps_charts;
+ ebpf_dc_read_global_table();
pthread_mutex_lock(&collect_data_mutex);
if (apps)
read_apps_table();