common-functions.sh 6.7 KB
Newer Older
1
2
#!/bin/bash

3
4
EHSIM_BASE="$(readlink -f $(dirname ${BASH_SOURCE[0]})/..)"
QEMU_CMD="$EHSIM_BASE/qemu/x86_64-softmmu/qemu-system-x86_64"
5
QEMU_IMG="$EHSIM_BASE/qemu/qemu-img"
6
7
GEM5_BASE="$EHSIM_BASE/gem5"
NS3_BASE="$EHSIM_BASE/ns-3"
8
9
OUTDIR_BASE="$EHSIM_BASE/experiments/out"
WORKDIR_BASE="$OUTDIR_BASE"
10
11
12

if [ -f local-config.sh ] ; then
    source local-config.sh
13
14
15
fi


16
if [ ! -d "$EHSIM_BASE" ] ; then
17
18
19
20
    echo "\$EHSIM_BASE should be set to the absolute path of the root"\
        "of this repo (local-config.sh)"
    exit 1
fi
21
if [ ! -f "$QEMU_CMD" ] ; then
22
23
24
25
    echo "\$QEMU_CMD should be set to the absolute path to a QEMU instance"\
        "with cosim support (local-config.sh)"
    exit 1
fi
26
27
28
29
30
if [ ! -d "$GEM5_BASE" ] ; then
    echo "\$GEM5_BASE should be set to the absolute path to a built gem5 repo"\
        "(local-config.sh)"
    exit 1
fi
31
32
33
34
35
if [ ! -d "$NS3_BASE" ] ; then
    echo "\$NS3_BASE should be set to the absolute path to a built ns3 repo"\
        "(local-config.sh)"
    exit 1
fi
36

37
QEMU_IMAGE=$EHSIM_BASE/images/output-base/base
38
QEMU_KERNEL=$EHSIM_BASE/images/bzImage
39
GEM5_IMAGE=$EHSIM_BASE/images/output-base/base.raw
40
GEM5_KERNEL=$EHSIM_BASE/images/vmlinux
41
42
43
44

# Args:
#   - experiment name
init_out() {
45
46
47
48
  export OUTDIR=$OUTDIR_BASE/$1/$2
  export WORKDIR=$WORKDIR_BASE/$1/$2
  rm -rf $OUTDIR $WORKDIR
  mkdir -p $OUTDIR $WORKDIR
49
  date > $OUTDIR/starttime
50
51
52
53
54
55
}

# Args:
#   - Instance name
#   - Cosim instance
#   - secondary hard drive
56
#   - [optional primary image name: default ubuntu1804-base]
57
#   - [optional: additinoal qemu arguments]
58
run_qemu() {
59
60
61
    img_a="$WORKDIR/qemu.hd.a.$1"
    img_b="$WORKDIR/qemu.hd.b.$1"
    pcisock="$WORKDIR/pci.$2"
62
63
    rm -f $img_a $img_b
    echo Creating disk for qemu $1
64
    if [ -z "$4" ]; then
65
        $QEMU_IMG create -f qcow2 -o backing_file=$QEMU_IMAGE $img_a
66
    else
67
        $QEMU_IMG create -f qcow2 -o backing_file="$EHSIM_BASE/images/output-$4/$4" $img_a
68
    fi
69
70
    cp $3 $img_b
    echo Starting qemu $1
71
72
    #i40e.debug=0x8fffffff
    #hugepages=1024
73
    $QEMU_CMD -machine q35 -cpu host \
74
75
        -drive file=$img_a,if=ide,index=0,media=disk \
        -drive file=$img_b,if=ide,index=1,media=disk,driver=raw \
76
        -kernel $QEMU_KERNEL \
77
78
        -append "earlyprintk=ttyS0 console=ttyS0 root=/dev/sda1 init=/home/ubuntu/guestinit.sh rw" \
        -serial mon:stdio -m $((16 * 1024)) -smp 1 -display none -enable-kvm \
79
80
        -nic none \
        -chardev socket,path=$pcisock,id=cosimcd \
81
82
        -device cosim-pci,chardev=cosimcd \
        $5 &>$OUTDIR/qemu.$1.log &
83
84
85
86
87
    pid=$!
    ALL_PIDS="$ALL_PIDS $pid"
    return $pid
}

88
89
90
91
92
93
94
# Args:
#   - Instance name
#   - Cosim instance
#   - secondary hard drive
#   - cpu type
#   - checkpoint dir
#   - extra flags
95
#   - [optional primary image name: default ubuntu1804-base]
96
97
run_gem5() {
    echo Starting gem5 $1
98
99
100
    pcisock="$WORKDIR/pci.$2"
    shm="$WORKDIR/shm.$2"
    cpdir="$WORKDIR/../checkpoint/checkpoints.$5"
101
    mkdir -p $cpdir
102
103
104
105
106
107
108

    if [ -z "$7" ]; then
        img="$GEM5_IMAGE"
    else
        img="$EHSIM_BASE/images/output-$7/$7.raw"
    fi

109
110
111
    $GEM5_BASE/build/X86/gem5.opt \
        --outdir=$OUTDIR/gem5.out.$1 \
        $GEM5_BASE/configs/cosim/cosim.py \
112
        --caches --l2cache --l3cache\
113
114
115
        --l1d_size=32kB \
        --l1i_size=32kB \
        --l2_size=2MB \
116
        --l3_size=32MB \
117
        --cacheline_size=64 \
118
        --cpu-clock=3GHz \
Hejing Li's avatar
Hejing Li committed
119
        --kernel=$GEM5_KERNEL --disk-image=$img --disk-image=$3 \
120
        --cpu-type=$4 --mem-size=16GB --cosim-pci=$pcisock --cosim-shm=$shm \
121
        --ddio-enabled --ddio-way-part=8 --mem-type=DDR4_2400_16x4 \
122
123
124
125
126
127
128
        --checkpoint-dir="$cpdir" $6 \
        &>$OUTDIR/gem5.$1.log &
    pid=$!
    ALL_PIDS="$ALL_PIDS $pid"
    return $pid
}

129
130
131
132
133
# Args:
#   - Instance name
run_corundum_verilator() {
    echo Starting corundum_verilator $1
    $EHSIM_BASE/corundum/corundum_verilator \
134
        $WORKDIR/pci.$1 $WORKDIR/eth.$1 $WORKDIR/shm.$1 \
135
136
137
138
139
140
141
142
143
144
145
            &>$OUTDIR/corundum_verilator.$1.log &
    pid=$!
    ALL_PIDS="$ALL_PIDS $pid"
    return $pid
}

# Args:
#   - Instance name
run_corundum_bm() {
    echo Starting corundum_bm $1
    $EHSIM_BASE/corundum_bm/corundum_bm \
146
        $WORKDIR/pci.$1 $WORKDIR/eth.$1 $WORKDIR/shm.$1 \
147
        &>$OUTDIR/corundum_bm.$1.log &
Antoine Kaufmann's avatar
Antoine Kaufmann committed
148
149
150
151
152
153
154
155
156
157
    pid=$!
    ALL_PIDS="$ALL_PIDS $pid"
    return $pid
}

# Args:
#   - Instance name
run_i40e_bm() {
    echo Starting i40e $1
    $EHSIM_BASE/i40e_bm/i40e_bm \
158
        $WORKDIR/pci.$1 $WORKDIR/eth.$1 $WORKDIR/shm.$1 \
Antoine Kaufmann's avatar
Antoine Kaufmann committed
159
        &>$OUTDIR/i40e_bm.$1.log &
160
161
162
163
164
165
166
167
168
    pid=$!
    ALL_PIDS="$ALL_PIDS $pid"
    return $pid
}

# Args:
#   - Instance name
#   - sim instance 1
#   - sim instance 2
169
#   - [optional: pcap filename]
170
171
run_wire() {
    echo Starting wire $1
172
173
174
175
176
177
    if [ -z "$4" ]; then
        pcap=
    else
        pcap="$OUTDIR/$4.pcap"
    fi

178
    $EHSIM_BASE/net_wire/net_wire \
179
        $WORKDIR/eth.$2 $WORKDIR/eth.$3 $pcap &>$OUTDIR/wire.$1.log &
180
181
182
183
184
    pid=$!
    ALL_PIDS="$ALL_PIDS $pid"
    return $pid
}

185
186
187
188
189
190
# Args:
#   - Instance name
#   - Port names
run_ns3_bridge() {
    ports=""
    for p in $2; do
191
        epath="`readlink -f $WORKDIR/eth.$p`"
192
193
        ports="$ports --CosimPort=$epath"
    done
194
    $NS3_BASE/cosim-run.sh cosim cosim-bridge-example \
195
196
197
198
199
200
        $ports &>$OUTDIR/ns3_bridge.$1.log &
    pid=$!
    ALL_PIDS="$ALL_PIDS $pid"
    return $pid
}

201
202
203
204
205
206
207
208
# Args:
#   - Instance name
#   - Left Port names
#   - Right Port names
#   - Other args
run_ns3_dumbbell() {
    ports=""
    for p in $2; do
209
        epath="`readlink -f $WORKDIR/eth.$p`"
210
211
212
        ports="$ports --CosimPortLeft=$epath"
    done
    for p in $3; do
213
        epath="`readlink -f $WORKDIR/eth.$p`"
214
215
216
        ports="$ports --CosimPortRight=$epath"
    done

217
    $NS3_BASE/cosim-run.sh cosim cosim-dumbbell-example \
218
        $ports $4 &>$OUTDIR/ns3_dumbbell.$1.log &
219
220
221
222
223
    pid=$!
    ALL_PIDS="$ALL_PIDS $pid"
    return $pid
}

Jialin Li's avatar
Jialin Li committed
224
225
226
227
228
229
230
231
# Args:
#   - Instance name
#   - Client Port names
#   - Server Port names
#   - Other args
run_ns3_sequencer() {
    ports=""
    for p in $2; do
232
        epath="`readlink -f $WORKDIR/eth.$p`"
Jialin Li's avatar
Jialin Li committed
233
234
235
        ports="$ports --ClientPort=$epath"
    done
    for p in $3; do
236
        epath="`readlink -f $WORKDIR/eth.$p`"
Jialin Li's avatar
Jialin Li committed
237
238
239
240
241
242
243
244
245
246
        ports="$ports --ServerPort=$epath"
    done

    $NS3_BASE/cosim-run.sh sequencer sequencer-single-switch-example \
        $ports $4 &>$OUTDIR/ns3_sequencer.$1.log &
    pid=$!
    ALL_PIDS="$ALL_PIDS $pid"
    return $pid
}

247
248
cleanup() {
    echo Cleaning up
249
250
251
252
    for p in $ALL_PIDS ; do
        kill $p &>/dev/null
    done
    sleep 1
253
254
255
    for p in $ALL_PIDS ; do
        kill -KILL $p &>/dev/null
    done
256

257
258
259
260
261
    if [ "$OUTDIR" != "$WORKDIR" ]; then
        rm -rf $WORKDIR
    else
        rm -f $WORKDIR/{qemu.hd.*,shm.*,pci.*,eth.*}
    fi
262
    date >>$OUTDIR/endtime
263
}
264

265
266
267
268
269
270
271
sighandler() {
    echo "Caught Interrupt, aborting...."
    cleanup
    exit 1
}

trap "sighandler" SIGINT