@cryptotaxi247 / netdata-1 / commits / 7f1f23d5f

Ebpf arrays (#11230)

Update our code to read the modified table.

thiagoftsm committed Jun 10, 2021 at 12:33 UTC 7f1f23d5fbfcbd46687ecd29419493ca1230821e
11 files changed +52 -20
collectors/ebpf.plugin/ebpf.c
+2 -1
@@ -103,7 +103,8 @@ ebpf_module_t ebpf_modules[] = {
103 { .thread_name = "swap", .config_name = "swap", .enabled = 0, .start_routine = ebpf_swap_thread,
104 .update_time = 1, .global_charts = 1, .apps_charts = 1, .mode = MODE_ENTRY,
105 .optional = 0, .apps_routine = ebpf_swap_create_apps_charts, .maps = NULL,
106 - .pid_map_size = ND_EBPF_DEFAULT_PID_SIZE, .names = NULL },
106 + .pid_map_size = ND_EBPF_DEFAULT_PID_SIZE, .names = NULL, .cfg = &swap_config,
107 + .config_file = NETDATA_DIRECTORY_SWAP_CONFIG_FILE},
108 { .thread_name = "vfs", .config_name = "swap", .enabled = 0, .start_routine = ebpf_vfs_thread,
109 .update_time = 1, .global_charts = 1, .apps_charts = 1, .mode = MODE_ENTRY,
110 .optional = 0, .apps_routine = ebpf_vfs_create_apps_charts, .maps = NULL,
collectors/ebpf.plugin/ebpf_cachestat.c
+14 -6
@@ -16,7 +16,8 @@ static netdata_publish_syscall_t cachestat_counter_publish_aggregated[NETDATA_CA
16
17 netdata_cachestat_pid_t *cachestat_vector = NULL;
18
19 -static netdata_idx_t *cachestat_hash_values = NULL;
19 +static netdata_idx_t cachestat_hash_values[NETDATA_CACHESTAT_END];
20 +static netdata_idx_t *cachestat_values = NULL;
21
22 static int read_thread_closed = 1;
23
@@ -78,7 +79,7 @@ static void ebpf_cachestat_cleanup(void *ptr)
79 ebpf_cleanup_publish_syscall(cachestat_counter_publish_aggregated);
80
81 freez(cachestat_vector);
81 - freez(cachestat_hash_values);
82 + freez(cachestat_values);
83
84 if (probe_links) {
85 struct bpf_program *prog;
@@ -333,12 +334,18 @@ static void read_global_table()
334 {
335 uint32_t idx;
336 netdata_idx_t *val = cachestat_hash_values;
336 - netdata_idx_t stored;
337 + netdata_idx_t *stored = cachestat_values;
338 int fd = map_fd[NETDATA_CACHESTAT_GLOBAL_STATS];
339
340 for (idx = NETDATA_KEY_CALLS_ADD_TO_PAGE_CACHE_LRU; idx < NETDATA_CACHESTAT_END; idx++) {
340 - if (!bpf_map_lookup_elem(fd, &idx, &stored)) {
341 - val[idx] = stored;
341 + if (!bpf_map_lookup_elem(fd, &idx, stored)) {
342 + int i;
343 + int end = ebpf_nprocs;
344 + netdata_idx_t total = 0;
345 + for (i = 0; i < end; i++)
346 + total += stored[i];
347 +
348 + val[idx] = total;
349 }
350 }
351 }
@@ -588,8 +595,9 @@ static void ebpf_cachestat_allocate_global_vectors(size_t length)
595 cachestat_pid = callocz((size_t)pid_max, sizeof(netdata_publish_cachestat_t *));
596 cachestat_vector = callocz((size_t)ebpf_nprocs, sizeof(netdata_cachestat_pid_t));
597
591 - cachestat_hash_values = callocz(length, sizeof(netdata_idx_t));
598 + cachestat_values = callocz((size_t)ebpf_nprocs, sizeof(netdata_idx_t));
599
600 + memset(cachestat_hash_values, 0, length * sizeof(netdata_idx_t));
601 memset(cachestat_counter_aggregated_data, 0, length * sizeof(netdata_syscall_stat_t));
602 memset(cachestat_counter_publish_aggregated, 0, length * sizeof(netdata_publish_syscall_t));
603 }
collectors/ebpf.plugin/ebpf_dcstat.c
+12 -3
@@ -17,6 +17,7 @@ static struct bpf_object *objects = NULL;
17
18 static int *map_fd = NULL;
19 static netdata_idx_t dcstat_hash_values[NETDATA_DCSTAT_IDX_END];
20 +static netdata_idx_t *dcstat_values = NULL;
21
22 static int read_thread_closed = 1;
23
@@ -117,6 +118,7 @@ static void ebpf_dcstat_cleanup(void *ptr)
118 }
119
120 freez(dcstat_vector);
121 + freez(dcstat_values);
122
123 ebpf_cleanup_publish_syscall(dcstat_counter_publish_aggregated);
124
@@ -284,12 +286,18 @@ static void read_global_table()
286 {
287 uint32_t idx;
288 netdata_idx_t *val = dcstat_hash_values;
287 - netdata_idx_t stored;
289 + netdata_idx_t *stored = dcstat_values;
290 int fd = map_fd[NETDATA_DCSTAT_GLOBAL_STATS];
291
292 for (idx = NETDATA_KEY_DC_REFERENCE; idx < NETDATA_DIRECTORY_CACHE_END; idx++) {
291 - if (!bpf_map_lookup_elem(fd, &idx, &stored)) {
292 - val[idx] = stored;
293 + if (!bpf_map_lookup_elem(fd, &idx, stored)) {
294 + int i;
295 + int end = ebpf_nprocs;
296 + netdata_idx_t total = 0;
297 + for (i = 0; i < end; i++)
298 + total += stored[i];
299 +
300 + val[idx] = total;
301 }
302 }
303 }
@@ -539,6 +547,7 @@ static void ebpf_dcstat_allocate_global_vectors(size_t length)
547 {
548 dcstat_pid = callocz((size_t)pid_max, sizeof(netdata_publish_dcstat_t *));
549 dcstat_vector = callocz((size_t)ebpf_nprocs, sizeof(netdata_dcstat_pid_t));
550 + dcstat_values = callocz((size_t)ebpf_nprocs, sizeof(netdata_idx_t));
551
552 memset(dcstat_counter_aggregated_data, 0, length*sizeof(netdata_syscall_stat_t));
553 memset(dcstat_counter_publish_aggregated, 0, length*sizeof(netdata_publish_syscall_t));
collectors/ebpf.plugin/ebpf_filesystem.c
+2
@@ -415,6 +415,8 @@ static void read_filesystem_table(ebpf_filesystem_partitions_t *efp)
415 total += values[i];
416 }
417
418 + if (idx >= NETDATA_FILESYSTEM_MAX_BINS)
419 + idx = NETDATA_FILESYSTEM_MAX_BINS - 1;
420 w->histogram[idx] = total;
421 }
422 }
collectors/ebpf.plugin/ebpf_process.c
+1 -1
@@ -284,7 +284,7 @@ static void read_hash_global_tables()
284 if (!bpf_map_lookup_elem(map_fd[1], &idx, val)) {
285 uint64_t total = 0;
286 int i;
287 - int end = (running_on_kernel < NETDATA_KERNEL_V4_15) ? 1 : ebpf_nprocs;
287 + int end = ebpf_nprocs;
288 for (i = 0; i < end; i++)
289 total += val[i];
290
collectors/ebpf.plugin/ebpf_socket.c
+1 -1
@@ -1509,7 +1509,7 @@ static void read_hash_global_tables()
1509 if (!bpf_map_lookup_elem(fd, &idx, val)) {
1510 uint64_t total = 0;
1511 int i;
1512 - int end = (running_on_kernel < NETDATA_KERNEL_V4_15) ? 1 : ebpf_nprocs;
1512 + int end = ebpf_nprocs;
1513 for (i = 0; i < end; i++)
1514 total += val[i];
1515
collectors/ebpf.plugin/ebpf_swap.c
+13 -3
@@ -12,6 +12,7 @@ static int *map_fd = NULL;
12 netdata_publish_swap_t *swap_vector = NULL;
13
14 static netdata_idx_t swap_hash_values[NETDATA_SWAP_END];
15 +static netdata_idx_t *swap_values = NULL;
16
17 netdata_publish_swap_t **swap_pid = NULL;
18
@@ -72,6 +73,7 @@ static void ebpf_swap_cleanup(void *ptr)
73 ebpf_cleanup_publish_syscall(swap_publish_aggregated);
74
75 freez(swap_vector);
76 + freez(swap_values);
77
78 if (probe_links) {
79 struct bpf_program *prog;
@@ -179,14 +181,20 @@ static void swap_send_global()
181 */
182 static void read_global_table()
183 {
182 - uint64_t stored;
184 + netdata_idx_t *stored = swap_values;
185 netdata_idx_t *val = swap_hash_values;
186 int fd = map_fd[NETDATA_SWAP_GLOBAL_TABLE];
187
188 uint32_t i, end = NETDATA_SWAP_END;
189 for (i = NETDATA_KEY_SWAP_READPAGE_CALL; i < end; i++) {
188 - if (!bpf_map_lookup_elem(fd, &i, &stored)) {
189 - val[i] = stored;
190 + if (!bpf_map_lookup_elem(fd, &i, stored)) {
191 + int j;
192 + int last = ebpf_nprocs;
193 + netdata_idx_t total = 0;
194 + for (j = 0; j < last; j++)
195 + total += stored[j];
196 +
197 + val[i] = total;
198 }
199 }
200 }
@@ -363,6 +371,8 @@ static void ebpf_swap_allocate_global_vectors()
371 swap_pid = callocz((size_t)pid_max, sizeof(netdata_publish_swap_t *));
372 swap_vector = callocz((size_t)ebpf_nprocs, sizeof(netdata_publish_swap_t));
373
374 + swap_values = callocz((size_t)ebpf_nprocs, sizeof(netdata_idx_t));
375 +
376 memset(swap_hash_values, 0, sizeof(swap_hash_values));
377 }
378
collectors/ebpf.plugin/ebpf_swap.h
+2
@@ -38,4 +38,6 @@ extern void *ebpf_swap_thread(void *ptr);
38 extern void ebpf_swap_create_apps_charts(struct ebpf_module *em, void *ptr);
39 extern void clean_swap_pid_structures();
40
41 +extern struct config swap_config;
42 +
43 #endif
collectors/ebpf.plugin/ebpf_vfs.c
+1 -1
@@ -167,7 +167,7 @@ static void read_global_table()
167 uint64_t total = 0;
168 if (!bpf_map_lookup_elem(fd, &idx, val)) {
169 int i;
170 - int end = (running_on_kernel < NETDATA_KERNEL_V4_15) ? 1 : ebpf_nprocs;
170 + int end = ebpf_nprocs;
171 for (i = 0; i < end; i++)
172 total += val[i];
173 }
packaging/ebpf.checksums
+3 -3
@@ -1,3 +1,3 @@
1 -f712ebedd6f052d1bfd4bf26ef50903d34db0fdb83dd48abf54eb7b00f29587c netdata-kernel-collector-glibc-v0.6.8.tar.xz
2 -0e34392c5928cc5a8c66348b6131186e2e9d35237d9ac303bae7cbf684b888fe netdata-kernel-collector-musl-v0.6.8.tar.xz
3 -29f5d13f0b894a6933142dc0677cf269b9114e7f03e8ff4192e560c6c7313631 netdata-kernel-collector-static-v0.6.8.tar.xz
1 +30f6be9ac8d62d1fe1e39e8af9a9298ecc72194605be2748be513467ee057cd1 netdata-kernel-collector-glibc-v0.6.9.tar.xz
2 +c856c7d48a7bb07f9ab3ea2a4bff06742049f106de8b950ce45019d970393fa1 netdata-kernel-collector-musl-v0.6.9.tar.xz
3 +4aeb5fcf0dde077691a6377bf824cc830d18dd8efbc06842ad47721c380cc211 netdata-kernel-collector-static-v0.6.9.tar.xz
packaging/ebpf.version
+1 -1
@@ -1 +1 @@
1 -v0.6.8
1 +v0.6.9