memswitch.py 4.72 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
    idx = 0
32
33
    def __init__(self):
        self.addr = []
Hejing Li's avatar
Hejing Li committed
34
35

    def run_cmds(self, node):
36
37
        commands = []
        for addr in self.addr:
38
            commands.append(f'busybox devmem 0x{addr:x} 64 0x{42 + self.idx} ')
39
40
41
            commands.append(f'busybox devmem 0x{addr:x} 64')

        return commands
Hejing Li's avatar
Hejing Li committed
42

43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 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
57
58
59
60
61

for h in ['gk']:
    e = exp.Experiment('memsw-' + h)
    e.checkpoint = False

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
    # 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'
    netmem0.size = 0x40000000
Hejing Li's avatar
Hejing Li committed
86

87
    netmem1 = sim.NetMem()
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
    netmem1.mac = '00:00:00:00:00:05'
    netmem1.name = 'netmem1'
    netmem1.size = 0x40000000

    ###
    node_config0 = node.NodeConfig()
    node_config0.nockp = True
    node_config0.app = MemTest()
    node_config0.app.addr.append(mem0.addr)
    node_config0.app.idx = 0

    node_config1 = node.NodeConfig()
    node_config1.nockp = True
    node_config1.app = MemTest()
    node_config1.app.addr.append(mem0.addr)
    node_config1.app.idx = 1

    node_config2 = node.NodeConfig()
    node_config2.nockp = True
    node_config2.app = MemTest()
    node_config2.app.addr.append(mem0.addr)
    node_config2.app.idx = 2
Hejing Li's avatar
Hejing Li committed
110
111
112
113
114
115
116
117

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

    e.add_network(net)

    if h == 'gk':
118
119
120
121
122
123
        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
124

125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
    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)
157
    netmem1.set_network(net)
Hejing Li's avatar
Hejing Li committed
158
159
160


    experiments.append(e)