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