From owner-p4-projects@FreeBSD.ORG Wed Feb 29 21:30:29 2012 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 1F82B1065675; Wed, 29 Feb 2012 21:30:29 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BD99A106564A for ; Wed, 29 Feb 2012 21:30:28 +0000 (UTC) (envelope-from gonzo@FreeBSD.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id A33638FC17 for ; Wed, 29 Feb 2012 21:30:28 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id q1TLUSJv077112 for ; Wed, 29 Feb 2012 21:30:28 GMT (envelope-from gonzo@FreeBSD.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id q1TLUSrx077108 for perforce@freebsd.org; Wed, 29 Feb 2012 21:30:28 GMT (envelope-from gonzo@FreeBSD.org) Date: Wed, 29 Feb 2012 21:30:28 GMT Message-Id: <201202292130.q1TLUSrx077108@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to gonzo@FreeBSD.org using -f From: Oleksandr Tymoshenko To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 207116 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Feb 2012 21:30:29 -0000 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