aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/Benchmarks.md4
-rw-r--r--src/benchmark.py27
-rw-r--r--src/falsesharing.py3
-rw-r--r--src/larson.py3
-rw-r--r--src/loop.py15
-rw-r--r--src/mysql.py3
6 files changed, 32 insertions, 23 deletions
diff --git a/doc/Benchmarks.md b/doc/Benchmarks.md
index 5320582..d747500 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 e5620ae..18934f7 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 859db03..f6375a6 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 6d15d46..736f00a 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 073a0ea..a3a9e1b 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 96904b6..d3eb528 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 = ""