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