"docs/EN/source/vscode:/vscode.git/clone" did not exist on "c47dc6e8287290714769342ae551765e23054183"
sysbench_memory.py 5.38 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
# 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.
"""

28
import simbricks.orchestration.experiment.experiment_environment as env
29
30
31
32
import simbricks.orchestration.experiments as exp
import simbricks.orchestration.nodeconfig as node
import simbricks.orchestration.simulators as sim

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
67
68
69
    def config_files(self, environment: env.ExpEnv):
        m = {
            'farmem.ko':
                open(f'{environment.repodir}/images/farmem/farmem.ko', 'rb')
        }
        return {**m, **super().config_files(environment)}
70
71

    def run_cmds(self, _):
72
73
74
        cmds = [
            'mount -t proc proc /proc', 'mount -t sysfs sysfs /sys', 'free -m'
        ]
75
        if self.disaggregated:
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
            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 += (
98
                f'numactl --membind={1 if self.disaggregated else 0} '
99
                f'--physcpubind={i} {sysbench_cmd} & '
100
            )
101
102
103
        parallel_cmd += 'wait'
        cmds.append(parallel_cmd)

104
        return cmds
105
106
107
108
109
110
111
112


# 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}')

113
        if not mem_type in mem_types:
114
115
            raise NameError(mem_type)

116
117
118
119
        mem = sim.BasicMemDev()
        mem.name = 'mem0'
        mem.addr = 0x2000000000

120
121
        # node config
        node_config = node.NodeConfig()
122
123
        node_config.cores = 1
        node_config.threads = 1
124
        node_config.memory = 4096
125
126
127
128
129
130
131
132
133
134
135
136
137
138
        # 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
        )
139
140
141
142
143
144
        node_config.app = app

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

        host.name = 'host.0'
        e.add_host(host)
        host.wait = True
156
157
        host.mem_latency = host.sync_period = mem.mem_latency = \
            mem.sync_period = 500
158

159
        if mem_type == 'basicmem':
160
161
162
163
164
            host.add_memdev(mem)
            e.add_memdev(mem)

        # add to experiments
        experiments.append(e)