root/opal/mca/timer/darwin/timer_darwin.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. opal_timer_base_get_cycles
  2. opal_timer_base_get_usec
  3. opal_timer_base_get_freq

   1 /*
   2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2014 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * $COPYRIGHT$
  13  *
  14  * Additional copyrights may follow
  15  *
  16  * $HEADER$
  17  */
  18 
  19 #ifndef OPAL_MCA_TIMER_DARWIN_TIMER_DARWIN_H
  20 #define OPAL_MCA_TIMER_DARWIN_TIMER_DARWIN_H
  21 
  22 #include "opal_config.h"
  23 #include <mach/mach_time.h>
  24 
  25 typedef uint64_t opal_timer_t;
  26 
  27 /* frequency in mhz */
  28 OPAL_DECLSPEC extern opal_timer_t opal_timer_darwin_freq;
  29 OPAL_DECLSPEC extern mach_timebase_info_data_t opal_timer_darwin_info;
  30 OPAL_DECLSPEC extern opal_timer_t opal_timer_darwin_bias;
  31 
  32 /**
  33  * Use the pragmatic solution proposed at
  34  * http://stackoverflow.com/questions/23378063/how-can-i-use-mach-absolute-time-without-overflowing/23378064#23378064
  35  */
  36 static inline opal_timer_t
  37 opal_timer_base_get_cycles(void)
  38 {
  39     uint64_t now = mach_absolute_time();
  40 
  41     if( opal_timer_darwin_info.denom == 0 ) {
  42         (void)mach_timebase_info(&opal_timer_darwin_info);
  43         if( opal_timer_darwin_info.denom > 1024 ) {
  44             double frac = (double)opal_timer_darwin_info.numer/opal_timer_darwin_info.denom;
  45             opal_timer_darwin_info.denom = 1024;
  46             opal_timer_darwin_info.numer = opal_timer_darwin_info.denom * frac + 0.5;
  47         }
  48         opal_timer_darwin_bias = now;
  49     }
  50     /* this is basically a wrapper around the "right" assembly to convert
  51        the tick counter off the PowerPC Time Base into nanos. */
  52     return (now - opal_timer_darwin_bias) * opal_timer_darwin_info.numer / opal_timer_darwin_info.denom;
  53 }
  54 
  55 
  56 static inline opal_timer_t
  57 opal_timer_base_get_usec(void)
  58 {
  59     /* freq is in Hz, so this gives usec */
  60     return opal_timer_base_get_cycles() / 1000;
  61 }
  62 
  63 
  64 static inline opal_timer_t
  65 opal_timer_base_get_freq(void)
  66 {
  67     return opal_timer_darwin_freq;
  68 }
  69 
  70 
  71 #define OPAL_TIMER_CYCLE_NATIVE 0
  72 #define OPAL_TIMER_CYCLE_SUPPORTED 1
  73 #define OPAL_TIMER_USEC_NATIVE 1
  74 #define OPAL_TIMER_USEC_SUPPORTED 1
  75 
  76 #endif

/* [<][>][^][v][top][bottom][index][help] */