Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions platform/mellanox/docker-syncd-mlnx/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
##
## SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES
## Copyright (c) 2016-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
## Apache-2.0
## Copyright (c) 2016-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
## SPDX-License-Identifier: Apache-2.0
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,7 +35,8 @@ RUN apt-get update && \
python3-pip \
python3-dev \
python3-jsonschema \
python-is-python3
python-is-python3 \
linuxptp

RUN pip3 install --upgrade pip
RUN apt-get purge -y python-pip
Expand Down Expand Up @@ -69,6 +70,7 @@ COPY ["supervisord.conf.j2", "/usr/share/sonic/templates/"]
COPY ["files/supervisor-proc-exit-listener", "/usr/bin"]
COPY ["critical_processes", "/etc/supervisor/"]
COPY ["platform_syncd_dump.sh", "/usr/bin/"]
COPY ["phcsync.sh", "/usr/bin/"]

RUN mkdir -p /etc/mlnx/
COPY ["sai-common.profile", "/etc/mlnx/"]
Expand Down
71 changes: 71 additions & 0 deletions platform/mellanox/docker-syncd-mlnx/phcsync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/bash
#
# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES
# Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#
# Script to synchronize ASIC PTP clocks with system realtime clock.
# This script runs continuously, syncing clocks every 60 seconds.
# This script shall not be running if PTP is enabled in the system.
#

PHC_CTL="/usr/sbin/phc_ctl"
SLEEP_INTERVAL=60

# Check if phc_ctl is available
if [ ! -x "$PHC_CTL" ]; then
echo "Error: phc_ctl not found. Exiting."
exit 1
fi

while :; do
# Refresh the list of PTP devices on each iteration
PTP_DEVICES=$(ls /dev/ptp[0-9]* 2>/dev/null)

if [ -z "$PTP_DEVICES" ]; then
sleep $SLEEP_INTERVAL
continue
fi

for dev in $PTP_DEVICES; do
# Extract device number from /dev/ptpXX
dev_num=${dev##*/ptp}

clock_name_file="/sys/class/ptp/ptp${dev_num}/clock_name"
if [[ ! -f "$clock_name_file" ]]; then
echo "Error: clock_name file not found for $dev ($clock_name_file), skipping" >&2
continue
fi

clock_name=$(cat "$clock_name_file" 2>/dev/null)
CLOCK_NAME_EXIT_CODE=$?
if [[ $CLOCK_NAME_EXIT_CODE -ne 0 ]] || [[ -z "$clock_name" ]]; then
echo "Error: Failed to read clock_name from $clock_name_file for $dev, skipping" >&2
continue
fi

if [[ "$clock_name" != "mlx5_ptp" ]]; then
# set CLOCK_REALTIME
"$PHC_CTL" "$dev" set 2>/dev/null
PHC_CTL_EXIT_CODE=$?
if [[ $PHC_CTL_EXIT_CODE -ne 0 ]]; then
echo "Error: Failed to sync clock for $dev (phc_ctl exit code: $PHC_CTL_EXIT_CODE)" >&2
fi
fi
done
sleep $SLEEP_INTERVAL
done
10 changes: 10 additions & 0 deletions platform/mellanox/docker-syncd-mlnx/supervisord.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,13 @@ dependent_startup_wait_for=rsyslogd:running
{% if ENABLE_ASAN == "y" %}
environment=ASAN_OPTIONS="log_path=/var/log/asan/syncd-asan.log{{ asan_extra_options }}"
{% endif %}

[program:phcsync]
command=/usr/bin/phcsync.sh
priority=3
autostart=false
autorestart=false
stdout_logfile=syslog
stderr_logfile=syslog
dependent_startup=true
dependent_startup_wait_for=rsyslogd:running