-
Notifications
You must be signed in to change notification settings - Fork 9
/
setup.sh
executable file
·173 lines (145 loc) · 4.95 KB
/
setup.sh
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash
# shellcheck disable=SC2317
set -e
# This is called from the on_demand scripts as some CPU settings do not persist across reboots.
setup-cpu () {
if [[ -d /sys/devices/system/cpu/intel_pstate ]]; then
configure-intel
elif [[ -d /sys/devices/system/cpu/cpufreq/boost ]]; then
configure-amd
fi
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/processor_state_control.html#baseline-perf
# > AWS Graviton processors have built-in power saving modes and operate at a fixed frequency. Therefore, they do not provide the ability for the operating system to control C-states and P-states.
}
configure-amd () {
echo 0 | sudo tee /sys/devices/system/cpu/cpufreq/boost
sudo cpupower frequency-set -g performance || echo 'ignoring'
}
configure-intel () {
# Keep commands simple so that they can be copied and pasted from this file with ease.
# TODO: Do we want to limit C-states in grub and rebuild the grub config?
echo 1 | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo
echo 100 | sudo tee /sys/devices/system/cpu/intel_pstate/min_perf_pct
# hwp_dynamic_boost may not exist if disabled at boot time
# (with `intel_pstate=no_hwp` in the kernel command line).
if [[ -r /sys/devices/system/cpu/intel_pstate/hwp_dynamic_boost ]]; then
echo 0 | sudo tee /sys/devices/system/cpu/intel_pstate/hwp_dynamic_boost
fi
echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/energy_performance_preference /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
}
# The linux-tools-common package (a dep of linux-tools-`uname -r`) brings in `perf`.
# https://docs.ruby-lang.org/en/master/contributing/building_ruby_md.html#label-Dependencies
setup-packages () {
sudo apt-get install -y \
autoconf \
bison \
build-essential \
cargo \
gperf \
libffi-dev \
libgdbm-dev \
libgmp-dev \
libncurses5-dev \
libreadline6-dev \
libsqlite3-dev \
libssl-dev \
libyaml-dev \
pkg-config \
ruby \
rustc \
sqlite3 \
zlib1g-dev \
$(if [[ -r /etc/ec2_version ]]; then echo linux-tools-aws linux-tools-"`uname -r`"; fi) \
&& true
# As of 2024-09-24 Ubuntu 24 comes with gcc 13 but a ppa can upgrade it to 14.
# Ubuntu 20 is capable of upgrading to 13.
upgrade-gcc 14
}
upgrade-gcc () {
local version="$1"
if ! dpkg -s gcc-$version; then
if sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && dpkg -S gcc-$version; then
sudo apt-get install -y gcc-$version
fi
fi
if ! update-alternatives --list gcc; then
old=($(dpkg --get-selections | cut -f 1 | grep -E '^gcc-[0-9]+$' | sed 's/gcc-//'))
for i in "${old[@]}"; do
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-$i 50 # --slave /usr/bin/g++ g++ /usr/bin/g++-$i
done
# g++-14 doesn't want to install currently.
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-$version 60 # --slave /usr/bin/g++ g++ /usr/bin/g++-$version
fi
gcc --version
}
setup-repos () {
local dir=${REPOS_DIR:-$HOME/ym}
mkdir -p "$dir"
cd "$dir"
# Setup one clone of ruby/ruby for each "ruby-config" we want to build.
[[ -d prod-yjit ]] || git clone https://github.com/ruby/ruby prod-yjit
[[ -d prev-yjit ]] || git clone --reference prod-yjit --dissociate https://github.com/ruby/ruby prev-yjit
[[ -d stats-yjit ]] || git clone --reference prod-yjit --dissociate https://github.com/ruby/ruby stats-yjit
# In case this script isn't being run from the repo.
[[ -d yjit-metrics ]] || git clone https://github.com/Shopify/yjit-metrics
# Clone raw-benchmark-data for pushing results.
[[ -d raw-benchmark-data ]] || git clone --branch main https://github.com/yjit-raw/benchmark-data raw-benchmark-data
}
setup-ruby-build () {
local dir=${RUBY_BUILD:-$HOME/src/ruby-build}
mkdir -p "${dir%/*}"
if ! [[ -x "$dir/bin/ruby-build" ]]; then
git clone https://github.com/rbenv/ruby-build "$dir"
else
(cd "$dir" && git pull)
fi
PATH=$dir/bin:$PATH
}
setup-ruby () {
local version=3.3.6
local prefix=/usr/local/ruby
local exe="$prefix/bin/ruby"
if ! [[ -x "$exe" ]] || ! "$exe" -e 'exit 1 unless RUBY_VERSION == ARGV[0]' "$version"; then
local user=`id -nu`
# Remove any old version.
sudo rm -rf "$prefix"
# Allow user-level install.
sudo mkdir -p "$prefix"
sudo chown "$user" "$prefix"
setup-ruby-build
ruby-build "$version" "$prefix"
fi
# Put into PATH without any fuss.
for i in ruby gem bundle; do
sudo ln -sf "$prefix/bin/$i" /usr/local/bin/$i
done
}
setup-all () {
setup-cpu
setup-packages
setup-ruby
setup-repos
}
if [[ $(id -u) = 0 ]]; then
echo "Don't run this as root, run it as a user that can sudo" >&2
exit 1
fi
usage=false
while [[ $# -gt 0 ]]; do
cmd="setup-$1"
shift
if type -t "$cmd" >/dev/null; then
set -x
"$cmd"
set +x
else
usage=true
fi
done
if $usage; then
cat <<USAGE >&2
Usage: $0 action...
Where actions are: cpu, packages, ruby, repos, or all
USAGE
exit 1
fi