"vscode:/vscode.git/clone" did not exist on "08f2bde4ba1a5ee9f86580c763e39274081d260b"
sysbench_memory.py 5.22 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
31
# 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

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


class SysbenchMemoryBenchmark(node.AppConfig):

    def __init__(
        self,
        disagg_addr: int,
        disagg_size: int,
        disaggregated: bool,
44
45
        time_limit: int,
        num_threads=1
46
47
48
49
50
51
52
53
    ):
        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
54
55
56
57
58
        """
        Time limit for sysbench benchmark in seconds.

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

    # pylint: disable=consider-using-with
    def config_files(self):
        m = {'farmem.ko': open('../images/farmem/farmem.ko', 'rb')}
        return {**m, **super().config_files()}

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

100
        return cmds
101
102
103
104
105
106
107
108


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

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

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

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

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

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

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

        # add to experiments
        experiments.append(e)