From f192bfae45c7d034c2d7a7d9aaf9a207cf9fb638 Mon Sep 17 00:00:00 2001
From: lioux <lioux@FreeBSD.org>
Date: Thu, 2 Jan 2003 05:46:09 +0000
Subject: o Remove ONLY_FOR_ARCHS limitation by adding timing support other  
 than RDTSC registers from Pentium. After a reminder by Garrett   Wollman
 <wollman@FreeBSD.org> [1] that FreeBSD has a gethrtime()   similar function,
 added experimental support for FreeBSD   clock_gettime(2) which should work
 in all FreeBSD supported ARCHes

o Add notes in both DESCR and PKGMESSAGE that there might be precision
  differences since this is experimental code

Reviewed by:	portmgr (silence/no objections)
Submitted by:	wollman [1]
---
 sysutils/clockspeed/Makefile                 |  9 +++++++-
 sysutils/clockspeed/files/patch-aa           | 32 +++++++++++++++++++++++-----
 sysutils/clockspeed/files/patch-ac           | 22 +++++++++++++++----
 sysutils/clockspeed/files/patch-timing.h     | 31 +++++++++++++++++++++++++++
 sysutils/clockspeed/files/tryclock_gettime.c |  8 +++++++
 sysutils/clockspeed/pkg-descr                |  5 +++++
 sysutils/clockspeed/pkg-message              |  5 +++++
 7 files changed, 102 insertions(+), 10 deletions(-)
 create mode 100644 sysutils/clockspeed/files/patch-timing.h
 create mode 100644 sysutils/clockspeed/files/tryclock_gettime.c

(limited to 'sysutils/clockspeed')

diff --git a/sysutils/clockspeed/Makefile b/sysutils/clockspeed/Makefile
index afb4f8c..3af11c9 100644
--- a/sysutils/clockspeed/Makefile
+++ b/sysutils/clockspeed/Makefile
@@ -17,7 +17,6 @@ MAINTAINER=	lioux@FreeBSD.org
 
 LIB_DEPENDS=	tai.1:${PORTSDIR}/devel/libtai
 
-ONLY_FOR_ARCHS=	i386
 ALL_TARGET=	it
 USE_REINPLACE=	yes
 INSTALL_TARGET=	setup check
@@ -31,6 +30,14 @@ RC_SCRIPT_STARTUP_DIR=		${PREFIX}/etc/rc.d
 
 .include <bsd.port.pre.mk>
 
+post-extract:
+# get this port working under FreeBSD non-i386
+	@${INSTALL} ${FILESDIR}/tryclock_gettime.c ${WRKSRC}
+	@${ECHO} tryclock_gettime.c >> ${WRKSRC}/FILES
+.for file in SYSDEPS TARGETS
+	@${ECHO} hasclock_gettime.h >> ${WRKSRC}/${file}
+.endfor
+
 post-patch: real-post-patch
 
 do-configure:
diff --git a/sysutils/clockspeed/files/patch-aa b/sysutils/clockspeed/files/patch-aa
index 4483dda..45f6287 100644
--- a/sysutils/clockspeed/files/patch-aa
+++ b/sysutils/clockspeed/files/patch-aa
@@ -1,6 +1,28 @@
---- Makefile.orig	Fri Jun 16 22:21:58 2000
-+++ Makefile	Fri Jun 16 22:23:28 2000
-@@ -293,10 +293,10 @@
+--- Makefile.orig	Tue Oct 13 15:37:28 1998
++++ Makefile	Sat Dec 21 14:50:57 2002
+@@ -74,6 +74,7 @@
+ 
+ clockspeed.o: \
+ compile clockspeed.c readwrite.h exit.h select.h scan.h fmt.h str.h \
++hasclock_gettime.h \
+ fifo.h open.h error.h auto_home.h timing.h hasrdtsc.h hasgethr.h
+ 	./compile clockspeed.c
+ 
+@@ -137,6 +138,13 @@
+ 	./makelib fs.a fmt_str.o fmt_uint.o fmt_uint0.o \
+ 	fmt_ulong.o scan_ulong.o
+ 
++hasclock_gettime.h: \
++tryclock_gettime.c compile load
++	( ( ./compile tryclock_gettime.c && ./load tryclock_gettime ) >/dev/null \
++	2>&1 \
++	&& echo \#define HASCLOCK_GETTIME 1 || exit 0 ) > hasclock_gettime.h
++	rm -f tryclock_gettime.o
++
+ hasgethr.h: \
+ trygethr.c compile load
+ 	( ( ./compile trygethr.c && ./load trygethr ) >/dev/null \
+@@ -293,10 +301,10 @@
  	chmod 400 shar
  
  sntpclock: \
@@ -14,7 +36,7 @@
  
  sntpclock.0: \
  sntpclock.1
-@@ -406,10 +406,10 @@
+@@ -406,10 +414,10 @@
  	./compile taia_unpack.c
  
  taiclock: \
@@ -28,7 +50,7 @@
  
  taiclock.0: \
  taiclock.1
-@@ -421,10 +421,10 @@
+@@ -421,10 +429,10 @@
  	./compile taiclock.c
  
  taiclockd: \
diff --git a/sysutils/clockspeed/files/patch-ac b/sysutils/clockspeed/files/patch-ac
index 6f94e6d..d28fb7c 100644
--- a/sysutils/clockspeed/files/patch-ac
+++ b/sysutils/clockspeed/files/patch-ac
@@ -1,6 +1,20 @@
 --- clockspeed.c.orig	Tue Oct 13 15:37:28 1998
-+++ clockspeed.c	Mon Nov 20 09:06:34 2000
-@@ -83,7 +83,7 @@
++++ clockspeed.c	Sat Dec 21 15:00:32 2002
+@@ -14,11 +14,13 @@
+ 
+ #ifndef HASRDTSC
+ #ifndef HASGETHRTIME
++#ifndef HASCLOCK_GETTIME
+ 
+   Error! Need an unadjusted hardware clock.
+ 
+ #endif
+ #endif
++#endif
+ 
+ struct point {
+   timing lowlevel;
+@@ -83,7 +85,7 @@
    if (deriv <= 0) return;
    if (deriv > 200000000) return; /* 5Hz ticks? be serious */
  
@@ -9,7 +23,7 @@
    if (fd == -1) return;
  
    buf[0] = 0;
-@@ -119,7 +119,7 @@
+@@ -119,7 +121,7 @@
    if (fsync(fd) == -1) { close(fd); return; }
    if (close(fd) == -1) return; /* NFS stupidity */
  
@@ -18,7 +32,7 @@
  }
  
  void main()
-@@ -136,16 +136,16 @@
+@@ -136,16 +138,16 @@
    if (chdir(auto_home) == -1) _exit(1);
    umask(033);
  
diff --git a/sysutils/clockspeed/files/patch-timing.h b/sysutils/clockspeed/files/patch-timing.h
new file mode 100644
index 0000000..dea14a7
--- /dev/null
+++ b/sysutils/clockspeed/files/patch-timing.h
@@ -0,0 +1,31 @@
+--- timing.h.orig	Tue Oct 13 15:37:28 1998
++++ timing.h	Wed Dec 25 17:20:03 2002
+@@ -3,6 +3,7 @@
+ 
+ #include "hasrdtsc.h"
+ #include "hasgethr.h"
++#include "hasclock_gettime.h"
+ #include <sys/types.h>
+ #include <sys/time.h>
+ 
+@@ -25,11 +26,20 @@
+ #define timing_diff(x,y) ((double) ((x)->t - (y)->t))
+ 
+ #else
++#ifdef HASCLOCK_GETTIME
++
++typedef struct { struct timespec t; } timing;
++#define timing_now(x) ((void) clock_gettime(CLOCK_REALTIME, &((x)->t)))
++/* in seconds */
++#define timing_diff(x,y) (((x)->t.tv_sec - (double) (y)->t.tv_sec) + (4294967296.0*((x)->t.tv_nsec - (double) (y)->t.tv_nsec)))/1e9)
++
++#else
+ 
+ #define timing timing_basic
+ #define timing_now timing_basic_now
+ #define timing_diff timing_basic_diff
+ 
++#endif
+ #endif
+ #endif
+ 
diff --git a/sysutils/clockspeed/files/tryclock_gettime.c b/sysutils/clockspeed/files/tryclock_gettime.c
new file mode 100644
index 0000000..0e5bd1c
--- /dev/null
+++ b/sysutils/clockspeed/files/tryclock_gettime.c
@@ -0,0 +1,8 @@
+#include <sys/time.h>
+
+main()
+{
+  struct timespec ts;
+
+  (void) clock_gettime(CLOCK_REALTIME, &ts);
+}
diff --git a/sysutils/clockspeed/pkg-descr b/sysutils/clockspeed/pkg-descr
index c2e390d..4e70876 100644
--- a/sysutils/clockspeed/pkg-descr
+++ b/sysutils/clockspeed/pkg-descr
@@ -13,4 +13,9 @@ without the hassles and potential security problems of an NTP server.
 This version of clockspeed can use the Pentium RDTSC tick counter or the
 Solaris gethrtime() nanosecond counter.
 
+A port to non-i386 platforms was done using the clock_gettime(2)
+function. Since this is somewhat experimental, there might be some
+tiny precision differences from the i386 platform versions. You
+have been warned!
+
 WWW: http://cr.yp.to/clockspeed.html
diff --git a/sysutils/clockspeed/pkg-message b/sysutils/clockspeed/pkg-message
index 5a6f932..779622c70 100644
--- a/sysutils/clockspeed/pkg-message
+++ b/sysutils/clockspeed/pkg-message
@@ -43,3 +43,8 @@ within milliseconds.
 Do not forget to add a cron(8) job with step 4 to periodically
 adjust clockspeed's drift rate. Once a week should be more than
 adequate.
+
+A port to non-i386 platforms was done using the clock_gettime(2)
+function. Since this is somewhat experimental, there might be some
+tiny precision differences from the i386 platform versions. You
+have been warned!
-- 
cgit v1.1