From owner-svn-src-projects@FreeBSD.ORG Tue Nov 13 03:00:02 2012 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 2817A8A7; Tue, 13 Nov 2012 03:00:02 +0000 (UTC) (envelope-from davide@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 052758FC08; Tue, 13 Nov 2012 03:00:02 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id qAD301Lt066538; Tue, 13 Nov 2012 03:00:01 GMT (envelope-from davide@svn.freebsd.org) Received: (from davide@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id qAD301R8066533; Tue, 13 Nov 2012 03:00:01 GMT (envelope-from davide@svn.freebsd.org) Message-Id: <201211130300.qAD301R8066533@svn.freebsd.org> From: Davide Italiano Date: Tue, 13 Nov 2012 03:00:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r242942 - in projects/calloutng/sys: kern sys X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Nov 2012 03:00:02 -0000 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 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, ×tepwarnings, 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 #include #include +#include #ifdef SMP #include @@ -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) {