From 53fbe7c442e483fee0bf4c198c7ef3183f141a5c Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Fri, 20 Nov 2015 18:53:43 +0000 Subject: use RMS for jitter. we're linking with enough libraries that libm is tiny. ok deraadt --- usr.sbin/ntpd/Makefile | 4 ++-- usr.sbin/ntpd/control.c | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/ntpd/Makefile b/usr.sbin/ntpd/Makefile index 20582ce62f1..d9acd258440 100644 --- a/usr.sbin/ntpd/Makefile +++ b/usr.sbin/ntpd/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.15 2015/10/05 17:26:22 deraadt Exp $ +# $OpenBSD: Makefile,v 1.16 2015/11/20 18:53:42 tedu Exp $ PROG= ntpd SRCS= ntpd.c log.c ntp.c ntp_msg.c parse.y config.c \ @@ -11,7 +11,7 @@ CFLAGS+= -Wmissing-declarations CFLAGS+= -Wshadow -Wpointer-arith -Wcast-qual CFLAGS+= -Wsign-compare YFLAGS= -LDADD+= -lutil -ltls -lssl -lcrypto +LDADD+= -lm -lutil -ltls -lssl -lcrypto DPADD+= ${LIBUTIL} ${LIBCRYPTO} ${LIBSSL} ${LIBTLS} LINKS= ${BINDIR}/ntpd ${BINDIR}/ntpctl MAN= ntpd.8 ntpd.conf.5 ntpctl.8 diff --git a/usr.sbin/ntpd/control.c b/usr.sbin/ntpd/control.c index 08740ba90aa..4f31836b81d 100644 --- a/usr.sbin/ntpd/control.c +++ b/usr.sbin/ntpd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.7 2015/10/23 14:52:20 phessler Exp $ */ +/* $OpenBSD: control.c,v 1.8 2015/11/20 18:53:42 tedu Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -33,6 +34,8 @@ #define CONTROL_BACKLOG 5 +#define square(x) ((x) * (x)) + int control_init(char *path) { @@ -354,21 +357,18 @@ build_show_peer(struct ctl_show_peer *cp, struct ntp_peer *p) cp->delay /= validdelaycnt; } - /* - * use simple average for jitter calculation, as the - * RFC5905-recommended RMS average needs the math library - */ jittercnt = 0; cp->jitter = 0.0; for (shift = 0; shift < OFFSET_ARRAY_SIZE; shift++) { if (p->reply[shift].delay > 0.0 && shift != best) { - cp->jitter += p->reply[shift].delay - - p->reply[best].delay; + cp->jitter += square(p->reply[shift].delay - + p->reply[best].delay); jittercnt++; } } if (jittercnt > 1) cp->jitter /= jittercnt; + cp->jitter = sqrt(cp->jitter); if (p->shift == 0) shift = OFFSET_ARRAY_SIZE - 1; -- cgit v1.2.3