xref: /linux/tools/testing/selftests/bpf/progs/bpf_loop_bench.c (revision 0526b56cbc3c489642bd6a5fe4b718dea7ef0ee8)
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 SEC("fentry/" SYS_PREFIX "sys_getpgid")
19 int benchmark(void *ctx)
20 {
21 	for (int i = 0; i < 1000; i++) {
22 		bpf_loop(nr_loops, empty_callback, NULL, 0);
23 
24 		__sync_add_and_fetch(&hits, nr_loops);
25 	}
26 	return 0;
27 }
28