Esempio n. 1
0
void Timer::StartTimer()
{
#ifdef OS_MAC
	startTime = UpTime();
#elif defined( TIMER_USE_CYCLE_COUNTER )
	CycleCounter c;
	startTime = c.count();
#else
#ifdef WIN32
	startTime = timeGetTime();
#else
	gettimeofday( &startTime, NULL );
#endif
#endif
}
Esempio n. 2
0
DWORDLONG rdtsc()
{
	DWORDLONG temp;
	AbsoluteTime now;
	Nanoseconds s;

	now = UpTime();
	s = AbsoluteToNanoseconds(now);
	temp = s.hi;
	temp <<= 32;
	temp += s.lo;

	// temp contains timestamp in nanosecs
	// temp * processor_speed_to_nsecs = timestamp in cpu cycles
	return (DWORDLONG) (temp * processor_speed_to_nsecs);
}
Esempio n. 3
0
double getTicks()
{
	//return 40;
	
	#ifdef _WIN32
	return (double) GetTickCount();
	#else

	Nanoseconds nano = AbsoluteToNanoseconds( UpTime() );
	// if you want that in (floating point) seconds:
	double seconds = ((double) UnsignedWideToUInt64( nano )) * 1e-9;
	return seconds * 1000.0;

	
	#endif

}
Esempio n. 4
0
OSStatus safe_delay_until(AbsoluteTime *pWakeUpTime)
{
    if(execution_context() == k_eExecutionContextMPTask)
    {
        return(MPDelayUntil(pWakeUpTime));
    }
    else
    {
        uint64_t ullWakeUpTime = force_cast<uint64_t>(*pWakeUpTime);

        while(force_cast<uint64_t>(UpTime()) < ullWakeUpTime)
        {
            idle();
        }

        return(noErr);
    }
}
Esempio n. 5
0
nglTime::nglTime()
{
#ifdef _POSIX_WORLD_
  struct timeval tv;

  gettimeofday (&tv, NULL);
  mValue = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0);
#endif // _POSIX_WORLD_

#if macintosh 
  Nanoseconds t = AbsoluteToNanoseconds(UpTime());
  mValue = ((double)UnsignedWideToUInt64(t)) / 1000000.0;
#endif // macintosh

#ifdef _WIN32_
  mValue = GetTime();
#endif // _WIN32_
}
Esempio n. 6
0
/*
================
Sys_Milliseconds
================
*/
int Sys_Milliseconds (void) {
#if 0
	int		c;
	
	c = clock();		// FIXME, make more accurate

	return c*1000/60;
#else
	AbsoluteTime	t;
	Nanoseconds		nano;
	double			doub;

#define kTwoPower32 (4294967296.0)      /* 2^32 */
	
	t = UpTime();
	nano = AbsoluteToNanoseconds( t );
	doub = (((double) nano.hi) * kTwoPower32) + nano.lo;
	
	return doub * 0.000001;	
#endif
}
Esempio n. 7
0
double
toc (void)
{
  double out;
#if defined(__MTA__)
  long ts;
  MTA("mta fence")
  ts = mta_get_clock (tic_ts);
  out = ((double)ts) * mta_clock_period ();
  /*fprintf (stderr, "%ld %g %g %g\n", ts, out, mta_clock_period(), mta_clock_freq());*/
#elif defined(__MacOSX__)
  AbsoluteTime ts;
  ts = UpTime ();
  out = 1.0e-9 * AbsoluteDeltaToNanoseconds (ts, tic_ts);
#else
  struct timespec ts;
  clock_gettime (TICTOC_CLOCK, &ts);
  out = (ts.tv_nsec - (double)tic_ts.tv_nsec) * 1.0e-9;
  out += (ts.tv_sec - (double)tic_ts.tv_sec);
#endif

  return out;
}
Esempio n. 8
0
void wxThread::Sleep( unsigned long milliseconds )
{
    AbsoluteTime wakeup = AddDurationToAbsolute( milliseconds, UpTime() );
    MPDelayUntil( &wakeup );
}
Esempio n. 9
0
unsigned long long GetTimeSinceBootInMilliseconds()
{
	UnsignedWide uw = AbsoluteToNanoseconds(UpTime());
	return ((((unsigned long long)uw.hi)<<32)|(uw.lo))/1000000;
}
Esempio n. 10
0
OSStatus safe_enter_critical_region(MPCriticalRegionID pCriticalRegionID, Duration lDuration, MPCriticalRegionID pCriticalRegionCriticalRegionID/* = kInvalidID*/)
{
    if(pCriticalRegionCriticalRegionID != kInvalidID)
    {
        if(at_mp())
        {
        // enter the critical region's critical region
            OSStatus lStatus = noErr;
            AbsoluteTime sExpiration;
            if(lDuration != kDurationImmediate && lDuration != kDurationForever)
            {
                sExpiration = AddDurationToAbsolute(lDuration, UpTime());
            }
            lStatus = MPEnterCriticalRegion(pCriticalRegionCriticalRegionID, lDuration);
            assert(lStatus == noErr || lStatus == kMPTimeoutErr);
            if(lStatus == noErr)
            {
            // calculate a new duration
                if(lDuration != kDurationImmediate && lDuration != kDurationForever)
                {
                // check if we have any time left
                    AbsoluteTime sUpTime(UpTime());
                    if(force_cast<uint64_t>(sExpiration) > force_cast<uint64_t>(sUpTime))
                    {
                    // reset our duration to our remaining time
                        lDuration = AbsoluteDeltaToDuration(sExpiration, sUpTime);
                    }
                    else
                    {
                    // no time left
                        lDuration = kDurationImmediate;
                    }
                }
            // if we entered the critical region, exit it again
                lStatus = MPExitCriticalRegion(pCriticalRegionCriticalRegionID);
                assert(lStatus == noErr);
            }
            else
            {
            // otherwise, give up
                return(lStatus);
            }
        }
        else
        {
        // if we're at system task time, try to enter the critical region's critical
        //    region until we succeed.  MP tasks will block on this until we let it go.
            OSStatus lStatus;
            do
            {
                lStatus = MPEnterCriticalRegion(pCriticalRegionCriticalRegionID, kDurationImmediate);
            } while(lStatus == kMPTimeoutErr);
            assert(lStatus == noErr);
        }
    }

// try to enter the critical region
    function<OSStatus, Duration> oEnterCriticalRegion;
    oEnterCriticalRegion = bind(MPEnterCriticalRegion, pCriticalRegionID, _1);
    OSStatus lStatus = safe_wait(oEnterCriticalRegion, lDuration);

// if we entered the critical region's critical region to get the critical region,
//    exit the critical region's critical region.
    if(pCriticalRegionCriticalRegionID != kInvalidID && at_mp() == false)
    {
        lStatus = MPExitCriticalRegion(pCriticalRegionCriticalRegionID);
        assert(lStatus == noErr);
    }
    return(lStatus);
}
Esempio n. 11
0
// Get local time as milliseconds since 00:00:00, Jan 1st 1970
wxLongLong wxGetLocalTimeMillis()
{
    wxLongLong val = 1000l;

    // If possible, use a function which avoids conversions from
    // broken-up time structures to milliseconds

#if defined(__WXPALMOS__)
    DateTimeType thenst;
    thenst.second  = 0;
    thenst.minute  = 0;
    thenst.hour    = 0;
    thenst.day     = 1;
    thenst.month   = 1;
    thenst.year    = 1970;
    thenst.weekDay = 5;
    uint32_t now = TimGetSeconds();
    uint32_t then = TimDateTimeToSeconds (&thenst);
    return SysTimeToMilliSecs(SysTimeInSecs(now - then));
#elif defined(__WXMSW__) && (defined(__WINE__) || defined(__MWERKS__))
    // This should probably be the way all WXMSW compilers should do it
    // Go direct to the OS for time

    SYSTEMTIME thenst = { 1970, 1, 4, 1, 0, 0, 0, 0 };  // 00:00:00 Jan 1st 1970
    FILETIME thenft;
    SystemTimeToFileTime( &thenst, &thenft );
    wxLongLong then( thenft.dwHighDateTime, thenft.dwLowDateTime );   // time in 100 nanoseconds

    SYSTEMTIME nowst;
    GetLocalTime( &nowst );
    FILETIME nowft;
    SystemTimeToFileTime( &nowst, &nowft );
    wxLongLong now( nowft.dwHighDateTime, nowft.dwLowDateTime );   // time in 100 nanoseconds

    return ( now - then ) / 10000.0;  // time from 00:00:00 Jan 1st 1970 to now in milliseconds

#elif defined(HAVE_GETTIMEOFDAY)
    struct timeval tp;
    if ( wxGetTimeOfDay(&tp, (struct timezone *)NULL) != -1 )
    {
        val *= tp.tv_sec;
        return (val + (tp.tv_usec / 1000));
    }
    else
    {
        wxLogError(_("wxGetTimeOfDay failed."));
        return 0;
    }
#elif defined(HAVE_FTIME)
    struct timeb tp;

    // ftime() is void and not int in some mingw32 headers, so don't
    // test the return code (well, it shouldn't fail anyhow...)
    (void)::ftime(&tp);
    val *= tp.time;
    return (val + tp.millitm);
#elif defined(__WXMAC__)

    static UInt64 gMilliAtStart = 0;

    Nanoseconds upTime = AbsoluteToNanoseconds( UpTime() );

    if ( gMilliAtStart == 0 )
    {
        time_t start = time(NULL);
        gMilliAtStart = ((UInt64) start) * 1000000L;
        gMilliAtStart -= upTime.lo / 1000 ;
        gMilliAtStart -= ( ( (UInt64) upTime.hi ) << 32 ) / (1000 * 1000);
    }

    UInt64 millival = gMilliAtStart;
    millival += upTime.lo / (1000 * 1000);
    millival += ( ( (UInt64) upTime.hi ) << 32 ) / (1000 * 1000);
    val = millival;

    return val;
#else // no gettimeofday() nor ftime()
    // We use wxGetLocalTime() to get the seconds since
    // 00:00:00 Jan 1st 1970 and then whatever is available
    // to get millisecond resolution.
    //
    // NOTE that this might lead to a problem if the clocks
    // use different sources, so this approach should be
    // avoided where possible.

    val *= wxGetLocalTime();

// GRG: This will go soon as all WIN32 seem to have ftime
// JACS: unfortunately not. WinCE doesn't have it.
#if defined (__WIN32__)
    // If your platform/compiler needs to use two different functions
    // to get ms resolution, please do NOT just shut off these warnings,
    // drop me a line instead at <*****@*****.**>

    // FIXME
#ifndef __WXWINCE__
    #warning "Possible clock skew bug in wxGetLocalTimeMillis()!"
#endif

    SYSTEMTIME st;
    ::GetLocalTime(&st);
    val += st.wMilliseconds;
#else // !Win32
    // If your platform/compiler does not support ms resolution please
    // do NOT just shut off these warnings, drop me a line instead at
    // <*****@*****.**>

    #if defined(__VISUALC__) || defined (__WATCOMC__)
        #pragma message("wxStopWatch will be up to second resolution!")
    #elif defined(__BORLANDC__)
        #pragma message "wxStopWatch will be up to second resolution!"
    #else
        #warning "wxStopWatch will be up to second resolution!"
    #endif // compiler
#endif

    return val;

#endif // time functions
}
Esempio n. 12
0
pascal void HIDTimer (EventLoopTimerRef inTimer, void* )
{
    #pragma unused (inTimer)
	static AbsoluteTime time = {0, 0};
	long				deadZone = 25;
   pRecContext			pContextInfo = NULL;
//	float				rotation[4] = {0.0f, 0.0f, 0.0f, 0.0f};

    AbsoluteTime currTime = UpTime ();
    float deltaTime = (float) AbsoluteDeltaToDuration (currTime, time);
	time = currTime;	// reset for next time interval
    if (0 > deltaTime)	// if negative microseconds
		deltaTime /= -1000000.0;
    else				// else milliseconds
		deltaTime /= 1000.0;
    if (deltaTime > 10.0) // skip pauses
        return;

    // get input values
    GetInput ();
	// apply to front window
	pContextInfo = GetCurrentContextInfo(FrontWindow()); // call back to main to get the current context info record
	if (!pContextInfo)
	{
		return; // not an application window so do not process
	}
	// apply input
	double panX=0, panY=0;
	if (gActionArray [kActionXAxis].pDevice && gActionArray [kActionXAxis].pElement && (abs (gActionArray [kActionXAxis].value) > deadZone)) {
		// pan
		panX = gActionArray [kActionXAxis].value;
		//panX = abs (gActionArray [kActionXAxis].value) * gActionArray [kActionXAxis].value * 0.002f;
		//panX = abs (gActionArray [kActionXAxis].value) * gActionArray [kActionXAxis].value * 0.002f / (1500.0f / -pContextInfo->camera.viewPos.z);
		//pContextInfo->camera.viewPos.x += panX;
	}
	if (gActionArray [kActionYAxis].pDevice && gActionArray [kActionYAxis].pElement && (abs (gActionArray [kActionYAxis].value) > deadZone)) {
		// pan
		panY = gActionArray [kActionYAxis].value;
		//panY = abs (gActionArray [kActionYAxis].value) * gActionArray [kActionYAxis].value * deltaTime * 0.002f;
		//panY = abs (gActionArray [kActionYAxis].value) * gActionArray [kActionYAxis].value * deltaTime * 0.002f / (1500.0f / -pContextInfo->camera.viewPos.z);
		//pContextInfo->camera.viewPos.y -= panY;
	}
	handleJoystickMovement(pContextInfo, panX, panY);

	//	doMouseDelta(panX, panY);
//	if (gActionArray [kActionZAxis].pDevice && gActionArray [kActionZAxis].pElement && (abs (gActionArray [kActionZAxis].value) > deadZone)) {
//		// dolly
//		GLfloat dolly = abs (gActionArray [kActionZAxis].value) * gActionArray [kActionZAxis].value * deltaTime * 0.002f * -pContextInfo->camera.viewPos.z / 500.0f;
//		pContextInfo->camera.viewPos.z += dolly;
//		if (pContextInfo->camera.viewPos.z == 0.0) // do not let z = 0.0
//			pContextInfo->camera.viewPos.z = 0.0001;
//	}
	// handle rotations about each respective axis
//	if (gActionArray [kActionXRot].pDevice && gActionArray [kActionXRot].pElement && (abs (gActionArray [kActionXRot].value) > deadZone)) {
//		rotation[0] = abs (gActionArray [kActionXRot].value) * -gActionArray [kActionXRot].value * deltaTime * 0.0003f;
//		rotation[1] = 1.0f;
//		rotation[2] = 0.0f;
//		rotation[3] = 0.0f;
//		addToRotationTrackball (rotation, pContextInfo->worldRotation);
//	}
//	if (gActionArray [kActionYRot].pDevice && gActionArray [kActionYRot].pElement && (abs (gActionArray [kActionYRot].value) > deadZone)) {
//		rotation[0] = abs (gActionArray [kActionYRot].value) * gActionArray [kActionYRot].value * deltaTime * 0.0003f;
//		rotation[1] = 0.0f;
//		rotation[2] = 1.0f;
//		rotation[3] = 0.0f;
//		addToRotationTrackball (rotation, pContextInfo->worldRotation);
//	}
//	if (gActionArray [kActionZRot].pDevice && gActionArray [kActionZRot].pElement && (abs (gActionArray [kActionZRot].value) > deadZone)) {
//		rotation[0] = abs (gActionArray [kActionZRot].value) * -gActionArray [kActionZRot].value * deltaTime * 0.0003f;
//		rotation[1] = 0.0f;
//		rotation[2] = 0.0f;
//		rotation[3] = 1.0f;
//		addToRotationTrackball (rotation, pContextInfo->worldRotation);
//	}
	// need to force draw here...
	{
		Rect rectPort;
		WindowRef window = FrontWindow ();
		GetWindowPortBounds (window, &rectPort);
		InvalWindowRect (window, &rectPort);
	}
}
static inline double	stopwatch_ClockCycleCounter_get_time_s ()
{
	const Nanoseconds	ns = AbsoluteToNanoseconds (UpTime ());

	return (ns.hi * 4294967296e-9 + ns.lo * 1e-9);
}
Esempio n. 14
0
bigtime_t ZTicks::sNow()
	{
	Nanoseconds theTicks = AbsoluteToNanoseconds(UpTime());
	return *reinterpret_cast<uint64*>(&theTicks) / 1000;
	}
Esempio n. 15
0
File: stat.c Progetto: doniexun/rtos
main() {
    int i;
    int tid;

    /* for stat */
    int IdleMem; /* idle task memeory address pData */
    unsigned int maxCnt;
    int memIdle;
    unsigned int idleCnt;
    int zero=0;
    int usage;
    unsigned long sum= 0;

    unsigned int upTime = 0;

    /*int loopCnt = 4;*/
    int loopCnt = 2;
    
    cprintf("Initializing .... ");
    /* get absolute data memory address of TID */
    IdleMem = GetAbsMem(IdleTaskTID);

    tid = Receive(&memIdle,sizeof(int));

    Reply(tid,NULL,NULL);
    /* wait until system reaches the stable state */
    Delay(TICKS_PER_SEC * 2);

    for(i = 0; i < loopCnt ; i++ ) {
	enterCS();
	/* reset the counter */
	absZero(IdleMem + memIdle, sizeof(int));
	exitCS();

	Delay(TICKS_PER_SEC * 1);

	/* get the maximum counter */
	enterCS();
	absRead(IdleMem + memIdle, &maxCnt, sizeof(int));
	exitCS();
	sum += maxCnt;
    } /* for */

    maxCnt = (int) sum / loopCnt;

/* if you don't want stat just undef this */
#ifdef DO_STAT
	console_xy(118,4);
	cprintf("Max:%x",maxCnt);

/* delete the initialzing message */
	console_xy(0,0);
	cprintf("                      ");
	console_xy(90,5);
	cprintf("Uptime:");

    while(1){
	enterCS();
	/* reset the counter */
	absZero(IdleMem + memIdle, sizeof(int));
	exitCS();

	Delay(TICKS_PER_SEC * 1);

	enterCS();
	/* read the number */
	absRead(IdleMem + memIdle, &idleCnt, sizeof(int));
	exitCS();

	if(maxCnt > 100 ) {
	    usage = (int)(100L - 100L * idleCnt / maxCnt);
	    if (usage > 100) {
		usage = 100;
	    } else if (usage < 0) {
		usage =   0;
	    }
	}
	else {
	    usage = 0;
	}

	console_xy(101,4);
	cprintf("%2d %% Idl:%x",usage, idleCnt);

	upTime = UpTime();
	console_xy(116,3);
	cprintf("%d",upTime);
	/*WakeUp(INIT_TID);*/

	/* XXX this is repitittion but ... */
	console_xy(118,4);
	cprintf("Max:%x",maxCnt);
    }
#endif /* DO_STAT */

    Exit();
}