This patch adds the pm data collection for the specific port. Signed-off-by: Anders Selhammer <anders.selham...@est.tech> --- clock.c | 4 ++++ port.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ port.h | 9 +++++++++ port_private.h | 4 ++++ 4 files changed, 78 insertions(+)
diff --git a/clock.c b/clock.c index 8135b39..ee5f855 100644 --- a/clock.c +++ b/clock.c @@ -148,11 +148,15 @@ static void clock_set_pmtime(struct clock *c) { struct timespec now; PMTimestamp pmtime; + struct port *p; clock_gettime(CLOCK_MONOTONIC, &now); pmtime = timespec_to_tmv(now); c->pm_stats_record.head.PMTime = pmtime; + LIST_FOREACH(p, &c->ports, list) { + port_set_pmtime(p, pmtime); + } } static void remove_subscriber(struct clock_subscriber *s) diff --git a/port.c b/port.c index 4ec8b70..6ae37b1 100644 --- a/port.c +++ b/port.c @@ -56,6 +56,12 @@ static int port_capable(struct port *p); static int port_is_ieee8021as(struct port *p); static void port_nrate_initialize(struct port *p); +void port_set_pmtime(struct port *p, PMTimestamp pmtime) +{ + p->pm_stats_record.head.PMTime = pmtime; + p->pm_counter_record.head.PMTime = pmtime; +} + static int announce_compare(struct ptp_message *m1, struct ptp_message *m2) { struct announce_msg *a = &m1->announce, *b = &m2->announce; @@ -329,6 +335,8 @@ static int add_foreign_master(struct port *p, struct ptp_message *m) struct ptp_message *tmp; int broke_threshold = 0, diff = 0; + p->pm_counter_record.counter[ANNOUNCE_FOREIGN_MASTER_RX]++; + LIST_FOREACH(fc, &p->foreign_masters, list) { if (msg_source_equal(m, fc)) { break; @@ -1235,6 +1243,9 @@ static int port_pdelay_request(struct port *p) pr_err("port %hu: send peer delay request failed", portnum(p)); goto out; } + + p->pm_counter_record.counter[PDELAY_REQ_TX]++; + if (msg_sots_missing(msg)) { pr_err("missing timestamp on transmitted peer delay request"); goto out; @@ -1298,6 +1309,9 @@ int port_delay_request(struct port *p) pr_err("port %hu: send delay request failed", portnum(p)); goto out; } + + p->pm_counter_record.counter[DELAY_REQ_TX]++; + if (msg_sots_missing(msg)) { pr_err("missing timestamp on transmitted delay request"); goto out; @@ -1354,7 +1368,11 @@ static int port_tx_announce(struct port *p) err = port_prepare_and_send(p, msg, 0); if (err) { pr_err("port %hu: send announce failed", portnum(p)); + goto out; } + + p->pm_counter_record.counter[ANNOUNCE_TX]++; +out: msg_put(msg); return err; } @@ -1420,6 +1438,9 @@ static int port_tx_sync(struct port *p, struct address *dst) pr_err("port %hu: send sync failed", portnum(p)); goto out; } + + p->pm_counter_record.counter[SYNC_TX]++; + if (p->timestamping == TS_ONESTEP || p->timestamping == TS_P2P1STEP) { goto out; } else if (msg_sots_missing(msg)) { @@ -1457,7 +1478,10 @@ static int port_tx_sync(struct port *p, struct address *dst) err = port_prepare_and_send(p, fup, 0); if (err) { pr_err("port %hu: send follow up failed", portnum(p)); + goto out; } + + p->pm_counter_record.counter[FOLLOWUP_TX]++; out: msg_put(msg); msg_put(fup); @@ -1705,6 +1729,8 @@ int process_announce(struct port *p, struct ptp_message *m) result = update_current_master(p, m); break; } + + p->pm_counter_record.counter[ANNOUNCE_RX]++; return result; } @@ -1724,6 +1750,10 @@ static int process_delay_req(struct port *p, struct ptp_message *m) return 0; } + if (!nsm) { + p->pm_counter_record.counter[DELAY_REQ_RX]++; + } + msg = msg_allocate(); if (!msg) { return -1; @@ -1760,11 +1790,14 @@ static int process_delay_req(struct port *p, struct ptp_message *m) pr_err("port %hu: send delay response failed", portnum(p)); goto out; } + if (nsm) { saved_seqnum_sync = p->seqnum.sync; p->seqnum.sync = m->header.sequenceId; err = port_tx_sync(p, &m->address); p->seqnum.sync = saved_seqnum_sync; + } else { + p->pm_counter_record.counter[DELAY_RESP_TX]++; } out: msg_put(msg); @@ -1808,6 +1841,8 @@ static void process_delay_resp(struct port *p, struct ptp_message *m) TAILQ_REMOVE(&p->delay_req, req, list); msg_put(req); + p->pm_counter_record.counter[DELAY_RESP_RX]++; + if (p->logMinDelayReqInterval == rsp->hdr.logMessageInterval) { return; } @@ -1850,6 +1885,8 @@ void process_follow_up(struct port *p, struct ptp_message *m) return; } + p->pm_counter_record.counter[FOLLOWUP_RX]++; + if (p->follow_up_info) { struct follow_up_info_tlv *fui = follow_up_info_extract(m); if (!fui) @@ -1910,6 +1947,8 @@ int process_pdelay_req(struct port *p, struct ptp_message *m) pid2str(&p->peer_portid)); } + p->pm_counter_record.counter[PDELAY_REQ_RX]++; + rsp = msg_allocate(); if (!rsp) { return -1; @@ -1958,6 +1997,8 @@ int process_pdelay_req(struct port *p, struct ptp_message *m) goto out; } + p->pm_counter_record.counter[PDELAY_RESP_TX]++; + /* * Send the follow up message right away. */ @@ -1981,7 +2022,10 @@ int process_pdelay_req(struct port *p, struct ptp_message *m) err = peer_prepare_and_send(p, fup, 0); if (err) { pr_err("port %hu: send pdelay_resp_fup failed", portnum(p)); + goto out; } + + p->pm_counter_record.counter[PDELAY_RESP_FOLLOWUP_TX]++; out: msg_put(rsp); msg_put(fup); @@ -2050,6 +2094,10 @@ calc: return; p->peerMeanPathDelay = tmv_to_TimeInterval(p->peer_delay); + if (clock_performance_monitoring(p->clock)) { + stats_add_value(p->pm_stats_record.meanLinkDelay, + tmv_dbl(p->peer_delay)); + } if (p->state == PS_UNCALIBRATED || p->state == PS_SLAVE) { clock_peer_delay(p->clock, p->peer_delay, t1, t2, @@ -2095,6 +2143,8 @@ int process_pdelay_resp(struct port *p, struct ptp_message *m) pid2str(&p->peer_portid)); } + p->pm_counter_record.counter[PDELAY_RESP_RX]++; + if (p->peer_delay_resp) { msg_put(p->peer_delay_resp); } @@ -2110,6 +2160,8 @@ void process_pdelay_resp_fup(struct port *p, struct ptp_message *m) return; } + p->pm_counter_record.counter[PDELAY_RESP_FOLLOWUP_RX]++; + if (p->peer_delay_fup) { msg_put(p->peer_delay_fup); } @@ -2147,6 +2199,8 @@ void process_sync(struct port *p, struct ptp_message *m) clock_sync_interval(p->clock, p->log_sync_interval); } + p->pm_counter_record.counter[SYNC_RX]++; + m->header.correction += p->asymmetry; if (one_step(m)) { @@ -2183,6 +2237,7 @@ void port_close(struct port *p) if (p->fault_fd >= 0) { close(p->fault_fd); } + pm_destroy_port_stats(&p->pm_stats_record); free(p); } @@ -2865,8 +2920,14 @@ struct port *port_open(int phc_index, goto err_tsproc; } } + if (pm_create_port_stats(&p->pm_stats_record)) { + pr_err("failed to create pm port stats"); + goto err_pmstats; + } return p; +err_pmstats: + pm_destroy_port_stats(&p->pm_stats_record); err_tsproc: tsproc_destroy(p->tsproc); err_transport: diff --git a/port.h b/port.h index a76b2bd..028701e 100644 --- a/port.h +++ b/port.h @@ -24,6 +24,7 @@ #include "foreign.h" #include "fsm.h" #include "notification.h" +#include "pm.h" #include "transport.h" /* forward declarations */ @@ -34,6 +35,14 @@ struct clock; struct port; /** + * Set the pm timestamp for the current port pm data. + * + * @param port A port instance. + * @param pmtime Current pm timestamp. + */ +void port_set_pmtime(struct port *p, PMTimestamp pmtime); + +/** * Returns the dataset from a port's best foreign clock record, if any * has yet been discovered. This function does not bring the returned * dataset up to date, so the caller should invoke port_compute_best() diff --git a/port_private.h b/port_private.h index 860a2bb..ae03509 100644 --- a/port_private.h +++ b/port_private.h @@ -24,6 +24,7 @@ #include "clock.h" #include "fsm.h" #include "msg.h" +#include "pm.h" #include "tmv.h" #define NSEC2SEC 1000000000LL @@ -120,6 +121,9 @@ struct port { unsigned int versionNumber; /*UInteger4*/ /* foreignMasterDS */ LIST_HEAD(fm, foreign_clock) foreign_masters; + /* performance monitoring */ + struct pm_port_stats pm_stats_record; + struct pm_port_counters pm_counter_record; }; #define portnum(p) (p->portIdentity.portNumber) -- 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