Add a new notification event for pmc clients to receive
PARENT_DATA_SET when a change is made there.

Signed-off-by: Miroslav Lichvar <mlich...@redhat.com>
---
 clock.c        | 26 +++++++++++++++++++++++---
 notification.h |  1 +
 pmc.c          | 10 ++++++----
 pmc_common.c   | 15 +++++++++++----
 4 files changed, 41 insertions(+), 11 deletions(-)

diff --git a/clock.c b/clock.c
index 5a64613..b0df2e4 100644
--- a/clock.c
+++ b/clock.c
@@ -819,9 +819,14 @@ static enum servo_state clock_no_adjust(struct clock *c, 
tmv_t ingress,
        return state;
 }
 
+static int clock_compare_pds(struct parentDS *pds1, struct parentDS *pds2)
+{
+       return memcmp(pds1, pds2, sizeof (*pds1));
+}
+
 static void clock_update_grandmaster(struct clock *c)
 {
-       struct parentDS *pds = &c->dad.pds;
+       struct parentDS *pds = &c->dad.pds, old_pds = *pds;
        memset(&c->cur, 0, sizeof(c->cur));
        memset(c->ptl, 0, sizeof(c->ptl));
 
@@ -836,11 +841,14 @@ static void clock_update_grandmaster(struct clock *c)
        c->tds.currentUtcOffset                 = c->utc_offset;
        c->tds.flags                            = c->time_flags;
        c->tds.timeSource                       = c->time_source;
+
+       if (clock_compare_pds(&old_pds, pds))
+               clock_notify_event(c, NOTIFY_PARENT_DATA_SET);
 }
 
 static void clock_update_slave(struct clock *c)
 {
-       struct parentDS *pds = &c->dad.pds;
+       struct parentDS *pds = &c->dad.pds, old_pds = *pds;
        struct timePropertiesDS tds;
        struct ptp_message *msg;
 
@@ -864,6 +872,9 @@ static void clock_update_slave(struct clock *c)
                pr_warning("running in a temporal vortex");
        }
        clock_update_time_properties(c, tds);
+
+       if (clock_compare_pds(&old_pds, pds))
+               clock_notify_event(c, NOTIFY_PARENT_DATA_SET);
 }
 
 static int clock_utc_correct(struct clock *c, tmv_t ingress)
@@ -1721,14 +1732,23 @@ int clock_manage(struct clock *c, struct port *p, 
struct ptp_message *msg)
 void clock_notify_event(struct clock *c, enum notification event)
 {
        struct port *uds = c->uds_rw_port;
-       struct PortIdentity pid = port_identity(uds);
+       struct PortIdentity pid;
        struct ptp_message *msg;
        int id;
 
+       /* A notification may come before UDS is created */
+       if (!uds)
+               return;
+
+       pid = port_identity(uds);
+
        switch (event) {
        case NOTIFY_TIME_SYNC:
                id = MID_TIME_STATUS_NP;
                break;
+       case NOTIFY_PARENT_DATA_SET:
+               id = MID_PARENT_DATA_SET;
+               break;
        default:
                return;
        }
diff --git a/notification.h b/notification.h
index 115f864..c1a6395 100644
--- a/notification.h
+++ b/notification.h
@@ -44,6 +44,7 @@ static inline bool event_bitmask_get(uint8_t *bitmask, 
unsigned int event)
 enum notification {
        NOTIFY_PORT_STATE,
        NOTIFY_TIME_SYNC,
+       NOTIFY_PARENT_DATA_SET,
 };
 
 #endif
diff --git a/pmc.c b/pmc.c
index 00e691f..357c40a 100644
--- a/pmc.c
+++ b/pmc.c
@@ -449,12 +449,14 @@ static void pmc_show(struct ptp_message *msg, FILE *fp)
        case MID_SUBSCRIBE_EVENTS_NP:
                sen = (struct subscribe_events_np *) mgt->data;
                fprintf(fp, "SUBSCRIBE_EVENTS_NP "
-                       IFMT "duration          %hu"
-                       IFMT "NOTIFY_PORT_STATE %s"
-                       IFMT "NOTIFY_TIME_SYNC  %s",
+                       IFMT "duration               %hu"
+                       IFMT "NOTIFY_PORT_STATE      %s"
+                       IFMT "NOTIFY_TIME_SYNC       %s"
+                       IFMT "NOTIFY_PARENT_DATA_SET %s",
                        sen->duration,
                        event_bitmask_get(sen->bitmask, NOTIFY_PORT_STATE) ? 
"on" : "off",
-                       event_bitmask_get(sen->bitmask, NOTIFY_TIME_SYNC) ? 
"on" : "off");
+                       event_bitmask_get(sen->bitmask, NOTIFY_TIME_SYNC) ? 
"on" : "off",
+                       event_bitmask_get(sen->bitmask, NOTIFY_PARENT_DATA_SET) 
? "on" : "off");
                break;
        case MID_SYNCHRONIZATION_UNCERTAIN_NP:
                mtd = (struct management_tlv_datum *) mgt->data;
diff --git a/pmc_common.c b/pmc_common.c
index 9e251c4..8efeacd 100644
--- a/pmc_common.c
+++ b/pmc_common.c
@@ -178,6 +178,7 @@ static void do_set_action(struct pmc *pmc, int action, int 
index, char *str)
        struct port_ds_np pnp;
        char onoff_port_state[4] = "off";
        char onoff_time_status[4] = "off";
+       char onoff_parent_data_set[4] = "off";
        char display_name[11] = {0};
        uint64_t jump;
        uint8_t key;
@@ -303,12 +304,14 @@ static void do_set_action(struct pmc *pmc, int action, 
int index, char *str)
                cnt = sscanf(str, " %*s %*s "
                             "duration          %hu "
                             "NOTIFY_PORT_STATE %3s "
-                            "NOTIFY_TIME_SYNC  %3s ",
+                            "NOTIFY_TIME_SYNC  %3s "
+                            "NOTIFY_PARENT_DATA_SET %3s ",
                             &sen.duration,
                             onoff_port_state,
-                            onoff_time_status);
-               if (cnt != 3) {
-                       fprintf(stderr, "%s SET needs 3 values\n",
+                            onoff_time_status,
+                            onoff_parent_data_set);
+               if (cnt != 4) {
+                       fprintf(stderr, "%s SET needs 4 values\n",
                                idtab[index].name);
                        break;
                }
@@ -318,6 +321,10 @@ static void do_set_action(struct pmc *pmc, int action, int 
index, char *str)
                if (!strcasecmp(onoff_time_status, "on")) {
                        event_bitmask_set(sen.bitmask, NOTIFY_TIME_SYNC, TRUE);
                }
+               if (!strcasecmp(onoff_parent_data_set, "on")) {
+                       event_bitmask_set(sen.bitmask, NOTIFY_PARENT_DATA_SET,
+                                         TRUE);
+               }
                pmc_send_set_action(pmc, code, &sen, sizeof(sen));
                break;
        case MID_SYNCHRONIZATION_UNCERTAIN_NP:
-- 
2.40.1



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

Reply via email to