4 local benchrun = require 'benchrun'
5 local perfdata = require 'perfdata'
6 local sysctl = require 'sysctl'
7 local csv = require 'csv'
9 local kDefaultNumWrites = 10000000000
11 local benchmark = benchrun.new {
12 name = 'xnu.per_cpu_counter',
15 modify_argparser = function(parser)
18 description = 'Path to benchmark binary'
21 name = '--cpu-workers',
22 description = 'Number of cpu workers'
25 name = '--through-max-workers',
26 description = 'Run benchmark for [1..n] cpu workers'
29 name = '--through-max-workers-fast',
30 description = 'Run benchmark for [1..2] and each power of four value in [4..n] cpu workers'
33 name = "--num-writes",
34 description = "number of writes",
35 default = kDefaultNumWrites
39 description = 'Which benchmark variant to run (scalable, atomic, or racy)',
41 choices = {"scalable", "atomic", "racy"}
46 assert(benchmark.opt.path, "No path supplied for fault throughput binary")
48 local ncpus, err = sysctl('hw.logicalcpu_max')
49 assert(ncpus > 0, 'invalid number of logical cpus')
50 local cpu_workers = tonumber(benchmark.opt.cpu_workers) or ncpus
52 local writes_per_second = perfdata.unit.custom('writes/sec')
55 function QueueTest(num_cores)
57 path = benchmark.opt.path,
58 num_cores = num_cores,
62 if benchmark.opt.through_max_workers then
63 for i = 1, cpu_workers do
66 elseif benchmark.opt.through_max_workers_fast then
68 while i <= cpu_workers do
70 -- Always do a run with two threads to see what the first part of
71 -- the scaling curve looks like
72 -- (and to measure perf on dual core systems).
73 if i == 1 and cpu_workers >= 2 then
79 QueueTest(cpu_workers)
82 for _, test in ipairs(tests) do
83 local args = {test.path, benchmark.opt.variant, benchmark.opt.num_writes, test.num_cores,
85 for out in benchmark:run(args) do
86 local result = out:match("-----Results-----\n(.*)")
87 benchmark:assert(result, "Unable to find result data in output")
88 local data = csv.openstring(result, {header = true})
89 for field in data:lines() do
90 for k, v in pairs(field) do
91 local unit = writes_per_second
92 local larger_better = true
97 benchmark.writer:add_value(k, unit, tonumber(v), {
98 [perfdata.larger_better] = larger_better,
99 threads = test.num_cores,
100 variant = benchmark.opt.variant