# 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("for f in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor") print("do") print(" echo performance >$f") print("done") # 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. The workload # ends with a sync command to make sure we include in the timing # all activity needed to actually make the disk reflect the complete # unpacking and removal, rather than some of the work still being # left outstanding to be caught up with later outside the timing. print("(time (tar xzf linux_3.8.0.orig.tar.gz; rm -rf linux-3.8; sync)) 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("for f in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor") print("do") print(" echo ondemand >$f") print("done")