2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright 2021-2022 NXP
5 REQUIRE_ISOCHRON
=${REQUIRE_ISOCHRON:=yes}
6 REQUIRE_LINUXPTP
=${REQUIRE_LINUXPTP:=yes}
12 if [[ "$REQUIRE_ISOCHRON" = "yes" ]]; then
13 # https://github.com/vladimiroltean/tsn-scripts
14 # WARNING: isochron versions pre-1.0 are unstable,
15 # always use the latest version
16 require_command isochron
18 if [[ "$REQUIRE_LINUXPTP" = "yes" ]]; then
19 require_command phc2sys
28 if ! [ -z "${uds_address}" ]; then
29 extra_args
="${extra_args} -z ${uds_address}"
32 phc2sys_log
="$(mktemp)"
34 chrt
-f 10 phc2sys
-m \
36 --step_threshold 0.00002 \
37 --first_step_threshold 0.00002 \
39 > "${phc2sys_log}" 2>&1 &
42 echo "phc2sys logs to ${phc2sys_log} and has pid ${phc2sys_pid}"
49 { kill ${phc2sys_pid} && wait ${phc2sys_pid}; } 2> /dev
/null
50 rm "${phc2sys_log}" 2> /dev
/null
53 # Replace space separators from interface list with underscores
56 local if_name_list
="$1"
58 echo "${if_name_list/ /_}"
66 local log
="ptp4l_log_$(if_names_to_label ${if_names})"
67 local pid
="ptp4l_pid_$(if_names_to_label ${if_names})"
70 for if_name
in ${if_names}; do
71 extra_args
="${extra_args} -i ${if_name}"
74 if [ "${slave_only}" = true
]; then
75 extra_args
="${extra_args} -s"
78 # declare dynamic variables ptp4l_log_${if_name} and ptp4l_pid_${if_name}
79 # as global, so that they can be referenced later
80 declare -g "${log}=$(mktemp)"
82 chrt
-f 10 ptp4l
-m -2 -P \
83 --step_threshold 0.00002 \
84 --first_step_threshold 0.00002 \
85 --tx_timestamp_timeout 100 \
86 --uds_address="${uds_address}" \
89 declare -g "${pid}=$!"
91 echo "ptp4l for interfaces ${if_names} logs to ${!log} and has pid ${!pid}"
99 local log
="ptp4l_log_$(if_names_to_label ${if_names})"
100 local pid
="ptp4l_pid_$(if_names_to_label ${if_names})"
102 { kill ${!pid} && wait ${!pid}; } 2> /dev
/null
103 rm "${!log}" 2> /dev
/null
109 local freq
="cpu${cpu}_freq"
110 local governor
="cpu${cpu}_governor"
112 # Kernel may be compiled with CONFIG_CPU_FREQ disabled
113 if ! [ -d /sys
/bus
/cpu
/devices
/cpu
${cpu}/cpufreq
]; then
117 # declare dynamic variables cpu${cpu}_freq and cpu${cpu}_governor as
118 # global, so they can be referenced later
119 declare -g "${freq}=$(cat /sys/bus/cpu/devices/cpu${cpu}/cpufreq/scaling_min_freq)"
120 declare -g "${governor}=$(cat /sys/bus/cpu/devices/cpu${cpu}/cpufreq/scaling_governor)"
122 cat /sys
/bus
/cpu
/devices
/cpu
${cpu}/cpufreq
/scaling_max_freq
> \
123 /sys
/bus
/cpu
/devices
/cpu
${cpu}/cpufreq
/scaling_min_freq
124 echo -n "performance" > \
125 /sys
/bus
/cpu
/devices
/cpu
${cpu}/cpufreq
/scaling_governor
131 local freq
="cpu${cpu}_freq"
132 local governor
="cpu${cpu}_governor"
134 if ! [ -d /sys
/bus
/cpu
/devices
/cpu
${cpu}/cpufreq
]; then
138 echo "${!freq}" > /sys
/bus
/cpu
/devices
/cpu
${cpu}/cpufreq
/scaling_min_freq
139 echo -n "${!governor}" > \
140 /sys
/bus
/cpu
/devices
/cpu
${cpu}/cpufreq
/scaling_governor
143 isochron_recv_start
()
149 local pid
="isochron_pid_${stats_port}"
151 if ! [ -z "${uds}" ]; then
152 extra_args
="${extra_args} --unix-domain-socket ${uds}"
156 --interface ${if_name} \
157 --sched-priority 98 \
159 --utc-tai-offset ${UTC_TAI_OFFSET} \
160 --stats-port ${stats_port} \
163 declare -g "${pid}=$!"
171 local pid
="isochron_pid_${stats_port}"
173 { kill ${!pid} && wait ${!pid}; } 2> /dev
/null
178 local sender_if_name
=$1; shift
179 local receiver_if_name
=$1; shift
180 local sender_uds
=$1; shift
181 local receiver_uds
=$1; shift
182 local base_time
=$1; shift
183 local cycle_time
=$1; shift
184 local shift_time
=$1; shift
185 local num_pkts
=$1; shift
187 local priority
=$1; shift
188 local dst_ip
=$1; shift
189 local isochron_dat
=$1; shift
191 local receiver_extra_args
=""
192 local vrf
="$(master_name_get ${sender_if_name})"
195 if ! [ -z "${dst_ip}" ]; then
199 if ! [ -z "${vrf}" ]; then
200 dst_ip
="${dst_ip}%${vrf}"
203 if ! [ -z "${vid}" ]; then
207 if [ -z "${receiver_uds}" ]; then
208 extra_args
="${extra_args} --omit-remote-sync"
211 if ! [ -z "${shift_time}" ]; then
212 extra_args
="${extra_args} --shift-time=${shift_time}"
215 if [ "${use_l2}" = "true" ]; then
216 extra_args
="${extra_args} --l2 --etype=0xdead ${vid}"
217 receiver_extra_args
="--l2 --etype=0xdead"
219 extra_args
="${extra_args} --l4 --ip-destination=${dst_ip}"
220 receiver_extra_args
="--l4"
223 cpufreq_max
${ISOCHRON_CPU}
225 isochron_recv_start
"${h2}" "${receiver_uds}" 5000 "${receiver_extra_args}"
228 --interface ${sender_if_name} \
229 --unix-domain-socket ${sender_uds} \
230 --priority ${priority} \
231 --base-time ${base_time} \
232 --cycle-time ${cycle_time} \
233 --num-frames ${num_pkts} \
236 --utc-tai-offset ${UTC_TAI_OFFSET} \
237 --cpu-mask $
((1 << ${ISOCHRON_CPU})) \
239 --sched-priority 98 \
241 --sync-threshold 5000 \
242 --output-file ${isochron_dat} \
246 isochron_recv_stop
5000
248 cpufreq_restore
${ISOCHRON_CPU}