aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/bpf/arraymap.c
diff options
context:
space:
mode:
authorYonghong Song <yhs@fb.com>2018-08-29 17:43:13 -0400
committerDaniel Borkmann <daniel@iogearbox.net>2018-08-30 08:03:53 -0400
commitc7b27c37af3da5a63f32b0bc99569e3069e4d9c1 (patch)
tree91ae3f4139905d41b937717f5e3de4522363f0dc /kernel/bpf/arraymap.c
parent234dbe3dc1db002076bb593c1f6dc5f3ebc46b21 (diff)
bpf: add bpffs pretty print for percpu arraymap/hash/lru_hash
Added bpffs pretty print for percpu arraymap, percpu hashmap and percpu lru hashmap. For each map <key, value> pair, the format is: <key_value>: { cpu0: <value_on_cpu0> cpu1: <value_on_cpu1> ... cpun: <value_on_cpun> } For example, on my VM, there are 4 cpus, and for test_btf test in the next patch: cat /sys/fs/bpf/pprint_test_percpu_hash You may get: ... 43602: { cpu0: {43602,0,-43602,0x3,0xaa52,0x3,{43602|[82,170,0,0,0,0,0,0]},ENUM_TWO} cpu1: {43602,0,-43602,0x3,0xaa52,0x3,{43602|[82,170,0,0,0,0,0,0]},ENUM_TWO} cpu2: {43602,0,-43602,0x3,0xaa52,0x3,{43602|[82,170,0,0,0,0,0,0]},ENUM_TWO} cpu3: {43602,0,-43602,0x3,0xaa52,0x3,{43602|[82,170,0,0,0,0,0,0]},ENUM_TWO} } 72847: { cpu0: {72847,0,-72847,0x3,0x11c8f,0x3,{72847|[143,28,1,0,0,0,0,0]},ENUM_THREE} cpu1: {72847,0,-72847,0x3,0x11c8f,0x3,{72847|[143,28,1,0,0,0,0,0]},ENUM_THREE} cpu2: {72847,0,-72847,0x3,0x11c8f,0x3,{72847|[143,28,1,0,0,0,0,0]},ENUM_THREE} cpu3: {72847,0,-72847,0x3,0x11c8f,0x3,{72847|[143,28,1,0,0,0,0,0]},ENUM_THREE} } ... Signed-off-by: Yonghong Song <yhs@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'kernel/bpf/arraymap.c')
-rw-r--r--kernel/bpf/arraymap.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c
index 0c17aab3ce5f..f9d24121be99 100644
--- a/kernel/bpf/arraymap.c
+++ b/kernel/bpf/arraymap.c
@@ -358,6 +358,29 @@ static void array_map_seq_show_elem(struct bpf_map *map, void *key,
358 rcu_read_unlock(); 358 rcu_read_unlock();
359} 359}
360 360
361static void percpu_array_map_seq_show_elem(struct bpf_map *map, void *key,
362 struct seq_file *m)
363{
364 struct bpf_array *array = container_of(map, struct bpf_array, map);
365 u32 index = *(u32 *)key;
366 void __percpu *pptr;
367 int cpu;
368
369 rcu_read_lock();
370
371 seq_printf(m, "%u: {\n", *(u32 *)key);
372 pptr = array->pptrs[index & array->index_mask];
373 for_each_possible_cpu(cpu) {
374 seq_printf(m, "\tcpu%d: ", cpu);
375 btf_type_seq_show(map->btf, map->btf_value_type_id,
376 per_cpu_ptr(pptr, cpu), m);
377 seq_puts(m, "\n");
378 }
379 seq_puts(m, "}\n");
380
381 rcu_read_unlock();
382}
383
361static int array_map_check_btf(const struct bpf_map *map, 384static int array_map_check_btf(const struct bpf_map *map,
362 const struct btf_type *key_type, 385 const struct btf_type *key_type,
363 const struct btf_type *value_type) 386 const struct btf_type *value_type)
@@ -398,6 +421,7 @@ const struct bpf_map_ops percpu_array_map_ops = {
398 .map_lookup_elem = percpu_array_map_lookup_elem, 421 .map_lookup_elem = percpu_array_map_lookup_elem,
399 .map_update_elem = array_map_update_elem, 422 .map_update_elem = array_map_update_elem,
400 .map_delete_elem = array_map_delete_elem, 423 .map_delete_elem = array_map_delete_elem,
424 .map_seq_show_elem = percpu_array_map_seq_show_elem,
401 .map_check_btf = array_map_check_btf, 425 .map_check_btf = array_map_check_btf,
402}; 426};
403 427