summaryrefslogtreecommitdiffstats
path: root/collectors/ebpf.plugin
diff options
context:
space:
mode:
Diffstat (limited to 'collectors/ebpf.plugin')
-rw-r--r--collectors/ebpf.plugin/ebpf.c137
-rw-r--r--collectors/ebpf.plugin/ebpf_cachestat.c34
-rw-r--r--collectors/ebpf.plugin/ebpf_dcstat.c46
-rw-r--r--collectors/ebpf.plugin/ebpf_disk.c26
-rw-r--r--collectors/ebpf.plugin/ebpf_fd.c31
-rw-r--r--collectors/ebpf.plugin/ebpf_hardirq.c25
-rw-r--r--collectors/ebpf.plugin/ebpf_mdflush.c23
-rw-r--r--collectors/ebpf.plugin/ebpf_mount.c26
-rw-r--r--collectors/ebpf.plugin/ebpf_oomkill.c4
-rw-r--r--collectors/ebpf.plugin/ebpf_shm.c30
-rw-r--r--collectors/ebpf.plugin/ebpf_softirq.c26
-rw-r--r--collectors/ebpf.plugin/ebpf_swap.c29
-rw-r--r--collectors/ebpf.plugin/ebpf_sync.c33
-rw-r--r--collectors/ebpf.plugin/ebpf_vfs.c29
14 files changed, 186 insertions, 313 deletions
diff --git a/collectors/ebpf.plugin/ebpf.c b/collectors/ebpf.plugin/ebpf.c
index 45303574f..ffab37de3 100644
--- a/collectors/ebpf.plugin/ebpf.c
+++ b/collectors/ebpf.plugin/ebpf.c
@@ -540,6 +540,31 @@ ARAL *ebpf_allocate_pid_aral(char *name, size_t size)
*****************************************************************/
/**
+ * Wait to avoid possible coredumps while process is closing.
+ */
+static inline void ebpf_check_before2go()
+{
+ int i = EBPF_OPTION_ALL_CHARTS;
+ usec_t max = USEC_PER_SEC, step = 200000;
+ while (i && max) {
+ max -= step;
+ sleep_usec(step);
+ i = 0;
+ int j;
+ pthread_mutex_lock(&ebpf_exit_cleanup);
+ for (j = 0; ebpf_modules[j].thread_name != NULL; j++) {
+ if (ebpf_modules[j].enabled == NETDATA_THREAD_EBPF_RUNNING)
+ i++;
+ }
+ pthread_mutex_unlock(&ebpf_exit_cleanup);
+ }
+
+ if (i) {
+ error("eBPF cannot unload all threads on time, but it will go away");
+ }
+}
+
+/**
* Close the collector gracefully
*/
static void ebpf_exit()
@@ -561,8 +586,10 @@ static void ebpf_exit()
#ifdef NETDATA_INTERNAL_CHECKS
error("Good bye world! I was PID %d", main_thread_id);
#endif
- printf("DISABLE\n");
+ fprintf(stdout, "EXIT\n");
+ fflush(stdout);
+ ebpf_check_before2go();
pthread_mutex_lock(&mutex_cgroup_shm);
if (shm_ebpf_cgroup.header) {
ebpf_unmap_cgroup_shared_memory();
@@ -604,6 +631,10 @@ static void ebpf_unload_unique_maps()
{
int i;
for (i = 0; ebpf_modules[i].thread_name; i++) {
+ // These threads are cleaned with other functions
+ if (i > EBPF_MODULE_SOCKET_IDX)
+ continue;
+
if (ebpf_modules[i].enabled != NETDATA_THREAD_EBPF_STOPPED) {
if (ebpf_modules[i].enabled != NETDATA_THREAD_EBPF_NOT_RUNNING)
error("Cannot unload maps for thread %s, because it is not stopped.", ebpf_modules[i].thread_name);
@@ -611,73 +642,18 @@ static void ebpf_unload_unique_maps()
continue;
}
- ebpf_unload_legacy_code(ebpf_modules[i].objects, ebpf_modules[i].probe_links);
- switch (i) {
- case EBPF_MODULE_CACHESTAT_IDX: {
-#ifdef LIBBPF_MAJOR_VERSION
- if (cachestat_bpf_obj)
- cachestat_bpf__destroy(cachestat_bpf_obj);
-#endif
- break;
- }
- case EBPF_MODULE_DCSTAT_IDX: {
-#ifdef LIBBPF_MAJOR_VERSION
- if (dc_bpf_obj)
- dc_bpf__destroy(dc_bpf_obj);
-#endif
- break;
- }
- case EBPF_MODULE_FD_IDX: {
-#ifdef LIBBPF_MAJOR_VERSION
- if (fd_bpf_obj)
- fd_bpf__destroy(fd_bpf_obj);
-#endif
- break;
- }
- case EBPF_MODULE_MOUNT_IDX: {
-#ifdef LIBBPF_MAJOR_VERSION
- if (mount_bpf_obj)
- mount_bpf__destroy(mount_bpf_obj);
-#endif
- break;
- }
- case EBPF_MODULE_SHM_IDX: {
-#ifdef LIBBPF_MAJOR_VERSION
- if (shm_bpf_obj)
- shm_bpf__destroy(shm_bpf_obj);
-#endif
- break;
- }
- case EBPF_MODULE_SOCKET_IDX: {
-#ifdef LIBBPF_MAJOR_VERSION
- if (socket_bpf_obj)
- socket_bpf__destroy(socket_bpf_obj);
-#endif
- break;
- }
- case EBPF_MODULE_SWAP_IDX: {
-#ifdef LIBBPF_MAJOR_VERSION
- if (bpf_obj)
- swap_bpf__destroy(bpf_obj);
-#endif
- break;
- }
- case EBPF_MODULE_VFS_IDX: {
+ if (ebpf_modules[i].load == EBPF_LOAD_LEGACY) {
+ ebpf_unload_legacy_code(ebpf_modules[i].objects, ebpf_modules[i].probe_links);
+ continue;
+ }
+
+ if (i == EBPF_MODULE_SOCKET_IDX) {
#ifdef LIBBPF_MAJOR_VERSION
- if (vfs_bpf_obj)
- vfs_bpf__destroy(vfs_bpf_obj);
+ if (socket_bpf_obj)
+ socket_bpf__destroy(socket_bpf_obj);
#endif
- break;
- }
- case EBPF_MODULE_PROCESS_IDX:
- case EBPF_MODULE_DISK_IDX:
- case EBPF_MODULE_HARDIRQ_IDX:
- case EBPF_MODULE_SOFTIRQ_IDX:
- case EBPF_MODULE_OOMKILL_IDX:
- case EBPF_MODULE_MDFLUSH_IDX:
- default:
- continue;
}
+
}
}
@@ -689,11 +665,15 @@ static void ebpf_unload_unique_maps()
static void ebpf_unload_filesystems()
{
if (ebpf_modules[EBPF_MODULE_FILESYSTEM_IDX].enabled == NETDATA_THREAD_EBPF_NOT_RUNNING ||
- ebpf_modules[EBPF_MODULE_SYNC_IDX].enabled == NETDATA_THREAD_EBPF_RUNNING)
+ ebpf_modules[EBPF_MODULE_FILESYSTEM_IDX].enabled == NETDATA_THREAD_EBPF_RUNNING ||
+ ebpf_modules[EBPF_MODULE_FILESYSTEM_IDX].load != EBPF_LOAD_LEGACY)
return;
int i;
for (i = 0; localfs[i].filesystem != NULL; i++) {
+ if (!localfs[i].objects)
+ continue;
+
ebpf_unload_legacy_code(localfs[i].objects, localfs[i].probe_links);
}
}
@@ -711,6 +691,15 @@ static void ebpf_unload_sync()
int i;
for (i = 0; local_syscalls[i].syscall != NULL; i++) {
+ if (!local_syscalls[i].enabled)
+ continue;
+
+#ifdef LIBBPF_MAJOR_VERSION
+ if (local_syscalls[i].sync_obj) {
+ sync_bpf__destroy(local_syscalls[i].sync_obj);
+ continue;
+ }
+#endif
ebpf_unload_legacy_code(local_syscalls[i].objects, local_syscalls[i].probe_links);
}
}
@@ -753,19 +742,7 @@ static void ebpf_stop_threads(int sig)
ebpf_exit_plugin = 1;
- usec_t max = USEC_PER_SEC, step = 100000;
- while (i && max) {
- max -= step;
- sleep_usec(step);
- i = 0;
- int j;
- pthread_mutex_lock(&ebpf_exit_cleanup);
- for (j = 0; ebpf_modules[j].thread_name != NULL; j++) {
- if (ebpf_modules[j].enabled == NETDATA_THREAD_EBPF_RUNNING)
- i++;
- }
- pthread_mutex_unlock(&ebpf_exit_cleanup);
- }
+ ebpf_check_before2go();
pthread_mutex_lock(&ebpf_exit_cleanup);
ebpf_unload_unique_maps();
@@ -2650,7 +2627,7 @@ int main(int argc, char **argv)
(void)heartbeat_next(&hb, step);
pthread_mutex_lock(&ebpf_exit_cleanup);
- if (ebpf_modules[i].enabled == NETDATA_THREAD_EBPF_RUNNING && process_pid_fd != -1) {
+ if (process_pid_fd != -1) {
pthread_mutex_lock(&collect_data_mutex);
if (++update_apps_list == update_apps_every) {
update_apps_list = 0;
diff --git a/collectors/ebpf.plugin/ebpf_cachestat.c b/collectors/ebpf.plugin/ebpf_cachestat.c
index 5bbbe1f43..c287136cf 100644
--- a/collectors/ebpf.plugin/ebpf_cachestat.c
+++ b/collectors/ebpf.plugin/ebpf_cachestat.c
@@ -337,27 +337,6 @@ static inline int ebpf_cachestat_load_and_attach(struct cachestat_bpf *obj, ebpf
*****************************************************************/
/**
- * Cachestat Free
- *
- * Cleanup variables after child threads to stop
- *
- * @param ptr thread data.
- */
-static void ebpf_cachestat_free(ebpf_module_t *em)
-{
- pthread_mutex_lock(&ebpf_exit_cleanup);
- em->enabled = NETDATA_THREAD_EBPF_STOPPING;
- pthread_mutex_unlock(&ebpf_exit_cleanup);
-
- freez(cachestat_vector);
- freez(cachestat_values);
-
- pthread_mutex_lock(&ebpf_exit_cleanup);
- em->enabled = NETDATA_THREAD_EBPF_STOPPED;
- pthread_mutex_unlock(&ebpf_exit_cleanup);
-}
-
-/**
* Cachestat exit.
*
* Cancel child and exit.
@@ -368,7 +347,18 @@ static void ebpf_cachestat_exit(void *ptr)
{
ebpf_module_t *em = (ebpf_module_t *)ptr;
- ebpf_cachestat_free(em);
+#ifdef LIBBPF_MAJOR_VERSION
+ if (cachestat_bpf_obj)
+ cachestat_bpf__destroy(cachestat_bpf_obj);
+#endif
+
+ if (em->objects) {
+ ebpf_unload_legacy_code(em->objects, em->probe_links);
+ }
+
+ pthread_mutex_lock(&ebpf_exit_cleanup);
+ em->enabled = NETDATA_THREAD_EBPF_STOPPED;
+ pthread_mutex_unlock(&ebpf_exit_cleanup);
}
/*****************************************************************
diff --git a/collectors/ebpf.plugin/ebpf_dcstat.c b/collectors/ebpf.plugin/ebpf_dcstat.c
index 5a07e4619..4157f0c87 100644
--- a/collectors/ebpf.plugin/ebpf_dcstat.c
+++ b/collectors/ebpf.plugin/ebpf_dcstat.c
@@ -286,55 +286,29 @@ void dcstat_update_publish(netdata_publish_dcstat_t *out, uint64_t cache_access,
*****************************************************************/
/**
- * Clean names
- *
- * Clean the optional names allocated during startup.
- */
-void ebpf_dcstat_clean_names()
-{
- size_t i = 0;
- while (dc_optional_name[i].program_name) {
- freez(dc_optional_name[i].optional);
- i++;
- }
-}
-
-/**
- * DCstat Free
+ * DCstat exit
*
- * Cleanup variables after child threads to stop
+ * Cancel child and exit.
*
* @param ptr thread data.
*/
-static void ebpf_dcstat_free(ebpf_module_t *em )
+static void ebpf_dcstat_exit(void *ptr)
{
- pthread_mutex_lock(&ebpf_exit_cleanup);
- em->enabled = NETDATA_THREAD_EBPF_STOPPING;
- pthread_mutex_unlock(&ebpf_exit_cleanup);
+ ebpf_module_t *em = (ebpf_module_t *)ptr;
- freez(dcstat_vector);
- freez(dcstat_values);
+#ifdef LIBBPF_MAJOR_VERSION
+ if (dc_bpf_obj)
+ dc_bpf__destroy(dc_bpf_obj);
+#endif
- ebpf_dcstat_clean_names();
+ if (em->objects)
+ ebpf_unload_legacy_code(em->objects, em->probe_links);
pthread_mutex_lock(&ebpf_exit_cleanup);
em->enabled = NETDATA_THREAD_EBPF_STOPPED;
pthread_mutex_unlock(&ebpf_exit_cleanup);
}
-/**
- * DCstat exit
- *
- * Cancel child and exit.
- *
- * @param ptr thread data.
- */
-static void ebpf_dcstat_exit(void *ptr)
-{
- ebpf_module_t *em = (ebpf_module_t *)ptr;
- ebpf_dcstat_free(em);
-}
-
/*****************************************************************
*
* APPS
diff --git a/collectors/ebpf.plugin/ebpf_disk.c b/collectors/ebpf.plugin/ebpf_disk.c
index 71c972777..231186b84 100644
--- a/collectors/ebpf.plugin/ebpf_disk.c
+++ b/collectors/ebpf.plugin/ebpf_disk.c
@@ -435,17 +435,18 @@ static void ebpf_cleanup_disk_list()
}
/**
- * DISK Free
+ * Disk exit.
*
- * Cleanup variables after child threads to stop
+ * Cancel child and exit.
*
* @param ptr thread data.
*/
-static void ebpf_disk_free(ebpf_module_t *em)
+static void ebpf_disk_exit(void *ptr)
{
- pthread_mutex_lock(&ebpf_exit_cleanup);
- em->enabled = NETDATA_THREAD_EBPF_STOPPING;
- pthread_mutex_unlock(&ebpf_exit_cleanup);
+ ebpf_module_t *em = (ebpf_module_t *)ptr;
+
+ if (em->objects)
+ ebpf_unload_legacy_code(em->objects, em->probe_links);
ebpf_disk_disable_tracepoints();
@@ -463,19 +464,6 @@ static void ebpf_disk_free(ebpf_module_t *em)
pthread_mutex_unlock(&ebpf_exit_cleanup);
}
-/**
- * Disk exit.
- *
- * Cancel child and exit.
- *
- * @param ptr thread data.
- */
-static void ebpf_disk_exit(void *ptr)
-{
- ebpf_module_t *em = (ebpf_module_t *)ptr;
- ebpf_disk_free(em);
-}
-
/*****************************************************************
*
* MAIN LOOP
diff --git a/collectors/ebpf.plugin/ebpf_fd.c b/collectors/ebpf.plugin/ebpf_fd.c
index 6d3868952..d39e6ae20 100644
--- a/collectors/ebpf.plugin/ebpf_fd.c
+++ b/collectors/ebpf.plugin/ebpf_fd.c
@@ -370,39 +370,28 @@ static inline int ebpf_fd_load_and_attach(struct fd_bpf *obj, ebpf_module_t *em)
*****************************************************************/
/**
- * FD Free
+ * FD Exit
*
- * Cleanup variables after child threads to stop
+ * Cancel child thread and exit.
*
* @param ptr thread data.
*/
-static void ebpf_fd_free(ebpf_module_t *em)
+static void ebpf_fd_exit(void *ptr)
{
- pthread_mutex_lock(&ebpf_exit_cleanup);
- em->enabled = NETDATA_THREAD_EBPF_STOPPING;
- pthread_mutex_unlock(&ebpf_exit_cleanup);
+ ebpf_module_t *em = (ebpf_module_t *)ptr;
- freez(fd_values);
- freez(fd_vector);
+#ifdef LIBBPF_MAJOR_VERSION
+ if (fd_bpf_obj)
+ fd_bpf__destroy(fd_bpf_obj);
+#endif
+ if (em->objects)
+ ebpf_unload_legacy_code(em->objects, em->probe_links);
pthread_mutex_lock(&ebpf_exit_cleanup);
em->enabled = NETDATA_THREAD_EBPF_STOPPED;
pthread_mutex_unlock(&ebpf_exit_cleanup);
}
-/**
- * FD Exit
- *
- * Cancel child thread and exit.
- *
- * @param ptr thread data.
- */
-static void ebpf_fd_exit(void *ptr)
-{
- ebpf_module_t *em = (ebpf_module_t *)ptr;
- ebpf_fd_free(em);
-}
-
/*****************************************************************
*
* MAIN LOOP
diff --git a/collectors/ebpf.plugin/ebpf_hardirq.c b/collectors/ebpf.plugin/ebpf_hardirq.c
index 113648ec9..f714c261c 100644
--- a/collectors/ebpf.plugin/ebpf_hardirq.c
+++ b/collectors/ebpf.plugin/ebpf_hardirq.c
@@ -188,35 +188,28 @@ void ebpf_hardirq_release(hardirq_val_t *stat)
*****************************************************************/
/**
- * Hardirq Free
+ * Hardirq Exit
*
- * Cleanup variables after child threads to stop
+ * Cancel child and exit.
*
* @param ptr thread data.
*/
-static void ebpf_hardirq_free(ebpf_module_t *em)
+static void hardirq_exit(void *ptr)
{
+ ebpf_module_t *em = (ebpf_module_t *)ptr;
+
+ if (em->objects)
+ ebpf_unload_legacy_code(em->objects, em->probe_links);
+
for (int i = 0; hardirq_tracepoints[i].class != NULL; i++) {
ebpf_disable_tracepoint(&hardirq_tracepoints[i]);
}
+
pthread_mutex_lock(&ebpf_exit_cleanup);
em->enabled = NETDATA_THREAD_EBPF_STOPPED;
pthread_mutex_unlock(&ebpf_exit_cleanup);
}
-/**
- * Hardirq Exit
- *
- * Cancel child and exit.
- *
- * @param ptr thread data.
- */
-static void hardirq_exit(void *ptr)
-{
- ebpf_module_t *em = (ebpf_module_t *)ptr;
- ebpf_hardirq_free(em);
-}
-
/*****************************************************************
* MAIN LOOP
*****************************************************************/
diff --git a/collectors/ebpf.plugin/ebpf_mdflush.c b/collectors/ebpf.plugin/ebpf_mdflush.c
index 321bd97ee..65ed860a4 100644
--- a/collectors/ebpf.plugin/ebpf_mdflush.c
+++ b/collectors/ebpf.plugin/ebpf_mdflush.c
@@ -39,21 +39,6 @@ static avl_tree_lock mdflush_pub;
static mdflush_ebpf_val_t *mdflush_ebpf_vals = NULL;
/**
- * MDflush Free
- *
- * Cleanup variables after child threads to stop
- *
- * @param ptr thread data.
- */
-static void ebpf_mdflush_free(ebpf_module_t *em)
-{
- freez(mdflush_ebpf_vals);
- pthread_mutex_lock(&ebpf_exit_cleanup);
- em->enabled = NETDATA_THREAD_EBPF_STOPPED;
- pthread_mutex_unlock(&ebpf_exit_cleanup);
-}
-
-/**
* MDflush exit
*
* Cancel thread and exit.
@@ -63,7 +48,13 @@ static void ebpf_mdflush_free(ebpf_module_t *em)
static void mdflush_exit(void *ptr)
{
ebpf_module_t *em = (ebpf_module_t *)ptr;
- ebpf_mdflush_free(em);
+
+ if (em->objects)
+ ebpf_unload_legacy_code(em->objects, em->probe_links);
+
+ pthread_mutex_lock(&ebpf_exit_cleanup);
+ em->enabled = NETDATA_THREAD_EBPF_STOPPED;
+ pthread_mutex_unlock(&ebpf_exit_cleanup);
}
/**
diff --git a/collectors/ebpf.plugin/ebpf_mount.c b/collectors/ebpf.plugin/ebpf_mount.c
index e0951f8c4..e48c89227 100644
--- a/collectors/ebpf.plugin/ebpf_mount.c
+++ b/collectors/ebpf.plugin/ebpf_mount.c
@@ -223,20 +223,6 @@ static inline int ebpf_mount_load_and_attach(struct mount_bpf *obj, ebpf_module_
*****************************************************************/
/**
- * Mount Free
- *
- * Cleanup variables after child threads to stop
- *
- * @param ptr thread data.
- */
-static void ebpf_mount_free(ebpf_module_t *em)
-{
- pthread_mutex_lock(&ebpf_exit_cleanup);
- em->enabled = NETDATA_THREAD_EBPF_STOPPED;
- pthread_mutex_unlock(&ebpf_exit_cleanup);
-}
-
-/**
* Mount Exit
*
* Cancel child thread.
@@ -246,7 +232,17 @@ static void ebpf_mount_free(ebpf_module_t *em)
static void ebpf_mount_exit(void *ptr)
{
ebpf_module_t *em = (ebpf_module_t *)ptr;
- ebpf_mount_free(em);
+
+#ifdef LIBBPF_MAJOR_VERSION
+ if (mount_bpf_obj)
+ mount_bpf__destroy(mount_bpf_obj);
+#endif
+ if (em->objects)
+ ebpf_unload_legacy_code(em->objects, em->probe_links);
+
+ pthread_mutex_lock(&ebpf_exit_cleanup);
+ em->enabled = NETDATA_THREAD_EBPF_STOPPED;
+ pthread_mutex_unlock(&ebpf_exit_cleanup);
}
/*****************************************************************
diff --git a/collectors/ebpf.plugin/ebpf_oomkill.c b/collectors/ebpf.plugin/ebpf_oomkill.c
index 094875292..c80f44873 100644
--- a/collectors/ebpf.plugin/ebpf_oomkill.c
+++ b/collectors/ebpf.plugin/ebpf_oomkill.c
@@ -52,6 +52,10 @@ static netdata_publish_syscall_t oomkill_publish_aggregated = {.name = "oomkill"
static void oomkill_cleanup(void *ptr)
{
ebpf_module_t *em = (ebpf_module_t *)ptr;
+
+ if (em->objects)
+ ebpf_unload_legacy_code(em->objects, em->probe_links);
+
pthread_mutex_lock(&ebpf_exit_cleanup);
em->enabled = NETDATA_THREAD_EBPF_STOPPED;
pthread_mutex_unlock(&ebpf_exit_cleanup);
diff --git a/collectors/ebpf.plugin/ebpf_shm.c b/collectors/ebpf.plugin/ebpf_shm.c
index 093d65b60..94ac624b3 100644
--- a/collectors/ebpf.plugin/ebpf_shm.c
+++ b/collectors/ebpf.plugin/ebpf_shm.c
@@ -289,23 +289,6 @@ static inline int ebpf_shm_load_and_attach(struct shm_bpf *obj, ebpf_module_t *e
*****************************************************************/
/**
- * SHM Free
- *
- * Cleanup variables after child threads to stop
- *
- * @param ptr thread data.
- */
-static void ebpf_shm_free(ebpf_module_t *em)
-{
- freez(shm_vector);
- freez(shm_values);
-
- pthread_mutex_lock(&ebpf_exit_cleanup);
- em->enabled = NETDATA_THREAD_EBPF_STOPPED;
- pthread_mutex_unlock(&ebpf_exit_cleanup);
-}
-
-/**
* SHM Exit
*
* Cancel child thread.
@@ -315,7 +298,18 @@ static void ebpf_shm_free(ebpf_module_t *em)
static void ebpf_shm_exit(void *ptr)
{
ebpf_module_t *em = (ebpf_module_t *)ptr;
- ebpf_shm_free(em);
+
+#ifdef LIBBPF_MAJOR_VERSION
+ if (shm_bpf_obj)
+ shm_bpf__destroy(shm_bpf_obj);
+#endif
+
+ if (em->objects)
+ ebpf_unload_legacy_code(em->objects, em->probe_links);
+
+ pthread_mutex_lock(&ebpf_exit_cleanup);
+ em->enabled = NETDATA_THREAD_EBPF_STOPPED;
+ pthread_mutex_unlock(&ebpf_exit_cleanup);
}
/*****************************************************************
diff --git a/collectors/ebpf.plugin/ebpf_softirq.c b/collectors/ebpf.plugin/ebpf_softirq.c
index 01e2d0a52..b5c77bf06 100644
--- a/collectors/ebpf.plugin/ebpf_softirq.c
+++ b/collectors/ebpf.plugin/ebpf_softirq.c
@@ -61,17 +61,18 @@ static softirq_val_t softirq_vals[] = {
static softirq_ebpf_val_t *softirq_ebpf_vals = NULL;
/**
- * Cachestat Free
+ * Cleanup
*
- * Cleanup variables after child threads to stop
+ * Clean up allocated memory.
*
* @param ptr thread data.
*/
-static void ebpf_softirq_free(ebpf_module_t *em)
+static void softirq_cleanup(void *ptr)
{
- pthread_mutex_lock(&ebpf_exit_cleanup);
- em->enabled = NETDATA_THREAD_EBPF_STOPPING;
- pthread_mutex_unlock(&ebpf_exit_cleanup);
+ ebpf_module_t *em = (ebpf_module_t *)ptr;
+
+ if (em->objects)
+ ebpf_unload_legacy_code(em->objects, em->probe_links);
for (int i = 0; softirq_tracepoints[i].class != NULL; i++) {
ebpf_disable_tracepoint(&softirq_tracepoints[i]);
@@ -83,19 +84,6 @@ static void ebpf_softirq_free(ebpf_module_t *em)
pthread_mutex_unlock(&ebpf_exit_cleanup);
}
-/**
- * Cleanup
- *
- * Clean up allocated memory.
- *
- * @param ptr thread data.
- */
-static void softirq_cleanup(void *ptr)
-{
- ebpf_module_t *em = (ebpf_module_t *)ptr;
- ebpf_softirq_free(em);
-}
-
/*****************************************************************
* MAIN LOOP
*****************************************************************/
diff --git a/collectors/ebpf.plugin/ebpf_swap.c b/collectors/ebpf.plugin/ebpf_swap.c
index c9129a3fa..492b59678 100644
--- a/collectors/ebpf.plugin/ebpf_swap.c
+++ b/collectors/ebpf.plugin/ebpf_swap.c
@@ -230,23 +230,6 @@ static inline int ebpf_swap_load_and_attach(struct swap_bpf *obj, ebpf_module_t
*****************************************************************/
/**
- * Cachestat Free
- *
- * Cleanup variables after child threads to stop
- *
- * @param ptr thread data.
- */
-static void ebpf_swap_free(ebpf_module_t *em)
-{
- freez(swap_vector);
- freez(swap_values);
-
- pthread_mutex_lock(&ebpf_exit_cleanup);
- em->enabled = NETDATA_THREAD_EBPF_STOPPED;
- pthread_mutex_unlock(&ebpf_exit_cleanup);
-}
-
-/**
* Swap exit
*
* Cancel thread and exit.
@@ -256,7 +239,17 @@ static void ebpf_swap_free(ebpf_module_t *em)
static void ebpf_swap_exit(void *ptr)
{
ebpf_module_t *em = (ebpf_module_t *)ptr;
- ebpf_swap_free(em);
+
+#ifdef LIBBPF_MAJOR_VERSION
+ if (bpf_obj)
+ swap_bpf__destroy(bpf_obj);
+#endif
+ if (em->objects)
+ ebpf_unload_legacy_code(em->objects, em->probe_links);
+
+ pthread_mutex_lock(&ebpf_exit_cleanup);
+ em->enabled = NETDATA_THREAD_EBPF_STOPPED;
+ pthread_mutex_unlock(&ebpf_exit_cleanup);
}
/*****************************************************************
diff --git a/collectors/ebpf.plugin/ebpf_sync.c b/collectors/ebpf.plugin/ebpf_sync.c
index 66e9c742c..9f1c0159d 100644
--- a/collectors/ebpf.plugin/ebpf_sync.c
+++ b/collectors/ebpf.plugin/ebpf_sync.c
@@ -349,6 +349,7 @@ static int ebpf_sync_initialize_syscall(ebpf_module_t *em)
for (i = 0; local_syscalls[i].syscall; i++) {
ebpf_sync_syscalls_t *w = &local_syscalls[i];
w->sync_maps = local_syscalls[i].sync_maps;
+ em->maps = local_syscalls[i].sync_maps;
if (w->enabled) {
if (em->load & EBPF_LOAD_LEGACY) {
if (ebpf_sync_load_legacy(w, em))
@@ -360,20 +361,23 @@ static int ebpf_sync_initialize_syscall(ebpf_module_t *em)
else {
char syscall[NETDATA_EBPF_MAX_SYSCALL_LENGTH];
ebpf_select_host_prefix(syscall, NETDATA_EBPF_MAX_SYSCALL_LENGTH, w->syscall, running_on_kernel);
- w->sync_obj = sync_bpf__open();
- if (!w->sync_obj) {
- errors++;
- } else {
- if (ebpf_is_function_inside_btf(default_btf, syscall)) {
+ if (ebpf_is_function_inside_btf(default_btf, syscall)) {
+ w->sync_obj = sync_bpf__open();
+ if (!w->sync_obj) {
+ w->enabled = false;
+ errors++;
+ } else {
if (ebpf_sync_load_and_attach(w->sync_obj, em, syscall, i)) {
+ w->enabled = false;
errors++;
}
- } else {
- if (ebpf_sync_load_legacy(w, em))
- errors++;
}
- em->thread_name = saved_name;
+ } else {
+ info("Cannot find syscall %s we are not going to monitor it.", syscall);
+ w->enabled = false;
}
+
+ em->thread_name = saved_name;
}
#endif
}
@@ -402,7 +406,7 @@ static int ebpf_sync_initialize_syscall(ebpf_module_t *em)
*/
static void ebpf_sync_read_global_table(int maps_per_core)
{
- netdata_idx_t stored[ebpf_nprocs];
+ netdata_idx_t stored[NETDATA_MAX_PROCESSOR];
uint32_t idx = NETDATA_SYNC_CALL;
int i;
for (i = 0; local_syscalls[i].syscall; i++) {
@@ -456,7 +460,7 @@ static void ebpf_send_sync_chart(char *id,
*/
static void sync_send_data()
{
- if (local_syscalls[NETDATA_SYNC_FSYNC_IDX].enabled || local_syscalls[NETDATA_SYNC_FDATASYNC_IDX].enabled) {
+ if (local_syscalls[NETDATA_SYNC_FSYNC_IDX].enabled && local_syscalls[NETDATA_SYNC_FDATASYNC_IDX].enabled) {
ebpf_send_sync_chart(NETDATA_EBPF_FILE_SYNC_CHART, NETDATA_SYNC_FSYNC_IDX, NETDATA_SYNC_FDATASYNC_IDX);
}
@@ -465,7 +469,7 @@ static void sync_send_data()
sync_counter_publish_aggregated[NETDATA_SYNC_MSYNC_IDX].dimension,
sync_hash_values[NETDATA_SYNC_MSYNC_IDX]);
- if (local_syscalls[NETDATA_SYNC_SYNC_IDX].enabled || local_syscalls[NETDATA_SYNC_SYNCFS_IDX].enabled) {
+ if (local_syscalls[NETDATA_SYNC_SYNC_IDX].enabled && local_syscalls[NETDATA_SYNC_SYNCFS_IDX].enabled) {
ebpf_send_sync_chart(NETDATA_EBPF_SYNC_CHART, NETDATA_SYNC_SYNC_IDX, NETDATA_SYNC_SYNCFS_IDX);
}
@@ -551,7 +555,7 @@ static void ebpf_create_sync_chart(char *id,
*/
static void ebpf_create_sync_charts(int update_every)
{
- if (local_syscalls[NETDATA_SYNC_FSYNC_IDX].enabled || local_syscalls[NETDATA_SYNC_FDATASYNC_IDX].enabled)
+ if (local_syscalls[NETDATA_SYNC_FSYNC_IDX].enabled && local_syscalls[NETDATA_SYNC_FDATASYNC_IDX].enabled)
ebpf_create_sync_chart(NETDATA_EBPF_FILE_SYNC_CHART,
"Monitor calls for <code>fsync(2)</code> and <code>fdatasync(2)</code>.", 21300,
NETDATA_SYNC_FSYNC_IDX, NETDATA_SYNC_FDATASYNC_IDX, update_every);
@@ -561,7 +565,7 @@ static void ebpf_create_sync_charts(int update_every)
"Monitor calls for <code>msync(2)</code>.", 21301,
NETDATA_SYNC_MSYNC_IDX, NETDATA_SYNC_MSYNC_IDX, update_every);
- if (local_syscalls[NETDATA_SYNC_SYNC_IDX].enabled || local_syscalls[NETDATA_SYNC_SYNCFS_IDX].enabled)
+ if (local_syscalls[NETDATA_SYNC_SYNC_IDX].enabled && local_syscalls[NETDATA_SYNC_SYNCFS_IDX].enabled)
ebpf_create_sync_chart(NETDATA_EBPF_SYNC_CHART,
"Monitor calls for <code>sync(2)</code> and <code>syncfs(2)</code>.", 21302,
NETDATA_SYNC_SYNC_IDX, NETDATA_SYNC_SYNCFS_IDX, update_every);
@@ -616,7 +620,6 @@ void *ebpf_sync_thread(void *ptr)
netdata_thread_cleanup_push(ebpf_sync_exit, ptr);
ebpf_module_t *em = (ebpf_module_t *)ptr;
- em->maps = sync_maps;
ebpf_set_sync_maps();
ebpf_sync_parse_syscalls();
diff --git a/collectors/ebpf.plugin/ebpf_vfs.c b/collectors/ebpf.plugin/ebpf_vfs.c
index bfc7ee8f7..6cafafc38 100644
--- a/collectors/ebpf.plugin/ebpf_vfs.c
+++ b/collectors/ebpf.plugin/ebpf_vfs.c
@@ -404,23 +404,6 @@ static inline int ebpf_vfs_load_and_attach(struct vfs_bpf *obj, ebpf_module_t *e
*****************************************************************/
/**
- * Cachestat Free
- *
- * Cleanup variables after child threads to stop
- *
- * @param ptr thread data.
- */
-static void ebpf_vfs_free(ebpf_module_t *em)
-{
- freez(vfs_hash_values);
- freez(vfs_vector);
-
- pthread_mutex_lock(&ebpf_exit_cleanup);
- em->enabled = NETDATA_THREAD_EBPF_STOPPED;
- pthread_mutex_unlock(&ebpf_exit_cleanup);
-}
-
-/**
* Exit
*
* Cancel thread and exit.
@@ -430,7 +413,17 @@ static void ebpf_vfs_free(ebpf_module_t *em)
static void ebpf_vfs_exit(void *ptr)
{
ebpf_module_t *em = (ebpf_module_t *)ptr;
- ebpf_vfs_free(em);
+
+#ifdef LIBBPF_MAJOR_VERSION
+ if (vfs_bpf_obj)
+ vfs_bpf__destroy(vfs_bpf_obj);
+#endif
+ if (em->objects)
+ ebpf_unload_legacy_code(em->objects, em->probe_links);
+
+ pthread_mutex_lock(&ebpf_exit_cleanup);
+ em->enabled = NETDATA_THREAD_EBPF_STOPPED;
+ pthread_mutex_unlock(&ebpf_exit_cleanup);
}
/*****************************************************************