Configure TAI Offset for T-GM PTP Deployments¶
About this task
In a T-GM deployment, phc2sys synchronizes the system clock
(CLOCK_REALTIME) with the NIC PHC and applies the UTC offset to
derive the correct UTC time from TAI. This page explains how T-GM
configurations automatically manage the TAI offset and leap seconds.
Background¶
PTP operates on TAI. Applications that require UTC time must know the
current TAI-UTC offset (currently 37 seconds) to convert between the two
timescales. The Linux kernel maintains this offset through the CLOCK_TAI clock,
which can be read directly by user-space applications.
In earlier releases, configuring phc2sys with a manual offset (-O 37) did not
update the kernel’s TAI clock. As a result, applications reading CLOCK_TAI
would see an incorrect offset of zero. In addition, maintaining leap second
flags and the currentUtcOffset field in PTP Announce messages required manual
operator intervention using pmc commands.
Automated Behavior¶
The following behaviors are handled automatically for T-GM deployments:
Note
This feature applies only to phc2sys instances configured with a manual
UTC offset using the -O option or utc_offset parameter. Instances
using automatic offset discovery (-a or -w), such as those running
in T-BC mode, obtain the offset from ptp4l and are therefore
unaffected.
- Kernel TAI offset
When phc2sys is configured with a manual UTC offset and the
utc_offset_validparameter in T-GM mode, it sets the kernelCLOCK_TAIclock to the correct value. Applications that useCLOCK_TAIcan therefore obtain accurate TAI time without any additional configuration.- Leap second flags
StarlingX reads the leap-seconds file and automatically updates the
leap61/leap59,currentUtcOffsetValid, andtimeTraceableflags in PTP Announce messages. These flags are asserted 12 hours before a scheduled leap second at midnight UTC and cleared 6 hours after the leap second occurs.- Dynamic currentUtcOffset
The
currentUtcOffsetvalue reported in PTP Announce messages is derived from the leap-seconds file. When a leap second occurs, the offset is incremented (or decremented) automatically.
Startup Behavior¶
On initial startup, phc2sys delays synchronization of CLOCK_REALTIME until the
UTC offset is confirmed to be valid and traceable. This prevents a transient
clock adjustment, such as a 37-second jump, during initialization that could
disrupt applications.
If phc2sys does not appear to synchronize the system clock after startup, verify that:
ptp4lhas reached the Master state (time properties are only reported after the port transitions to Master).pmc -u -b 0 'GET TIME_PROPERTIES_DATA_SET'showscurrentUtcOffsetValid 1.The
utc_offset_validparameter is set to1on the phc2sys instance.
Once these conditions are met, phc2sys begins synchronizing
CLOCK_REALTIME and updates the kernel CLOCK_TAI offset.
Prerequisites
The system is configured as a T-GM with
ts2phcand GNSS.A valid leap-seconds file is present on the system. For instructions on maintaining the leap-seconds file, see Update Leap Seconds File.
PTP services are running and the
ptp4lport is in the Master state.phc2sys is running and healthy (required for kernel leap second insertion).
Configure TAI Offset¶
To enable automated TAI offset and leap flag management, configure the following on your T-GM system:
Ensure that the
ts2phcinstance has a valid leap-seconds file configured:~(keystone_admin)]$ system ptp-instance-parameter-add <ts2phc-instance> leapfile=/usr/share/zoneinfo/leap-seconds.list
Configure the
phc2sysinstance with a manual UTC offset and mark it as valid:~(keystone_admin)]$ system ptp-instance-parameter-add <phc2sys-instance> utc_offset=37 ~(keystone_admin)]$ system ptp-instance-parameter-add <phc2sys-instance> utc_offset_valid=1
Apply the configuration:
~(keystone_admin)]$ system ptp-instance-apply
The utc_offset_valid parameter instructs phc2sys to treat the configured
UTC offset as authoritative and set the CLOCK_TAI kernel accordingly.
Without this parameter, the kernel TAI offset remains at zero even when
utc_offset is configured.
Note
The default leap-seconds file is located at /usr/share/zoneinfo/leap-seconds.list.
This file is part of the base OS image. For instructions on updating it when new leap seconds are
announced, see Update Leap Seconds File.
Note
StarlingX reads the leap-seconds file when PTP services start. If you deploy
an updated leap-seconds file, restart PTP services with system
ptp-instance-apply to reload the new data.
Leap Second Lifecycle¶
The automated leap second handling follows this timeline:
Timing |
System action |
|---|---|
12 hours before midnight UTC |
StarlingX sets |
At midnight UTC |
The kernel inserts (or removes) the leap second; phc2sys suspends clock updates during the transition |
6 hours after midnight UTC |
StarlingX clears leap flags and updates |
Important
phc2sys must be running at midnight UTC for the kernel to apply the leap second. If phc2sys is stopped before the leap event, the kernel considers the clock unsynchronized and does not apply the leap second.
Verify TAI Offset¶
After configuring a T-GM deployment, verify that the automated TAI offset is working correctly.
Confirm that the kernel TAI offset is set:
~(keystone_admin)] $ python3 -c "import os, time; \ tai=os.clock_gettime(os.CLOCK_TAI); utc=time.time(); \ print(f'TAI - UTC = {int(tai - utc)} seconds')" TAI - UTC = 37 secondsVerify that
currentUtcOffsetValidandtimeTraceableare set in PTP:~(keystone_admin)]$ sudo pmc -u -b 0 'GET TIME_PROPERTIES_DATA_SET' currentUtcOffset 37 leap61 0 leap59 0 currentUtcOffsetValid 1 ptpTimescale 1 timeTraceable 1 frequencyTraceable 1
Confirm that the TAI offset appears in phc2sys logs:
~(keystone_admin)]$ sudo grep -i "tai offset" /var/log/user.log
Verify Leap Second Handling¶
To confirm that StarlingX correctly handles a leap second event, check the following at each stage of the lifecycle.
Before the leap second (12+ hours prior):
Verify that leap flags have been asserted in PTP Announce messages:
~(keystone_admin)]$ sudo pmc -u -b 0 'GET TIME_PROPERTIES_DATA_SET' currentUtcOffset 37 leap61 1 currentUtcOffsetValid 1 timeTraceable 1
Confirm that phc2sys has detected the pending leap and configured the kernel to apply it:
~(keystone_admin)]$ sudo grep -i "leap" /var/log/user.log phc2sys[...]: clock set to insert leap second at midnight (UTC)
After the leap second (within 6 hours):
Verify that the kernel TAI offset has incremented:
~(keystone_admin)]$ python3 -c "import os, time; \ tai=os.clock_gettime(os.CLOCK_TAI); utc=time.time(); \ print(f'TAI - UTC = {int(tai - utc)} seconds')" TAI - UTC = 38 secondsConfirm that phc2sys suspended and resumed clock updates:
~(keystone_admin)]$ sudo grep -i "suspend\|leap" /var/log/user.log phc2sys[...]: clock set to insert leap second at midnight (UTC) phc2sys[...]: clock update suspended due to leap second
After flag clearing (6+ hours post-leap):
Verify that flags have been cleared and offset updated:
~(keystone_admin)]$ sudo pmc -u -b 0 'GET TIME_PROPERTIES_DATA_SET'
currentUtcOffset 38
leap61 0
leap59 0
currentUtcOffsetValid 1
timeTraceable 1
currentUtcOffset should reflect the new value (incremented by 1 for a
positive leap second, decremented by 1 for a negative leap second).
Note
If the leap second was not applied (TAI offset remains unchanged, no “suspended” log message is present), verify that phc2sys was running continuously through midnight UTC. If phc2sys was stopped or terminated, the kernel does not apply the scheduled leap second.
Manual Override¶
The automated behavior does not prevent manual intervention. Operators can
still use the pmc command to set flags directly if needed:
~(keystone_admin)]$ sudo pmc -u -b 0 -f /etc/linuxptp/ptpinstance/ptp4l-<instance>.conf \
-s /var/run/ptp4l-<instance> \
'SET GRANDMASTER_SETTINGS_NP clockClass 6 clockAccuracy 0x21 offsetScaledLogVariance 0x4e5d \
currentUtcOffset 37 leap61 1 leap59 0 currentUtcOffsetValid 1 ptpTimescale 1 \
timeTraceable 1 frequencyTraceable 1 timeSource 0x20'
Manual overrides are temporary and will be restored to the automated values shortly after the next PTP service polling interval.
Upgrade Considerations¶
When upgrading from an earlier release:
Existing T-GM configurations using
-O 37orutc_offset=37continue to work without changes. To enable the new kernelCLOCK_TAIoffset feature, addutc_offset_valid=1to the phc2sys instance:~(keystone_admin)]$ system ptp-instance-parameter-add <phc2sys-instance> utc_offset_valid=1 ~(keystone_admin)]$ system ptp-instance-apply
Without this parameter, the system behavior remains unchanged:
CLOCK_TAIremains at zero. Leap-second flag automation is enabled regardless of this parameter.If you previously used a manual
pmc SET GRANDMASTER_SETTINGS_NPcron job or script for leap second handling, it can be removed after upgrade.The
utc_offsetparameter is no longer required in theptp4linstance configuration for T-GM mode. Existing configurations that explicitly specify this parameter remain supported and are unaffected.
Operational Considerations¶
Leap-seconds file maintenance: The leap-seconds file expires semi-annually (June and December). If the file has expired, StarlingX continues to use the last known UTC offset value but does not assert leap flags for future events. Check
/var/log/user.logfor warnings about an expired leap-seconds file. See Update Leap Seconds File for the update procedure.T-BC mode: In T-BC mode, leap second flags propagate automatically from the upstream Grandmaster via PTP Announce messages. No local leap-seconds file configuration is required on T-BC nodes.
Leap second abolishment: CGPM has resolved to discontinue the use of leap seconds by 2035. Until this transition is complete, the leap-seconds file remains necessary for correct TAI-UTC conversion.