xref: /linux/tools/testing/selftests/bpf/progs/bpf_loop_bench.c (revision e7d759f31ca295d589f7420719c311870bb3166f)
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2021 Facebook */
3 
4 #include "vmlinux.h"
5 #include <bpf/bpf_helpers.h>
6 #include "bpf_misc.h"
7 
8 char _license[] SEC("license") = "GPL";
9 
10 u32 nr_loops;
11 long hits;
12 
13 static int empty_callback(__u32 index, void *data)
14 {
15 	return 0;
16 }
17 
18 static int outer_loop(__u32 index, void *data)
19 {
20 	bpf_loop(nr_loops, empty_callback, NULL, 0);
21 	__sync_add_and_fetch(&hits, nr_loops);
22 	return 0;
23 }
24 
25 SEC("fentry/" SYS_PREFIX "sys_getpgid")
26 int benchmark(void *ctx)
27 {
28 	bpf_loop(1000, outer_loop, NULL, 0);
29 	return 0;
30 }
31