xref: /xnu-8792.41.9/tests/pmap_bench.c (revision 5c2921b07a2480ab43ec66f5b9e41cb872bc554f) !
1 #include <sys/sysctl.h>
2 
3 #include <darwintest.h>
4 #include <darwintest_perf.h>
5 
6 T_GLOBAL_META(
7 	T_META_NAMESPACE("xnu.arm"),
8 	T_META_RADAR_COMPONENT_NAME("xnu"),
9 	T_META_RADAR_COMPONENT_VERSION("arm"),
10 	T_META_OWNER("jharmening")
11 	);
12 
13 T_DECL(pmap_call_benchmark, "pmap call overhead benchmark")
14 {
15 	int num_loops = 100000;
16 	dt_stat_time_t s = dt_stat_time_create("average pmap function call overhead for %d calls", num_loops);
17 	while (!dt_stat_stable(s)) {
18 		dt_stat_token start = dt_stat_time_begin(s);
19 		T_QUIET; T_ASSERT_POSIX_SUCCESS(sysctlbyname("kern.pmap_call_overhead_test", NULL, NULL,
20 		    &num_loops, sizeof(num_loops)), "invoke pmap call overhead test sysctl");
21 		dt_stat_time_end_batch(s, num_loops, start);
22 	}
23 	dt_stat_finalize(s);
24 }
25 
26 T_DECL(pmap_page_protect_benchmark, "pmap_page_protect() overhead benchmark")
27 {
28 	struct {
29 		unsigned int num_loops;
30 		unsigned int num_aliases;
31 	} ppo_in;
32 	ppo_in.num_loops = 1000;
33 	uint64_t duration;
34 	size_t duration_size = sizeof(duration);
35 	for (ppo_in.num_aliases = 1; ppo_in.num_aliases <= 128; ppo_in.num_aliases <<= 1) {
36 		T_QUIET; T_ASSERT_POSIX_SUCCESS(sysctlbyname("kern.pmap_page_protect_overhead_test",
37 		    &duration, &duration_size, &ppo_in, sizeof(ppo_in)),
38 		    "invoke pmap_page_protect() overhead test sysctl");
39 		T_LOG("%u-loop duration (in ticks) for %u aliases: %llu", ppo_in.num_loops, ppo_in.num_aliases, duration);
40 	}
41 }
42