diff options
-rw-r--r-- | tools/bpf/bpftool/map.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c index 097b1a5e046b..f74a8bcbda87 100644 --- a/tools/bpf/bpftool/map.c +++ b/tools/bpf/bpftool/map.c | |||
@@ -36,6 +36,7 @@ | |||
36 | #include <assert.h> | 36 | #include <assert.h> |
37 | #include <errno.h> | 37 | #include <errno.h> |
38 | #include <fcntl.h> | 38 | #include <fcntl.h> |
39 | #include <linux/kernel.h> | ||
39 | #include <stdbool.h> | 40 | #include <stdbool.h> |
40 | #include <stdio.h> | 41 | #include <stdio.h> |
41 | #include <stdlib.h> | 42 | #include <stdlib.h> |
@@ -90,7 +91,8 @@ static bool map_is_map_of_progs(__u32 type) | |||
90 | static void *alloc_value(struct bpf_map_info *info) | 91 | static void *alloc_value(struct bpf_map_info *info) |
91 | { | 92 | { |
92 | if (map_is_per_cpu(info->type)) | 93 | if (map_is_per_cpu(info->type)) |
93 | return malloc(info->value_size * get_possible_cpus()); | 94 | return malloc(round_up(info->value_size, 8) * |
95 | get_possible_cpus()); | ||
94 | else | 96 | else |
95 | return malloc(info->value_size); | 97 | return malloc(info->value_size); |
96 | } | 98 | } |
@@ -161,9 +163,10 @@ static void print_entry_json(struct bpf_map_info *info, unsigned char *key, | |||
161 | jsonw_name(json_wtr, "value"); | 163 | jsonw_name(json_wtr, "value"); |
162 | print_hex_data_json(value, info->value_size); | 164 | print_hex_data_json(value, info->value_size); |
163 | } else { | 165 | } else { |
164 | unsigned int i, n; | 166 | unsigned int i, n, step; |
165 | 167 | ||
166 | n = get_possible_cpus(); | 168 | n = get_possible_cpus(); |
169 | step = round_up(info->value_size, 8); | ||
167 | 170 | ||
168 | jsonw_name(json_wtr, "key"); | 171 | jsonw_name(json_wtr, "key"); |
169 | print_hex_data_json(key, info->key_size); | 172 | print_hex_data_json(key, info->key_size); |
@@ -176,7 +179,7 @@ static void print_entry_json(struct bpf_map_info *info, unsigned char *key, | |||
176 | jsonw_int_field(json_wtr, "cpu", i); | 179 | jsonw_int_field(json_wtr, "cpu", i); |
177 | 180 | ||
178 | jsonw_name(json_wtr, "value"); | 181 | jsonw_name(json_wtr, "value"); |
179 | print_hex_data_json(value + i * info->value_size, | 182 | print_hex_data_json(value + i * step, |
180 | info->value_size); | 183 | info->value_size); |
181 | 184 | ||
182 | jsonw_end_object(json_wtr); | 185 | jsonw_end_object(json_wtr); |
@@ -207,9 +210,10 @@ static void print_entry_plain(struct bpf_map_info *info, unsigned char *key, | |||
207 | 210 | ||
208 | printf("\n"); | 211 | printf("\n"); |
209 | } else { | 212 | } else { |
210 | unsigned int i, n; | 213 | unsigned int i, n, step; |
211 | 214 | ||
212 | n = get_possible_cpus(); | 215 | n = get_possible_cpus(); |
216 | step = round_up(info->value_size, 8); | ||
213 | 217 | ||
214 | printf("key:\n"); | 218 | printf("key:\n"); |
215 | fprint_hex(stdout, key, info->key_size, " "); | 219 | fprint_hex(stdout, key, info->key_size, " "); |
@@ -217,7 +221,7 @@ static void print_entry_plain(struct bpf_map_info *info, unsigned char *key, | |||
217 | for (i = 0; i < n; i++) { | 221 | for (i = 0; i < n; i++) { |
218 | printf("value (CPU %02d):%c", | 222 | printf("value (CPU %02d):%c", |
219 | i, info->value_size > 16 ? '\n' : ' '); | 223 | i, info->value_size > 16 ? '\n' : ' '); |
220 | fprint_hex(stdout, value + i * info->value_size, | 224 | fprint_hex(stdout, value + i * step, |
221 | info->value_size, " "); | 225 | info->value_size, " "); |
222 | printf("\n"); | 226 | printf("\n"); |
223 | } | 227 | } |