-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfirst_run.sh
executable file
·217 lines (190 loc) · 6.8 KB
/
first_run.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/bin/bash -e
#
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(©) 2024 Intel Corporation
# Intel® Tiber™ Broadcast Suite
#
set -eo pipefail
SCRIPT_DIR="$(readlink -f "$(dirname -- "${BASH_SOURCE[0]}")")"
. "${SCRIPT_DIR}/scripts/common.sh"
TIBER_STACK_DEBUG="${TIBER_STACK_DEBUG:-1}" # (future) Force where possible instead of try to configure
rm -f /tmp/kahawai_lcore.lock # Remove MtlManager legacy indicator/switch if exists
print_logo_anim # Print intel animated terminal logo
function setup_jq_package()
{
local PM=""
prompt 'Starting setup jq package sequence.'
if [[ -x "$(command -v jq)" ]]; then
prompt 'Found jq package installed and PATH available.'
return 0
fi
PM="$(setup_package_manager)" || exit 1
$PM update && $PM install -y jq && return 0
error "Got non zero return code from '$PM update && $PM install -y jq && return 0'"
return 1
}
function add_fstab_line()
{
ADD_LINE_STRING="${1:-nodev /hugepages hugetlbfs pagesize=1GB 0 0}"
grep "${ADD_LINE_STRING}" || echo -e "\n${ADD_LINE_STRING}" >> /etc/fstab
}
function copy_nicctl_script()
{
local script_result=""
script_result="0"
prompt 'Starting copy_nicctl_script sequence.'
if [ ! -f "/usr/local/bin/nicctl.sh" ]; then
docker create --name mtl-tmp mtl-manager:latest 2>&1 && \
docker cp mtl-tmp:/home/mtl/nicctl.sh /usr/local/bin 2>&1 && \
docker rm mtl-tmp 2>&1
script_result="$?"
fi
if [ "$script_result" != "0" ]; then
. versions.env 2>&1 &&
STRIPPED_VER=${MTL_VER#v} 2>&1 &&
wget -O /usr/local/bin/nicctl.sh https://raw.githubusercontent.com/OpenVisualCloud/Media-Transport-Library/refs/heads/maint-"${STRIPPED_VER}"/script/nicctl.sh 2>&1 &&
chmod +x /usr/local/bin/nicctl.sh 2>&1
script_result="$?"
fi
if [ "$script_result" == "0" ]; then
prompt 'Finished copy_nicctl_script sequence. Success.'
return 0
fi
error 'Finished copy_nicctl_script sequence.'
return 1
}
function setup_vfio_subsytem()
{
prompt 'Starting setup_vfio_subsytem sequence.'
if [[ "${TIBER_STACK_DEBUG}" != "0" ]]; then
getent group 2110 > /dev/null || groupadd -g 2110 vfio
usermod -aG vfio "$USER"
touch /etc/udev/rules.d/10-vfio.rules
if ! grep -q '^SUBSYSTEM=="vfio", GROUP="vfio"' /etc/udev/rules.d/10-vfio.rules; then
echo 'SUBSYSTEM=="vfio", GROUP="vfio", MODE="0660"' >> /etc/udev/rules.d/10-vfio.rules
udevadm control --reload-rules
udevadm trigger
fi
else
chmod 777 -R /dev/vfio
fi
prompt 'Finished setup_vfio_subsytem sequence. Success'
}
function setup_hugepages()
{
prompt 'Starting setup_hugepages sequence.'
mkdir -p /tmp/hugepages /hugepages
# lsmem --json | jq '.memory[].size'
for pt in /sys/devices/system/node/node*
do
# sysctl -w vm.nr_hugepages=4096
echo 2048 > "$pt/hugepages/hugepages-2048kB/nr_hugepages";
echo 1 > "$pt/hugepages/hugepages-1048576kB/nr_hugepages";
done
mount -t hugetlbfs hugetlbfs /tmp/hugepages -o pagesize=2M
mount -t hugetlbfs hugetlbfs /hugepages -o pagesize=1G
# add_fstab_line "nodev /tmp/hugepages hugetlbfs pagesize=2M 0 0"
# add_fstab_line "nodev /hugepages hugetlbfs pagesize=1GB 0 0"
prompt 'Finished setup_hugepages sequence. Success'
}
function setup_docker_network()
{
prompt 'Starting setup_docker_network sequence.'
local parent_nic=""
parent_nic="$(get_default_route_nic)"
if ! docker network create --subnet 192.168.2.0/24 --gateway 192.168.2.100 -o parent="${parent_nic}" my_net_801f0 2>/dev/null; then
warning 'Network with name my_net_801f0 already exists'
fi
prompt 'Finished setup_docker_network sequence. Success'
}
function setup_nic_virtual_functions()
{
prompt 'Starting create virtual functions sequence.'
if [ -n "$E810_PCIE_SPECIFIED" ]; then
output=$(echo "$E810_PCIE_SPECIFIED" | tr ' ' '\n')
prompt "Selected NICs $E810_PCIE_SPECIFIED"
else
output=$(get_intel_nic_device | cut -f1 -d' ' | awk '{print "0000:"$1}')
fi
IFS=$'\n'
[ -f "/usr/local/bin/nicctl.sh" ] || copy_nicctl_script
if [ "$?" -ne "0" ]; then
error 'Container mtl-manager:latest or nicctl.sh script failed. Exiting.'
exit 1
fi
while IFS= read -r line; do
/usr/local/bin/nicctl.sh disable_vf "$line" 1>/dev/null
if ! /usr/local/bin/nicctl.sh create_vf "$line" ; then
error "Error occurred while creating VF for device: '$line'"
exit 2
fi
done <<< "$output"
prompt 'Finished create virtual functions sequence. Success.'
}
function setup_mtl_manager_container
{
prompt 'Starting run sequence for mtl-manager:latest image.'
container_id="$(docker ps -aq -f name=^mtl-manager$)"
if [ -n "$container_id" ]; then
if [ "$(docker inspect -f '{{.State.Running}}' "$container_id")" = "true" ]; then
prompt 'Container mtl-manager is already running.'
else
warning 'Container mtl-manager exists but is not running. Removing it.'
docker rm "$container_id"
docker run -d \
--name mtl-manager \
--privileged --net=host \
-v /var/run/imtl:/var/run/imtl \
-v /sys/fs/bpf:/sys/fs/bpf \
mtl-manager:latest || return 2
fi
else
docker run -d \
--name mtl-manager \
--privileged --net=host \
-v /var/run/imtl:/var/run/imtl \
-v /sys/fs/bpf:/sys/fs/bpf \
mtl-manager:latest || return 2
fi
prompt 'Finished run sequence for mtl-manager:latest image. Success.'
}
print_help() {
echo "Usage: $0 [-l] [-h] [-e PCIe_ADDRESSES]"
echo "Options:"
echo " -l For users running Intel® Tiber™ Broadcast Suite on bare metal."
echo " -h Display this help message."
echo " -e Specify the PCIe addresses for the E810 NIC."
echo " By default, all PCIe E810 addresses are selected."
echo " e.g. ./first_run.sh -e \"0000:4b:00.0 0000:4b:00.1 \""
exit 0
}
while getopts "lhe:" opt; do
case ${opt} in
l )
setup_vfio_subsytem
setup_hugepages
setup_nic_virtual_functions
if ! setup_mtl_manager_container 1>/dev/null 2>&1 && ! pgrep -x "MtlManager" > /dev/null; then
prompt 'Now starting Mtl Manager'
nohup sudo MtlManager > /dev/null 2>&1 &
prompt 'Mtl Manager running in background'
fi
exit 0
;;
h )
print_help
;;
e )
E810_PCIE_SPECIFIED=${OPTARG}
;;
\? )
exit 1
;;
esac
done
setup_jq_package
setup_vfio_subsytem
setup_hugepages
setup_docker_network
setup_nic_virtual_functions
setup_mtl_manager_container