1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2020 Facebook
3 
4 #include <linux/bpf.h>
5 #include <stdint.h>
6 #include <bpf/bpf_helpers.h>
7 
8 char _license[] SEC("license") = "GPL";
9 
10 struct {
11 	__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
12 	__uint(value_size, sizeof(int));
13 	__uint(key_size, sizeof(int));
14 } perfbuf SEC(".maps");
15 
16 const volatile int batch_cnt = 0;
17 
18 long sample_val = 42;
19 long dropped __attribute__((aligned(128))) = 0;
20 
21 SEC("fentry/__x64_sys_getpgid")
22 int bench_perfbuf(void *ctx)
23 {
24 	__u64 *sample;
25 	int i;
26 
27 	for (i = 0; i < batch_cnt; i++) {
28 		if (bpf_perf_event_output(ctx, &perfbuf, BPF_F_CURRENT_CPU,
29 					  &sample_val, sizeof(sample_val)))
30 			__sync_add_and_fetch(&dropped, 1);
31 	}
32 	return 0;
33 }
34