common-functions.sh 6.41 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
8
9
10
GEM5_BASE="$EHSIM_BASE/gem5"
NS3_BASE="$EHSIM_BASE/ns-3"

if [ -f local-config.sh ] ; then
    source local-config.sh
11
12
13
fi


14
if [ ! -d "$EHSIM_BASE" ] ; then
15
16
17
18
    echo "\$EHSIM_BASE should be set to the absolute path of the root"\
        "of this repo (local-config.sh)"
    exit 1
fi
19
if [ ! -f "$QEMU_CMD" ] ; then
20
21
22
23
    echo "\$QEMU_CMD should be set to the absolute path to a QEMU instance"\
        "with cosim support (local-config.sh)"
    exit 1
fi
24
25
26
27
28
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
29
30
31
32
33
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
34

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

# Args:
#   - experiment name
init_out() {
43
  export OUTDIR=./out/$1/$2
44
45
  rm -rf $OUTDIR
  mkdir -p $OUTDIR
46
  date > $OUTDIR/starttime
47
48
49
50
51
52
}

# Args:
#   - Instance name
#   - Cosim instance
#   - secondary hard drive
53
#   - [optional primary image name: default ubuntu1804-base]
54
55
56
57
58
59
run_qemu() {
    img_a="$OUTDIR/qemu.hd.a.$1"
    img_b="$OUTDIR/qemu.hd.b.$1"
    pcisock="$OUTDIR/pci.$2"
    rm -f $img_a $img_b
    echo Creating disk for qemu $1
60
    if [ -z "$4" ]; then
61
        $QEMU_IMG create -f qcow2 -o backing_file=$QEMU_IMAGE $img_a
62
    else
63
        $QEMU_IMG create -f qcow2 -o backing_file="$EHSIM_BASE/images/output-$4/$4" $img_a
64
    fi
65
66
    cp $3 $img_b
    echo Starting qemu $1
67
68
    #i40e.debug=0x8fffffff
    #hugepages=1024
69
    $QEMU_CMD -machine q35 -cpu host \
70
71
        -drive file=$img_a,if=ide,index=0,media=disk \
        -drive file=$img_b,if=ide,index=1,media=disk,driver=raw \
72
        -kernel $QEMU_KERNEL \
73
74
        -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 \
75
76
77
78
79
80
81
82
        -nic none \
        -chardev socket,path=$pcisock,id=cosimcd \
        -device cosim-pci,chardev=cosimcd &>$OUTDIR/qemu.$1.log &
    pid=$!
    ALL_PIDS="$ALL_PIDS $pid"
    return $pid
}

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

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

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

124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# Args:
#   - Instance name
run_corundum_verilator() {
    echo Starting corundum_verilator $1
    $EHSIM_BASE/corundum/corundum_verilator \
        $OUTDIR/pci.$1 $OUTDIR/eth.$1 $OUTDIR/shm.$1 \
            &>$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 \
        $OUTDIR/pci.$1 $OUTDIR/eth.$1 $OUTDIR/shm.$1 \
        &>$OUTDIR/corundum_bm.$1.log &
Antoine Kaufmann's avatar
Antoine Kaufmann committed
143
144
145
146
147
148
149
150
151
152
153
154
    pid=$!
    ALL_PIDS="$ALL_PIDS $pid"
    return $pid
}

# Args:
#   - Instance name
run_i40e_bm() {
    echo Starting i40e $1
    $EHSIM_BASE/i40e_bm/i40e_bm \
        $OUTDIR/pci.$1 $OUTDIR/eth.$1 $OUTDIR/shm.$1 \
        &>$OUTDIR/i40e_bm.$1.log &
155
156
157
158
159
160
161
162
163
    pid=$!
    ALL_PIDS="$ALL_PIDS $pid"
    return $pid
}

# Args:
#   - Instance name
#   - sim instance 1
#   - sim instance 2
164
#   - [optional: pcap filename]
165
166
run_wire() {
    echo Starting wire $1
167
168
169
170
171
172
    if [ -z "$4" ]; then
        pcap=
    else
        pcap="$OUTDIR/$4.pcap"
    fi

173
    $EHSIM_BASE/net_wire/net_wire \
174
        $OUTDIR/eth.$2 $OUTDIR/eth.$3 $pcap &>$OUTDIR/wire.$1.log &
175
176
177
178
179
    pid=$!
    ALL_PIDS="$ALL_PIDS $pid"
    return $pid
}

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

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

212
    $NS3_BASE/cosim-run.sh cosim cosim-dumbbell-example \
213
        $ports $4 &>$OUTDIR/ns3_dumbbell.$1.log &
214
215
216
217
218
    pid=$!
    ALL_PIDS="$ALL_PIDS $pid"
    return $pid
}

Jialin Li's avatar
Jialin Li committed
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# Args:
#   - Instance name
#   - Client Port names
#   - Server Port names
#   - Other args
run_ns3_sequencer() {
    ports=""
    for p in $2; do
        epath="`readlink -f $OUTDIR/eth.$p`"
        ports="$ports --ClientPort=$epath"
    done
    for p in $3; do
        epath="`readlink -f $OUTDIR/eth.$p`"
        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
}

242
243
cleanup() {
    echo Cleaning up
244
245
246
247
    for p in $ALL_PIDS ; do
        kill $p &>/dev/null
    done
    sleep 1
248
249
250
    for p in $ALL_PIDS ; do
        kill -KILL $p &>/dev/null
    done
251

252
    rm -f $OUTDIR/{qemu.hd.*,shm.*,pci.*,eth.*}
253
    date >>$OUTDIR/endtime
254
}
255

256
257
258
259
260
261
262
sighandler() {
    echo "Caught Interrupt, aborting...."
    cleanup
    exit 1
}

trap "sighandler" SIGINT