Deleted Added
full compact
dtrace_subr.c (194850) dtrace_subr.c (195710)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *

--- 5 unchanged lines hidden (view full) ---

14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 *
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *

--- 5 unchanged lines hidden (view full) ---

14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 *
22 * $FreeBSD: head/sys/cddl/dev/dtrace/amd64/dtrace_subr.c 194850 2009-06-24 16:03:57Z avg $
22 * $FreeBSD: head/sys/cddl/dev/dtrace/amd64/dtrace_subr.c 195710 2009-07-15 17:07:39Z avg $
23 *
24 */
25/*
26 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
28 */
29
30#include <sys/param.h>

--- 330 unchanged lines hidden (view full) ---

361
362 return (1);
363}
364#endif
365
366static int64_t tgt_cpu_tsc;
367static int64_t hst_cpu_tsc;
368static int64_t tsc_skew[MAXCPU];
23 *
24 */
25/*
26 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
28 */
29
30#include <sys/param.h>

--- 330 unchanged lines hidden (view full) ---

361
362 return (1);
363}
364#endif
365
366static int64_t tgt_cpu_tsc;
367static int64_t hst_cpu_tsc;
368static int64_t tsc_skew[MAXCPU];
369static uint64_t nsec_scale;
369
370
371/* See below for the explanation of this macro. */
372#define SCALE_SHIFT 28
373
370static void
371dtrace_gethrtime_init_sync(void *arg)
372{
373#ifdef CHECK_SYNC
374 /*
375 * Delay this function from returning on one
376 * of the CPUs to check that the synchronisation
377 * works.

--- 18 unchanged lines hidden (view full) ---

396 tgt_cpu_tsc = rdtsc();
397 else
398 hst_cpu_tsc = rdtsc();
399}
400
401static void
402dtrace_gethrtime_init(void *arg)
403{
374static void
375dtrace_gethrtime_init_sync(void *arg)
376{
377#ifdef CHECK_SYNC
378 /*
379 * Delay this function from returning on one
380 * of the CPUs to check that the synchronisation
381 * works.

--- 18 unchanged lines hidden (view full) ---

400 tgt_cpu_tsc = rdtsc();
401 else
402 hst_cpu_tsc = rdtsc();
403}
404
405static void
406dtrace_gethrtime_init(void *arg)
407{
408 uint64_t tsc_f;
404 cpumask_t map;
405 int i;
409 cpumask_t map;
410 int i;
406 struct pcpu *cp;
407
411
412 /*
413 * Get TSC frequency known at this moment.
414 * This should be constant if TSC is invariant.
415 * Otherwise tick->time conversion will be inaccurate, but
416 * will preserve monotonic property of TSC.
417 */
418 tsc_f = tsc_freq;
419
420 /*
421 * The following line checks that nsec_scale calculated below
422 * doesn't overflow 32-bit unsigned integer, so that it can multiply
423 * another 32-bit integer without overflowing 64-bit.
424 * Thus minimum supported TSC frequency is 62.5MHz.
425 */
426 KASSERT(tsc_f > (NANOSEC >> (32 - SCALE_SHIFT)), ("TSC frequency is too low"));
427
428 /*
429 * We scale up NANOSEC/tsc_f ratio to preserve as much precision
430 * as possible.
431 * 2^28 factor was chosen quite arbitrarily from practical
432 * considerations:
433 * - it supports TSC frequencies as low as 62.5MHz (see above);
434 * - it provides quite good precision (e < 0.01%) up to THz
435 * (terahertz) values;
436 */
437 nsec_scale = ((uint64_t)NANOSEC << SCALE_SHIFT) / tsc_f;
438
408 /* The current CPU is the reference one. */
409 tsc_skew[curcpu] = 0;
410
411 for (i = 0; i <= mp_maxid; i++) {
412 if (i == curcpu)
413 continue;
414
439 /* The current CPU is the reference one. */
440 tsc_skew[curcpu] = 0;
441
442 for (i = 0; i <= mp_maxid; i++) {
443 if (i == curcpu)
444 continue;
445
415 if ((cp = pcpu_find(i)) == NULL)
446 if (pcpu_find(i) == NULL)
416 continue;
417
418 map = 0;
419 map |= (1 << curcpu);
420 map |= (1 << i);
421
422 smp_rendezvous_cpus(map, dtrace_gethrtime_init_sync,
423 dtrace_gethrtime_init_cpu,

--- 10 unchanged lines hidden (view full) ---

434 * be called from a probe context and guaranteed not to have
435 * instrumented with probes itself.
436 *
437 * Returns nanoseconds since boot.
438 */
439uint64_t
440dtrace_gethrtime()
441{
447 continue;
448
449 map = 0;
450 map |= (1 << curcpu);
451 map |= (1 << i);
452
453 smp_rendezvous_cpus(map, dtrace_gethrtime_init_sync,
454 dtrace_gethrtime_init_cpu,

--- 10 unchanged lines hidden (view full) ---

465 * be called from a probe context and guaranteed not to have
466 * instrumented with probes itself.
467 *
468 * Returns nanoseconds since boot.
469 */
470uint64_t
471dtrace_gethrtime()
472{
442 return ((rdtsc() + tsc_skew[curcpu]) * (int64_t) 1000000000 / tsc_freq);
473 uint64_t tsc;
474 uint32_t lo;
475 uint32_t hi;
476
477 /*
478 * We split TSC value into lower and higher 32-bit halves and separately
479 * scale them with nsec_scale, then we scale them down by 2^28
480 * (see nsec_scale calculations) taking into account 32-bit shift of
481 * the higher half and finally add.
482 */
483 tsc = rdtsc() + tsc_skew[curcpu];
484 lo = tsc;
485 hi = tsc >> 32;
486 return (((lo * nsec_scale) >> SCALE_SHIFT) +
487 ((hi * nsec_scale) << (32 - SCALE_SHIFT)));
443}
444
445uint64_t
446dtrace_gethrestime(void)
447{
448 printf("%s(%d): XXX\n",__func__,__LINE__);
449 return (0);
450}

--- 56 unchanged lines hidden ---
488}
489
490uint64_t
491dtrace_gethrestime(void)
492{
493 printf("%s(%d): XXX\n",__func__,__LINE__);
494 return (0);
495}

--- 56 unchanged lines hidden ---