Просмотр исходного кода

Ebpf arrays (#11230)

Update our code to read the modified table.
thiagoftsm 3 лет назад
Родитель
Сommit
7f1f23d5fb

+ 2 - 1
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,

+ 14 - 6
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));
 }

+ 12 - 3
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));

+ 2 - 0
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;
     }
 }

+ 1 - 1
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];
 

+ 1 - 1
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];
 

+ 13 - 3
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));
 }
 

+ 2 - 0
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

+ 1 - 1
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];
         }

+ 3 - 3
packaging/ebpf.checksums

@@ -1,3 +1,3 @@
-f712ebedd6f052d1bfd4bf26ef50903d34db0fdb83dd48abf54eb7b00f29587c  netdata-kernel-collector-glibc-v0.6.8.tar.xz
-0e34392c5928cc5a8c66348b6131186e2e9d35237d9ac303bae7cbf684b888fe  netdata-kernel-collector-musl-v0.6.8.tar.xz
-29f5d13f0b894a6933142dc0677cf269b9114e7f03e8ff4192e560c6c7313631  netdata-kernel-collector-static-v0.6.8.tar.xz
+30f6be9ac8d62d1fe1e39e8af9a9298ecc72194605be2748be513467ee057cd1  netdata-kernel-collector-glibc-v0.6.9.tar.xz
+c856c7d48a7bb07f9ab3ea2a4bff06742049f106de8b950ce45019d970393fa1  netdata-kernel-collector-musl-v0.6.9.tar.xz
+4aeb5fcf0dde077691a6377bf824cc830d18dd8efbc06842ad47721c380cc211  netdata-kernel-collector-static-v0.6.9.tar.xz

Некоторые файлы не были показаны из-за большого количества измененных файлов