> -----Original Message----- > From: Petr Machata [mailto:pe...@mellanox.com] > Sent: Tuesday, September 10, 2019 5:24 AM > To: linuxptp-devel@lists.sourceforge.net > Cc: Petr Machata <pe...@mellanox.com>; Keller, Jacob E > <jacob.e.kel...@intel.com> > Subject: [PATCH v2 1/2] port: Introduce per-port stats for received and > transmitted > messages > > Add struct PortStats to keep per-port number of messages sent and received, > split by message type. Bump TX counters after messages are sent > successfully, and RX counters after a message is received. To keep things > simple, reserve one counter for each theoretically possible message type, > including the reserved ones. > > Signed-off-by: Petr Machata <pe...@mellanox.com> > --- > > Notes: > v2: > - Add MAX_MESSAGE_TYPES with comment instead of using a bare constant. >
Great, thanks! -Jake > ddt.h | 7 +++++++ > port.c | 25 +++++++++++++++++++++++-- > port_private.h | 1 + > 3 files changed, 31 insertions(+), 2 deletions(-) > > diff --git a/ddt.h b/ddt.h > index 4acaa4f..56449a3 100644 > --- a/ddt.h > +++ b/ddt.h > @@ -100,4 +100,11 @@ struct FaultRecord { > struct PTPText faultDescription; > }; > > +/* Four bits are dedicated to messageType field */ > +#define MAX_MESSAGE_TYPES 16 > +struct PortStats { > + uint64_t rxMsgType[MAX_MESSAGE_TYPES]; > + uint64_t txMsgType[MAX_MESSAGE_TYPES]; > +}; > + > #endif > diff --git a/port.c b/port.c > index 5a4a116..471e6f4 100644 > --- a/port.c > +++ b/port.c > @@ -580,6 +580,16 @@ static int path_trace_ignore(struct port *p, struct > ptp_message *m) > return 0; > } > > +static void port_stats_inc_rx(struct port *p, const struct ptp_message *msg) > +{ > + p->stats.rxMsgType[msg_type(msg)]++; > +} > + > +static void port_stats_inc_tx(struct port *p, const struct ptp_message *msg) > +{ > + p->stats.txMsgType[msg_type(msg)]++; > +} > + > static int peer_prepare_and_send(struct port *p, struct ptp_message *msg, > enum transport_event event) > { > @@ -595,6 +605,7 @@ static int peer_prepare_and_send(struct port *p, struct > ptp_message *msg, > if (cnt <= 0) { > return -1; > } > + port_stats_inc_tx(p, msg); > if (msg_sots_valid(msg)) { > ts_add(&msg->hwts.ts, p->tx_timestamp_offset); > } > @@ -2627,6 +2638,7 @@ static enum fsm_event bc_event(struct port *p, int > fd_index) > msg_put(msg); > return EV_NONE; > } > + port_stats_inc_rx(p, msg); > if (port_ignore(p, msg)) { > msg_put(msg); > return EV_NONE; > @@ -2691,14 +2703,22 @@ int port_forward(struct port *p, struct ptp_message > *msg) > { > int cnt; > cnt = transport_send(p->trp, &p->fda, TRANS_GENERAL, msg); > - return cnt <= 0 ? -1 : 0; > + if (cnt <= 0) { > + return -1; > + } > + port_stats_inc_tx(p, msg); > + return 0; > } > > int port_forward_to(struct port *p, struct ptp_message *msg) > { > int cnt; > cnt = transport_sendto(p->trp, &p->fda, TRANS_GENERAL, msg); > - return cnt <= 0 ? -1 : 0; > + if (cnt <= 0) { > + return -1; > + } > + port_stats_inc_tx(p, msg); > + return 0; > } > > int port_prepare_and_send(struct port *p, struct ptp_message *msg, > @@ -2717,6 +2737,7 @@ int port_prepare_and_send(struct port *p, struct > ptp_message *msg, > if (cnt <= 0) { > return -1; > } > + port_stats_inc_tx(p, msg); > if (msg_sots_valid(msg)) { > ts_add(&msg->hwts.ts, p->tx_timestamp_offset); > } > diff --git a/port_private.h b/port_private.h > index 9a5022d..5789fbb 100644 > --- a/port_private.h > +++ b/port_private.h > @@ -139,6 +139,7 @@ struct port { > struct fault_interval flt_interval_pertype[FT_CNT]; > enum fault_type last_fault_type; > unsigned int versionNumber; /*UInteger4*/ > + struct PortStats stats; > /* foreignMasterDS */ > LIST_HEAD(fm, foreign_clock) foreign_masters; > /* TC book keeping */ > -- > 2.20.1 _______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel