Tara Subedi 200bf6832a DEV: Improve Holdover logic for clock/ts2phc instance
This commit introduces following two improvements on holdover
logic for the clock and ts2phc instances:
- New threshold "locked_to_holdover_threshold_seconds" is intro-
duced, clock/ts2phc should be locked at least for the threshold
time before transitioning state from locked to holdover, otherw-
ise state should transition to holdover-unstable instead of
holdover. This improves the state transition to the holdover only
when the system stabilize.
- New threshold "holdover_seconds" for clock/ts2phc. When the
state stay in holdover more than the threshold time, the state
changes to holdover-expired.

PTP4l instance uses minimum of its own vs source/chained ts2phc/
clock's holdover seconds to determine its holdover expiration, to
honour source holdover-expiration too and sets clock class to 140
accordingly. In case of holdover-unstable, clock class sets to 255.

TEST PLAN:
PASS: Without explicit monitoring parameters, shows default
      values for ts2phc and clock
      - system ptp-instance-apply
      - check /etc/linuxptp/ptpinstance/instance-monitoring.conf
        [tsinst0]
        holdover_seconds 14400
        locked_to_holdover_threshold_seconds 300
        [clock]
        holdover_seconds 14400
        locked_to_holdover_threshold_seconds 300
      - check /var/log/collectd.log
        ptp plugin PTP instance tsinst0's monitoring_parameters:
        {'holdover_seconds': 14400,
        'locked_to_holdover_threshold_seconds': 300}
        ptp plugin PTP instance clock's monitoring_parameters:
        {'holdover_seconds': 14400,
        'locked_to_holdover_threshold_seconds': 300}
PASS: With explicit monitoring parameters, shows configured values
      for ts2phc and clock
      - system ptp-instance-parameter-add tsinst0 --section monitoring
        holdover_seconds=200 locked_to_holdover_threshold_seconds=100
      - system ptp-instance-parameter-add clkinst0 --section monitoring
        holdover_seconds=201 locked_to_holdover_threshold_seconds=101
      - system ptp-instance-apply
      - check /etc/linuxptp/ptpinstance/instance-monitoring.conf
        [tsinst0]
        holdover_seconds 200
        locked_to_holdover_threshold_seconds 100
        [clock]
        holdover_seconds 201
        locked_to_holdover_threshold_seconds 101
      - check /var/log/collectd.log
        info ptp plugin PTP instance tsinst0's monitoring_parameters:
        {'holdover_seconds': 200,
        'locked_to_holdover_threshold_seconds': 100}
        ptp plugin PTP instance clock's monitoring_parameters:
        {'holdover_seconds': 201,
        'locked_to_holdover_threshold_seconds': 101}
PASS: With explicit wrong monitoring parameters, shows default values
      for ts2phc and clock
      - system ptp-instance-parameter-delete tsinst0 --section
        monitoring holdover_seconds=200
        locked_to_holdover_threshold_seconds=100
      - system ptp-instance-parameter-add tsinst0 --section
        monitoring holdover_seconds=200xx
        locked_to_holdover_threshold_seconds=100yy
      - system ptp-instance-apply
      - check /etc/linuxptp/ptpinstance/instance-monitoring.conf
        [tsinst0]
        holdover_seconds 200xx
        locked_to_holdover_threshold_seconds 100yy
      - check /var/log/collectd.log
        - info ptp plugin Reading PTP instance tsinst0's parameter
        holdover_seconds value:200xx from config file /etc/linuxptp
        /ptpinstance/instance-monitoring.conf failed. error:
        invalid literal for int() with base 10: '200xx'.
        Using default value:14400
        - info ptp plugin Reading PTP instance tsinst0's parameter
        locked_to_holdover_threshold_seconds value:100yy from config file
        /etc/linuxptp/ptpinstance/instance-monitoring.conf failed.
        error: invalid literal for int() with base 10: '100yy'.
        Using default value:300
        - info ptp plugin PTP instance tsinst0's monitoring_parameters:
        {'holdover_seconds': 14400,
        'locked_to_holdover_threshold_seconds': 300}
   PASS: With ts2phc, clock and two ptp4l instances:
         [tsinst0]
         holdover_seconds 200
         locked_to_holdover_threshold_seconds 100
         [clock]
         holdover_seconds 201
         locked_to_holdover_threshold_seconds 101

         (clock class checked with "GET GRANDMASTER_SETTINGS_NP")
         1)
          event: GNSS down, SMA1 up
          alarm: "GNSS signal loss state: LockStatus.UNLOCKED"
          clock-class: 248 for both ptp instances

         2.1)
         event: SMA1 down too (to trigger locked to holdover
            after locked_to_holdover_threshold_seconds of clock
            ( emulate by converting pin config:
            output (function 2) to input (function 1)
            (python /usr/share/puppet/modules/platform/files/
             change_network_card_pins.py enp81s0f0 SMA1 1)
         alarm: "1PPS signal loss state: LockStatus.HOLDOVER"
               after 210 s:
               "1PPS signal loss state: holdover-expired"
         collectd.log:
              - PTP instance clock interface enp138s0f0's state
              LockStatus.HOLDOVER overwritten to holdover-expired
              as it has been on holdover over threshold: 210.116908 > 201

              - ptp plugin ptp-inst2 holdover timer: 211.217202 seconds
              holdover_seconds: 14400 source clock holdover_seconds: 201
         clock-class:
              - 248 for one ptp instance-1
              - 7 for ptp instance-2 when holdover
              - 140 for ptp instance-2 when holdover-expired
         2.2)
         event: SMA1 down too (to trigger locked to holdover
                before locked_to_holdover_threshold_seconds of clock
         alarm: "1PPS signal loss state: holdover-unstable(freerun)"
         collectd.log:
              - ptp plugin PTP instance clock interface enp138s0f0's state
              LockStatus.HOLDOVER overwritten to holdover-unstable
              (freerun) as it has not been locked long enough:
              29.920566 < 101
              - ptp plugin ptp-inst2 new clock class: 248, as no holdover
              timestamp found for instance_type: clock and interface:
              enp138s0f0
         clock-class: 248 for both ptp4l instances

   PASS: With ts2phc, clock and two ptp4l instances:
         [tsinst0]
         holdover_seconds 200
         locked_to_holdover_threshold_seconds 100
         [clock]
         holdover_seconds 201
         locked_to_holdover_threshold_seconds 101

         (clock class checked with "GET GRANDMASTER_SETTINGS_NP")
         1)
          event: GNSS up, SMA1 up
          alarm: no alarm
          clock-class: 6 for both ptp instances
         2)
          event: GNSS down (to trigger locked to holdover
                after locked_to_holdover_threshold_seconds of ts2phc)
          alarm:
            GNSS signal loss state: LockStatus.HOLDOVER
            after 210 sec,
            GNSS signal loss state: holdover-expired
          clock-class: 7 when holdover and 140 when holdover-expired

Story: 2011536
Task: 53546

Depends-on: https://review.opendev.org/c/starlingx/config/+/971385
Depends-on: https://review.opendev.org/c/starlingx/stx-puppet/+/971660

Change-Id: I801ecea50752d97a9e79a88420ace9c22d6821ea
Signed-off-by: Tara Nath Subedi <tara.subedi@windriver.com>
2025-12-30 20:49:00 -05:00
2019-09-09 14:37:23 -05:00
2019-09-09 14:37:23 -05:00
2019-09-09 14:37:23 -05:00
Description
StarlingX system monitoring and repoting tools
4.7 MiB
Languages
Python 85.4%
Perl 13.9%
Makefile 0.6%
Shell 0.1%