Linux Audio

Check our new training course

Yocto / OpenEmbedded training

Feb 10-13, 2025
Register
Loading...
v6.13.7
 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_ARRAY);
11	__uint(max_entries, 3);
12	__type(key, __u32);
13	__type(value, __u64);
14} arraymap1 SEC(".maps");
15
16struct {
17	__uint(type, BPF_MAP_TYPE_HASH);
18	__uint(max_entries, 10);
19	__type(key, __u64);
20	__type(value, __u32);
21} hashmap1 SEC(".maps");
22
23__u32 key_sum = 0;
24__u64 val_sum = 0;
25
26SEC("iter/bpf_map_elem")
27int dump_bpf_array_map(struct bpf_iter__bpf_map_elem *ctx)
28{
29	__u32 *hmap_val, *key = ctx->key;
30	__u64 *val = ctx->value;
31
32	if (key == (void *)0 || val == (void *)0)
33		return 0;
34
35	bpf_seq_write(ctx->meta->seq, key, sizeof(__u32));
36	bpf_seq_write(ctx->meta->seq, val, sizeof(__u64));
37	key_sum += *key;
38	val_sum += *val;
39
40	/* workaround - It's necessary to do this convoluted (val, key)
41	 * write into hashmap1, instead of simply doing
42	 *   bpf_map_update_elem(&hashmap1, val, key, BPF_ANY);
43	 * because key has MEM_RDONLY flag and bpf_map_update elem expects
44	 * types without this flag
45	 */
46	bpf_map_update_elem(&hashmap1, val, val, BPF_ANY);
47	hmap_val = bpf_map_lookup_elem(&hashmap1, val);
48	if (hmap_val)
49		*hmap_val = *key;
50
51	*val = *key;
52	return 0;
53}
v6.8
 1// SPDX-License-Identifier: GPL-2.0
 2/* Copyright (c) 2020 Facebook */
 3#include "bpf_iter.h"
 4#include <bpf/bpf_helpers.h>
 5#include <bpf/bpf_tracing.h>
 6
 7char _license[] SEC("license") = "GPL";
 8
 9struct key_t {
10	int a;
11	int b;
12	int c;
13};
14
15struct {
16	__uint(type, BPF_MAP_TYPE_ARRAY);
17	__uint(max_entries, 3);
18	__type(key, __u32);
19	__type(value, __u64);
20} arraymap1 SEC(".maps");
21
22struct {
23	__uint(type, BPF_MAP_TYPE_HASH);
24	__uint(max_entries, 10);
25	__type(key, __u64);
26	__type(value, __u32);
27} hashmap1 SEC(".maps");
28
29__u32 key_sum = 0;
30__u64 val_sum = 0;
31
32SEC("iter/bpf_map_elem")
33int dump_bpf_array_map(struct bpf_iter__bpf_map_elem *ctx)
34{
35	__u32 *hmap_val, *key = ctx->key;
36	__u64 *val = ctx->value;
37
38	if (key == (void *)0 || val == (void *)0)
39		return 0;
40
41	bpf_seq_write(ctx->meta->seq, key, sizeof(__u32));
42	bpf_seq_write(ctx->meta->seq, val, sizeof(__u64));
43	key_sum += *key;
44	val_sum += *val;
45
46	/* workaround - It's necessary to do this convoluted (val, key)
47	 * write into hashmap1, instead of simply doing
48	 *   bpf_map_update_elem(&hashmap1, val, key, BPF_ANY);
49	 * because key has MEM_RDONLY flag and bpf_map_update elem expects
50	 * types without this flag
51	 */
52	bpf_map_update_elem(&hashmap1, val, val, BPF_ANY);
53	hmap_val = bpf_map_lookup_elem(&hashmap1, val);
54	if (hmap_val)
55		*hmap_val = *key;
56
57	*val = *key;
58	return 0;
59}