1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2020 Facebook
6 #include <bpf/bpf_helpers.h>
8 char _license
[] SEC("license") = "GPL";
11 __uint(type
, BPF_MAP_TYPE_RINGBUF
);
12 } ringbuf
SEC(".maps");
14 const volatile int batch_cnt
= 0;
15 const volatile long use_output
= 0;
18 long dropped
__attribute__((aligned(128))) = 0;
20 const volatile long wakeup_data_size
= 0;
22 static __always_inline
long get_flags()
26 if (!wakeup_data_size
)
29 sz
= bpf_ringbuf_query(&ringbuf
, BPF_RB_AVAIL_DATA
);
30 return sz
>= wakeup_data_size
? BPF_RB_FORCE_WAKEUP
: BPF_RB_NO_WAKEUP
;
33 SEC("fentry/__x64_sys_getpgid")
34 int bench_ringbuf(void *ctx
)
40 for (i
= 0; i
< batch_cnt
; i
++) {
41 sample
= bpf_ringbuf_reserve(&ringbuf
,
42 sizeof(sample_val
), 0);
44 __sync_add_and_fetch(&dropped
, 1);
48 bpf_ringbuf_submit(sample
, flags
);
52 for (i
= 0; i
< batch_cnt
; i
++) {
54 if (bpf_ringbuf_output(&ringbuf
, &sample_val
,
55 sizeof(sample_val
), flags
))
56 __sync_add_and_fetch(&dropped
, 1);