[Git][NTPsec/ntpsec][deglobal] Deglobalized packet_counters.

Ian Bruene gitlab at mg.gitlab.com
Mon May 14 14:45:33 UTC 2018


Ian Bruene pushed to branch deglobal at NTPsec / ntpsec


Commits:
334a0ae4 by Ian Bruene at 2018-05-14T14:43:42Z
Deglobalized packet_counters.

- - - - -


4 changed files:

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


Changes:

=====================================
include/ntpd.h
=====================================
--- a/include/ntpd.h
+++ b/include/ntpd.h
@@ -231,17 +231,19 @@ extern	void	reset_auth_stats(void);
 /*
  * Other statistics of possible interest
  */
-extern uint64_t packets_dropped;	/* # packets dropped on reception */
-extern uint64_t packets_ignored;	/* received on wild card interface */
-extern uint64_t packets_received;	/* total number of packets received */
-extern uint64_t packets_sent;		/* total number of packets sent */
-extern uint64_t packets_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. */
-extern uint64_t handler_calls;	/* number of calls to interrupt handler */
-extern uint64_t handler_pkts;	/* number of pkts received by handler */
-extern uptime_t io_timereset;	/* time counters were reset */
+struct packet_counters {
+   uint64_t packets_dropped;	/* # packets dropped on reception */
+   uint64_t packets_ignored;	/* received on wild card interface */
+   uint64_t packets_received;	/* total number of packets received */
+   uint64_t packets_sent;		/* total number of packets sent */
+   uint64_t packets_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 */
 extern bool	disable_dynamic_updates;


=====================================
ntpd/ntp_control.c
=====================================
--- a/ntpd/ntp_control.c
+++ b/ntpd/ntp_control.c
@@ -1956,7 +1956,7 @@ ctl_putsys(
 
 	case CS_IOSTATS_RESET:
 		ctl_putuint(sys_var[varid].text,
-			    current_time - io_timereset);
+			    current_time - pkt_count.io_timereset);
 		break;
 
 	case CS_TOTAL_RBUF:
@@ -1976,31 +1976,31 @@ ctl_putsys(
 		break;
 
 	case CS_IO_DROPPED:
-		ctl_putuint(sys_var[varid].text, packets_dropped);
+		ctl_putuint(sys_var[varid].text, pkt_count.packets_dropped);
 		break;
 
 	case CS_IO_IGNORED:
-		ctl_putuint(sys_var[varid].text, packets_ignored);
+		ctl_putuint(sys_var[varid].text, pkt_count.packets_ignored);
 		break;
 
 	case CS_IO_RECEIVED:
-		ctl_putuint(sys_var[varid].text, packets_received);
+		ctl_putuint(sys_var[varid].text, pkt_count.packets_received);
 		break;
 
 	case CS_IO_SENT:
-		ctl_putuint(sys_var[varid].text, packets_sent);
+		ctl_putuint(sys_var[varid].text, pkt_count.packets_sent);
 		break;
 
 	case CS_IO_SENDFAILED:
-		ctl_putuint(sys_var[varid].text, packets_notsent);
+		ctl_putuint(sys_var[varid].text, pkt_count.packets_notsent);
 		break;
 
 	case CS_IO_WAKEUPS:
-		ctl_putuint(sys_var[varid].text, handler_calls);
+		ctl_putuint(sys_var[varid].text, pkt_count.handler_calls);
 		break;
 
 	case CS_IO_GOODWAKEUPS:
-		ctl_putuint(sys_var[varid].text, handler_pkts);
+		ctl_putuint(sys_var[varid].text, pkt_count.handler_pkts);
 		break;
 
 	case CS_TIMERSTATS_RESET:


=====================================
ntpd/ntp_io.c
=====================================
--- a/ntpd/ntp_io.c
+++ b/ntpd/ntp_io.c
@@ -97,15 +97,7 @@ static nic_rule *nic_rule_list;
 /*
  * Other statistics of possible interest
  */
-uint64_t packets_dropped;	/* total # of packets dropped on reception */
-uint64_t packets_ignored;	/* packets received on wild card interface */
-uint64_t packets_received;	/* total # of packets received */
-uint64_t packets_sent;		/* total # of packets sent */
-uint64_t packets_notsent;	/* total # of packets which couldn't be sent */
-
-uint64_t handler_calls;		/* # 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;
 
 /*
  * Interface stuff
@@ -2177,10 +2169,10 @@ sendpkt(
 		    &dest->sa, SOCKLEN(dest));
 	if (cc == -1) {
 		src->notsent++;
-		packets_notsent++;
+		pkt_count.packets_notsent++;
 	} else	{
 		src->sent++;
-		packets_sent++;
+		pkt_count.packets_sent++;
 	}
 }
 
@@ -2216,7 +2208,7 @@ read_refclock_packet(
 		char buf[RX_BUFF_SIZE];
 
 		buflen = read(fd, buf, sizeof buf);
-		packets_dropped++;
+		pkt_count.packets_dropped++;
 		return (buflen);
 	}
 
@@ -2251,7 +2243,7 @@ read_refclock_packet(
 	consumed = indicate_refclock_packet(rp, rb);
 	if (!consumed) {
 		rp->recvcount++;
-		packets_received++;
+		pkt_count.packets_received++;
 	}
 
 	return (int)buflen;
@@ -2301,9 +2293,9 @@ read_network_packet(
 			    : "drop",
 			free_recvbuffs(), fd, socktoa(&from)));
 		if (itf->ignore_packets)
-			packets_ignored++;
+			pkt_count.packets_ignored++;
 		else
-			packets_dropped++;
+			pkt_count.packets_dropped++;
 		return (buflen);
 	}
 
@@ -2364,7 +2356,7 @@ read_network_packet(
 		if (   IN6_IS_ADDR_LOOPBACK(PSOCK_ADDR6(&rb->recv_srcadr))
 		    && !IN6_IS_ADDR_LOOPBACK(PSOCK_ADDR6(&itf->sin))
 		   ) {
-			packets_dropped++;
+			pkt_count.packets_dropped++;
 			DPRINT(2, ("DROPPING that packet\n"));
 			freerecvbuf(rb);
 			return buflen;
@@ -2389,7 +2381,7 @@ read_network_packet(
 	add_full_recv_buffer(rb);
 
 	itf->received++;
-	packets_received++;
+	pkt_count.packets_received++;
 	return (buflen);
 }
 
@@ -2467,7 +2459,7 @@ input_handler(
 	struct asyncio_reader *	next_asyncio_reader;
 #endif
 
-	handler_calls++;
+	pkt_count.handler_calls++;
 	select_count = 0;
 
 	/*
@@ -2476,7 +2468,7 @@ input_handler(
 	 */
 	ts = *cts;
 
-	++handler_pkts;
+	++pkt_count.handler_pkts;
 
 #ifdef REFCLOCK
 	/*
@@ -3016,15 +3008,15 @@ findbcastinter(
 void
 io_clr_stats(void)
 {
-	packets_dropped = 0;
-	packets_ignored = 0;
-	packets_received = 0;
-	packets_sent = 0;
-	packets_notsent = 0;
+	pkt_count.packets_dropped = 0;
+	pkt_count.packets_ignored = 0;
+	pkt_count.packets_received = 0;
+	pkt_count.packets_sent = 0;
+	pkt_count.packets_notsent = 0;
 
-	handler_calls = 0;
-	handler_pkts = 0;
-	io_timereset = current_time;
+	pkt_count.handler_calls = 0;
+	pkt_count.handler_pkts = 0;
+	pkt_count.io_timereset = current_time;
 }
 
 


=====================================
ntpd/refclock_generic.c
=====================================
--- a/ntpd/refclock_generic.c
+++ b/ntpd/refclock_generic.c
@@ -1902,7 +1902,7 @@ local_input(
 					buf->fd           = rbufp->fd;
 					buf->recv_peer    = rbufp->recv_peer;
 					parse->generic->io.recvcount++;
-					packets_received++;
+					pkt_count.packets_received++;
 					add_full_recv_buffer(buf);
 				}
 				parse_iodone(&parse->parseio);



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

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/334a0ae4c7818aa11af873b55afaf09fbeff3f09
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/20180514/723e21f0/attachment.html>


More information about the vc mailing list