/* If this function is NULL, polling is not needed */ static int display_update(void *handle, void *device, int x, int y, int w, int h) { UInt64 t1; UInt64 t2; int delta; IMAGE *img = image_find(handle, device); if (img == NULL) return -1; Microseconds((UnsignedWide*)&t1); delta = (t1 - img->update_time) / 1000000L; if (img->update_interval < 1) img->update_interval = 1; /* seconds */ if (delta < 0) img->update_time = t1; else if (delta > img->update_interval) { /* redraw window */ window_invalidate(img->windowRef); /* Make sure the update interval is at least 10 times * what it takes to paint the window */ Microseconds((UnsignedWide*)&t2); delta = (t2 - t1) / 1000; if (delta < 0) delta += 60000; /* delta = time to redraw */ if (delta > img->update_interval * 100) img->update_interval = delta/100; img->update_time = t2; } return gsdll_poll(handle); }
/* _GSocket_Output_Timeout: * For blocking sockets, wait until data can be sent without * blocking or until timeout ellapses. */ GSocketError _GSocket_Output_Timeout(GSocket *socket) { if ( !socket->m_non_blocking ) { UnsignedWide now , start ; short formerTakesEvents = socket->m_takesEvents ; Microseconds(&start); now = start ; socket->m_takesEvents = FALSE ; while( (now.hi * 4294967296.0 + now.lo) - (start.hi * 4294967296.0 + start.lo) < socket->m_timeout * 1000.0 ) { OTResult state ; state = OTGetEndpointState(socket->m_endpoint); if ( state == T_DATAXFER || state == T_INREL ) { socket->m_takesEvents = formerTakesEvents ; return GSOCK_NOERROR; } Microseconds(&now); } socket->m_takesEvents = formerTakesEvents ; socket->m_error = GSOCK_TIMEDOUT; return GSOCK_TIMEDOUT; } return GSOCK_NOERROR; }
TEST(DurationTest, Timeval) { EXPECT_EQ(Duration(timeval{10, 0}), Seconds(10)); EXPECT_EQ(Duration(timeval{0, 7}), Microseconds(7)); EXPECT_EQ(Duration(timeval{2, 123}), Seconds(2) + Microseconds(123)); timeval t{2, 123}; Duration d(t); EXPECT_EQ(d.timeval().tv_sec, t.tv_sec); EXPECT_EQ(d.timeval().tv_usec, t.tv_usec); t.tv_usec = 0; d = Duration(t); EXPECT_EQ(d.timeval().tv_sec, t.tv_sec); EXPECT_EQ(d.timeval().tv_usec, t.tv_usec); // Negative times. t.tv_sec = 0; t.tv_usec = -1; d = Duration(t); EXPECT_EQ(d.timeval().tv_sec, t.tv_sec); EXPECT_EQ(d.timeval().tv_usec, t.tv_usec); d = Microseconds(-1); EXPECT_EQ(d.timeval().tv_sec, t.tv_sec); EXPECT_EQ(d.timeval().tv_usec, t.tv_usec); t.tv_sec = -1; t.tv_usec = -30; d = Duration(t); EXPECT_EQ(d.timeval().tv_sec, t.tv_sec); EXPECT_EQ(d.timeval().tv_usec, t.tv_usec); }
static void * SoundTask(void *) { long long curt; static long long last; Microseconds((UnsignedWide *) &last); while (!stopNow) { if (!mboxPause) { if (musicboxmode == kMBXSoundEmulation) SPCPlayExec(); else S9xMainLoop(); } last += (1000000 / Memory.ROMFramesPerSecond); Microseconds((UnsignedWide *) &curt); if (last > curt) usleep(last - curt); } return nil; }
int main(int argc, char *argv[]) { int i, j, k, ret, loops, freq, log2_N, jobs, N, mb = mbox_open(); unsigned t[2]; double tsq[2]; GPU_FFT_COMPLEX *base; struct GPU_FFT *fft; log2_N = argc>1? atoi(argv[1]) : 12; // 8 <= log2_N <= 21 jobs = argc>2? atoi(argv[2]) : 1; // transforms per batch loops = argc>3? atoi(argv[3]) : 1; // test repetitions if (argc<2 || jobs<1 || loops<1) { printf(Usage); return -1; } N = 1<<log2_N; // FFT length ret = gpu_fft_prepare(mb, log2_N, GPU_FFT_REV, jobs, &fft); // call once switch(ret) { case -1: printf("Unable to enable V3D. Please check your firmware is up to date.\n"); return -1; case -2: printf("log2_N=%d not supported. Try between 8 and 21.\n", log2_N); return -1; case -3: printf("Out of memory. Try a smaller batch or increase GPU memory.\n"); return -1; case -4: printf("Unable to map Videocore peripherals into ARM memory space.\n"); return -1; } for (k=0; k<loops; k++) { for (j=0; j<jobs; j++) { base = fft->in + j*fft->step; // input buffer for (i=0; i<N; i++) base[i][0] = base[i][1] = 0; freq = j+1; base[freq][0] = base[N-freq][0] = 0.5; } usleep(1); // Yield to OS t[0] = Microseconds(); gpu_fft_execute(fft); // call one or many times t[1] = Microseconds(); tsq[0]=tsq[1]=0; for (j=0; j<jobs; j++) { base = fft->out + j*fft->step; // output buffer freq = j+1; for (i=0; i<N; i++) { double re = cos(2*GPU_FFT_PI*freq*i/N); tsq[0] += pow(re, 2); tsq[1] += pow(re - base[i][0], 2) + pow(base[i][1], 2); } } printf("rel_rms_err = %0.2g, usecs = %d, k = %d\n", sqrt(tsq[1]/tsq[0]), (t[1]-t[0])/jobs, k); } gpu_fft_release(fft); // Videocore memory lost if not freed ! return 0; }
void TclpGetTime( Tcl_Time *timePtr) /* Location to store time information. */ { UnsignedWide micro; #ifndef NO_LONG_LONG long long *microPtr; #endif if (initalized == false) { MachineLocation loc; long int offset; ReadLocation(&loc); offset = loc.u.gmtDelta & 0x00ffffff; if (offset & 0x00800000) { offset = offset | 0xff000000; } if (ReadDateTime(&baseSeconds) != noErr) { /* * This should never happen! */ return; } /* * Remove the local offset that ReadDateTime() adds. */ baseSeconds -= offset; Microseconds(µOffset); initalized = true; } Microseconds(µ); #ifndef NO_LONG_LONG microPtr = (long long *) µ *microPtr -= *((long long *) µOffset); timePtr->sec = baseSeconds + (*microPtr / 1000000); timePtr->usec = *microPtr % 1000000; #else SubtractUnsignedWide(µ, µOffset, µ); /* * This lovely computation is equal to: base + (micro / 1000000) * For the .hi part the ratio of 0x100000000 / 1000000 has been * reduced to avoid overflow. This computation certainly has * problems as the .hi part gets large. However, your application * would have to run for a long time to make that happen. */ timePtr->sec = baseSeconds + (micro.lo / 1000000) + (long) (micro.hi * ((double) 33554432.0 / 15625.0)); timePtr->usec = micro.lo % 1000000; #endif }
float Sys_Timer(void) { static UInt64 start = 0; UInt64 counter = 0; if (start == 0) { Microseconds((UnsignedWide *)&start); return 0.0f; } Microseconds((UnsignedWide *)&counter); return (counter - start) / 1000000.0f; }
void GLtexture::copyFramebuffer(const Rect& r) { glBindTexture(GL_TEXTURE_2D, getObject()); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, r.x, r.y, r.width, r.height); #if 0 ulonglong_t start = Microseconds(); ulonglong_t end = Microseconds(); Printf("GLtexture::copyFramebuffer: %d microseconds\n", end - start); GLrender::checkErrors(); #endif }
void gpp_get_realtime (long *pdt) { UnsignedWide microTickCount, nMicroTickCount; long idate; static const int mstart[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; long secs; DateTimeRec dateRec; static DateTimeRec baseDateRec = {1980, 1, 1, 0, 0, 0, 1}; void do_get_clock (DateTimeRec *dateRec, long *pdt); if ((beginMicroTickCount.lo == 0)&&(beginMicroTickCount.hi == 0) ) { Microseconds(&beginMicroTickCount); } Microseconds(µTickCount); nMicroTickCount.lo = microTickCount.lo - beginMicroTickCount.lo; nMicroTickCount.hi = microTickCount.hi - beginMicroTickCount.hi; GetDateTime ((unsigned long *) &secs); SecondsToDate (secs, &dateRec); /* If the date is reasonable, subtract the days since Jan. 1, 1980 */ idate = ((long) dateRec.year - 1980) * 365 + /* days per year */ (((long) dateRec.year - 1)/4 - 1979/4) + /* intervening leap days */ (1979/100 - ((long) dateRec.year - 1)/100) + (((long) dateRec.month - 1)/400 - 1979/400) + mstart[dateRec.month - 1] + /* month is 1-origin */ dateRec.day - 1; /* day of month is 1-origin */ idate += (2 < dateRec.month && (dateRec.year % 4 == 0 && (dateRec.year % 100 != 0 || dateRec.year % 400 == 0))); pdt[0] = ((idate*24 + dateRec.hour) * 60 + dateRec.minute) * 60 + dateRec.second; pdt[1] = nMicroTickCount.lo * 100; //#define DEBUG_CLOCK 1 #ifdef DEBUG_CLOCK fprintf(stderr,"pdt[0] = %ld pdt[1] = %ld\n", pdt[0], pdt[1]); fprintf(stderr,"b hi[0] = %ld lo[1] = %ld\n", beginMicroTickCount.hi, beginMicroTickCount.lo); fprintf(stderr,"m hi[0] = %ld lo[1] = %ld\n", microTickCount.hi, microTickCount.lo); #endif }
void flext::Sleep(double s) { if(s <= 0) return; #if FLEXT_OS == FLEXT_OS_WIN #if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x400 #if 0 LARGE_INTEGER liDueTime; liDueTime.QuadPart = (LONGLONG)(-1.e7*s); // Create a waitable timer. HANDLE hTimer = CreateWaitableTimer(NULL,TRUE,NULL); if(hTimer) { if(SetWaitableTimer(hTimer,&liDueTime,0,NULL,NULL,0)) // Wait for the timer. WaitForSingleObject(hTimer,INFINITE); // != WAIT_OBJECT_0) else ::Sleep((long)(s*1000.)); CloseHandle(hTimer); } else #else LARGE_INTEGER cnt; if(perffrq && QueryPerformanceCounter(&cnt)) { LONGLONG dst = (LONGLONG)(cnt.QuadPart+perffrq*s); for(;;) { SwitchToThread(); // while waiting switch to another thread QueryPerformanceCounter(&cnt); if(cnt.QuadPart > dst) break; } } else #endif #endif // last resort.... ::Sleep((long)(s*1000.)); #elif FLEXT_OS == FLEXT_OS_LINUX || FLEXT_OS == FLEXT_OS_IRIX || FLEXT_OSAPI == FLEXT_OSAPI_MAC_MACH // POSIX usleep((long)(s*1000000.)); #elif FLEXT_OS == FLEXT_OS_MAC // that's just for OS9 & Carbon! UnsignedWide tick; Microseconds(&tick); double target = tick.hi*((double)(1L<<((sizeof tick.lo)*4))*(double)(1L<<((sizeof tick.lo)*4)))+tick.lo+s*1.e6; for(;;) { // this is just a loop running until the time has passed - stone age (but we yield at least) Microseconds(&tick); if(target <= tick.hi*((double)(1L<<((sizeof tick.lo)*4))*(double)(1L<<((sizeof tick.lo)*4)))+tick.lo) break; YieldToAnyThread(); // yielding surely reduces the timing precision (but we're civilized) } #else #error Not implemented #endif }
void ProfileOperaPop() // PROFILE_OPERA_POP(x) { if (s_profile_opera_file && s_profile_opera_data.GetCount()) { unsigned long long current_time; Microseconds((UnsignedWide*) ¤t_time); ProfileOperaData* data = s_profile_opera_data.Remove(s_profile_opera_data.GetCount()-1); unsigned long long long_delta = current_time - data->m_start_time; unsigned int delta = (unsigned long)((long_delta+500)/1000); if (delta >= 10) { for (UINT32 i = 0; i < s_profile_opera_data.GetCount(); i++) { fprintf(s_profile_opera_file, " "); } fprintf(s_profile_opera_file,"%08llu: %4u\n", data->m_unique_id, delta); fflush(s_profile_opera_file); } delete data; } }
/* * This function is called every time the random pool needs * stirring, and will acquire the system time. */ void noise_get_light(void (*func) (void *, int)) { UnsignedWide utc; Microseconds(&utc); func(&utc, sizeof(utc)); }
NMUInt32 GetTimestampMilliseconds() { NMUInt32 timestamp = 0; NMUInt32 clocksPerSec; #ifdef OP_PLATFORM_MAC_CFM double clocks; #else clock_t clocks; #endif #ifdef OP_PLATFORM_MAC_CFM UnsignedWide mSeconds; clocksPerSec = 1000000; // Magic Number = Microseconds Microseconds( &mSeconds ); // Convert to appropriate type in the floating point domain clocks = ( mSeconds.hi * 4294967296.0 + mSeconds.lo ); #else clocksPerSec = MACHINE_TICKS_PER_SECOND; clocks = machine_tick_count(); #endif timestamp = (NMUInt32)((clocks / (double)clocksPerSec) * (double)MILLISECS_PER_SEC); return timestamp; }
globle double gentime() { #if MAC UnsignedWide result; Microseconds(&result); return(((((double) result.hi) * kTwoPower32) + result.lo) / 1000000.0); #endif #if IBM_MCW unsigned long int result; result = GetTickCount(); return((double) result / 1000.0); #endif #if IBM_TBC && (! WINDOW_INTERFACE) unsigned long int result; result = biostime(0,(long int) 0); return((double) result / 18.2); #endif #if GENERIC || (! MAC) return((double) clock() / (double) CLOCKS_PER_SEC); #endif }
double flext::GetOSTime() { double tm; #if FLEXT_OS == FLEXT_OS_WIN LARGE_INTEGER cnt; if(perffrq && QueryPerformanceCounter(&cnt)) tm = cnt.QuadPart/perffrq; else { SYSTEMTIME systm; FILETIME fltm; GetSystemTime(&systm); SystemTimeToFileTime(&systm,&fltm); tm = ((LARGE_INTEGER *)&fltm)->QuadPart*1.e-7; } #elif FLEXT_OS == FLEXT_OS_LINUX || FLEXT_OS == FLEXT_OS_IRIX || FLEXT_OSAPI == FLEXT_OSAPI_MAC_MACH // POSIX timeval tmv; gettimeofday(&tmv,NULL); tm = tmv.tv_sec+tmv.tv_usec*1.e-6; #elif FLEXT_OS == FLEXT_OS_MAC // that's just for OS9 & Carbon! UnsignedWide tick; Microseconds(&tick); tm = (tick.hi*((double)(1L<<((sizeof tick.lo)*4))*(double)(1L<<((sizeof tick.lo)*4)))+tick.lo)*1.e-6; #else #error Not implemented #endif return tm-starttime; }
UINT32 macos_gettick(void) { UnsignedWide current; Microseconds(¤t); return((UINT32)((current.hi * 4294967) + (current.lo / 1000))); }
void MacOpTimer::Start(UINT32 ms) { UnsignedWide ticks; Microseconds(&ticks); long long msecs = ticks.hi; msecs <<= 32; msecs |= ticks.lo; m_startTime = msecs / 1000; m_interval = ms; EventTimerInterval fireDelay = ms * kEventDurationMillisecond; if (m_timerRef) { SetEventLoopTimerNextFireTime(m_timerRef,fireDelay); } else { InstallEventLoopTimer(gMainEventLoop,//GetMainEventLoop(), fireDelay, kEventDurationNoWait, timerUPP, this, &m_timerRef); } }
// // Get time in fractional seconds. // Supported via system calls on Unix, WIN32, and MacOS. // Other systems which support GLUT are also supported (with lesser accuracy.) // double EdenTimeInSeconds(void) { #if defined(EDEN_UNIX) struct timeval tv; // Seconds and microseconds since Jan 1, 1970. #elif defined(_WIN32) FILETIME ft; // Hundreds of nanoseconds since Jan 1, 1601. #elif defined(EDEN_MACOS) UnsignedWide _time; #else int ms; #endif #if defined(EDEN_UNIX) gettimeofday(&tv, NULL); return ((double)tv.tv_sec + (double)tv.tv_usec * 0.000001); #elif defined(_WIN32) GetSystemTimeAsFileTime(&ft); return ((double)(*((LONGLONG *)&ft) - FILETIME_TO_EPOCH_OFFSET) * 0.0000001); #elif defined(EDEN_MACOS) Microseconds(&_time); return (4294.967296 * (double)_time.hi + 0.000001 * (double)_time.lo); // 2^32 = 4294967296. #else ms = glutGet(GLUT_ELAPSED_TIME); return ((double)ms / 1000.0); #endif }
static bool consumeFrequency(const char* input, int* index, Microseconds* result) { const char* expectedToken; double val; if (!consumeDouble(input, index, &val)) { return false; } consumeWhitespace(input, index); switch (input[*index]) { case 'H': expectedToken = "Hz"; break; case 'k': expectedToken = "kHz"; val *= 1000; break; default: return false; } *result = Microseconds(1000000/val); return consumeToken(expectedToken, input, index); }
TEST_F(KeysManagerShardedTest, GetKeyForValidationTimesOutIfRefresherIsNotRunning) { operationContext()->setDeadlineAfterNowBy(Microseconds(250 * 1000)); ASSERT_THROWS(keyManager() ->getKeyForValidation(operationContext(), 1, LogicalTime(Timestamp(100, 0))) .status_with_transitional_ignore(), DBException); }
int cputime () { UnsignedWide msecs; Microseconds (&msecs); return(int)(*(long long *)&msecs / 1000); }
/* * This function is called on every keypress or mouse move, and * will add the current time to the noise pool. It gets the scan * code or mouse position passed in, and adds that too. */ void noise_ultralight(unsigned long data) { UnsignedWide utc; Microseconds(&utc); random_add_noise(&utc, sizeof(utc)); random_add_noise(&data, sizeof(data)); }
void getNanoSeconds(ASIOTimeStamp *time) { UnsignedWide ys; Microseconds(&ys); double r = 1000. * ((double)ys.hi * twoRaisedTo32 + (double)ys.lo); time->hi = (unsigned long)(r / twoRaisedTo32); time->lo = (unsigned long)(r - (double)time->hi * twoRaisedTo32); }
TEST_F(KeysManagerShardedTest, GetKeyForValidationTimesOutIfRefresherIsNotRunning) { operationContext()->setDeadlineAfterNowBy(Microseconds(250 * 1000), ErrorCodes::ExceededTimeLimit); ASSERT_THROWS( keyManager()->getKeyForValidation(operationContext(), 1, LogicalTime(Timestamp(100, 0))), DBException); }
void wxThread::Sleep(unsigned long milliseconds) { UnsignedWide start, now; Microseconds(&start); double mssleep = milliseconds * 1000 ; double msstart, msnow ; msstart = (start.hi * 4294967296.0 + start.lo) ; do { YieldToAnyThread(); Microseconds(&now); msnow = (now.hi * 4294967296.0 + now.lo) ; } while( msnow - msstart < mssleep ); }
unsigned long TclpGetClicks() { UnsignedWide micros; Microseconds(µs); return micros.lo; }
ULONG32 GetTickCount() { unsigned long long micro_now; Microseconds((UnsignedWide*)µ_now); return micro_now / 1000L; }
// return microseconds UINT32 GetTickCountInUSec() { unsigned long long micro_now; Microseconds((UnsignedWide*)µ_now); return micro_now; }
int bbMilliSecs(){ double t; UnsignedWide uw; Microseconds( &uw ); t=(uw.hi<<(32-9))|(uw.lo>>9); //divide by 512...! return (int) (long long) ( t/(1000.0/512.0) ); }
void GBWorld::SimulateOneFrame() { #if GBWORLD_PROFILING && MAC UnsignedWide start, phaseStart, end; Microseconds(&start); #endif previousSidesAlive = SidesAlive(); if ( autoReseed ) ReseedDeadSides(); AddManna(); PROFILE_PHASE(thinkTime, ThinkAllObjects();)