diff -r 8a9b86071c15 perf.py --- a/perf.py Fri Dec 04 14:15:34 2015 -0800 +++ b/perf.py Wed Feb 03 15:07:27 2016 +0200 @@ -88,6 +88,25 @@ info = logging.info +def have_taskset(): + """Check if we are running on Linux and if the taskset command is + available. Taskset specifies CPU affinity for a given workload, + meaning that we can run the benchmarks on a given core to minimize + run to run variation. + """ + if (platform.system() == "Linux"): + command = ["taskset", "-V"] + try: + subproc = subprocess.Popen(command, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + out, err = subproc.communicate() + return True + except: + return False + return False + + def interpreter_version(python, _cache={}): """Return the interpreter version for the given Python interpreter. *python* is the base command (as a list) to execute the interpreter. @@ -2557,6 +2576,12 @@ " Unladen Swallow binaries. This is useful for" " examining many benchmarks for optimization" " effects.")) + parser.add_option("--affinity", metavar="CPU_LIST", default=None, + help=("Specify CPU affinity for benchmark runs. This way," + " benchmarks can be forced to run on a given CPU to" + " minimize run to run variation. This is" + " implemented on Linux and uses the taskset" + " command.")) options, args = parser.parse_args(argv) @@ -2575,6 +2600,14 @@ base_cmd_prefix = [base] + base_args changed_cmd_prefix = [changed] + changed_args + if options.affinity: + if not have_taskset(): + raise Exception("Option --affinity not available. Command" + " taskset not found") + taskset_prefix = ["taskset", "--cpu-list", options.affinity] + base_cmd_prefix = taskset_prefix + base_cmd_prefix + changed_cmd_prefix = taskset_prefix + changed_cmd_prefix + logging.basicConfig(level=logging.INFO) if options.track_memory: