|
1 | 1 | #!/usr/bin/env bash |
2 | 2 |
|
3 | | -# Usage: run.sh TARGET BIN |
4 | | -# Example: run.sh linux server-bw |
5 | | -# run.sh hermit client-bw |
| 3 | +# Usage: run.sh TARGET BIN [--rftrace] [--user-networking] |
| 4 | +# Example: run.sh linux tcp-server-bw |
| 5 | +# run.sh hermit tcp-client-bw |
6 | 6 |
|
7 | 7 | set -o errexit |
8 | 8 |
|
| 9 | +rftrace=false |
| 10 | +user_networking=false |
| 11 | +target= |
| 12 | +bin= |
| 13 | + |
| 14 | +while [[ $# -gt 0 ]]; do |
| 15 | + case "$1" in |
| 16 | + --rftrace) |
| 17 | + rftrace=true |
| 18 | + shift |
| 19 | + ;; |
| 20 | + --user-networking) |
| 21 | + user_networking=true |
| 22 | + shift |
| 23 | + ;; |
| 24 | + -*) |
| 25 | + echo "Unknown option: $1" >&2 |
| 26 | + exit 1 |
| 27 | + ;; |
| 28 | + *) |
| 29 | + if [[ -z "$target" ]]; then |
| 30 | + target="$1" |
| 31 | + elif [[ -z "$bin" ]]; then |
| 32 | + bin="$1" |
| 33 | + else |
| 34 | + echo "Unexpected argument: $1" >&2 |
| 35 | + exit 1 |
| 36 | + fi |
| 37 | + shift |
| 38 | + ;; |
| 39 | + esac |
| 40 | +done |
| 41 | + |
9 | 42 | netbench_dir="${0%/*}" |
10 | 43 | root_dir="$netbench_dir"/../.. |
11 | 44 |
|
12 | | -bin=$2 |
13 | 45 | args="--bytes 1048576 --rounds 1000" |
14 | 46 |
|
15 | 47 | hermit() { |
16 | | - echo "Building $bin image" |
17 | | - |
18 | | - cargo build --manifest-path "$netbench_dir"/Cargo.toml --bin $bin \ |
19 | | - -Zbuild-std=core,alloc,std,panic_abort -Zbuild-std-features=compiler-builtins-mem \ |
20 | | - --target x86_64-unknown-hermit \ |
21 | | - --release |
22 | | - |
23 | | - echo "Launching $bin image on QEMU" |
24 | | - |
25 | | - qemu-system-x86_64 -cpu host \ |
26 | | - -enable-kvm -display none -smp 1 -m 1G -serial stdio \ |
27 | | - -kernel "$root_dir"/kernel/hermit-loader-x86_64 \ |
28 | | - -initrd "$root_dir"/target/x86_64-unknown-hermit/release/$bin \ |
29 | | - -netdev tap,id=net0,ifname=tap10,script=no,downscript=no,vhost=on \ |
30 | | - -device virtio-net-pci,netdev=net0,disable-legacy=on \ |
31 | | - -append "-- --address 10.0.5.1 $args" |
| 48 | + echo "Building $bin image" |
| 49 | + |
| 50 | + rustflags= |
| 51 | + |
| 52 | + cargo_cmd=( |
| 53 | + cargo build |
| 54 | + --manifest-path "$netbench_dir"/Cargo.toml |
| 55 | + --bin "$bin" |
| 56 | + -Zbuild-std=core,alloc,std,panic_abort |
| 57 | + -Zbuild-std-features=compiler-builtins-mem |
| 58 | + --target "$(uname -m)-unknown-hermit" |
| 59 | + --profile release-debug |
| 60 | + ) |
| 61 | + |
| 62 | + features=() |
| 63 | + |
| 64 | + if $rftrace; then |
| 65 | + features+=(rftrace) |
| 66 | + rustflags="-Zinstrument-mcount" |
| 67 | + |
| 68 | + mkdir -p tracedir |
| 69 | + |
| 70 | + sudo /usr/libexec/virtiofsd \ |
| 71 | + --socket-path=/tmp/vhostqemu \ |
| 72 | + --shared-dir=$(pwd)/tracedir \ |
| 73 | + --announce-submounts \ |
| 74 | + --sandbox none \ |
| 75 | + --seccomp none \ |
| 76 | + --inode-file-handles=never & |
| 77 | + sleep 1 |
| 78 | + |
| 79 | + sudo chmod 777 /tmp/vhostqemu |
| 80 | + fi |
| 81 | + |
| 82 | + if $user_networking; then |
| 83 | + features+=(dhcp) |
| 84 | + fi |
| 85 | + |
| 86 | + features_str="${features[*]}" |
| 87 | + cargo_cmd+=(--features "$features_str") |
| 88 | + |
| 89 | + RUSTFLAGS="$rustflags" "${cargo_cmd[@]}" |
| 90 | + |
| 91 | + echo "Launching $bin image on QEMU" |
| 92 | + |
| 93 | + qemu_cmd=( |
| 94 | + qemu-system-$(uname -m) |
| 95 | + -cpu host |
| 96 | + -enable-kvm |
| 97 | + -display none |
| 98 | + -smp 1 |
| 99 | + -m 1G |
| 100 | + -serial stdio |
| 101 | + -kernel "$root_dir/kernel/hermit-loader-$(uname -m)" |
| 102 | + -initrd "$root_dir/target/$(uname -m)-unknown-hermit/release-debug/$bin" |
| 103 | + ) |
| 104 | + |
| 105 | + if $rftrace; then |
| 106 | + qemu_cmd+=( |
| 107 | + -chardev socket,id=char0,path=/tmp/vhostqemu |
| 108 | + -device vhost-user-fs-pci,queue-size=1024,packed=on,chardev=char0,tag=tracedir |
| 109 | + -object memory-backend-file,id=mem,size=1G,mem-path=/dev/shm,share=on |
| 110 | + -numa node,memdev=mem |
| 111 | + ) |
| 112 | + fi |
| 113 | + |
| 114 | + if $user_networking; then |
| 115 | + qemu_cmd+=( |
| 116 | + -netdev user,id=net0,hostfwd=tcp::9975-:9975,hostfwd=udp::9975-:9975,net=192.168.76.0/24,dhcpstart=192.168.76.9 |
| 117 | + -device virtio-net-pci,netdev=net0,disable-legacy=on |
| 118 | + -append "-- --address 127.0.0.1 $args" |
| 119 | + ) |
| 120 | + else |
| 121 | + qemu_cmd+=( |
| 122 | + -netdev tap,id=net0,ifname=tap10,script=no,downscript=no,vhost=on |
| 123 | + -device virtio-net-pci,netdev=net0,disable-legacy=on |
| 124 | + -append "-- --address 10.0.5.1 $args" |
| 125 | + ) |
| 126 | + fi |
| 127 | + |
| 128 | + sudo "${qemu_cmd[@]}" |
| 129 | + |
| 130 | + if $rftrace; then |
| 131 | + sleep 1 |
| 132 | + nm -n "$root_dir"/target/$(uname -m)-unknown-hermit/release-debug/$bin >tracedir/$bin.sym |
| 133 | + uftrace dump -d tracedir --flame-graph >tracedir/flamegraph.txt |
| 134 | + flamegraph.pl tracedir/flamegraph.txt >tracedir/flamegraph.svg |
| 135 | + firefox tracedir/flamegraph.svg |
| 136 | + fi |
32 | 137 | } |
33 | 138 |
|
34 | 139 | linux() { |
35 | | - echo "Launching $bin on linux" |
| 140 | + echo "Launching $bin on linux" |
| 141 | + |
| 142 | + if $user_networking; then |
| 143 | + address=127.0.0.1 |
| 144 | + else |
| 145 | + address=10.0.5.3 |
| 146 | + fi |
36 | 147 |
|
37 | | - cargo run --manifest-path "$netbench_dir"/Cargo.toml --bin $bin \ |
38 | | - --release \ |
39 | | - --target x86_64-unknown-linux-gnu \ |
40 | | - -- \ |
41 | | - --address 10.0.5.3 $args |
| 148 | + cargo run --manifest-path "$netbench_dir"/Cargo.toml --bin $bin \ |
| 149 | + --release \ |
| 150 | + --target $(uname -m)-unknown-linux-gnu \ |
| 151 | + -- \ |
| 152 | + --address $address $args |
42 | 153 | } |
43 | 154 |
|
44 | | -$1 |
| 155 | +$target |
0 commit comments