diff --git a/doc/Benchmarks.md b/doc/Benchmarks.md index 53205829deffb4c2b03bf033d7f3710b4eab5ded..d74750031b9f354e9eb990fd5f3c9ce06978b6e3 100644 --- a/doc/Benchmarks.md +++ b/doc/Benchmarks.md @@ -54,8 +54,6 @@ Delorie using the tools from dj/malloc branch of the glibc. #### loop.py as Example ```python -import multiprocessing - from src.benchmark import Benchmark @@ -69,7 +67,7 @@ class Benchmark_Loop(Benchmark): self.args = { "maxsize": [2 ** x for x in range(6, 16)], - "nthreads": range(1, multiprocessing.cpu_count() * 2 + 1) + "nthreads": Benchmark.scale_threads_for_cpus(2) } self.requirements = ["loop"] diff --git a/src/benchmark.py b/src/benchmark.py index e5620aeea843142b7181823f0861a54047e819b2..18934f7b2f2f9d700f98ceca489f3b9a605a505d 100644 --- a/src/benchmark.py +++ b/src/benchmark.py @@ -2,6 +2,7 @@ from collections import namedtuple import csv import itertools import matplotlib.pyplot as plt +import multiprocessing import numpy as np import os import pickle @@ -27,6 +28,26 @@ class Benchmark (object): "allocators": allocators, } + @staticmethod + def scale_threads_for_cpus(factor): + cpus = multiprocessing.cpu_count() + max_threads = cpus * factor + steps = 1 + if max_threads > 40: + steps = 2 + if max_threads > 100: + steps = 5 + if max_threads > 200: + steps = 10 + + # Special thread counts + nthreads = set([1, cpus/2, cpus, cpus*factor]) + nthreads.update(range(steps, cpus * factor + 1, steps)) + nthreads = list(nthreads) + nthreads.sort() + + return nthreads + def __init__(self): # Set default values for k in Benchmark.defaults: @@ -48,6 +69,12 @@ class Benchmark (object): if not hasattr(self, "requirements"): self.requirements = [] + print_debug("Creating benchmark", self.name) + print_debug("Cmd:", self.cmd) + print_debug("Args:", self.args) + print_debug("Requirements:", self.requirements) + print_debug("Results dictionary:", self.results) + def save(self, path=None): f = path if path else self.name + ".save" print_info("Saving results to:", self.name + ".save") diff --git a/src/falsesharing.py b/src/falsesharing.py index 859db03bc8c2dfe81bfbea3d0d611759f69a1eeb..f6375a69baf1face0b8f1374df808382933f62aa 100644 --- a/src/falsesharing.py +++ b/src/falsesharing.py @@ -1,5 +1,4 @@ import matplotlib.pyplot as plt -import multiprocessing import numpy as np import re @@ -20,7 +19,7 @@ class Benchmark_Falsesharing(Benchmark): self.args = { "bench": ["thrash", "scratch"], - "threads": range(1, multiprocessing.cpu_count() * 2 + 1) + "threads": Benchmark.scale_threads_for_cpus(2) } self.requirements = ["cache-thrash", "cache-scratch"] diff --git a/src/larson.py b/src/larson.py index 6d15d46463527695c3774f1c4db379e22810cacc..736f00a5e5c8a25ad2c20cb192f6ad89c53c1f94 100644 --- a/src/larson.py +++ b/src/larson.py @@ -1,4 +1,3 @@ -import multiprocessing import re from src.benchmark import Benchmark @@ -19,7 +18,7 @@ class Benchmark_Larson(Benchmark): self.args = { "maxsize": [8, 32, 64, 128, 256, 512, 1024], - "threads": range(1, multiprocessing.cpu_count() * 2 + 1) + "threads": Benchmark.scale_threads_for_cpus(2) } self.requirements = ["larson"] diff --git a/src/loop.py b/src/loop.py index 073a0ea59448c85c89f8bff021cc17eadee74c14..a3a9e1b69132efd25179fdb714b9ed0897d84f4d 100644 --- a/src/loop.py +++ b/src/loop.py @@ -1,5 +1,3 @@ -import multiprocessing - from src.benchmark import Benchmark @@ -11,19 +9,8 @@ class Benchmark_Loop(Benchmark): self.cmd = "loop{binary_suffix} {nthreads} 1000000 {maxsize}" - cpus = multiprocessing.cpu_count() - steps = 1 - if cpus > 20: - steps = 2 - if cpus > 50: - steps = 5 - - # Special thread counts - nthreads = set([1, cpus/2, cpus, cpus*2]) - nthreads.update(range(steps, cpus * 2 + 1, steps)) - self.args = {"maxsize": [2 ** x for x in range(6, 16)], - "nthreads": list(nthreads)} + "nthreads": Benchmark.scale_threads_for_cpus(2)} self.requirements = ["loop"] super().__init__() diff --git a/src/mysql.py b/src/mysql.py index 96904b6f02e97d652bcb33acbcf512059b7077c6..d3eb528a4ffa2c779103c1c0a96b0f46eb7c753d 100644 --- a/src/mysql.py +++ b/src/mysql.py @@ -1,6 +1,5 @@ import copy import matplotlib.pyplot as plt -import multiprocessing import numpy as np import os import re @@ -36,7 +35,7 @@ class Benchmark_MYSQL(Benchmark): if "hoard" in self.allocators: del(self.allocators["hoard"]) - self.args = {"nthreads": range(1, multiprocessing.cpu_count() + 1)} + self.args = {"nthreads": Benchmark.scale_threads_for_cpus(1)} self.cmd = cmd self.measure_cmd = ""