memswitch.py 6.17 KB
Newer Older
Hejing Li's avatar
Hejing Li committed
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.

import simbricks.orchestration.experiments as exp
import simbricks.orchestration.nodeconfig as node
import simbricks.orchestration.simulators as sim

experiments = []
num_of_netmem =[1, 2, 3, 4]

class MemTest(node.AppConfig):
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

    def __init__(
        self, 
        disagg_addr: int,
        idx: int,
        disagg_size: int,
        disaggregated: bool,
        time_limit: int
    ):
        self.disagg_addr = disagg_addr
        self.idx = idx
        self.disagg_size = disagg_size
        self.disaggregated = disaggregated
        self.time_limit = time_limit

    def config_files(self):
        m = {'farmem.ko': open('../images/farmem/farmem.ko', 'rb')}
        return {**m, **super().config_files()}
Hejing Li's avatar
Hejing Li committed
49
50

    def run_cmds(self, node):
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
        commands = [
            'mount -t proc proc /proc',
            'mount -t sysfs sysfs /sys',
            'free -m',
            (
                f'insmod /tmp/guest/farmem.ko base_addr=0x{self.disagg_addr:x} '
                f'size=0x{self.disagg_size:x} nnid=1 drain_node=1'
            ),
            'free -m',
            'numactl -H',
            (
                f'numactl --membind={1 if self.disaggregated else 0} '
                'sysbench '
                f'--time={self.time_limit} '
                '--validate=on '
                '--histogram=on '
                'memory '
                '--memory-oper=write '
                '--memory-block-size=16M '
                '--memory-access-mode=rnd '
                '--memory-total-size=1K run'
            )
        ]

        # for addr in self.addr:
        #     commands.append(f'busybox devmem 0x{addr:x} 64 0x{42 + self.idx} ')
        #     commands.append(f'busybox devmem 0x{addr:x} 64')
78
79

        return commands
Hejing Li's avatar
Hejing Li committed
80

81
82
83
84
85
86
87
88
89
90
91
92
93
94
# host 0 <-> memnic 0 \         / netmem 0
# host 1 <-> memnic 1 -  Switch 
# host 2 <-> memnic 2 /         \ netmem 1
#
# [netmem 0] and [netmem 1] each has 2 GB memory.
# each host has 1 GB of far memory.
# [host 0] only uses [netmem 0], [host 1] only uses [netmem 1]
# [host 2] has 512 MB at [netmem 0] and 512 MB at [netmem 1] 

# AS_ID,    VADDR_START(include),V  ADDR_END(not include),  MEMNODE_MAC,    PHYS_START
sw_mem_map = [(0, 0, 1024*1024*1024, '00:00:00:00:00:04', 0),
            (1, 0, 1024*1024*1024, '00:00:00:00:00:05', 0),
            (2, 0, 512*1024*1024, '00:00:00:00:00:04', 1024*1024*1024),
            (2, 512*1024*1024, 1024*1024*1024, '00:00:00:00:00:05', 1024*1024*1024)]
Hejing Li's avatar
Hejing Li committed
95

96
for h in ['gk', 'gt']:
Hejing Li's avatar
Hejing Li committed
97
    e = exp.Experiment('memsw-' + h)
98
    e.checkpoint = True
Hejing Li's avatar
Hejing Li committed
99

100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
    # Add three MemNics for each host
    mem0 = sim.MemNIC()
    mem0.name = 'mem0'
    mem0.addr = 0x2000000000 #0x2000000000000000
    mem0.mac = '00:00:00:00:00:01'
    mem0.as_id = 0

    mem1 = sim.MemNIC()
    mem1.name = 'mem1'
    mem1.addr = 0x2000000000 #0x2000000000000000
    mem1.mac = '00:00:00:00:00:02'
    mem1.as_id = 1

    mem2 = sim.MemNIC()
    mem2.name = 'mem2'
    mem2.addr = 0x2000000000 #0x2000000000000000
    mem2.mac = '00:00:00:00:00:03'
    mem2.as_id = 2

    # Add two NetMes
    netmem0 = sim.NetMem()
    netmem0.mac = '00:00:00:00:00:04'
    netmem0.name = 'netmem0'
123
    netmem0.size = 0x80000000
Hejing Li's avatar
Hejing Li committed
124

125
    netmem1 = sim.NetMem()
126
127
    netmem1.mac = '00:00:00:00:00:05'
    netmem1.name = 'netmem1'
128
    netmem1.size = 0x80000000
129
130
131

    ###
    node_config0 = node.NodeConfig()
132
133
134
    node_config0.kcmd_append += 'numa=fake=2'
    #node_config0.nockp = True
    node_config0.app = MemTest(mem0.addr, 0, mem0.size, True, 5)
135
136

    node_config1 = node.NodeConfig()
137
138
139
    node_config1.kcmd_append += 'numa=fake=2'
    #node_config1.nockp = True
    node_config1.app = MemTest(mem1.addr, 1, mem1.size, True, 5)
140
141

    node_config2 = node.NodeConfig()
142
143
144
    node_config2.kcmd_append += 'numa=fake=2'
    #node_config2.nockp = True
    node_config2.app = MemTest(mem2.addr, 2, mem2.size, True, 5)
Hejing Li's avatar
Hejing Li committed
145
146
147
148
149
150
151
152

    net = sim.MemSwitchNet()
    for tp in sw_mem_map:
        net.mem_map.append(tp)

    e.add_network(net)

    if h == 'gk':
153
154
155
156
157
158
        def gem5_kvm(node_config: node.NodeConfig):
            h = sim.Gem5Host(node_config)
            h.cpu_type = 'X86KvmCPU'
            h.variant = 'opt'
            return h
        HostClass = gem5_kvm
Hejing Li's avatar
Hejing Li committed
159

160
161
162
163
164
165
166
167
    if h == 'gt':
        def gem5_timing(node_config: node.NodeConfig):
            h = sim.Gem5Host(node_config)
            h.cpu_type = 'TimingSimpleCPU'
            h.variant = 'opt'
            return h
        HostClass = gem5_timing

168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
    elif h == 'qk':
        HostClass = sim.QemuHost
    
    # Add hosts
    host_0 = HostClass(node_config0)
    host_1 = HostClass(node_config1)
    host_2 = HostClass(node_config2)
  
    host_0.name = 'host.0'
    host_1.name = 'host.1'
    host_2.name = 'host.2'

    e.add_host(host_0)
    e.add_host(host_1)
    e.add_host(host_2)

    host_0.wait = True
    host_1.wait = True
    host_2.wait = True

    mem0.set_network(net)
    mem1.set_network(net)
    mem2.set_network(net)
    e.add_memdev(mem0)
    e.add_memdev(mem1)
    e.add_memdev(mem2)

    host_0.add_memdev(mem0)
    host_1.add_memdev(mem1)
    host_2.add_memdev(mem2)

    netmem0.set_network(net)
200
    netmem1.set_network(net)
Hejing Li's avatar
Hejing Li committed
201
202
203


    experiments.append(e)