1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2020 Facebook
5 #include <bpf/bpf_helpers.h>
8 char _license[] SEC("license") = "GPL";
18 __uint(type, BPF_MAP_TYPE_RINGBUF);
19 } ringbuf SEC(".maps");
39 SEC("fentry/" SYS_PREFIX "sys_getpgid")
40 int test_ringbuf(void *ctx)
42 int cur_pid = bpf_get_current_pid_tgid() >> 32;
43 struct sample *sample;
48 sample = bpf_ringbuf_reserve(&ringbuf, sizeof(*sample), 0);
50 __sync_fetch_and_add(&dropped, 1);
55 bpf_get_current_comm(sample->comm, sizeof(sample->comm));
56 sample->value = value;
59 __sync_fetch_and_add(&total, 1);
61 if (sample->seq & 1) {
62 /* copy from reserved sample to a new one... */
63 bpf_ringbuf_output(&ringbuf, sample, sizeof(*sample), flags);
64 /* ...and then discard reserved sample */
65 bpf_ringbuf_discard(sample, flags);
66 __sync_fetch_and_add(&discarded, 1);
68 bpf_ringbuf_submit(sample, flags);
71 avail_data = bpf_ringbuf_query(&ringbuf, BPF_RB_AVAIL_DATA);
72 ring_size = bpf_ringbuf_query(&ringbuf, BPF_RB_RING_SIZE);
73 cons_pos = bpf_ringbuf_query(&ringbuf, BPF_RB_CONS_POS);
74 prod_pos = bpf_ringbuf_query(&ringbuf, BPF_RB_PROD_POS);