diff options
author | thiagoftsm <thiagoftsm@gmail.com> | 2021-06-10 12:33:14 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-10 12:33:14 +0000 |
commit | 7f1f23d5fbfcbd46687ecd29419493ca1230821e (patch) | |
tree | e24c0d5c41ca0a098a0859bceed1ce138eb46f7a /collectors | |
parent | 86c9ada59d5d7e1876d36aa1ffea13f1da90b10d (diff) |
Ebpf arrays (#11230)
Update our code to read the modified table.
Diffstat (limited to 'collectors')
-rw-r--r-- | collectors/ebpf.plugin/ebpf.c | 3 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_cachestat.c | 20 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_dcstat.c | 15 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_filesystem.c | 2 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_process.c | 2 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_socket.c | 2 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_swap.c | 16 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_swap.h | 2 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf_vfs.c | 2 |
9 files changed, 48 insertions, 16 deletions
diff --git a/collectors/ebpf.plugin/ebpf.c b/collectors/ebpf.plugin/ebpf.c index b7dd0a53ef..07918f8d53 100644 --- a/collectors/ebpf.plugin/ebpf.c +++ b/collectors/ebpf.plugin/ebpf.c @@ -103,7 +103,8 @@ ebpf_module_t ebpf_modules[] = { { .thread_name = "swap", .config_name = "swap", .enabled = 0, .start_routine = ebpf_swap_thread, .update_time = 1, .global_charts = 1, .apps_charts = 1, .mode = MODE_ENTRY, .optional = 0, .apps_routine = ebpf_swap_create_apps_charts, .maps = NULL, - .pid_map_size = ND_EBPF_DEFAULT_PID_SIZE, .names = NULL }, + .pid_map_size = ND_EBPF_DEFAULT_PID_SIZE, .names = NULL, .cfg = &swap_config, + .config_file = NETDATA_DIRECTORY_SWAP_CONFIG_FILE}, { .thread_name = "vfs", .config_name = "swap", .enabled = 0, .start_routine = ebpf_vfs_thread, .update_time = 1, .global_charts = 1, .apps_charts = 1, .mode = MODE_ENTRY, .optional = 0, .apps_routine = ebpf_vfs_create_apps_charts, .maps = NULL, diff --git a/collectors/ebpf.plugin/ebpf_cachestat.c b/collectors/ebpf.plugin/ebpf_cachestat.c index 3f99179940..dd70f229ee 100644 --- a/collectors/ebpf.plugin/ebpf_cachestat.c +++ b/collectors/ebpf.plugin/ebpf_cachestat.c @@ -16,7 +16,8 @@ static netdata_publish_syscall_t cachestat_counter_publish_aggregated[NETDATA_CA netdata_cachestat_pid_t *cachestat_vector = NULL; -static netdata_idx_t *cachestat_hash_values = NULL; +static netdata_idx_t cachestat_hash_values[NETDATA_CACHESTAT_END]; +static netdata_idx_t *cachestat_values = NULL; static int read_thread_closed = 1; @@ -78,7 +79,7 @@ static void ebpf_cachestat_cleanup(void *ptr) ebpf_cleanup_publish_syscall(cachestat_counter_publish_aggregated); freez(cachestat_vector); - freez(cachestat_hash_values); + freez(cachestat_values); if (probe_links) { struct bpf_program *prog; @@ -333,12 +334,18 @@ static void read_global_table() { uint32_t idx; netdata_idx_t *val = cachestat_hash_values; - netdata_idx_t stored; + netdata_idx_t *stored = cachestat_values; int fd = map_fd[NETDATA_CACHESTAT_GLOBAL_STATS]; for (idx = NETDATA_KEY_CALLS_ADD_TO_PAGE_CACHE_LRU; idx < NETDATA_CACHESTAT_END; idx++) { - if (!bpf_map_lookup_elem(fd, &idx, &stored)) { - val[idx] = stored; + if (!bpf_map_lookup_elem(fd, &idx, stored)) { + int i; + int end = ebpf_nprocs; + netdata_idx_t total = 0; + for (i = 0; i < end; i++) + total += stored[i]; + + val[idx] = total; } } } @@ -588,8 +595,9 @@ static void ebpf_cachestat_allocate_global_vectors(size_t length) cachestat_pid = callocz((size_t)pid_max, sizeof(netdata_publish_cachestat_t *)); cachestat_vector = callocz((size_t)ebpf_nprocs, sizeof(netdata_cachestat_pid_t)); - cachestat_hash_values = callocz(length, sizeof(netdata_idx_t)); + cachestat_values = callocz((size_t)ebpf_nprocs, sizeof(netdata_idx_t)); + memset(cachestat_hash_values, 0, length * sizeof(netdata_idx_t)); memset(cachestat_counter_aggregated_data, 0, length * sizeof(netdata_syscall_stat_t)); memset(cachestat_counter_publish_aggregated, 0, length * sizeof(netdata_publish_syscall_t)); } diff --git a/collectors/ebpf.plugin/ebpf_dcstat.c b/collectors/ebpf.plugin/ebpf_dcstat.c index 4fcfc16741..1f58d11337 100644 --- a/collectors/ebpf.plugin/ebpf_dcstat.c +++ b/collectors/ebpf.plugin/ebpf_dcstat.c @@ -17,6 +17,7 @@ static struct bpf_object *objects = NULL; static int *map_fd = NULL; static netdata_idx_t dcstat_hash_values[NETDATA_DCSTAT_IDX_END]; +static netdata_idx_t *dcstat_values = NULL; static int read_thread_closed = 1; @@ -117,6 +118,7 @@ static void ebpf_dcstat_cleanup(void *ptr) } freez(dcstat_vector); + freez(dcstat_values); ebpf_cleanup_publish_syscall(dcstat_counter_publish_aggregated); @@ -284,12 +286,18 @@ static void read_global_table() { uint32_t idx; netdata_idx_t *val = dcstat_hash_values; - netdata_idx_t stored; + netdata_idx_t *stored = dcstat_values; int fd = map_fd[NETDATA_DCSTAT_GLOBAL_STATS]; for (idx = NETDATA_KEY_DC_REFERENCE; idx < NETDATA_DIRECTORY_CACHE_END; idx++) { - if (!bpf_map_lookup_elem(fd, &idx, &stored)) { - val[idx] = stored; + if (!bpf_map_lookup_elem(fd, &idx, stored)) { + int i; + int end = ebpf_nprocs; + netdata_idx_t total = 0; + for (i = 0; i < end; i++) + total += stored[i]; + + val[idx] = total; } } } @@ -539,6 +547,7 @@ static void ebpf_dcstat_allocate_global_vectors(size_t length) { 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_values = callocz((size_t)ebpf_nprocs, sizeof(netdata_idx_t)); memset(dcstat_counter_aggregated_data, 0, length*sizeof(netdata_syscall_stat_t)); memset(dcstat_counter_publish_aggregated, 0, length*sizeof(netdata_publish_syscall_t)); diff --git a/collectors/ebpf.plugin/ebpf_filesystem.c b/collectors/ebpf.plugin/ebpf_filesystem.c index d41ce134a7..68521c07a6 100644 --- a/collectors/ebpf.plugin/ebpf_filesystem.c +++ b/collectors/ebpf.plugin/ebpf_filesystem.c @@ -415,6 +415,8 @@ static void read_filesystem_table(ebpf_filesystem_partitions_t *efp) total += values[i]; } + if (idx >= NETDATA_FILESYSTEM_MAX_BINS) + idx = NETDATA_FILESYSTEM_MAX_BINS - 1; w->histogram[idx] = total; } } diff --git a/collectors/ebpf.plugin/ebpf_process.c b/collectors/ebpf.plugin/ebpf_process.c index 91c9352a1f..798102a10b 100644 --- a/collectors/ebpf.plugin/ebpf_process.c +++ b/collectors/ebpf.plugin/ebpf_process.c @@ -284,7 +284,7 @@ static void read_hash_global_tables() if (!bpf_map_lookup_elem(map_fd[1], &idx, val)) { uint64_t total = 0; int i; - int end = (running_on_kernel < NETDATA_KERNEL_V4_15) ? 1 : ebpf_nprocs; + int end = ebpf_nprocs; for (i = 0; i < end; i++) total += val[i]; diff --git a/collectors/ebpf.plugin/ebpf_socket.c b/collectors/ebpf.plugin/ebpf_socket.c index 360ee407a6..eab801ae1a 100644 --- a/collectors/ebpf.plugin/ebpf_socket.c +++ b/collectors/ebpf.plugin/ebpf_socket.c @@ -1509,7 +1509,7 @@ static void read_hash_global_tables() if (!bpf_map_lookup_elem(fd, &idx, val)) { uint64_t total = 0; int i; - int end = (running_on_kernel < NETDATA_KERNEL_V4_15) ? 1 : ebpf_nprocs; + int end = ebpf_nprocs; for (i = 0; i < end; i++) total += val[i]; diff --git a/collectors/ebpf.plugin/ebpf_swap.c b/collectors/ebpf.plugin/ebpf_swap.c index 3f2298ebd3..701822f453 100644 --- a/collectors/ebpf.plugin/ebpf_swap.c +++ b/collectors/ebpf.plugin/ebpf_swap.c @@ -12,6 +12,7 @@ static int *map_fd = NULL; netdata_publish_swap_t *swap_vector = NULL; static netdata_idx_t swap_hash_values[NETDATA_SWAP_END]; +static netdata_idx_t *swap_values = NULL; netdata_publish_swap_t **swap_pid = NULL; @@ -72,6 +73,7 @@ static void ebpf_swap_cleanup(void *ptr) ebpf_cleanup_publish_syscall(swap_publish_aggregated); freez(swap_vector); + freez(swap_values); if (probe_links) { struct bpf_program *prog; @@ -179,14 +181,20 @@ static void swap_send_global() */ static void read_global_table() { - uint64_t stored; + netdata_idx_t *stored = swap_values; netdata_idx_t *val = swap_hash_values; int fd = map_fd[NETDATA_SWAP_GLOBAL_TABLE]; uint32_t i, end = NETDATA_SWAP_END; for (i = NETDATA_KEY_SWAP_READPAGE_CALL; i < end; i++) { - if (!bpf_map_lookup_elem(fd, &i, &stored)) { - val[i] = stored; + if (!bpf_map_lookup_elem(fd, &i, stored)) { + int j; + int last = ebpf_nprocs; + netdata_idx_t total = 0; + for (j = 0; j < last; j++) + total += stored[j]; + + val[i] = total; } } } @@ -363,6 +371,8 @@ static void ebpf_swap_allocate_global_vectors() swap_pid = callocz((size_t)pid_max, sizeof(netdata_publish_swap_t *)); swap_vector = callocz((size_t)ebpf_nprocs, sizeof(netdata_publish_swap_t)); + swap_values = callocz((size_t)ebpf_nprocs, sizeof(netdata_idx_t)); + memset(swap_hash_values, 0, sizeof(swap_hash_values)); } diff --git a/collectors/ebpf.plugin/ebpf_swap.h b/collectors/ebpf.plugin/ebpf_swap.h index 58e575cd37..7ff8a6f167 100644 --- a/collectors/ebpf.plugin/ebpf_swap.h +++ b/collectors/ebpf.plugin/ebpf_swap.h @@ -38,4 +38,6 @@ extern void *ebpf_swap_thread(void *ptr); extern void ebpf_swap_create_apps_charts(struct ebpf_module *em, void *ptr); extern void clean_swap_pid_structures(); +extern struct config swap_config; + #endif diff --git a/collectors/ebpf.plugin/ebpf_vfs.c b/collectors/ebpf.plugin/ebpf_vfs.c index f3dd7d877c..6bc27e0f91 100644 --- a/collectors/ebpf.plugin/ebpf_vfs.c +++ b/collectors/ebpf.plugin/ebpf_vfs.c @@ -167,7 +167,7 @@ static void read_global_table() uint64_t total = 0; if (!bpf_map_lookup_elem(fd, &idx, val)) { int i; - int end = (running_on_kernel < NETDATA_KERNEL_V4_15) ? 1 : ebpf_nprocs; + int end = ebpf_nprocs; for (i = 0; i < end; i++) total += val[i]; } |