forked from open-edge-platform/edge-ai-libraries
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunch.sh
More file actions
223 lines (188 loc) · 6.16 KB
/
launch.sh
File metadata and controls
223 lines (188 loc) · 6.16 KB
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
217
218
219
220
221
222
223
#!/bin/bash
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2025 Intel Corporation
# Parse arguments
helpFunction()
{
echo ""
echo "Usage: $0 -n <nic_num> -a <cpu_affinity> -f <igpu_frequency>"
echo "\t-n Network interface (has to be igb/igc), e.g. enp2s0"
echo "\t-a CPU core affinity to run real-time thread, e.g. 1"
echo "\t-f Set iGPU frequency, e.g. 200"
exit 1 # Exit script after printing help
}
while getopts n:a:f:h flag
do
case "${flag}" in
n) nic=${OPTARG};;
a) affinity=${OPTARG};;
f) freq=${OPTARG};;
h) helpFunction;;
?) helpFunction;;
esac
done
if [ -z "${nic}" ]; then
echo "Error: no NIC specified. Please use -n argument to specify NIC name, e.g. enp2s0."
exit 1
fi
if [ -z "${affinity}" ]; then
affinity=1
fi
if [ -z "${freq}" ]; then
freq=200
fi
echo "Network interface: $nic"
echo "CPU core affinity: $affinity"
echo "iGPU frequency: $freq"
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit 1
fi
# Install depends
echo "Install dependent Debian packages..."
apt update && apt install -y eci-softplc dmidecode msr-tools stress-ng
echo "Done install dependencies"
# Find MAC address
mac=$(ifconfig ${nic} | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}')
if [ -z "${mac}" ]; then
# Check if EtherCAT master has been started
master_status=$(ethercat master | grep "attached")
ret=$?
if [ "$ret" -ne 0 || -z "$master_status" ]; then
echo "Error: Not get MAC address of the network device."
exit 1
fi
fi
echo "MAC address: $mac"
# Find PCIE device slot
echo "Configure EtherCAT..."
slot=$(dmesg | grep ${nic} | grep -o -E '([[:xdigit:]]{1,4}:){2}[[:xdigit:]]{1,2}.[[:xdigit:]]{1,1}' | head -n 1)
if [ -z "${slot}" ]; then
echo "Error: Not get network device slot name."
exit 1
else
echo "NIC device slot: $slot"
fi
# Find NIC kernel driver name
driver=$(dmesg | grep ${nic} | grep -o -E 'ig[b,c]' | head -n 1)
if [ -z "${driver}" ]; then
echo "Error: Not get network device kernel driver name."
exit 1
else
echo "NIC device kernel driver: $driver"
fi
# Configure EtherCAT
ethercat_config_script_path="/etc/sysconfig/ethercat"
if [ -e ${ethercat_config_script_path} ]; then
echo "Configure the EtherCAT MAC address..."
sed -i "s/MASTER0_DEVICE=\".*\"/MASTER0_DEVICE=\"$mac\"/" /etc/sysconfig/ethercat
echo "Configure the EtherCAT device module..."
sed -i "s/DEVICE_MODULES=\".*\"/DEVICE_MODULES=\"$driver\"/" /etc/sysconfig/ethercat
echo "Configure the EtherCAT device slot..."
sed -i "s/REBIND_NICS=\".*\"/REBIND_NICS=\"$slot\"/" /etc/sysconfig/ethercat
else
echo "Error: cannot find the file /etc/sysconfig/ethercat."
exit 1
fi
echo "Done configure EtherCAT"
# Real-time tuning
echo "Make real-time configurations"
# Move all IRQs to core 0.
for i in `cat /proc/interrupts | grep '^ *[0-9]*[0-9]:' | awk {'print $1'} | sed 's/:$//' `;
do
echo setting $i to affine for core zero
echo 1 > /proc/irq/$i/smp_affinity
done
# Disable kernel machine check interrupt
#echo 0 > /sys/devices/system/machinecheck/machinecheck0/check_interval
# Disable rc6
# echo 0 > /sys/class/drm/card0/gt_rc6_enable
echo -1 > /proc/sys/kernel/sched_rt_runtime_us
#Move all rcu tasks to core 0.
for i in `pgrep rcu`; do taskset -pc 0 $i; done
#Change realtime attribute of all rcu tasks to SCHED_OTHER and priority 0
for i in `pgrep rcu`; do chrt -v -o -p 0 $i; done
#Change realtime attribute of all tasks on core 1 to SCHED_OTHER and priority 0
for i in `pgrep /1`; do chrt -v -o -p 0 $i; done
#Change realtime attribute of all tasks to SCHED_OTHER and priority 0
for i in `ps -A -o pid`; do chrt -v -o -p 0 $i; done
# Set iGPU frequency
echo "Set iGPU frequency as $freq MHz"
echo $freq > /sys/class/drm/card0/gt_max_freq_mhz
echo $freq > /sys/class/drm/card0/gt_min_freq_mhz
# Stop timers
systemctl stop *timer
# Disabling timer migration
echo 0 > /proc/sys/kernel/timer_migration
echo "Done real-time configurations"
# Setup PMUs to capture cache miss
echo "Setting up cache miss PMUs..."
# Setting up User Mode access to PMU
echo "Setting up User Mode access to PMU..."
echo 2 > /sys/bus/event_source/devices/cpu/rdpmc
# Setting up PMU events for CPU Core #1, running RT workload
echo "Setting up PMU evnets..."
# MEM_LOAD_RETIRED.L2_HIT
wrmsr -p 1 0x186 0x4302d1
# MEM_LOAD_RETIRED.L2_MISS
wrmsr -p 1 0x187 0x4310d1
# MEM_LOAD_RETIRED.L3_HIT
wrmsr -p 1 0x188 0x4304d1
# MEM_LOAD_RETIRED.L3_MISS
wrmsr -p 1 0x189 0x4320d1
echo "Done setting cache miss PMUs"
# Check EtherCAT master status
echo "Check EtherCAT master status..."
master_status=$(ethercat master | grep "attached")
ret=$?
if [ "$ret" -ne 0 ]; then
echo "EtherCAT master is not started yet"
# Re-start EtherCAT master stack
/etc/init.d/ethercat start
ret=$?
if [ "$ret" -ne 0 ]; then
echo "Failed to start EtherCAT master stack"
exit 1
else
# Check master status again
master_status=$(ethercat master | grep "attached")
if [ -z "$master_status" ]; then
echo "Ethernet divice is not successfully bounded to EtherCAT master stack"
exit 1
fi
fi
else
if [ -z "$master_status" ]; then
echo "Ethernet divice is not successfully bounded to EtherCAT master stack"
exit 1
fi
fi
echo "Done check EtherCAT master status"
# Check EtherCAT slave status
echo "Check EtherCAT slave status..."
sleep 8
slave_num=$(ethercat slaves | wc -l)
if [ "$slave_num" -ne 6 ]; then
echo "Failed to get slave status"
exit 1
fi
echo "Done check EtherCAT slave status"
# Launch benchmark program
echo "Launch the benchmark program..."
benchmark_path="/opt/plcopen/plcopen_benchmark"
if [ ! -e "$benchmark_path" ]; then
echo "PLCopen benchmark program doesn't exist"
exit 1
fi
os_type=$(uname -a)
# Preempt RT
if [[ -n $(echo $os_type | grep "intel-ese-standard-lts-rt") ]]; then
echo "Running on Preempt RT system"
/opt/plcopen/plcopen_benchmark -n /opt/plcopen/inovance_six_1ms.xml -i 1000 -a $affinity -m 6 -t 259200 -l -o -r -c
fi
# Xenomai
if [[ -n $(echo $os_type | grep "intel-ese-standard-lts-dovetail") ]]; then
echo "Running on Xenomai system"
echo 0 > /proc/xenomai/clock/coreclk
/opt/plcopen/plcopen_benchmark -n /opt/plcopen/inovance_six_1ms.xml -i 1000 -a $affinity -m 6 -t 86400 -l -o -r -c
fi