Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* Copyright (c) 2020 Facebook */
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_ARRAY);
0017     __uint(max_entries, 3);
0018     __type(key, __u32);
0019     __type(value, __u32);
0020 } arraymap1 SEC(".maps");
0021 
0022 /* will set before prog run */
0023 volatile const __u32 num_cpus = 0;
0024 
0025 __u32 key_sum = 0, val_sum = 0;
0026 
0027 SEC("iter/bpf_map_elem")
0028 int dump_bpf_percpu_array_map(struct bpf_iter__bpf_map_elem *ctx)
0029 {
0030     __u32 *key = ctx->key;
0031     void *pptr = ctx->value;
0032     __u32 step;
0033     int i;
0034 
0035     if (key == (void *)0 || pptr == (void *)0)
0036         return 0;
0037 
0038     key_sum += *key;
0039 
0040     step = 8;
0041     for (i = 0; i < num_cpus; i++) {
0042         val_sum += *(__u32 *)pptr;
0043         pptr += step;
0044     }
0045     return 0;
0046 }