1*94d3b452SApple OSS Distributions#!/usr/local/bin/recon 2*94d3b452SApple OSS Distributions 3*94d3b452SApple OSS Distributionslocal benchrun = require 'benchrun' 4*94d3b452SApple OSS Distributionslocal csv = require 'csv' 5*94d3b452SApple OSS Distributionslocal os = require 'os' 6*94d3b452SApple OSS Distributionslocal perfdata = require 'perfdata' 7*94d3b452SApple OSS Distributionslocal sysctl = require 'sysctl' 8*94d3b452SApple OSS Distributions 9*94d3b452SApple OSS Distributionsrequire 'strict' 10*94d3b452SApple OSS Distributions 11*94d3b452SApple OSS Distributionslocal benchmark = benchrun.new({ 12*94d3b452SApple OSS Distributions name = 'xnu.zero_fill_fault_throughput', 13*94d3b452SApple OSS Distributions version = 1, 14*94d3b452SApple OSS Distributions arg = arg, 15*94d3b452SApple OSS Distributions modify_argparser = function(parser) 16*94d3b452SApple OSS Distributions parser:option{ 17*94d3b452SApple OSS Distributions name = '--cpu-workers', 18*94d3b452SApple OSS Distributions description = 'Number of threads to bring up to do faulting work', 19*94d3b452SApple OSS Distributions convert = tonumber, 20*94d3b452SApple OSS Distributions argname = 'count', 21*94d3b452SApple OSS Distributions } 22*94d3b452SApple OSS Distributions parser:flag{ 23*94d3b452SApple OSS Distributions name = '--through-max-workers', 24*94d3b452SApple OSS Distributions description = 'Run with [1..n] CPU workers', 25*94d3b452SApple OSS Distributions } 26*94d3b452SApple OSS Distributions parser:flag{ 27*94d3b452SApple OSS Distributions name = '--through-max-workers-fast', 28*94d3b452SApple OSS Distributions description = 'Run with 1, 2, and each power of four value in [4..n] CPU workers', 29*94d3b452SApple OSS Distributions } 30*94d3b452SApple OSS Distributions parser:option{ 31*94d3b452SApple OSS Distributions name = '--path', 32*94d3b452SApple OSS Distributions description = 'Path to fault throughput binary', 33*94d3b452SApple OSS Distributions count = 1, -- This is a required option. 34*94d3b452SApple OSS Distributions } 35*94d3b452SApple OSS Distributions parser:option{ 36*94d3b452SApple OSS Distributions name = '--duration', 37*94d3b452SApple OSS Distributions description = 'How long, in seconds, to run each iteration', 38*94d3b452SApple OSS Distributions default = 30, 39*94d3b452SApple OSS Distributions convert = tonumber, 40*94d3b452SApple OSS Distributions argname = 'seconds', 41*94d3b452SApple OSS Distributions } 42*94d3b452SApple OSS Distributions parser:option{ 43*94d3b452SApple OSS Distributions name = '--variant', 44*94d3b452SApple OSS Distributions description = 'Which benchmark variant to run', 45*94d3b452SApple OSS Distributions choices = { 'separate-objects', 'share-objects' }, 46*94d3b452SApple OSS Distributions default = 'separate-objects', 47*94d3b452SApple OSS Distributions argname = 'name', 48*94d3b452SApple OSS Distributions } 49*94d3b452SApple OSS Distributions parser:option{ 50*94d3b452SApple OSS Distributions name = '--first-cpu', 51*94d3b452SApple OSS Distributions description = 'Pin threads to CPUs, starting with this CPU ID; requires enable_skstb=1 boot-arg', 52*94d3b452SApple OSS Distributions default = -1, 53*94d3b452SApple OSS Distributions convert = tonumber, 54*94d3b452SApple OSS Distributions argname = 'cpu-id' 55*94d3b452SApple OSS Distributions } 56*94d3b452SApple OSS Distributions parser:flag{ 57*94d3b452SApple OSS Distributions name = '--verbose', 58*94d3b452SApple OSS Distributions description = 'Enable verbose logging at a performance cost', 59*94d3b452SApple OSS Distributions } 60*94d3b452SApple OSS Distributions end, 61*94d3b452SApple OSS Distributions}) 62*94d3b452SApple OSS Distributions 63*94d3b452SApple OSS Distributionslocal ncpus, _ = sysctl('hw.logicalcpu_max') 64*94d3b452SApple OSS Distributionsbenchmark:assert(ncpus > 0, 'invalid number of logical CPUs') 65*94d3b452SApple OSS Distributionslocal cpu_workers = benchmark.opt.cpu_workers or ncpus 66*94d3b452SApple OSS Distributionsbenchmark:assert(cpu_workers > 0, 'invalid number of CPU workers') 67*94d3b452SApple OSS Distributions 68*94d3b452SApple OSS Distributionsbenchmark:assert(benchmark.opt.first_cpu > -2, 'negative first CPU') 69*94d3b452SApple OSS Distributionsbenchmark:assert(benchmark.opt.first_cpu < ncpus, 'invalid first CPU') 70*94d3b452SApple OSS Distributions 71*94d3b452SApple OSS Distributionslocal page_throughput_unit = perfdata.unit.custom('pages/sec') 72*94d3b452SApple OSS Distributions 73*94d3b452SApple OSS Distributionslocal test_threads = {} 74*94d3b452SApple OSS Distributions 75*94d3b452SApple OSS Distributionsif benchmark.opt.through_max_workers then 76*94d3b452SApple OSS Distributions for i = 1, cpu_workers do 77*94d3b452SApple OSS Distributions table.insert(test_threads, i) 78*94d3b452SApple OSS Distributions end 79*94d3b452SApple OSS Distributionselseif benchmark.opt.through_max_workers_fast then 80*94d3b452SApple OSS Distributions local i = 1 81*94d3b452SApple OSS Distributions while i <= cpu_workers do 82*94d3b452SApple OSS Distributions table.insert(test_threads, i) 83*94d3b452SApple OSS Distributions -- Always do a run with two threads to see what the first part of the 84*94d3b452SApple OSS Distributions -- scaling curve looks like (and to measure perf on dual core systems). 85*94d3b452SApple OSS Distributions if i == 1 and cpu_workers >= 2 then 86*94d3b452SApple OSS Distributions table.insert(test_threads, i + 1) 87*94d3b452SApple OSS Distributions end 88*94d3b452SApple OSS Distributions i = i * 4 89*94d3b452SApple OSS Distributions end 90*94d3b452SApple OSS Distributionselse 91*94d3b452SApple OSS Distributions table.insert(test_threads, cpu_workers) 92*94d3b452SApple OSS Distributionsend 93*94d3b452SApple OSS Distributions 94*94d3b452SApple OSS Distributionsfor _, thread_count in ipairs(test_threads) do 95*94d3b452SApple OSS Distributions local cmd = { 96*94d3b452SApple OSS Distributions benchmark.opt.path; 97*94d3b452SApple OSS Distributions echo = true, 98*94d3b452SApple OSS Distributions name = ('with %d CPU workers%s'):format(thread_count, 99*94d3b452SApple OSS Distributions thread_count == 1 and '' or 's'), 100*94d3b452SApple OSS Distributions } 101*94d3b452SApple OSS Distributions if benchmark.opt.verbose then 102*94d3b452SApple OSS Distributions cmd[#cmd + 1] = '-v' 103*94d3b452SApple OSS Distributions end 104*94d3b452SApple OSS Distributions cmd[#cmd + 1] = benchmark.opt.variant 105*94d3b452SApple OSS Distributions cmd[#cmd + 1] = benchmark.opt.duration 106*94d3b452SApple OSS Distributions cmd[#cmd + 1] = thread_count 107*94d3b452SApple OSS Distributions if benchmark.opt.first_cpu ~= -1 then 108*94d3b452SApple OSS Distributions cmd[#cmd + 1] = benchmark.opt.first_cpu 109*94d3b452SApple OSS Distributions end 110*94d3b452SApple OSS Distributions 111*94d3b452SApple OSS Distributions for out in benchmark:run(cmd) do 112*94d3b452SApple OSS Distributions local result = out:match('-----Results-----\n(.*)') 113*94d3b452SApple OSS Distributions benchmark:assert(result, 'unable to find result data in output') 114*94d3b452SApple OSS Distributions local data = csv.openstring(result, { header = true }) 115*94d3b452SApple OSS Distributions for field in data:lines() do 116*94d3b452SApple OSS Distributions for k, v in pairs(field) do 117*94d3b452SApple OSS Distributions benchmark.writer:add_value(k, page_throughput_unit, tonumber(v), { 118*94d3b452SApple OSS Distributions [perfdata.larger_better] = true, 119*94d3b452SApple OSS Distributions threads = thread_count, 120*94d3b452SApple OSS Distributions variant = benchmark.opt.variant 121*94d3b452SApple OSS Distributions }) 122*94d3b452SApple OSS Distributions end 123*94d3b452SApple OSS Distributions end 124*94d3b452SApple OSS Distributions end 125*94d3b452SApple OSS Distributionsend 126*94d3b452SApple OSS Distributions 127*94d3b452SApple OSS Distributionsbenchmark:finish() 128