File Index
Files and directories
Sign in
FILE

bpf_iter_bpf_percpu_array_map.c

File preview with syntax highlighting.

linux-6.19.14/tools/testing/selftests/bpf/progs/bpf_iter_bpf_percpu_array_map.c 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
 7char _license[] SEC("license") = "GPL";
 8
 9struct {
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 */
17volatile const __u32 num_cpus = 0;
18
19__u32 key_sum = 0, val_sum = 0;
20
21SEC("iter/bpf_map_elem")
22int 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}
~/ Read-only file preview.