svn commit: r242942 - in projects/calloutng/sys: kern sys

Davide Italiano davide at FreeBSD.org
Tue Nov 13 03:00:02 UTC 2012


Author: davide
Date: Tue Nov 13 03:00:01 2012
New Revision: 242942
URL: http://svnweb.freebsd.org/changeset/base/242942

Log:
  Implement TIMESEL(). This macro allow to select between getbinuptime() or
  binuptime() depending on the value passed to it. The rationale behind is
  that the effect of the relative error of getbinuptime() becomes small
  if the intervals we're dealing with increase.
  While here, move some macros to <sys/time.h> in order to avoid code
  duplication.
  
  Reviewed by:	mav

Modified:
  projects/calloutng/sys/kern/kern_clocksource.c
  projects/calloutng/sys/kern/kern_tc.c
  projects/calloutng/sys/kern/kern_timeout.c
  projects/calloutng/sys/sys/time.h

Modified: projects/calloutng/sys/kern/kern_clocksource.c
==============================================================================
--- projects/calloutng/sys/kern/kern_clocksource.c	Tue Nov 13 02:50:39 2012	(r242941)
+++ projects/calloutng/sys/kern/kern_clocksource.c	Tue Nov 13 03:00:01 2012	(r242942)
@@ -147,15 +147,6 @@ struct pcpu_state {
 
 static DPCPU_DEFINE(struct pcpu_state, timerstate);
 
-#define FREQ2BT(freq, bt)						\
-{									\
-	(bt)->sec = 0;							\
-	(bt)->frac = ((uint64_t)0x8000000000000000  / (freq)) << 1;	\
-}
-#define BT2FREQ(bt)							\
-	(((uint64_t)0x8000000000000000 + ((bt)->frac >> 2)) /		\
-	    ((bt)->frac >> 1))
-
 /*
  * Timer broadcast IPI handler.
  */

Modified: projects/calloutng/sys/kern/kern_tc.c
==============================================================================
--- projects/calloutng/sys/kern/kern_tc.c	Tue Nov 13 02:50:39 2012	(r242941)
+++ projects/calloutng/sys/kern/kern_tc.c	Tue Nov 13 03:00:01 2012	(r242942)
@@ -119,6 +119,11 @@ static int timestepwarnings;
 SYSCTL_INT(_kern_timecounter, OID_AUTO, stepwarnings, CTLFLAG_RW,
     &timestepwarnings, 0, "Log time steps");
 
+int tc_timethreshold;
+struct bintime tick_bt;
+SYSCTL_INT(_kern, OID_AUTO, tc_timethreshold, CTLFLAG_RW, 
+    &tc_timethreshold, 0, "Precision threshold for timing measurements"); 
+
 static void tc_windup(void);
 static void cpu_tick_calibrate(int);
 
@@ -1708,6 +1713,7 @@ tc_ticktock(int cnt)
 static void
 inittimecounter(void *dummy)
 {
+	int tick_rate;
 	u_int p;
 
 	/*
@@ -1723,6 +1729,9 @@ inittimecounter(void *dummy)
 	else
 		tc_tick = 1;
 	p = (tc_tick * 1000000) / hz;
+	tc_timethreshold = 20 * imin(1000000000 / hz, 1000000);
+	tick_rate = imax(hz, tc_tick);
+	FREQ2BT(tick_rate, &tick_bt);
 	printf("Timecounters tick every %d.%03u msec\n", p / 1000, p % 1000);
 
 #ifdef FFCLOCK

Modified: projects/calloutng/sys/kern/kern_timeout.c
==============================================================================
--- projects/calloutng/sys/kern/kern_timeout.c	Tue Nov 13 02:50:39 2012	(r242941)
+++ projects/calloutng/sys/kern/kern_timeout.c	Tue Nov 13 03:00:01 2012	(r242942)
@@ -55,6 +55,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/sleepqueue.h>
 #include <sys/sysctl.h>
 #include <sys/smp.h>
+#include <sys/time.h>
 
 #ifdef SMP
 #include <machine/cpu.h>
@@ -171,12 +172,6 @@ struct callout_cpu cc_cpu;
 #define	CC_UNLOCK(cc)	mtx_unlock_spin(&(cc)->cc_lock)
 #define	CC_LOCK_ASSERT(cc)	mtx_assert(&(cc)->cc_lock, MA_OWNED)
 
-#define FREQ2BT(freq, bt)                                               \
-{                                                                       \
-        (bt)->sec = 0;                                                  \
-        (bt)->frac = ((uint64_t)0x8000000000000000  / (freq)) << 1;     \
-}
-
 #define	TIME_T_MAX							\
 	(sizeof(time_t) == (sizeof(int64_t)) ? INT64_MAX : INT32_MAX)
 

Modified: projects/calloutng/sys/sys/time.h
==============================================================================
--- projects/calloutng/sys/sys/time.h	Tue Nov 13 02:50:39 2012	(r242941)
+++ projects/calloutng/sys/sys/time.h	Tue Nov 13 03:00:01 2012	(r242942)
@@ -55,6 +55,21 @@ struct bintime {
 	uint64_t frac;
 };
 
+extern int tc_timethreshold;
+extern struct bintime tick_bt;
+
+#define FREQ2BT(freq, bt)                                               \
+{                                                                       \
+        (bt)->sec = 0;                                                  \
+        (bt)->frac = ((uint64_t)0x8000000000000000  / (freq)) << 1;     \
+}
+#define BT2FREQ(bt)                                                     \
+        (((uint64_t)0x8000000000000000 + ((bt)->frac >> 2)) /           \
+            ((bt)->frac >> 1))
+
+#define TIMESEL(x, bt)          					\
+	(((x) < (c_timethreshold)) ? binuptime(&bt) : getbinuptime(&bt))
+
 static __inline void
 bintime_addx(struct bintime *bt, uint64_t x)
 {


More information about the svn-src-projects mailing list