Add support for the free-running mode that will not adjust the sink
clock when enabled.

Signed-off-by: Maciek Machnikowski <mac...@machnikowski.net>
---
 phc2sys.8 |  4 ++++
 phc2sys.c | 14 +++++++++++---
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/phc2sys.8 b/phc2sys.8
index 99fc937..42f2bdb 100644
--- a/phc2sys.8
+++ b/phc2sys.8
@@ -323,6 +323,10 @@ Same as option
 .B \-E
 (see above).
 
+.TP
+.B free-running
+Don't adjust the sink clock if enabled. The default is 0 (disabled).
+
 .TP
 .B transportSpecific
 The transport specific field. Must be in the range 0 to 255.
diff --git a/phc2sys.c b/phc2sys.c
index 599f9bd..c974a2b 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -63,6 +63,7 @@
 #define NS_PER_SEC 1000000000LL
 
 #define PHC_PPS_OFFSET_LIMIT 10000000
+int    g_free_running;
 
 struct clock {
        LIST_ENTRY(clock) list;
@@ -103,6 +104,7 @@ struct phc2sys_private {
        int forced_sync_offset;
        int kernel_leap;
        int state_changed;
+       int free_running;
        struct pmc_agent *agent;
        LIST_HEAD(port_head, port) ports;
        LIST_HEAD(clock_head, clock) clocks;
@@ -121,7 +123,7 @@ static int normalize_state(int state);
 static struct servo *servo_add(struct phc2sys_private *priv,
                               struct clock *clock)
 {
-       double ppb;
+       double ppb = 0;
        int max_ppb;
        struct servo *servo;
 
@@ -129,7 +131,8 @@ static struct servo *servo_add(struct phc2sys_private *priv,
        ppb = clockadj_get_freq(clock->clkid);
        /* The reading may silently fail and return 0, reset the frequency to
           make sure ppb is the actual frequency of the clock. */
-       clockadj_set_freq(clock->clkid, ppb);
+       if (!priv->free_running)
+               clockadj_set_freq(clock->clkid, ppb);
        if (clock->clkid == CLOCK_REALTIME) {
                sysclk_set_leap(0);
                max_ppb = sysclk_max_freq();
@@ -530,7 +533,7 @@ static void update_clock_stats(struct clock *clock, 
unsigned int max_count,
 static void update_clock(struct phc2sys_private *priv, struct clock *clock,
                         int64_t offset, uint64_t ts, int64_t delay)
 {
-       enum servo_state state;
+       enum servo_state state = SERVO_UNLOCKED;
        double ppb;
 
        if (!clock->servo) {
@@ -544,6 +547,9 @@ static void update_clock(struct phc2sys_private *priv, 
struct clock *clock,
 
        offset += get_sync_offset(priv, clock);
 
+       if (priv->free_running)
+               goto report;
+
        if (clock->sanity_check && clockcheck_sample(clock->sanity_check, ts))
                servo_reset(clock->servo);
 
@@ -568,6 +574,7 @@ static void update_clock(struct phc2sys_private *priv, 
struct clock *clock,
                break;
        }
 
+report:
        if (clock->offset_stats) {
                update_clock_stats(clock, priv->stats_max_count, offset, ppb, 
delay);
        } else {
@@ -1286,6 +1293,7 @@ int main(int argc, char *argv[])
        }
        priv.kernel_leap = config_get_int(cfg, NULL, "kernel_leap");
        priv.sanity_freq_limit = config_get_int(cfg, NULL, "sanity_freq_limit");
+       priv.free_running = config_get_int(cfg, NULL, "free_running");
 
        snprintf(uds_local, sizeof(uds_local), "/var/run/phc2sys.%d",
                 getpid());
-- 
2.36.1



_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to