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