Beispiel #1
0
void
_PR_MD_INTERVAL_INIT()
{
    char *envp;
    ULONG timerFreq;
    APIRET rc;

    if ((envp = getenv("NSPR_OS2_NO_HIRES_TIMER")) != NULL) {
        if (atoi(envp) == 1)
           return;
    }

    timerFreq = 0; /* OS/2 high-resolution timer frequency in Hz */
    rc = DosTmrQueryFreq(&timerFreq);
    if (NO_ERROR == rc) {
        useHighResTimer = PR_TRUE;
        PR_ASSERT(timerFreq != 0);
        while (timerFreq > PR_INTERVAL_MAX) {
            timerFreq >>= 1;
            _os2_bitShift++;
            _os2_highMask = (_os2_highMask << 1)+1;
        }

        _os2_ticksPerSec = timerFreq;
        PR_ASSERT(_os2_ticksPerSec > PR_INTERVAL_MIN);
    }
cairo_perf_ticks_t
cairo_perf_timer_elapsed (void) {
    ULONG freq;

    DosTmrQueryFreq(&freq);
    /* return time difference in milliseconds */
    return (timer.stop - timer.start) / freq * 1000;
}
/*--------------------------------------------------------------------------------------*\
 * UProfiling : stop                                                                    *
 *              Stop the profiling                                                      *
\*--------------------------------------------------------------------------------------*/
UProfiling             &UProfiling::stop(void)
{
    double              dTimeStart=0;
    double              dTimeStop=0;
                                        /* Timer ticks/second */
#ifdef  __OS2__
    LONG                lTimeMicroSec=0;
    ULONG               ulTimerFrequency=0;
#endif  /* __OS2__ */
#ifdef  __WIN32__
    double              dTimerFrequency=0;
    LARGE_INTEGER       liTimerFrequency;
#endif  /* __WIN32__ */

#ifdef  __OS2__
                                        /* Get stop time */
    DosTmrQueryTime(&hrTimer.qwTimerStop);
                                        /* Get timer resolution */
    DosTmrQueryFreq(&ulTimerFrequency);
#endif  /* __OS2__ */
#ifdef  __WIN32__
                                        /* Get stop time */
    QueryPerformanceCounter(&hrTimer.liTimerStop);
                                        /* Get timer resolution */
    QueryPerformanceFrequency(&liTimerFrequency);
#endif  /* __WIN32__ */
                                        /* Calculate elapsed time */
#ifdef  __OS2__
    dTimeStart=(double)ULONG_MAX+1;
    dTimeStart*=(double)hrTimer.qwTimerStart.ulHi;
    dTimeStart+=(double)hrTimer.qwTimerStart.ulLo;
    dTimeStop=(double)ULONG_MAX+1;
    dTimeStop*=(double)hrTimer.qwTimerStop.ulHi;
    dTimeStop+=(double)hrTimer.qwTimerStop.ulLo;
    lTimeMicroSec=(ULONG)(((dTimeStop-dTimeStart)/(double)ulTimerFrequency)*1000000);
                                        /* When accessing the timer with multiple
                                           threads, sometimes the start timestamp
                                           is higher than the stop timestamp. I
                                           have no idea why */
    if(lTimeMicroSec>0)
        ulTimeMicroSec=(ULONG)lTimeMicroSec;
    else
        ulTimeMicroSec=(ULONG)(lTimeMicroSec*(-1));
#endif  /* __OS2__ */
#ifdef  __WIN32__
    dTimeStart=(double)ULONG_MAX+1;
    dTimeStart*=(double)hrTimer.liTimerStart.HighPart;
    dTimeStart+=(double)hrTimer.liTimerStart.LowPart;
    dTimeStop=(double)ULONG_MAX+1;
    dTimeStop*=(double)hrTimer.liTimerStop.HighPart;
    dTimeStop+=(double)hrTimer.liTimerStop.LowPart;
    dTimerFrequency=(((double)liTimerFrequency.HighPart)*(1<<32))+
        (double)liTimerFrequency.LowPart;
    ulTimeMicroSec=(ULONG)(((dTimeStop-dTimeStart)/dTimerFrequency)*1000000);
#endif  /* __WIN32__ */
    memset(&hrTimer, 0, sizeof(hrTimer));
    return(*this);
}
Beispiel #4
0
//  #define gettime(now) _ftime(now)  // DosTmrQueryTime
  void gettime(_time *now)
  {
      ULONG ulTmrFreq; // Hertz
      QWORD qwTmrTime; // now
      DosTmrQueryFreq(&ulTmrFreq);
      DosTmrQueryTime(&qwTmrTime);
      now->time    = (int)(qwTmrTime.ulLo/ulTmrFreq);
      now->millitm = (qwTmrTime.ulLo-(ulTmrFreq*now->time))*MICRONS/ulTmrFreq;
  }
Beispiel #5
0
static cairo_always_inline double
_cairo_time_1s (void)
{
    ULONG freq;

    DosTmrQueryFreq (&freq);

    return freq;
}
Beispiel #6
0
/*** Clock ***/
mtime_t mdate (void)
{
    /* We don't need the real date, just the value of a high precision timer */
    QWORD counter;
    ULONG freq;
    if (DosTmrQueryTime(&counter) || DosTmrQueryFreq(&freq))
        abort();

    /* Convert to from (1/freq) to microsecond resolution */
    /* We need to split the division to avoid 63-bits overflow */
    lldiv_t d = lldiv (Q2LL(counter), freq);

    return (d.quot * 1000000) + ((d.rem * 1000000) / freq);
}
Beispiel #7
0
nsresult
TimeStamp::Startup()
{
  if (gInitialized)
    return NS_OK;

  const char *envp;
  APIRET rc;

  // Use the same variable as NSPR's os2inrval.c does to let the user disable the
  // high-resolution timer (it is known that it doesn't work well on some hardware)
  if ((envp = getenv("NSPR_OS2_NO_HIRES_TIMER")) != NULL) {
    if (atoi(envp) != 1) {
      // Attempt to use the high-res timer
      rc = DosTmrQueryFreq(&gTicksPerSec);
      if (rc == NO_ERROR)
        gUseHighResTimer = true;
    }
  }

  if (!gUseHighResTimer) {
    // TimeStamp has to use bare PRLock instead of mozilla::Mutex
    // because TimeStamp can be used very early in startup.
    gTimeStampLock = PR_NewLock();
    if (!gTimeStampLock)
      return NS_ERROR_OUT_OF_MEMORY;
    gRolloverCount = 1;
    gLastNow = 0;
    gTicksPerSec = PR_TicksPerSecond();
  }

  gTicksPerSecDbl = gTicksPerSec;
  gTicksPerMsDbl = gTicksPerSecDbl / 1000.0;

  gInitialized = true;
  sFirstTimeStamp = TimeStamp::Now();
  sProcessCreation = TimeStamp();

  return NS_OK;
}
Beispiel #8
0
static osd_ticks_t init_cycle_counter(void)
{
    osd_ticks_t start, end;
    osd_ticks_t a, b;

    ULONG  frequency;
    PTIB   ptib;
    ULONG  ulClass;
    ULONG  ulDelta;

    DosGetInfoBlocks( &ptib, NULL );
    ulClass = HIBYTE( ptib->tib_ptib2->tib2_ulpri );
    ulDelta = LOBYTE( ptib->tib_ptib2->tib2_ulpri );

    if ( DosTmrQueryFreq( &frequency ) == 0 )
    {
        // use performance counter if available as it is constant
        cycle_counter = performance_cycle_counter;
        ticks_counter = performance_cycle_counter;

        ticks_per_second = frequency;

        // return the current cycle count
        return (*cycle_counter)();
    }
    else
    {
        fprintf(stderr, "No Timer available!\n");
        exit(-1);
    }

    // temporarily set our priority higher
    DosSetPriority( PRTYS_THREAD, PRTYC_TIMECRITICAL, PRTYD_MAXIMUM, 0 );

    // wait for an edge on the timeGetTime call
    a = SDL_GetTicks();
    do
    {
        b = SDL_GetTicks();
    } while (a == b);

    // get the starting cycle count
    start = (*cycle_counter)();

    // now wait for 1/4 second total
    do
    {
        a = SDL_GetTicks();
    } while (a - b < 250);

    // get the ending cycle count
    end = (*cycle_counter)();

    // compute ticks_per_sec
    ticks_per_second = (end - start) * 4;

    // restore our priority
    DosSetPriority( PRTYS_THREAD, ulClass, ulDelta, 0 );

    // return the current cycle count
    return (*cycle_counter)();
}
Beispiel #9
0
/****************************************************************************
REMARKS:
Initialise the Zen Timer module internals.
****************************************************************************/
void __ZTimerInit(void)
{
    DosTmrQueryFreq(&frequency);
}