|
| 1 | +#!/bin/sh |
| 2 | +# Set a machine into benchmarking mode. |
| 3 | +# |
| 4 | +# For native Linux, and Intel-only for now (AMD has a different way of disabling turbo) |
| 5 | +# |
| 6 | +# References: https://llvm.org/docs/Benchmarking.html |
| 7 | + |
| 8 | +PACKAGES=cpupower tuned ss turbostat lscpu lspci ip ethtool jq nginx hitch stunnel iperf3 nuttcp httping git hyperfine |
| 9 | + |
| 10 | +install_packages() |
| 11 | +{ |
| 12 | + # This is for Fedora 42, adapt for your own OS |
| 13 | + sudo dnf install "${PACKAGES}" |
| 14 | +} |
| 15 | + |
| 16 | +stop_services() |
| 17 | +{ |
| 18 | + sudo cp /lib/systemd/system/rescue.target /lib/systemd/system/benchmark.target |
| 19 | + sudo systemctl add-wants benchmark.target sshd.service |
| 20 | + sudo systemctl isolate benchmark.target |
| 21 | + sudo systemctl list-units --state=running |
| 22 | +} |
| 23 | + |
| 24 | +start_services() |
| 25 | +{ |
| 26 | + sudo systemctl isolate multi-user.target |
| 27 | +} |
| 28 | + |
| 29 | +set_cpu() |
| 30 | +{ |
| 31 | + # Prevent frequency-scaling |
| 32 | + sudo cpupower frequency-set -g performance |
| 33 | + |
| 34 | + # Prevent entering C-states to reduce latency and avoid menu governor bugs (there was one recently) |
| 35 | + sudo cpupower idle-set -D 0 |
| 36 | + |
| 37 | + # Disable Turbo Boost for more stable measurements |
| 38 | + # cpupower set --turbo-boost 0 doesn't work when the driver is intel_pstate instead of cpufreq |
| 39 | + sudo sh -c 'echo 1 >/sys/devices/system/cpu/intel_pstate/no_turbo' |
| 40 | + |
| 41 | + sudo cpupower -c all set --perf-bias 0 |
| 42 | + |
| 43 | + # Bring system into a consistent state |
| 44 | + # TODO: switch and reboot between the two |
| 45 | + #sudo tuned-adm profile network-latency |
| 46 | + |
| 47 | + sudo tuned-adm profile network-throughput |
| 48 | + |
| 49 | + # we could use tuned-adm verify, but there is a bug where it tries to read non-existent hung_task_timeout_secs |
| 50 | +} |
| 51 | + |
| 52 | +describe() |
| 53 | +{ |
| 54 | + # Check all the settings we've changed above |
| 55 | + |
| 56 | + # List running processes |
| 57 | + set -x |
| 58 | + sudo systemctl list-units --state=running |
| 59 | + LIBPROC_HIDE_KERNEL=1 ps -ejH |
| 60 | + |
| 61 | + sudo cpupower -c all frequency-info |
| 62 | + sudo cpupower -c all idle-info |
| 63 | + sudo cpupower -c all info |
| 64 | + sudo cat /sys/devices/system/cpu/intel_pstate/no_turbo |
| 65 | + sudo tuned-adm profile_info |
| 66 | + sudo ss -neopatium |
| 67 | + |
| 68 | + lscpu |
| 69 | + sudo turbostat true |
| 70 | + sudo lspci -k |
| 71 | + sudo ip a |
| 72 | + |
| 73 | + for P in /sys/class/net/*; do |
| 74 | + IFACE=$(basename "${P}") |
| 75 | + sudo ethtool "${IFACE}" |
| 76 | + sudo ethtool -k "${IFACE}" |
| 77 | + done |
| 78 | + |
| 79 | + sudo sos report --batch |
| 80 | + |
| 81 | + set +x |
| 82 | +} |
| 83 | + |
| 84 | +open_ports() |
| 85 | +{ |
| 86 | + # iperf3, nuttcp |
| 87 | + for P in 5201 5000 5001 5101 5102 5103 5104; do |
| 88 | + sudo firewall-cmd --add-port "${P}/tcp" |
| 89 | + done |
| 90 | +} |
| 91 | + |
| 92 | +iperf3_server() |
| 93 | +{ |
| 94 | + iperf3 -s |
| 95 | +} |
| 96 | + |
| 97 | +iperf3_client() |
| 98 | +{ |
| 99 | + # TODO: autodetect IP |
| 100 | + iperf3 --json --logfile iperf3.json -c 10.70.58.43 |
| 101 | +} |
| 102 | + |
| 103 | + |
0 commit comments