# The following variable controls the number of runs that will # be done in each of the two experimental conditions. repetitions = 20 # Start by making a list of 0s and 1s, which then is randomized. # Before randomization, settings = [0, 0, 0, ..., 1, 1, 1, ...]. settings = repetitions*[0] + repetitions*[1] # Now we shuffle settings into a random order # This makes it the basic schedule of our experimental runs, # at the level of 0s and 1s, without the details of what those mean. import random random.shuffle(settings) # We print out a shell script (to run with bash) that will conduct # the experiment. # First, we print some commands to be done just once, before the runs. # Arrange that timing results show the total elapsed (real) time in # decimal form, as a number of seconds. print "TIMEFORMAT=%R" # Output a heading line indicating what the two columns are in the # CSV (comma separated values) output that this script produces. print "echo buffering,time" # For repeatability's sake, keep the clock rates at their maximum values. # (Any other commands to do just once that enhance repeatability would # go here too.) print "echo performance >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" print "echo performance >/sys/devices/system/cpu/cpu1/cpufreq/scaling_governor" # Now we are ready to loop through the various experimental runs, putting # the appropriate commands for each into the script. for s in settings: # Output the buffering setting to the script's CSV output. print "echo -n "+str(s)+"," # For repeatability's sake, before doing each timing run, # push all deferred output to disk and then drop # from memory all pages and other file-related structures. print "sync" print "echo 3 >/proc/sys/vm/drop_caches" # Put the buffering setting into effect. print "hdparm -q -W"+str(s)+" /dev/sda" # Time a workload consisting of unpacking the Linux source code # and then removing the resulting directory tree. print "(time (tar xjf /usr/src/linux-source-2.6.28.tar.bz2; rm -rf linux-source-2.6.28)) 2>&1" # Now we print out the commands that should go in the script just once # after all the experimental runs are over. # In case the last experimental run left the hard disk buffering turned # off, turn it back on (so the system will run normally hereafter). print "hdparm -q -W1 /dev/sda" # Since we no longer need repeatable performance, we can revert back # to the normal power-savings mode where the clock rate varies. print "echo ondemand >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" print "echo ondemand >/sys/devices/system/cpu/cpu1/cpufreq/scaling_governor"