sysbench_memory.py 5.32 KB
Newer Older
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
# Copyright 2021 Max Planck Institute for Software Systems, and
# National University of Singapore
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
Runs sysbench memory benchmarks for different memory configurations.

Used to compare latency and throughput of disaggregated memory to local one.
"""

import simbricks.orchestration.experiments as exp
import simbricks.orchestration.nodeconfig as node
import simbricks.orchestration.simulators as sim
31
from simbricks.orchestration.experiment.experiment_environment import ExpEnv
32

33
host_types = ['gem5', 'simics']
34
35
36
37
38
39
40
41
42
43
44
mem_types = ['local', 'basicmem']
experiments = []


class SysbenchMemoryBenchmark(node.AppConfig):

    def __init__(
        self,
        disagg_addr: int,
        disagg_size: int,
        disaggregated: bool,
45
46
        time_limit: int,
        num_threads=1
47
48
49
50
51
52
53
54
    ):
        self.disagg_addr = disagg_addr
        """Address of disaggregated memory start."""
        self.disagg_size = disagg_size
        """Size of disaggregated memory."""
        self.disaggregated = disaggregated
        """Whether to use disaggregated memory."""
        self.time_limit = time_limit
55
56
57
58
59
        """
        Time limit for sysbench benchmark in seconds.

        0 to disable limit.
        """
60
61
        self.num_threads = num_threads
        """Number of cores to run the benchmark on in parallel."""
62
63

    # pylint: disable=consider-using-with
64
65
66
    def config_files(self, env: ExpEnv):
        m = {'farmem.ko': open(f'{env.repodir}/images/farmem/farmem.ko', 'rb')}
        return {**m, **super().config_files(env)}
67
68

    def run_cmds(self, _):
69
70
71
        cmds = [
            'mount -t proc proc /proc', 'mount -t sysfs sysfs /sys', 'free -m'
        ]
72
        if self.disaggregated:
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
            cmds.append(
                f'insmod /tmp/guest/farmem.ko '
                f'base_addr=0x{self.disagg_addr:x} '
                f'size=0x{self.disagg_size:x} nnid=1 drain_node=1'
            )
            cmds.append('free -m')
            cmds.append('numactl -H')

        sysbench_cmd = (
            'sysbench '
            f'--time={self.time_limit} '
            '--histogram=on '
            'memory '
            '--memory-oper=read '
            '--memory-block-size=16M '
            '--memory-access-mode=rnd '
            '--memory-total-size=0 run'
        )

        parallel_cmd = str()
        for i in range(self.num_threads):
            parallel_cmd += (
95
                f'numactl --membind={1 if self.disaggregated else 0} '
96
                f'--physcpubind={i} {sysbench_cmd} & '
97
            )
98
99
100
        parallel_cmd += 'wait'
        cmds.append(parallel_cmd)

101
        return cmds
102
103
104
105
106
107
108
109


# Create multiple experiments with different simulator permutations, which can
# be filtered later.
for host_type in host_types:
    for mem_type in mem_types:
        e = exp.Experiment(f'sysbench_memory-{host_type}-{mem_type}')

110
        if not mem_type in mem_types:
111
112
            raise NameError(mem_type)

113
114
115
116
        mem = sim.BasicMemDev()
        mem.name = 'mem0'
        mem.addr = 0x2000000000

117
118
        # node config
        node_config = node.NodeConfig()
119
120
        node_config.cores = 1
        node_config.threads = 1
121
        node_config.memory = 4096
122
123
124
125
126
127
128
129
130
131
132
133
134
135
        # TODO Simics offers no way to extend the kernel command line. Instead,
        # the base image has to be rebuilt to set the following option using
        # GRUB in `images/scripts/install-base.sh`.
        if host_type != 'simics':
            node_config.kcmd_append += 'numa=fake=2'

        # app config
        app = SysbenchMemoryBenchmark(
            mem.addr,
            mem.size,
            mem_type == 'basicmem',
            1,
            node_config.cores * node_config.threads
        )
136
137
138
139
140
141
        node_config.app = app

        # host
        if host_type == 'gem5':
            host = sim.Gem5Host(node_config)
            e.checkpoint = True
142
143
144
145
146
        elif host_type == 'simics':
            host = sim.SimicsHost(node_config)
            host.sync = True
            host.timing = True
            e.checkpoint = True
147
148
149
150
151
152
        else:
            raise NameError(host_type)

        host.name = 'host.0'
        e.add_host(host)
        host.wait = True
153
154
        host.mem_latency = host.sync_period = mem.mem_latency = \
            mem.sync_period = 500
155

156
        if mem_type == 'basicmem':
157
158
159
160
161
            host.add_memdev(mem)
            e.add_memdev(mem)

        # add to experiments
        experiments.append(e)