diff -r 8a9b86071c15 perf.py --- a/perf.py Fri Dec 04 14:15:34 2015 -0800 +++ b/perf.py Wed Feb 03 10:22:02 2016 +0200 @@ -88,6 +88,24 @@ 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"] + subproc = subprocess.Popen(command, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + out, err = subproc.communicate() + if subproc.returncode != 0: + return False + else: + return True + + 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 +2575,12 @@ " Unladen Swallow binaries. This is useful for" " examining many benchmarks for optimization" " effects.")) + parser.add_option("--affinity", metavar="CPU_MASK", 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 +2599,10 @@ base_cmd_prefix = [base] + base_args changed_cmd_prefix = [changed] + changed_args + if options.affinity and have_taskset(): + base_cmd_prefix = ["taskset", options.affinity] + base_cmd_prefix + changed_cmd_prefix = ["taskset", options.affinity] + changed_cmd_prefix + logging.basicConfig(level=logging.INFO) if options.track_memory: