aboutsummaryrefslogtreecommitdiff
path: root/src/benchmarks/falsesharing.py
blob: 203aeb8b6496bce9608c8c50d722dedfa91d65db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""Definition of the falsesahring benchmark"""

import re

import matplotlib.pyplot as plt
import numpy as np

from src.benchmark import Benchmark

TIME_RE = re.compile("^Time elapsed = (?P<time>\\d*\\.\\d*) seconds.$")


class BenchmarkFalsesharing(Benchmark):
    """Falsesharing benchmark.

    This benchmarks makes small allocations and writes to them multiple
    times. If the allocated objects are on the same cache line the writes
    will be expensive because of cache thrashing.
    """

    def __init__(self):
        self.name = "falsesharing"

        self.cmd = "cache-{bench}{binary_suffix} {threads} 100 8 1000000"

        self.args = {"bench": ["thrash", "scratch"],
                     "threads": Benchmark.scale_threads_for_cpus(2)}

        self.requirements = ["cache-thrash", "cache-scratch"]
        super().__init__()

    def process_output(self, result, stdout, stderr, allocator, perm, verbose):
        result["time"] = TIME_RE.match(stdout).group("time")

    def summary(self):
        # Speedup thrash
        args = self.results["args"]
        nthreads = args["threads"]
        allocators = self.results["allocators"]

        for bench in self.results["args"]["bench"]:
            for allocator in allocators:
                y_vals = []

                single_threaded_perm = self.Perm(bench=bench, threads=1)
                single_threaded = np.mean([float(m["time"])
                                           for m in self.results[allocator][single_threaded_perm]])

                for perm in self.iterate_args_fixed({"bench": bench}, args=args):

                    data = [float(m["time"]) for m in self.results[allocator][perm]]

                    y_vals.append(single_threaded / np.mean(data))

                plt.plot(nthreads, y_vals, marker='.', linestyle='-',
                         label=allocator, color=allocators[allocator]["color"])

            plt.legend()
            plt.xlabel("threads")
            plt.ylabel("speedup")
            plt.title(bench + " speedup")
            plt.savefig(self.name + "." + bench + ".png")
            plt.clf()

        self.plot_fixed_arg("({L1-dcache-load-misses}/{L1-dcache-loads})*100",
                            ylabel="'l1 cache misses in %'",
                            title="'cache misses: ' + arg + ' ' + str(arg_value)",
                            filepostfix="l1-misses",
                            fixed=["bench"])

        self.plot_fixed_arg("({LLC-load-misses}/{LLC-loads})*100",
                            ylabel="'llc cache misses in %'",
                            title="'LLC misses: ' + arg + ' ' + str(arg_value)",
                            filepostfix="llc-misses",
                            fixed=["bench"])


falsesharing = BenchmarkFalsesharing()