[Git][NTPsec/ntpsec][master] Converted stat_count struct to a module level global.

Eric S. Raymond gitlab at mg.gitlab.com
Wed Aug 28 17:43:53 UTC 2019



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


Commits:
f904f8ce by Ian Bruene at 2019-08-28T01:13:46Z
Converted stat_count struct to a module level global.

- - - - -


4 changed files:

- include/ntpd.h
- ntpd/ntp_control.c
- ntpd/ntp_proto.c
- ntpd/ntp_util.c


Changes:

=====================================
include/ntpd.h
=====================================
@@ -168,6 +168,21 @@ extern	void	set_sys_tick_precision(double);
 extern	void	proto_config	(int, unsigned long, double);
 extern	void	proto_clr_stats (void);
 
+extern uptime_t stat_stattime(void);
+extern uint64_t stat_received(void);
+extern uint64_t stat_processed(void);
+extern uint64_t stat_restricted(void);
+extern void increment_restricted(void);
+extern uint64_t stat_newversion(void);
+extern uint64_t stat_oldversion(void);
+extern uint64_t stat_badlength(void);
+extern uint64_t stat_badauth(void);
+extern uint64_t stat_declined(void);
+extern uint64_t stat_limitrejected(void);
+extern uint64_t stat_kodsent(void);
+extern uptime_t stat_use_stattime(void);
+extern void set_use_stattime(uptime_t stime);
+
 
 
 /* ntp_restrict.c */
@@ -369,25 +384,6 @@ extern struct system_variables sys_vars;
 extern l_fp	sys_authdelay;		/* authentication delay */
 extern int	sys_minsane;		/* minimum candidates */
 
-/*
- * Statistics counters
- */
-struct statistics_counters {
-	uptime_t	sys_stattime;		/* time since sysstats reset */
-	uint64_t	sys_received;		/* packets received */
-	uint64_t	sys_processed;		/* packets for this host */
-	uint64_t	sys_restricted;		/* restricted packets */
-	uint64_t	sys_newversion;		/* current version  */
-	uint64_t	sys_oldversion;		/* old version */
-	uint64_t	sys_badlength;		/* bad length or format */
-	uint64_t	sys_badauth;		/* bad authentication */
-	uint64_t	sys_declined;		/* declined */
-	uint64_t	sys_limitrejected;	/* rate exceeded */
-	uint64_t	sys_kodsent;		/* KoD sent */
-	uptime_t	use_stattime;		/* time since usestats reset */
-};
-extern volatile struct statistics_counters stat_count;
-
 /* Signalling: Set by signal handlers */
 struct signals_detected {
 	bool sawALRM;


=====================================
ntpd/ntp_control.c
=====================================
@@ -1666,48 +1666,47 @@ ctl_putsys(
 		break;
 
 	case CS_SS_RESET:
-		ctl_putuint(sys_var[varid].text,
-			    current_time - stat_count.sys_stattime);
+		ctl_putuint(sys_var[varid].text, current_time - stat_stattime());
 		break;
 
 	case CS_SS_RECEIVED:
-		ctl_putuint(sys_var[varid].text, stat_count.sys_received);
+        ctl_putuint(sys_var[varid].text, stat_received());
 		break;
 
 	case CS_SS_THISVER:
-		ctl_putuint(sys_var[varid].text, stat_count.sys_newversion);
+		ctl_putuint(sys_var[varid].text, stat_newversion());
 		break;
 
 	case CS_SS_OLDVER:
-		ctl_putuint(sys_var[varid].text, stat_count.sys_oldversion);
+		ctl_putuint(sys_var[varid].text, stat_oldversion());
 		break;
 
 	case CS_SS_BADFORMAT:
-		ctl_putuint(sys_var[varid].text, stat_count.sys_badlength);
+		ctl_putuint(sys_var[varid].text, stat_badlength());
 		break;
 
 	case CS_SS_BADAUTH:
-		ctl_putuint(sys_var[varid].text, stat_count.sys_badauth);
+		ctl_putuint(sys_var[varid].text, stat_badauth());
 		break;
 
 	case CS_SS_DECLINED:
-		ctl_putuint(sys_var[varid].text, stat_count.sys_declined);
+		ctl_putuint(sys_var[varid].text, stat_declined());
 		break;
 
 	case CS_SS_RESTRICTED:
-		ctl_putuint(sys_var[varid].text, stat_count.sys_restricted);
+		ctl_putuint(sys_var[varid].text, stat_restricted());
 		break;
 
 	case CS_SS_LIMITED:
-		ctl_putuint(sys_var[varid].text, stat_count.sys_limitrejected);
+		ctl_putuint(sys_var[varid].text, stat_limitrejected());
 		break;
 
 	case CS_SS_KODSENT:
-		ctl_putuint(sys_var[varid].text, stat_count.sys_kodsent);
+		ctl_putuint(sys_var[varid].text, stat_kodsent());
 		break;
 
 	case CS_SS_PROCESSED:
-		ctl_putuint(sys_var[varid].text, stat_count.sys_processed);
+		ctl_putuint(sys_var[varid].text, stat_processed());
 		break;
 
 	case CS_AUTHDELAY:
@@ -2990,7 +2989,7 @@ static void configure(
 				"MODE6: runtime config from %s rejected due"
                                 " to nomodify restriction",
 				socktoa(&rbufp->recv_srcadr));
-		stat_count.sys_restricted++;
+		increment_restricted();
 		return;
 	}
 
@@ -3445,7 +3444,7 @@ static void read_mru_list(
 				"MODE6: mrulist from %s rejected due to"
                                 " nomrulist restriction",
 				socktoa(&rbufp->recv_srcadr));
-		stat_count.sys_restricted++;
+		increment_restricted();
 		return;
 	}
 	/*


=====================================
ntpd/ntp_proto.c
=====================================
@@ -145,8 +145,92 @@ static int sys_orphwait = NTP_ORPHWAIT; /* orphan wait */
  * Statistics counters - first the good, then the bad
  * These get reset every hour if sysstats is enabled.
  */
+struct statistics_counters {
+	uptime_t	sys_stattime;		/* time since sysstats reset */
+	uint64_t	sys_received;		/* packets received */
+	uint64_t	sys_processed;		/* packets for this host */
+	uint64_t	sys_restricted;		/* restricted packets */
+	uint64_t	sys_newversion;		/* current version  */
+	uint64_t	sys_oldversion;		/* old version */
+	uint64_t	sys_badlength;		/* bad length or format */
+	uint64_t	sys_badauth;		/* bad authentication */
+	uint64_t	sys_declined;		/* declined */
+	uint64_t	sys_limitrejected;	/* rate exceeded */
+	uint64_t	sys_kodsent;		/* KoD sent */
+	uptime_t	use_stattime;		/* time since usestats reset */
+};
 volatile struct statistics_counters stat_count;
 
+uptime_t stat_stattime(void)
+{
+  return stat_count.sys_stattime;
+}
+
+uint64_t stat_received(void)
+{
+  return stat_count.sys_received;
+}
+
+uint64_t stat_processed(void)
+{
+  return stat_count.sys_processed;
+}
+
+uint64_t stat_restricted(void)
+{
+  return stat_count.sys_restricted;
+}
+
+void increment_restricted(void)
+{
+  stat_count.sys_restricted++;
+}
+
+uint64_t stat_newversion(void)
+{
+  return stat_count.sys_newversion;
+}
+
+uint64_t stat_oldversion(void)
+{
+  return stat_count.sys_oldversion;
+}
+
+uint64_t stat_badlength(void)
+{
+  return stat_count.sys_badlength;
+}
+
+uint64_t stat_badauth(void)
+{
+  return stat_count.sys_badauth;
+}
+
+uint64_t stat_declined(void)
+{
+  return stat_count.sys_declined;
+}
+
+uint64_t stat_limitrejected(void)
+{
+  return stat_count.sys_limitrejected;
+}
+
+uint64_t stat_kodsent(void)
+{
+  return stat_count.sys_kodsent;
+}
+
+uptime_t stat_use_stattime(void)
+{
+  return stat_count.sys_stattime;
+}
+
+void set_use_stattime(uptime_t stime) {
+  stat_count.sys_stattime = stime;
+}
+
+
 double	measured_tick;		/* non-overridable sys_tick (s) */
 
 static	void	clock_combine	(peer_select *, int, int);


=====================================
ntpd/ntp_util.c
=====================================
@@ -591,12 +591,11 @@ record_sys_stats(void)
 		fprintf(sysstats.fp,
 		    "%s %u %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64
 		    " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 "\n",
-		    timespec_to_MJDtime(&now), current_time - stat_count.sys_stattime,
-			stat_count.sys_received, stat_count.sys_processed,
-			stat_count.sys_newversion, stat_count.sys_oldversion,
-			stat_count.sys_restricted, stat_count.sys_badlength,
-		    stat_count.sys_badauth, stat_count.sys_declined,
-			stat_count.sys_limitrejected, stat_count.sys_kodsent);
+			timespec_to_MJDtime(&now), current_time - stat_stattime(),
+			stat_received(), stat_processed(), stat_newversion(),
+			stat_oldversion(), stat_restricted(), stat_badlength(),
+			stat_badauth(), stat_declined(), stat_limitrejected(),
+			stat_kodsent());
 		fflush(sysstats.fp);
 		proto_clr_stats();
 	}
@@ -635,7 +634,7 @@ void record_use_stats(void)
 		stimex += usage.ru_stime.tv_sec -  oldusage.ru_stime.tv_sec;
 		fprintf(usestats.fp,
 		    "%s %u %.3f %.3f %ld %ld %ld %ld %ld %ld %ld %ld %ld\n",
-		    timespec_to_MJDtime(&now), current_time - stat_count.use_stattime,
+		    timespec_to_MJDtime(&now), current_time - stat_stattime(),
 		    utime, stimex,
 		    usage.ru_minflt -   oldusage.ru_minflt,
 		    usage.ru_majflt -   oldusage.ru_majflt,
@@ -648,7 +647,7 @@ void record_use_stats(void)
 		    usage.ru_maxrss );
 		fflush(usestats.fp);
 		oldusage = usage;
-		stat_count.use_stattime = current_time;
+		set_use_stattime(current_time);
 	}
 }
 



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

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/f904f8ce7cfbfdcf162e3d900a2fc857f21dae00
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/20190828/fd0bef93/attachment-0001.htm>


More information about the vc mailing list