]> Git Repo - linux.git/blob - tools/testing/selftests/bpf/progs/bpf_iter_bpf_percpu_array_map.c
Linux 6.14-rc3
[linux.git] / tools / testing / selftests / bpf / progs / bpf_iter_bpf_percpu_array_map.c
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2020 Facebook */
3 #include <vmlinux.h>
4 #include <bpf/bpf_helpers.h>
5 #include <bpf/bpf_tracing.h>
6
7 char _license[] SEC("license") = "GPL";
8
9 struct {
10         __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
11         __uint(max_entries, 3);
12         __type(key, __u32);
13         __type(value, __u32);
14 } arraymap1 SEC(".maps");
15
16 /* will set before prog run */
17 volatile const __u32 num_cpus = 0;
18
19 __u32 key_sum = 0, val_sum = 0;
20
21 SEC("iter/bpf_map_elem")
22 int dump_bpf_percpu_array_map(struct bpf_iter__bpf_map_elem *ctx)
23 {
24         __u32 *key = ctx->key;
25         void *pptr = ctx->value;
26         __u32 step;
27         int i;
28
29         if (key == (void *)0 || pptr == (void *)0)
30                 return 0;
31
32         key_sum += *key;
33
34         step = 8;
35         for (i = 0; i < num_cpus; i++) {
36                 val_sum += *(__u32 *)pptr;
37                 pptr += step;
38         }
39         return 0;
40 }
This page took 0.033005 seconds and 4 git commands to generate.