This patch adds the pm data collection based on data from the active
slave port.

Signed-off-by: Anders Selhammer <anders.selham...@est.tech>
---
 clock.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 clock.h |  7 +++++++
 2 files changed, 53 insertions(+)

diff --git a/clock.c b/clock.c
index 8e7af0d..8135b39 100644
--- a/clock.c
+++ b/clock.c
@@ -34,6 +34,7 @@
 #include "missing.h"
 #include "msg.h"
 #include "phc.h"
+#include "pm.h"
 #include "port.h"
 #include "servo.h"
 #include "stats.h"
@@ -122,6 +123,9 @@ struct clock {
        struct clockcheck *sanity_check;
        struct interface uds_interface;
        LIST_HEAD(clock_subscribers_head, clock_subscriber) subscribers;
+       /* performance monitoring */
+       int performance_monitoring;
+       struct pm_clock_stats pm_stats_record;
 };
 
 struct clock the_clock;
@@ -135,6 +139,22 @@ static int cid_eq(struct ClockIdentity *a, struct 
ClockIdentity *b)
        return 0 == memcmp(a, b, sizeof(*a));
 }
 
+int clock_performance_monitoring(struct clock *c)
+{
+       return c->performance_monitoring;
+}
+
+static void clock_set_pmtime(struct clock *c)
+{
+       struct timespec now;
+       PMTimestamp pmtime;
+
+       clock_gettime(CLOCK_MONOTONIC, &now);
+       pmtime = timespec_to_tmv(now);
+
+       c->pm_stats_record.head.PMTime = pmtime;
+}
+
 static void remove_subscriber(struct clock_subscriber *s)
 {
        LIST_REMOVE(s, list);
@@ -276,6 +296,7 @@ void clock_destroy(struct clock *c)
        stats_destroy(c->stats.offset);
        stats_destroy(c->stats.freq);
        stats_destroy(c->stats.delay);
+       pm_destroy_clock_stats(&c->pm_stats_record);
        if (c->sanity_check) {
                clockcheck_destroy(c->sanity_check);
        }
@@ -1099,6 +1120,11 @@ struct clock *clock_create(enum clock_type type, struct 
config *config,
                return NULL;
        }
 
+       if (pm_create_clock_stats(&c->pm_stats_record)) {
+               pr_err("failed to create pm clock stats");
+               return NULL;
+       }
+
        /* Create the UDS interface. */
        c->uds_port = port_open(phc_index, timestamping, 0, udsif, c);
        if (!c->uds_port) {
@@ -1122,6 +1148,10 @@ struct clock *clock_create(enum clock_type type, struct 
config *config,
        }
        port_dispatch(c->uds_port, EV_INITIALIZE, 0);
 
+       if (c->performance_monitoring) {
+               clock_set_pmtime(c);
+       }
+
        return c;
 }
 
@@ -1521,11 +1551,19 @@ int clock_poll(struct clock *c)
 void clock_path_delay(struct clock *c, tmv_t req, tmv_t rx)
 {
        tsproc_up_ts(c->tsproc, req, rx);
+       if (c->performance_monitoring) {
+               stats_add_value(c->pm_stats_record.slaveMasterDelay,
+                               tmv_dbl(tmv_sub(rx, req)));
+       }
 
        if (tsproc_update_delay(c->tsproc, &c->path_delay))
                return;
 
        c->cur.meanPathDelay = tmv_to_TimeInterval(c->path_delay);
+       if (c->performance_monitoring) {
+               stats_add_value(c->pm_stats_record.meanPathDelay,
+                               tmv_dbl(c->path_delay));
+       }
 
        if (c->stats.delay)
                stats_add_value(c->stats.delay, tmv_dbl(c->path_delay));
@@ -1597,6 +1635,10 @@ enum servo_state clock_synchronize(struct clock *c, 
tmv_t ingress, tmv_t origin)
        c->ingress_ts = ingress;
 
        tsproc_down_ts(c->tsproc, origin, ingress);
+       if (c->performance_monitoring) {
+               stats_add_value(c->pm_stats_record.masterSlaveDelay,
+                               tmv_dbl(tmv_sub(ingress, origin)));
+       }
 
        if (tsproc_update_offset(c->tsproc, &c->master_offset, &weight)) {
                return state;
@@ -1607,6 +1649,10 @@ enum servo_state clock_synchronize(struct clock *c, 
tmv_t ingress, tmv_t origin)
        }
 
        c->cur.offsetFromMaster = tmv_to_TimeInterval(c->master_offset);
+       if (c->performance_monitoring) {
+               stats_add_value(c->pm_stats_record.offsetFromMaster,
+                               tmv_dbl(c->master_offset));
+       }
 
        if (c->free_running) {
                return clock_no_adjust(c, ingress, origin);
diff --git a/clock.h b/clock.h
index 3fa026d..c06d485 100644
--- a/clock.h
+++ b/clock.h
@@ -43,6 +43,13 @@ enum clock_type {
 };
 
 /**
+ * Obtain the performance monitoring attribute from a clock.
+ * @param c  The clock instance.
+ * @return   The value of the clock's performance monitoring flag.
+ */
+int clock_performance_monitoring(struct clock *c);
+
+/**
  * Obtains a reference to the best foreign master of a clock.
  * @param c  The clock instance.
  * @return   A pointer to the data set of the foreign master,
-- 
1.8.3.1


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to