From 7817aecdf972b7f3202d386ae97f2e77663261b9 Mon Sep 17 00:00:00 2001 From: hunt Date: Sun, 26 Mar 2006 22:47:10 +0000 Subject: 2006-03-26 Martin Hunt * bench2/bench.rb (Bench::run): Instead of loading the module once and running against different numbers of threads, load and unload the module each time. Then keep track of failures per thread. Also use the new itest to keep the tests the same size regardless of the number of threads. (Bench::initialize): Make itest if needed. (Bench::load, Stapbench::load): Increase buffer size to 8MB. * bench2/itest.c: Change arg to be the number of threads instead of the number of millions of calls to make. This makes it easy to divide the work among multiple threads without making the test run many times longer. --- runtime/bench2/bench.rb | 53 ++++++++++++++++++++++++++++--------------------- runtime/bench2/itest.c | 9 ++++----- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/runtime/bench2/bench.rb b/runtime/bench2/bench.rb index dbda5e13..3a1efc7c 100644 --- a/runtime/bench2/bench.rb +++ b/runtime/bench2/bench.rb @@ -6,7 +6,7 @@ # Public License (GPL); either version 2, or (at your option) any # later version. -# Where to fine laptop frequency files +# Where to find laptop frequency files MAXFILE = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq" MINFILE = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq" @@ -22,7 +22,7 @@ class Bench @code = nil @file = nil @trans = 1 - @failures = "" + @failures = [] @results = [] if @@printed_header == 0 print_header @@ -34,6 +34,12 @@ class Bench break end end + # now do make + `make` + if $? != 0 || !File.exist?('itest') + puts "ERROR: Compiling itest failed\n" + exit + end end if @@runtime.nil? for path in ['/usr/share/systemtap/runtime', '/usr/local/share/systemtap/runtime'] @@ -54,23 +60,23 @@ class Bench def run compile - load @results = [] - @failures = "" + @failures = [] @@num_threads.each do |threads| - bench = []; sum=0 - threads.times {|cpu| fork {exec "./itest 1 > #{@dir}/bench#{cpu}"}} - threads.times {Process.waitpid(-1)} - threads.times {|x| bench[x] = `cat #{@dir}/bench#{x}`.split[0].to_i - @@ftime} - threads.times {|x| sum = sum + bench[x]} - @results[threads-1] = sum / (threads * threads) - end - `sudo killall -HUP stpd` - sleep 5 - File.open("#{@dir}/xxx.out") do |file| - file.each_line {|line| @failures += line if line =~ /WARNING/} + load + sum=0 + threads.times {|cpu| fork {exec "./itest #{threads} > #{@dir}/bench#{cpu}"}} + threads.times {Process.waitpid(-1)} # wait for itest(s) to exit + `sudo killall -HUP stpd` + Process.wait # wait for stpd to exit + threads.times {|x| sum = sum + `cat #{@dir}/bench#{x}`.split[0].to_i - @@ftime} + @results[threads] = sum / (threads * threads) + File.open("#{@dir}/xxx.out") do |file| + file.each_line do |line| + @failures[threads] = line.match(/were ([\d]*)/)[1] + end + end end - Process.wait cleanup end @@ -87,10 +93,11 @@ class Bench printf(" ") end printf(": %-20s", @desc) - @results.each {|x| printf("\t%d",x) unless x.nil? } + @@num_threads.each {|thread| printf("\t%5d",@results[thread])} printf("\n") - if @failures != "" - printf("%s\n", @failures) + @@num_threads.each do |thread| + printf("WARNING: %d transport failures with %d threads\n", \ + @failures[thread], thread) unless @failures[thread].nil? end end end @@ -121,7 +128,7 @@ class Bench end def load - args = "-rmq" + args = "-rmq -b 8" if @trans == RELAYFS then args = "-mq" end fork do exec "sudo #{@@stpd} #{args} #{@dir}/bench.ko > #{@dir}/xxx 2> #{@dir}/xxx.out" end sleep 5 @@ -218,14 +225,14 @@ obj-m := bench.o end puts "-"*64 check_cpuspeed - @@ftime = `./itest 5`.to_i + @@ftime = `./itest 1`.to_i puts "For comparison, function call overhead is #@@ftime nsecs." puts "Times below are nanoseconds per probe and include kprobe overhead." puts "-"*64 puts "+--- S = Script, R = Runtime" puts "|+-- * = Relayfs \tThreads" printf "|| NAME " - @@num_threads.each {|n| printf("\t%d",n)} + @@num_threads.each {|n| printf("\t %d",n)} printf "\n" end @@ -256,7 +263,7 @@ class Stapbench < Bench cleanup exit end - args = "-rmq" + args = "-rmq -b 8" if @trans == RELAYFS then args = "-mq" end fork do exec "sudo #{@@stpd} #{args} #{@dir}/bench.ko > #{@dir}/xxx 2> #{@dir}/xxx.out" end sleep 5 diff --git a/runtime/bench2/itest.c b/runtime/bench2/itest.c index dc385567..efba623a 100644 --- a/runtime/bench2/itest.c +++ b/runtime/bench2/itest.c @@ -28,7 +28,7 @@ uint64 stop() void usage(char *name) { - printf ("Usage %s [time]\nWhere \"time\" is millions of times to loop.\n", name); + printf ("Usage %s [num_threads]\nitest will call sys_getuid() 1000000/num_threads times.\n", name); exit(1); } @@ -42,16 +42,15 @@ int main(int argc, char *argv[]) if (argc == 2) { n = strtol(argv[1], NULL, 10); - if (n == 0) + if (n <= 0) usage(argv[0]); } - start(); - for (i = 0; i < n * 1000000; i++) + for (i = 0; i < 1000000/n; i++) getuid(); - nsecs = stop() / (n * 1000); + nsecs = stop() * n / 1000; /* returns nanosecs per call */ printf("%lld\n", nsecs); -- cgit