[Git][NTPsec/ntpsec][master] Conversion of packet counters struct to a module-level global.

Eric S. Raymond gitlab at mg.gitlab.com
Sat Aug 24 18:48:35 UTC 2019



Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
ef898a0d by Ian Bruene at 2019-08-24T16:57:11Z
Conversion of packet counters struct to a module-level global.

- - - - -


4 changed files:

- include/ntpd.h
- ntpd/ntp_control.c
- ntpd/ntp_io.c
- ntpd/refclock_generic.c


Changes:

=====================================
include/ntpd.h
=====================================
@@ -98,6 +98,15 @@ extern	void	io_open_sockets	(void);
 extern	void	io_clr_stats	(void);
 extern	void	sendpkt		(sockaddr_u *, endpt *, void *, unsigned int);
 extern const char * latoa(endpt *);
+extern  uint64_t dropped_count(void);
+extern  uint64_t ignored_count(void);
+extern  uint64_t received_count(void);
+extern  void     inc_received_count(void);
+extern  uint64_t sent_count(void);
+extern  uint64_t notsent_count(void);
+extern  uint64_t handler_calls_count(void);
+extern  uint64_t handler_pkts_count(void);
+extern  uptime_t counter_reset_time(void);
 
 /* ntp_loopfilter.c */
 extern	void	init_loopfilter(void);
@@ -240,23 +249,6 @@ extern char *ntp_signd_socket;
 /* ntp_control.c */
 extern keyid_t	ctl_auth_keyid;		/* keyid used for authenticating write requests */
 
-/*
- * Other statistics of possible interest
- */
-struct packet_counters {
-	uint64_t dropped;	/* # packets dropped on reception */
-	uint64_t ignored;	/* received on wild card interface */
-	uint64_t received;	/* total number of packets received */
-	uint64_t sent;		/* total number of packets sent */
-	uint64_t notsent;	/* total number of packets which couldn't be sent */
-	/* There used to be a signal handler for received packets. */
-	/* It's not needed now that the kernel time stamps packets. */
-	uint64_t handler_calls;	/* number of calls to interrupt handler */
-	uint64_t handler_pkts;	/* number of pkts received by handler */
-	uptime_t io_timereset;	/* time counters were reset */
-};
-extern volatile struct packet_counters pkt_count;
-
 /* ntp_io.c */
 struct ntp_io_data {
   bool disable_dynamic_updates; /* if true, scan interfaces once only */


=====================================
ntpd/ntp_control.c
=====================================
@@ -1879,7 +1879,7 @@ ctl_putsys(
 
 	case CS_IOSTATS_RESET:
 		ctl_putuint(sys_var[varid].text,
-			    current_time - pkt_count.io_timereset);
+            current_time - counter_reset_time());
 		break;
 
 	case CS_TOTAL_RBUF:
@@ -1900,31 +1900,31 @@ ctl_putsys(
 		break;
 
 	case CS_IO_DROPPED:
-		ctl_putuint(sys_var[varid].text, pkt_count.dropped);
+        ctl_putuint(sys_var[varid].text, dropped_count());
 		break;
 
 	case CS_IO_IGNORED:
-		ctl_putuint(sys_var[varid].text, pkt_count.ignored);
+        ctl_putuint(sys_var[varid].text, ignored_count());
 		break;
 
 	case CS_IO_RECEIVED:
-		ctl_putuint(sys_var[varid].text, pkt_count.received);
+        ctl_putuint(sys_var[varid].text, received_count());
 		break;
 
 	case CS_IO_SENT:
-		ctl_putuint(sys_var[varid].text, pkt_count.sent);
+        ctl_putuint(sys_var[varid].text, sent_count());
 		break;
 
 	case CS_IO_SENDFAILED:
-		ctl_putuint(sys_var[varid].text, pkt_count.notsent);
+        ctl_putuint(sys_var[varid].text, notsent_count());
 		break;
 
 	case CS_IO_WAKEUPS:
-		ctl_putuint(sys_var[varid].text, pkt_count.handler_calls);
+        ctl_putuint(sys_var[varid].text, handler_calls_count());
 		break;
 
 	case CS_IO_GOODWAKEUPS:
-		ctl_putuint(sys_var[varid].text, pkt_count.handler_pkts);
+        ctl_putuint(sys_var[varid].text, handler_pkts_count());
 		break;
 
 	case CS_TIMERSTATS_RESET:


=====================================
ntpd/ntp_io.c
=====================================
@@ -86,6 +86,18 @@ static nic_rule *nic_rule_list;
 /*
  * Other statistics of possible interest
  */
+struct packet_counters {
+	uint64_t dropped;	/* # packets dropped on reception */
+	uint64_t ignored;	/* received on wild card interface */
+	uint64_t received;	/* total number of packets received */
+	uint64_t sent;		/* total number of packets sent */
+	uint64_t notsent;	/* total number of packets which couldn't be sent */
+	/* There used to be a signal handler for received packets. */
+	/* It's not needed now that the kernel time stamps packets. */
+	uint64_t handler_calls;	/* number of calls to interrupt handler */
+	uint64_t handler_pkts;	/* number of pkts received by handler */
+	uptime_t io_timereset;	/* time counters were reset */
+};
 volatile struct packet_counters pkt_count;
 
 /*
@@ -2744,6 +2756,69 @@ io_clr_stats(void)
 	pkt_count.io_timereset = current_time;
 }
 
+/*
+ * dropped_count - return the number of dropped packets
+ */
+uint64_t dropped_count(void) {
+  return pkt_count.dropped;
+}
+
+/*
+ * ignored_count - return the number of ignored packets
+ */
+uint64_t ignored_count(void) {
+  return pkt_count.ignored;
+}
+
+/*
+ * received_count - return the number of received packets
+ */
+uint64_t received_count(void) {
+  return pkt_count.received;
+}
+
+/*
+ * inc_recieved_count - increment the number of received packets
+ * required so that refclock_generic.c can track its packets
+ */
+void inc_received_count(void) {
+  pkt_count.received++;
+}
+
+/*
+ * sent_count - return the number of sent packets
+ */
+uint64_t sent_count(void) {
+  return pkt_count.sent;
+}
+/*
+ * notsent_count - return the number of not sent packets
+ */
+uint64_t notsent_count(void) {
+  return pkt_count.notsent;
+}
+
+/*
+ * handler_calls_count - return the number of handler calls
+ */
+uint64_t handler_calls_count(void) {
+  return pkt_count.handler_calls;
+}
+
+/*
+ * handler_pkts_count - return the number of handler packets
+ */
+uint64_t handler_pkts_count(void) {
+  return pkt_count.handler_pkts;
+}
+
+/*
+ * counter_reset_time - return the time of the last counter reset
+ */
+uptime_t counter_reset_time(void) {
+  return pkt_count.io_timereset;
+}
+
 
 #ifdef REFCLOCK
 /*


=====================================
ntpd/refclock_generic.c
=====================================
@@ -1909,7 +1909,7 @@ local_input(
 					buf->fd           = rbufp->fd;
 					buf->recv_peer    = rbufp->recv_peer;
 					parse->generic->io.recvcount++;
-					pkt_count.received++;
+					inc_received_count();
 					local_receive(buf);
 					freerecvbuf(buf);
 				}



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/ef898a0d4f4803cd90a149af926298fe6801404b

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/ef898a0d4f4803cd90a149af926298fe6801404b
You're receiving this email because of your account on gitlab.com.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20190824/e15dacc4/attachment-0001.htm>


More information about the vc mailing list