Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 29 Feb 2012 21:30:28 GMT
From:      Oleksandr Tymoshenko <gonzo@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 207116 for review
Message-ID:  <201202292130.q1TLUSrx077108@skunkworks.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@207116?ac=10

Change 207116 by gonzo@gonzo_thinkpad on 2012/02/29 21:30:19

	switch to nanotime/nanouptime for timimg purpose

Affected files ...

.. //depot/projects/dtrace-mips/sys/cddl/dev/dtrace/mips/dtrace_subr.c#4 edit

Differences ...

==== //depot/projects/dtrace-mips/sys/cddl/dev/dtrace/mips/dtrace_subr.c#4 (text+ko) ====

@@ -105,73 +105,6 @@
         dtrace_xcall(DTRACE_CPUALL, (dtrace_xcall_t)dtrace_sync_func, NULL);
 }
 
-static int64_t	tgt_cpu_counter;
-static int64_t	hst_cpu_counter;
-static int64_t	counter_skew[MAXCPU];
-static uint64_t	nsec_scale;
-
-/* See below for the explanation of this macro. */
-#define SCALE_SHIFT	28
-
-static void
-dtrace_gethrtime_init_cpu(void *arg)
-{
-	uintptr_t cpu = (uintptr_t) arg;
-
-	if (cpu == curcpu)
-		tgt_cpu_counter = mips_rd_count();
-	else
-		hst_cpu_counter = mips_rd_count();
-}
-
-static void
-dtrace_gethrtime_init(void *arg)
-{
-	struct pcpu *pc;
-	cpuset_t map;
-	int i;
-
-	/*
-	 * The following line checks that nsec_scale calculated below
-	 * doesn't overflow 32-bit unsigned integer, so that it can multiply
-	 * another 32-bit integer without overflowing 64-bit.
-	 * Thus minimum supported TSC frequency is 62.5MHz.
-	 */
-	KASSERT(counter_freq > (NANOSEC >> (32 - SCALE_SHIFT)), ("COUNT frequency is too low"));
-
-	/*
-	 * We scale up NANOSEC/counter_freq ratio to preserve as much precision
-	 * as possible.
-	 * 2^28 factor was chosen quite arbitrarily from practical
-	 * considerations:
-	 * - it supports TSC frequencies as low as 62.5MHz (see above);
-	 * - it provides quite good precision (e < 0.01%) up to THz
-	 *   (terahertz) values;
-	 */
-	nsec_scale = ((uint64_t)NANOSEC << SCALE_SHIFT) / counter_freq;
-
-	/* The current CPU is the reference one. */
-	sched_pin();
-	counter_skew[curcpu] = 0;
-	CPU_FOREACH(i) {
-		if (i == curcpu)
-			continue;
-
-		pc = pcpu_find(i);
-		CPU_SETOF(PCPU_GET(cpuid), &map);
-		CPU_SET(pc->pc_cpuid, &map);
-
-		smp_rendezvous_cpus(map, NULL,
-		    dtrace_gethrtime_init_cpu,
-		    smp_no_rendevous_barrier, (void *)(uintptr_t) i);
-
-		counter_skew[i] = tgt_cpu_counter - hst_cpu_counter;
-	}
-	sched_unpin();
-}
-
-SYSINIT(dtrace_gethrtime_init, SI_SUB_SMP, SI_ORDER_ANY, dtrace_gethrtime_init, NULL);
-
 /*
  * DTrace needs a high resolution time function which can
  * be called from a probe context and guaranteed not to have
@@ -182,21 +115,12 @@
 uint64_t
 dtrace_gethrtime()
 {
-	uint64_t counter;
-	uint32_t lo;
-	uint32_t hi;
+	struct      timespec curtime;
+
+	nanouptime(&curtime);
+
+	return (curtime.tv_sec * 1000000000UL + curtime.tv_nsec);
 
-	/*
-	 * We split TSC value into lower and higher 32-bit halves and separately
-	 * scale them with nsec_scale, then we scale them down by 2^28
-	 * (see nsec_scale calculations) taking into account 32-bit shift of
-	 * the higher half and finally add.
-	 */
-	counter = mips_rd_count() + counter_skew[curcpu];
-	lo = counter;
-	hi = counter >> 32;
-	return (((lo * nsec_scale) >> SCALE_SHIFT) +
-	    ((hi * nsec_scale) << (32 - SCALE_SHIFT)));
 }
 
 uint64_t



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201202292130.q1TLUSrx077108>