diff options
Diffstat (limited to '')
-rw-r--r-- | src/collectors/ebpf.plugin/ebpf_dcstat.c (renamed from collectors/ebpf.plugin/ebpf_dcstat.c) | 585 |
1 files changed, 305 insertions, 280 deletions
diff --git a/collectors/ebpf.plugin/ebpf_dcstat.c b/src/collectors/ebpf.plugin/ebpf_dcstat.c index 4ff6c82ab..7fa9ca1f0 100644 --- a/collectors/ebpf.plugin/ebpf_dcstat.c +++ b/src/collectors/ebpf.plugin/ebpf_dcstat.c @@ -59,9 +59,16 @@ netdata_ebpf_targets_t dc_targets[] = { {.name = "lookup_fast", .mode = EBPF_LOA {.name = "d_lookup", .mode = EBPF_LOAD_TRAMPOLINE}, {.name = NULL, .mode = EBPF_LOAD_TRAMPOLINE}}; -#ifdef NETDATA_DEV_MODE -int dcstat_disable_priority; -#endif +struct netdata_static_thread ebpf_read_dcstat = { + .name = "EBPF_READ_DCSTAT", + .config_section = NULL, + .config_name = NULL, + .env_name = NULL, + .enabled = 1, + .thread = NULL, + .init_routine = NULL, + .start_routine = NULL +}; #ifdef LIBBPF_MAJOR_VERSION /** @@ -75,7 +82,6 @@ static inline void ebpf_dc_disable_probes(struct dc_bpf *obj) { bpf_program__set_autoload(obj->progs.netdata_lookup_fast_kprobe, false); bpf_program__set_autoload(obj->progs.netdata_d_lookup_kretprobe, false); - bpf_program__set_autoload(obj->progs.netdata_dcstat_release_task_kprobe, false); } /* @@ -89,7 +95,6 @@ static inline void ebpf_dc_disable_trampoline(struct dc_bpf *obj) { bpf_program__set_autoload(obj->progs.netdata_lookup_fast_fentry, false); bpf_program__set_autoload(obj->progs.netdata_d_lookup_fexit, false); - bpf_program__set_autoload(obj->progs.netdata_dcstat_release_task_fentry, false); } /** @@ -106,9 +111,6 @@ static void ebpf_dc_set_trampoline_target(struct dc_bpf *obj) bpf_program__set_attach_target(obj->progs.netdata_d_lookup_fexit, 0, dc_targets[NETDATA_DC_TARGET_D_LOOKUP].name); - - bpf_program__set_attach_target(obj->progs.netdata_dcstat_release_task_fentry, 0, - EBPF_COMMON_FNCT_CLEAN_UP); } /** @@ -125,7 +127,7 @@ static int ebpf_dc_attach_probes(struct dc_bpf *obj) obj->links.netdata_d_lookup_kretprobe = bpf_program__attach_kprobe(obj->progs.netdata_d_lookup_kretprobe, true, dc_targets[NETDATA_DC_TARGET_D_LOOKUP].name); - int ret = libbpf_get_error(obj->links.netdata_d_lookup_kretprobe); + long ret = libbpf_get_error(obj->links.netdata_d_lookup_kretprobe); if (ret) return -1; @@ -140,13 +142,6 @@ static int ebpf_dc_attach_probes(struct dc_bpf *obj) if (ret) return -1; - obj->links.netdata_dcstat_release_task_kprobe = bpf_program__attach_kprobe(obj->progs.netdata_dcstat_release_task_kprobe, - false, - EBPF_COMMON_FNCT_CLEAN_UP); - ret = libbpf_get_error(obj->links.netdata_dcstat_release_task_kprobe); - if (ret) - return -1; - return 0; } @@ -206,19 +201,6 @@ netdata_ebpf_program_loaded_t ebpf_dc_update_load(ebpf_module_t *em) } /** - * Disable Release Task - * - * Disable release task when apps is not enabled. - * - * @param obj is the main structure for bpf objects. - */ -static void ebpf_dc_disable_release_task(struct dc_bpf *obj) -{ - bpf_program__set_autoload(obj->progs.netdata_dcstat_release_task_kprobe, false); - bpf_program__set_autoload(obj->progs.netdata_dcstat_release_task_fentry, false); -} - -/** * Load and attach * * Load and attach the eBPF code in kernel. @@ -241,9 +223,6 @@ static inline int ebpf_dc_load_and_attach(struct dc_bpf *obj, ebpf_module_t *em) ebpf_dc_adjust_map(obj, em); - if (!em->apps_charts && !em->cgroup_charts) - ebpf_dc_disable_release_task(obj); - int ret = dc_bpf__load(obj); if (ret) { return ret; @@ -298,11 +277,11 @@ static void ebpf_obsolete_specific_dc_charts(char *type, int update_every); * * @param em a pointer to `struct ebpf_module` */ -static void ebpf_obsolete_dc_services(ebpf_module_t *em) +static void ebpf_obsolete_dc_services(ebpf_module_t *em, char *id) { ebpf_write_chart_obsolete(NETDATA_SERVICE_FAMILY, + id, NETDATA_DC_HIT_CHART, - "", "Percentage of files inside directory cache", EBPF_COMMON_DIMENSION_PERCENTAGE, NETDATA_DIRECTORY_CACHE_SUBMENU, @@ -312,8 +291,8 @@ static void ebpf_obsolete_dc_services(ebpf_module_t *em) em->update_every); ebpf_write_chart_obsolete(NETDATA_SERVICE_FAMILY, + id, NETDATA_DC_REFERENCE_CHART, - "", "Count file access", EBPF_COMMON_DIMENSION_FILES, NETDATA_DIRECTORY_CACHE_SUBMENU, @@ -323,8 +302,8 @@ static void ebpf_obsolete_dc_services(ebpf_module_t *em) em->update_every); ebpf_write_chart_obsolete(NETDATA_SERVICE_FAMILY, + id, NETDATA_DC_REQUEST_NOT_CACHE_CHART, - "", "Files not present inside directory cache", EBPF_COMMON_DIMENSION_FILES, NETDATA_DIRECTORY_CACHE_SUBMENU, @@ -334,14 +313,14 @@ static void ebpf_obsolete_dc_services(ebpf_module_t *em) em->update_every); ebpf_write_chart_obsolete(NETDATA_SERVICE_FAMILY, + id, NETDATA_DC_REQUEST_NOT_FOUND_CHART, - "", "Files not found", EBPF_COMMON_DIMENSION_FILES, NETDATA_DIRECTORY_CACHE_SUBMENU, NETDATA_EBPF_CHART_TYPE_LINE, NETDATA_SYSTEMD_DC_NOT_FOUND_CONTEXT, - 21202, + 21203, em->update_every); } @@ -355,12 +334,13 @@ static void ebpf_obsolete_dc_services(ebpf_module_t *em) static inline void ebpf_obsolete_dc_cgroup_charts(ebpf_module_t *em) { pthread_mutex_lock(&mutex_cgroup_shm); - ebpf_obsolete_dc_services(em); - ebpf_cgroup_target_t *ect; for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) { - if (ect->systemd) + if (ect->systemd) { + ebpf_obsolete_dc_services(em, ect->name); + continue; + } ebpf_obsolete_specific_dc_charts(ect->name, em->update_every); } @@ -378,6 +358,7 @@ void ebpf_obsolete_dc_apps_charts(struct ebpf_module *em) { struct ebpf_target *w; int update_every = em->update_every; + pthread_mutex_lock(&collect_data_mutex); for (w = apps_groups_root_target; w; w = w->next) { if (unlikely(!(w->charts_created & (1<<EBPF_MODULE_DCSTAT_IDX)))) continue; @@ -428,6 +409,7 @@ void ebpf_obsolete_dc_apps_charts(struct ebpf_module *em) w->charts_created &= ~(1<<EBPF_MODULE_DCSTAT_IDX); } + pthread_mutex_unlock(&collect_data_mutex); } /** @@ -473,6 +455,9 @@ static void ebpf_dcstat_exit(void *ptr) { ebpf_module_t *em = (ebpf_module_t *)ptr; + if (ebpf_read_dcstat.thread) + netdata_thread_cancel(*ebpf_read_dcstat.thread); + if (em->enabled == NETDATA_THREAD_EBPF_FUNCTION_RUNNING) { pthread_mutex_lock(&lock); if (em->cgroup_charts) { @@ -486,11 +471,6 @@ static void ebpf_dcstat_exit(void *ptr) ebpf_obsolete_dc_global(em); -#ifdef NETDATA_DEV_MODE - if (ebpf_aral_dcstat_pid) - ebpf_statistic_obsolete_aral_chart(em, dcstat_disable_priority); -#endif - fflush(stdout); pthread_mutex_unlock(&lock); } @@ -523,6 +503,173 @@ static void ebpf_dcstat_exit(void *ptr) *****************************************************************/ /** + * Apps Accumulator + * + * Sum all values read from kernel and store in the first address. + * + * @param out the vector with read values. + * @param maps_per_core do I need to read all cores? + */ +static void ebpf_dcstat_apps_accumulator(netdata_dcstat_pid_t *out, int maps_per_core) +{ + int i, end = (maps_per_core) ? ebpf_nprocs : 1; + netdata_dcstat_pid_t *total = &out[0]; + uint64_t ct = total->ct; + for (i = 1; i < end; i++) { + netdata_dcstat_pid_t *w = &out[i]; + total->cache_access += w->cache_access; + total->file_system += w->file_system; + total->not_found += w->not_found; + + if (w->ct > ct) + ct = w->ct; + } + total->ct = ct; +} + +/** + * Read Directory Cache APPS table + * + * Read the apps table and store data inside the structure. + * + * @param maps_per_core do I need to read all cores? + */ +static void ebpf_read_dc_apps_table(int maps_per_core, int max_period) +{ + netdata_dcstat_pid_t *cv = dcstat_vector; + int fd = dcstat_maps[NETDATA_DCSTAT_PID_STATS].map_fd; + size_t length = sizeof(netdata_dcstat_pid_t); + if (maps_per_core) + length *= ebpf_nprocs; + + uint32_t key = 0, next_key = 0; + while (bpf_map_get_next_key(fd, &key, &next_key) == 0) { + if (bpf_map_lookup_elem(fd, &key, cv)) { + goto end_dc_loop; + } + + ebpf_dcstat_apps_accumulator(cv, maps_per_core); + + ebpf_pid_stat_t *pid_stat = ebpf_get_pid_entry(key, cv->tgid); + if (pid_stat) { + netdata_publish_dcstat_t *publish = &pid_stat->dc; + if (!publish->ct || publish->ct != cv->ct) { + memcpy(&publish->curr, &cv[0], sizeof(netdata_dcstat_pid_t)); + pid_stat->not_updated = 0; + } else if (++pid_stat->not_updated >= max_period) { + bpf_map_delete_elem(fd, &key); + pid_stat->not_updated = 0; + } + } + +end_dc_loop: + // We are cleaning to avoid passing data read from one process to other. + memset(cv, 0, length); + key = next_key; + } +} + +/** + * Cachestat sum PIDs + * + * Sum values for all PIDs associated to a group + * + * @param publish output structure. + * @param root structure with listed IPs + */ +void ebpf_dcstat_sum_pids(netdata_publish_dcstat_t *publish, struct ebpf_pid_on_target *root) +{ + memset(&publish->curr, 0, sizeof(netdata_dcstat_pid_t)); + netdata_dcstat_pid_t *dst = &publish->curr; + while (root) { + int32_t pid = root->pid; + ebpf_pid_stat_t *pid_stat = ebpf_get_pid_entry(pid, 0); + if (pid_stat) { + netdata_publish_dcstat_t *w = &pid_stat->dc; + netdata_dcstat_pid_t *src = &w->curr; + dst->cache_access += src->cache_access; + dst->file_system += src->file_system; + dst->not_found += src->not_found; + } + + root = root->next; + } +} + +/** + * Resume apps data + */ +void ebpf_dc_resume_apps_data() +{ + struct ebpf_target *w; + + for (w = apps_groups_root_target; w; w = w->next) { + if (unlikely(!(w->charts_created & (1<<EBPF_MODULE_DCSTAT_IDX)))) + continue; + + ebpf_dcstat_sum_pids(&w->dcstat, w->root_pid); + + uint64_t cache = w->dcstat.curr.cache_access; + uint64_t not_found = w->dcstat.curr.not_found; + + dcstat_update_publish(&w->dcstat, cache, not_found); + } +} + +/** + * DCstat thread + * + * Thread used to generate dcstat charts. + * + * @param ptr a pointer to `struct ebpf_module` + * + * @return It always return NULL + */ +void *ebpf_read_dcstat_thread(void *ptr) +{ + heartbeat_t hb; + heartbeat_init(&hb); + + ebpf_module_t *em = (ebpf_module_t *)ptr; + + int maps_per_core = em->maps_per_core; + int update_every = em->update_every; + + int counter = update_every - 1; + + uint32_t lifetime = em->lifetime; + uint32_t running_time = 0; + usec_t period = update_every * USEC_PER_SEC; + int max_period = update_every * EBPF_CLEANUP_FACTOR; + while (!ebpf_plugin_exit && running_time < lifetime) { + (void)heartbeat_next(&hb, period); + if (ebpf_plugin_exit || ++counter != update_every) + continue; + + netdata_thread_disable_cancelability(); + + pthread_mutex_lock(&collect_data_mutex); + ebpf_read_dc_apps_table(maps_per_core, max_period); + ebpf_dc_resume_apps_data(); + pthread_mutex_unlock(&collect_data_mutex); + + counter = 0; + + pthread_mutex_lock(&ebpf_exit_cleanup); + if (running_time && !em->running_time) + running_time = update_every; + else + running_time += update_every; + + em->running_time = running_time; + pthread_mutex_unlock(&ebpf_exit_cleanup); + netdata_thread_enable_cancelability(); + } + + return NULL; +} + +/** * Create apps charts * * Call ebpf_create_chart to create the charts on apps submenu. @@ -611,106 +758,14 @@ void ebpf_dcstat_create_apps_charts(struct ebpf_module *em, void *ptr) *****************************************************************/ /** - * Apps Accumulator - * - * Sum all values read from kernel and store in the first address. - * - * @param out the vector with read values. - * @param maps_per_core do I need to read all cores? - */ -static void dcstat_apps_accumulator(netdata_dcstat_pid_t *out, int maps_per_core) -{ - int i, end = (maps_per_core) ? ebpf_nprocs : 1; - netdata_dcstat_pid_t *total = &out[0]; - for (i = 1; i < end; i++) { - netdata_dcstat_pid_t *w = &out[i]; - total->cache_access += w->cache_access; - total->file_system += w->file_system; - total->not_found += w->not_found; - } -} - -/** - * Save PID values - * - * Save the current values inside the structure - * - * @param out vector used to plot charts - * @param publish vector with values read from hash tables. - */ -static inline void dcstat_save_pid_values(netdata_publish_dcstat_t *out, netdata_dcstat_pid_t *publish) -{ - memcpy(&out->curr, &publish[0], sizeof(netdata_dcstat_pid_t)); -} - -/** - * Fill PID - * - * Fill PID structures - * - * @param current_pid pid that we are collecting data - * @param out values read from hash tables; - */ -static void dcstat_fill_pid(uint32_t current_pid, netdata_dcstat_pid_t *publish) -{ - netdata_publish_dcstat_t *curr = dcstat_pid[current_pid]; - if (!curr) { - curr = ebpf_publish_dcstat_get(); - dcstat_pid[current_pid] = curr; - } - - dcstat_save_pid_values(curr, publish); -} - -/** - * Read Directory Cache APPS table - * - * Read the apps table and store data inside the structure. - * - * @param maps_per_core do I need to read all cores? - */ -static void read_dc_apps_table(int maps_per_core) -{ - netdata_dcstat_pid_t *cv = dcstat_vector; - uint32_t key; - struct ebpf_pid_stat *pids = ebpf_root_of_pids; - int fd = dcstat_maps[NETDATA_DCSTAT_PID_STATS].map_fd; - size_t length = sizeof(netdata_dcstat_pid_t); - if (maps_per_core) - length *= ebpf_nprocs; - - while (pids) { - key = pids->pid; - - if (bpf_map_lookup_elem(fd, &key, cv)) { - pids = pids->next; - continue; - } - - dcstat_apps_accumulator(cv, maps_per_core); - - dcstat_fill_pid(key, cv); - - // We are cleaning to avoid passing data read from one process to other. - memset(cv, 0, length); - - pids = pids->next; - } -} - -/** * Update cgroup * * Update cgroup data based in collected PID. * * @param maps_per_core do I need to read all cores? */ -static void ebpf_update_dc_cgroup(int maps_per_core) +static void ebpf_update_dc_cgroup() { - netdata_dcstat_pid_t *cv = dcstat_vector; - int fd = dcstat_maps[NETDATA_DCSTAT_PID_STATS].map_fd; - size_t length = sizeof(netdata_dcstat_pid_t)*ebpf_nprocs; - ebpf_cgroup_target_t *ect; pthread_mutex_lock(&mutex_cgroup_shm); for (ect = ebpf_cgroup_pids; ect; ect = ect->next) { @@ -718,19 +773,11 @@ static void ebpf_update_dc_cgroup(int maps_per_core) for (pids = ect->pids; pids; pids = pids->next) { int pid = pids->pid; netdata_dcstat_pid_t *out = &pids->dc; - if (likely(dcstat_pid) && dcstat_pid[pid]) { - netdata_publish_dcstat_t *in = dcstat_pid[pid]; + ebpf_pid_stat_t *local_pid = ebpf_get_pid_entry(pid, 0); + if (local_pid) { + netdata_publish_dcstat_t *in = &local_pid->dc; memcpy(out, &in->curr, sizeof(netdata_dcstat_pid_t)); - } else { - memset(cv, 0, length); - if (bpf_map_lookup_elem(fd, &pid, cv)) { - continue; - } - - dcstat_apps_accumulator(cv, maps_per_core); - - memcpy(out, cv, sizeof(netdata_dcstat_pid_t)); } } } @@ -763,32 +810,6 @@ static void ebpf_dc_read_global_tables(netdata_idx_t *stats, int maps_per_core) } /** - * Cachestat sum PIDs - * - * Sum values for all PIDs associated to a group - * - * @param publish output structure. - * @param root structure with listed IPs - */ -void ebpf_dcstat_sum_pids(netdata_publish_dcstat_t *publish, struct ebpf_pid_on_target *root) -{ - memset(&publish->curr, 0, sizeof(netdata_dcstat_pid_t)); - netdata_dcstat_pid_t *dst = &publish->curr; - while (root) { - int32_t pid = root->pid; - netdata_publish_dcstat_t *w = dcstat_pid[pid]; - if (w) { - netdata_dcstat_pid_t *src = &w->curr; - dst->cache_access += src->cache_access; - dst->file_system += src->file_system; - dst->not_found += src->not_found; - } - - root = root->next; - } -} - -/** * Send data to Netdata calling auxiliary functions. * * @param root the target list. @@ -798,17 +819,11 @@ void ebpf_dcache_send_apps_data(struct ebpf_target *root) struct ebpf_target *w; collected_number value; + pthread_mutex_lock(&collect_data_mutex); for (w = root; w; w = w->next) { if (unlikely(!(w->charts_created & (1<<EBPF_MODULE_DCSTAT_IDX)))) continue; - ebpf_dcstat_sum_pids(&w->dcstat, w->root_pid); - - uint64_t cache = w->dcstat.curr.cache_access; - uint64_t not_found = w->dcstat.curr.not_found; - - dcstat_update_publish(&w->dcstat, cache, not_found); - value = (collected_number) w->dcstat.ratio; ebpf_write_begin_chart(NETDATA_APP_FAMILY, w->clean_name, "_ebpf_dc_hit"); write_chart_dimension("ratio", value); @@ -845,6 +860,7 @@ void ebpf_dcache_send_apps_data(struct ebpf_target *root) ebpf_write_end_chart(); w->dcstat.prev.not_found = w->dcstat.curr.not_found; } + pthread_mutex_unlock(&collect_data_mutex); } /** @@ -1024,45 +1040,82 @@ void ebpf_dc_calc_chart_values() **/ static void ebpf_create_systemd_dc_charts(int update_every) { - ebpf_create_charts_on_systemd(NETDATA_DC_HIT_CHART, - "Percentage of files inside directory cache", - EBPF_COMMON_DIMENSION_PERCENTAGE, - NETDATA_DIRECTORY_CACHE_SUBMENU, - NETDATA_EBPF_CHART_TYPE_LINE, - 21200, - ebpf_algorithms[NETDATA_EBPF_ABSOLUTE_IDX], - NETDATA_SYSTEMD_DC_HIT_RATIO_CONTEXT, NETDATA_EBPF_MODULE_NAME_DCSTAT, - update_every); + static ebpf_systemd_args_t data_dc_hit_ratio = { + .title = "Percentage of files inside directory cache", + .units = EBPF_COMMON_DIMENSION_PERCENTAGE, + .family = NETDATA_DIRECTORY_CACHE_SUBMENU, + .charttype = NETDATA_EBPF_CHART_TYPE_LINE, + .order = 21200, + .algorithm = EBPF_CHART_ALGORITHM_ABSOLUTE, + .context = NETDATA_SYSTEMD_DC_HIT_RATIO_CONTEXT, + .module = NETDATA_EBPF_MODULE_NAME_DCSTAT, + .update_every = 0, + .suffix = NETDATA_DC_HIT_CHART, + .dimension = "percentage" + }; - ebpf_create_charts_on_systemd(NETDATA_DC_REFERENCE_CHART, - "Count file access", - EBPF_COMMON_DIMENSION_FILES, - NETDATA_DIRECTORY_CACHE_SUBMENU, - NETDATA_EBPF_CHART_TYPE_LINE, - 21201, - ebpf_algorithms[NETDATA_EBPF_ABSOLUTE_IDX], - NETDATA_SYSTEMD_DC_REFERENCE_CONTEXT, NETDATA_EBPF_MODULE_NAME_DCSTAT, - update_every); + static ebpf_systemd_args_t data_dc_references = { + .title = "Count file access", + .units = EBPF_COMMON_DIMENSION_FILES, + .family = NETDATA_DIRECTORY_CACHE_SUBMENU, + .charttype = NETDATA_EBPF_CHART_TYPE_LINE, + .order = 21201, + .algorithm = EBPF_CHART_ALGORITHM_ABSOLUTE, + .context = NETDATA_SYSTEMD_DC_REFERENCE_CONTEXT, + .module = NETDATA_EBPF_MODULE_NAME_DCSTAT, + .update_every = 0, + .suffix = NETDATA_DC_REFERENCE_CHART, + .dimension = "files" + }; - ebpf_create_charts_on_systemd(NETDATA_DC_REQUEST_NOT_CACHE_CHART, - "Files not present inside directory cache", - EBPF_COMMON_DIMENSION_FILES, - NETDATA_DIRECTORY_CACHE_SUBMENU, - NETDATA_EBPF_CHART_TYPE_LINE, - 21202, - ebpf_algorithms[NETDATA_EBPF_ABSOLUTE_IDX], - NETDATA_SYSTEMD_DC_NOT_CACHE_CONTEXT, NETDATA_EBPF_MODULE_NAME_DCSTAT, - update_every); + static ebpf_systemd_args_t data_dc_not_cache = { + .title = "Files not present inside directory cache", + .units = EBPF_COMMON_DIMENSION_FILES, + .family = NETDATA_DIRECTORY_CACHE_SUBMENU, + .charttype = NETDATA_EBPF_CHART_TYPE_LINE, + .order = 21202, + .algorithm = EBPF_CHART_ALGORITHM_ABSOLUTE, + .context = NETDATA_SYSTEMD_DC_NOT_CACHE_CONTEXT, + .module = NETDATA_EBPF_MODULE_NAME_DCSTAT, + .update_every = 0, + .suffix = NETDATA_DC_REQUEST_NOT_CACHE_CHART, + .dimension = "files" + }; - ebpf_create_charts_on_systemd(NETDATA_DC_REQUEST_NOT_FOUND_CHART, - "Files not found", - EBPF_COMMON_DIMENSION_FILES, - NETDATA_DIRECTORY_CACHE_SUBMENU, - NETDATA_EBPF_CHART_TYPE_LINE, - 21202, - ebpf_algorithms[NETDATA_EBPF_ABSOLUTE_IDX], - NETDATA_SYSTEMD_DC_NOT_FOUND_CONTEXT, NETDATA_EBPF_MODULE_NAME_DCSTAT, - update_every); + static ebpf_systemd_args_t data_dc_not_found = { + .title = "Files not found", + .units = EBPF_COMMON_DIMENSION_FILES, + .family = NETDATA_DIRECTORY_CACHE_SUBMENU, + .charttype = NETDATA_EBPF_CHART_TYPE_LINE, + .order = 21203, + .algorithm = EBPF_CHART_ALGORITHM_ABSOLUTE, + .context = NETDATA_SYSTEMD_DC_NOT_CACHE_CONTEXT, + .module = NETDATA_EBPF_MODULE_NAME_DCSTAT, + .update_every = 0, + .suffix = NETDATA_DC_REQUEST_NOT_FOUND_CHART, + .dimension = "files" + }; + + if (!data_dc_not_cache.update_every) + data_dc_hit_ratio.update_every = data_dc_not_cache.update_every = + data_dc_not_found.update_every = data_dc_references.update_every = update_every; + + ebpf_cgroup_target_t *w; + for (w = ebpf_cgroup_pids; w; w = w->next) { + if (unlikely(!w->systemd || w->flags & NETDATA_EBPF_SERVICES_HAS_DC_CHART)) + continue; + + data_dc_hit_ratio.id = data_dc_not_cache.id = data_dc_not_found.id = data_dc_references.id = w->name; + ebpf_create_charts_on_systemd(&data_dc_hit_ratio); + + ebpf_create_charts_on_systemd(&data_dc_not_found); + + ebpf_create_charts_on_systemd(&data_dc_not_cache); + + ebpf_create_charts_on_systemd(&data_dc_references); + + w->flags |= NETDATA_EBPF_SERVICES_HAS_DC_CHART; + } } /** @@ -1072,48 +1125,37 @@ static void ebpf_create_systemd_dc_charts(int update_every) */ static void ebpf_send_systemd_dc_charts() { - collected_number value; ebpf_cgroup_target_t *ect; - ebpf_write_begin_chart(NETDATA_SERVICE_FAMILY, NETDATA_DC_HIT_CHART, ""); - for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) { - if (unlikely(ect->systemd) && unlikely(ect->updated)) { - write_chart_dimension(ect->name, (long long) ect->publish_dc.ratio); + collected_number value; + for (ect = ebpf_cgroup_pids; ect; ect = ect->next) { + if (unlikely(!(ect->flags & NETDATA_EBPF_SERVICES_HAS_DC_CHART)) ) { + continue; } - } - ebpf_write_end_chart(); - ebpf_write_begin_chart(NETDATA_SERVICE_FAMILY, NETDATA_DC_REFERENCE_CHART, ""); - for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) { - if (unlikely(ect->systemd) && unlikely(ect->updated)) { - write_chart_dimension(ect->name, (long long) ect->publish_dc.cache_access); - } - } - ebpf_write_end_chart(); + ebpf_write_begin_chart(NETDATA_SERVICE_FAMILY, ect->name, NETDATA_DC_HIT_CHART); + write_chart_dimension("percentage", (long long) ect->publish_dc.ratio); + ebpf_write_end_chart(); - ebpf_write_begin_chart(NETDATA_SERVICE_FAMILY, NETDATA_DC_REQUEST_NOT_CACHE_CHART, ""); - for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) { - if (unlikely(ect->systemd) && unlikely(ect->updated)) { - value = (collected_number) (!ect->publish_dc.cache_access) ? 0 : - (long long )ect->publish_dc.curr.file_system - (long long)ect->publish_dc.prev.file_system; - ect->publish_dc.prev.file_system = ect->publish_dc.curr.file_system; + ebpf_write_begin_chart(NETDATA_SERVICE_FAMILY, ect->name, NETDATA_DC_REFERENCE_CHART); + write_chart_dimension("files", (long long) ect->publish_dc.cache_access); + ebpf_write_end_chart(); - write_chart_dimension(ect->name, (long long) value); - } - } - ebpf_write_end_chart(); + ebpf_write_begin_chart(NETDATA_SERVICE_FAMILY, ect->name, NETDATA_DC_REQUEST_NOT_CACHE_CHART); + value = (collected_number) (!ect->publish_dc.cache_access) ? 0 : + (long long )ect->publish_dc.curr.file_system - (long long)ect->publish_dc.prev.file_system; + ect->publish_dc.prev.file_system = ect->publish_dc.curr.file_system; + write_chart_dimension("files", (long long) value); + ebpf_write_end_chart(); - ebpf_write_begin_chart(NETDATA_SERVICE_FAMILY, NETDATA_DC_REQUEST_NOT_FOUND_CHART, ""); - for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) { - if (unlikely(ect->systemd) && unlikely(ect->updated)) { - value = (collected_number) (!ect->publish_dc.cache_access) ? 0 : + ebpf_write_begin_chart(NETDATA_SERVICE_FAMILY, ect->name, NETDATA_DC_REQUEST_NOT_FOUND_CHART); + value = (collected_number) (!ect->publish_dc.cache_access) ? 0 : (long long)ect->publish_dc.curr.not_found - (long long)ect->publish_dc.prev.not_found; - ect->publish_dc.prev.not_found = ect->publish_dc.curr.not_found; + ect->publish_dc.prev.not_found = ect->publish_dc.curr.not_found; - write_chart_dimension(ect->name, (long long) value); - } + write_chart_dimension("files", (long long) value); + ebpf_write_end_chart(); } - ebpf_write_end_chart(); } /** @@ -1159,15 +1201,11 @@ static void ebpf_send_specific_dc_data(char *type, netdata_publish_dcstat_t *pdc */ void ebpf_dc_send_cgroup_data(int update_every) { - if (!ebpf_cgroup_pids) - return; - pthread_mutex_lock(&mutex_cgroup_shm); ebpf_cgroup_target_t *ect; ebpf_dc_calc_chart_values(); - int has_systemd = shm_ebpf_cgroup.header->systemd_enabled; - if (has_systemd) { + if (shm_ebpf_cgroup.header->systemd_enabled) { if (send_cgroup_chart) { ebpf_create_systemd_dc_charts(update_every); } @@ -1223,12 +1261,9 @@ static void dcstat_collector(ebpf_module_t *em) counter = 0; netdata_apps_integration_flags_t apps = em->apps_charts; ebpf_dc_read_global_tables(stats, maps_per_core); - pthread_mutex_lock(&collect_data_mutex); - if (apps) - read_dc_apps_table(maps_per_core); if (cgroups) - ebpf_update_dc_cgroup(maps_per_core); + ebpf_update_dc_cgroup(); pthread_mutex_lock(&lock); @@ -1237,16 +1272,10 @@ static void dcstat_collector(ebpf_module_t *em) if (apps & NETDATA_EBPF_APPS_FLAG_CHART_CREATED) ebpf_dcache_send_apps_data(apps_groups_root_target); -#ifdef NETDATA_DEV_MODE - if (ebpf_aral_dcstat_pid) - ebpf_send_data_aral_chart(ebpf_aral_dcstat_pid, em); -#endif - if (cgroups) ebpf_dc_send_cgroup_data(update_every); pthread_mutex_unlock(&lock); - pthread_mutex_unlock(&collect_data_mutex); pthread_mutex_lock(&ebpf_exit_cleanup); if (running_time && !em->running_time) @@ -1301,17 +1330,10 @@ static void ebpf_create_dc_global_charts(int update_every) * * We are not testing the return, because callocz does this and shutdown the software * case it was not possible to allocate. - * - * @param apps is apps enabled? */ -static void ebpf_dcstat_allocate_global_vectors(int apps) +static void ebpf_dcstat_allocate_global_vectors() { - if (apps) { - ebpf_dcstat_aral_init(); - dcstat_pid = callocz((size_t)pid_max, sizeof(netdata_publish_dcstat_t *)); - dcstat_vector = callocz((size_t)ebpf_nprocs, sizeof(netdata_dcstat_pid_t)); - } - + dcstat_vector = callocz((size_t)ebpf_nprocs, sizeof(netdata_dcstat_pid_t)); dcstat_values = callocz((size_t)ebpf_nprocs, sizeof(netdata_idx_t)); memset(dcstat_counter_aggregated_data, 0, NETDATA_DCSTAT_IDX_END * sizeof(netdata_syscall_stat_t)); @@ -1388,7 +1410,7 @@ void *ebpf_dcstat_thread(void *ptr) goto enddcstat; } - ebpf_dcstat_allocate_global_vectors(em->apps_charts); + ebpf_dcstat_allocate_global_vectors(); int algorithms[NETDATA_DCSTAT_IDX_END] = { NETDATA_EBPF_ABSOLUTE_IDX, NETDATA_EBPF_ABSOLUTE_IDX, NETDATA_EBPF_ABSOLUTE_IDX, @@ -1403,13 +1425,16 @@ void *ebpf_dcstat_thread(void *ptr) ebpf_create_dc_global_charts(em->update_every); ebpf_update_stats(&plugin_statistics, em); ebpf_update_kernel_memory_with_vector(&plugin_statistics, em->maps, EBPF_ACTION_STAT_ADD); -#ifdef NETDATA_DEV_MODE - if (ebpf_aral_dcstat_pid) - dcstat_disable_priority = ebpf_statistic_create_aral_chart(NETDATA_EBPF_DCSTAT_ARAL_NAME, em); -#endif pthread_mutex_unlock(&lock); + ebpf_read_dcstat.thread = mallocz(sizeof(netdata_thread_t)); + netdata_thread_create(ebpf_read_dcstat.thread, + ebpf_read_dcstat.name, + NETDATA_THREAD_OPTION_DEFAULT, + ebpf_read_dcstat_thread, + em); + dcstat_collector(em); enddcstat: |