0001
0002
0003 #include "bpf_iter.h"
0004 #include <bpf/bpf_helpers.h>
0005 #include <bpf/bpf_tracing.h>
0006
0007 char _license[] SEC("license") = "GPL";
0008
0009 struct key_t {
0010 int a;
0011 int b;
0012 int c;
0013 };
0014
0015 struct {
0016 __uint(type, BPF_MAP_TYPE_PERCPU_HASH);
0017 __uint(max_entries, 3);
0018 __type(key, struct key_t);
0019 __type(value, __u32);
0020 } hashmap1 SEC(".maps");
0021
0022
0023 volatile const __u32 num_cpus = 0;
0024
0025
0026 __u32 key_sum_a = 0, key_sum_b = 0, key_sum_c = 0;
0027 __u32 val_sum = 0;
0028
0029 SEC("iter/bpf_map_elem")
0030 int dump_bpf_percpu_hash_map(struct bpf_iter__bpf_map_elem *ctx)
0031 {
0032 struct key_t *key = ctx->key;
0033 void *pptr = ctx->value;
0034 __u32 step;
0035 int i;
0036
0037 if (key == (void *)0 || pptr == (void *)0)
0038 return 0;
0039
0040 key_sum_a += key->a;
0041 key_sum_b += key->b;
0042 key_sum_c += key->c;
0043
0044 step = 8;
0045 for (i = 0; i < num_cpus; i++) {
0046 val_sum += *(__u32 *)pptr;
0047 pptr += step;
0048 }
0049 return 0;
0050 }