1*043036a2SApple OSS Distributions#!/usr/local/bin/recon 2*043036a2SApple OSS Distributionsrequire 'strict' 3*043036a2SApple OSS Distributions 4*043036a2SApple OSS Distributionslocal benchrun = require 'benchrun' 5*043036a2SApple OSS Distributionslocal perfdata = require 'perfdata' 6*043036a2SApple OSS Distributionslocal sysctl = require 'sysctl' 7*043036a2SApple OSS Distributionslocal csv = require 'csv' 8*043036a2SApple OSS Distributions 9*043036a2SApple OSS Distributionslocal kDefaultNumWrites = 10000000000 10*043036a2SApple OSS Distributions 11*043036a2SApple OSS Distributionslocal benchmark = benchrun.new { 12*043036a2SApple OSS Distributions name = 'xnu.per_cpu_counter', 13*043036a2SApple OSS Distributions version = 1, 14*043036a2SApple OSS Distributions arg = arg, 15*043036a2SApple OSS Distributions modify_argparser = function(parser) 16*043036a2SApple OSS Distributions parser:argument{ 17*043036a2SApple OSS Distributions name = 'path', 18*043036a2SApple OSS Distributions description = 'Path to benchmark binary' 19*043036a2SApple OSS Distributions } 20*043036a2SApple OSS Distributions parser:option{ 21*043036a2SApple OSS Distributions name = '--cpu-workers', 22*043036a2SApple OSS Distributions description = 'Number of cpu workers' 23*043036a2SApple OSS Distributions } 24*043036a2SApple OSS Distributions parser:flag{ 25*043036a2SApple OSS Distributions name = '--through-max-workers', 26*043036a2SApple OSS Distributions description = 'Run benchmark for [1..n] cpu workers' 27*043036a2SApple OSS Distributions } 28*043036a2SApple OSS Distributions parser:flag{ 29*043036a2SApple OSS Distributions name = '--through-max-workers-fast', 30*043036a2SApple OSS Distributions description = 'Run benchmark for [1..2] and each power of four value in [4..n] cpu workers' 31*043036a2SApple OSS Distributions } 32*043036a2SApple OSS Distributions parser:option { 33*043036a2SApple OSS Distributions name = "--num-writes", 34*043036a2SApple OSS Distributions description = "number of writes", 35*043036a2SApple OSS Distributions default = kDefaultNumWrites 36*043036a2SApple OSS Distributions } 37*043036a2SApple OSS Distributions parser:option{ 38*043036a2SApple OSS Distributions name = '--variant', 39*043036a2SApple OSS Distributions description = 'Which benchmark variant to run (scalable, atomic, or racy)', 40*043036a2SApple OSS Distributions default = 'scalable', 41*043036a2SApple OSS Distributions choices = {"scalable", "atomic", "racy"} 42*043036a2SApple OSS Distributions } 43*043036a2SApple OSS Distributions end 44*043036a2SApple OSS Distributions} 45*043036a2SApple OSS Distributions 46*043036a2SApple OSS Distributionsassert(benchmark.opt.path, "No path supplied for fault throughput binary") 47*043036a2SApple OSS Distributions 48*043036a2SApple OSS Distributionslocal ncpus, err = sysctl('hw.logicalcpu_max') 49*043036a2SApple OSS Distributionsassert(ncpus > 0, 'invalid number of logical cpus') 50*043036a2SApple OSS Distributionslocal cpu_workers = tonumber(benchmark.opt.cpu_workers) or ncpus 51*043036a2SApple OSS Distributions 52*043036a2SApple OSS Distributionslocal writes_per_second = perfdata.unit.custom('writes/sec') 53*043036a2SApple OSS Distributionslocal tests = {} 54*043036a2SApple OSS Distributions 55*043036a2SApple OSS Distributionsfunction QueueTest(num_cores) 56*043036a2SApple OSS Distributions table.insert(tests, { 57*043036a2SApple OSS Distributions path = benchmark.opt.path, 58*043036a2SApple OSS Distributions num_cores = num_cores, 59*043036a2SApple OSS Distributions }) 60*043036a2SApple OSS Distributionsend 61*043036a2SApple OSS Distributions 62*043036a2SApple OSS Distributionsif benchmark.opt.through_max_workers then 63*043036a2SApple OSS Distributions for i = 1, cpu_workers do 64*043036a2SApple OSS Distributions QueueTest(i) 65*043036a2SApple OSS Distributions end 66*043036a2SApple OSS Distributionselseif benchmark.opt.through_max_workers_fast then 67*043036a2SApple OSS Distributions local i = 1 68*043036a2SApple OSS Distributions while i <= cpu_workers do 69*043036a2SApple OSS Distributions QueueTest(i) 70*043036a2SApple OSS Distributions -- Always do a run with two threads to see what the first part of 71*043036a2SApple OSS Distributions -- the scaling curve looks like 72*043036a2SApple OSS Distributions -- (and to measure perf on dual core systems). 73*043036a2SApple OSS Distributions if i == 1 and cpu_workers >= 2 then 74*043036a2SApple OSS Distributions QueueTest(i + 1) 75*043036a2SApple OSS Distributions end 76*043036a2SApple OSS Distributions i = i * 4 77*043036a2SApple OSS Distributions end 78*043036a2SApple OSS Distributionselse 79*043036a2SApple OSS Distributions QueueTest(cpu_workers) 80*043036a2SApple OSS Distributionsend 81*043036a2SApple OSS Distributions 82*043036a2SApple OSS Distributionsfor _, test in ipairs(tests) do 83*043036a2SApple OSS Distributions local args = {test.path, benchmark.opt.variant, benchmark.opt.num_writes, test.num_cores, 84*043036a2SApple OSS Distributions echo = true} 85*043036a2SApple OSS Distributions for out in benchmark:run(args) do 86*043036a2SApple OSS Distributions local result = out:match("-----Results-----\n(.*)") 87*043036a2SApple OSS Distributions benchmark:assert(result, "Unable to find result data in output") 88*043036a2SApple OSS Distributions local data = csv.openstring(result, {header = true}) 89*043036a2SApple OSS Distributions for field in data:lines() do 90*043036a2SApple OSS Distributions for k, v in pairs(field) do 91*043036a2SApple OSS Distributions local unit = writes_per_second 92*043036a2SApple OSS Distributions local larger_better = true 93*043036a2SApple OSS Distributions if k == "loss" then 94*043036a2SApple OSS Distributions unit = percentage 95*043036a2SApple OSS Distributions larger_better = false 96*043036a2SApple OSS Distributions end 97*043036a2SApple OSS Distributions benchmark.writer:add_value(k, unit, tonumber(v), { 98*043036a2SApple OSS Distributions [perfdata.larger_better] = larger_better, 99*043036a2SApple OSS Distributions threads = test.num_cores, 100*043036a2SApple OSS Distributions variant = benchmark.opt.variant 101*043036a2SApple OSS Distributions }) 102*043036a2SApple OSS Distributions end 103*043036a2SApple OSS Distributions end 104*043036a2SApple OSS Distributions end 105*043036a2SApple OSS Distributionsend 106*043036a2SApple OSS Distributions 107*043036a2SApple OSS Distributionsbenchmark:finish() 108