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