void testguidedn() { int i,j,k; double start; double meantime, sd; double getclock(void); printf("\n"); printf("--------------------------------------------------------\n"); printf("Computing GUIDED %d time\n",cksz); for (k=0; k<=OUTERREPS; k++){ start = getclock(); #pragma omp parallel private(j) { for (j=0; j<innerreps; j++){ #pragma omp for schedule(guided,cksz) for (i=0; i<itersperthr*nthreads; i++){ delay(delaylength); } } } times[k] = (getclock() - start) * 1.0e6 / (double) innerreps; } stats (&meantime, &sd); printf("GUIDED %d time = %f microseconds +/- %f\n", cksz, meantime, CONF95*sd); printf("GUIDED %d overhead = %f microseconds +/- %f\n", cksz, meantime-reftime, CONF95*(sd+refsd)); }
void testcopyprivnew() { int n,j,k; double start; double meantime, sd; // double getclock(void); n=IDA; printf("\n"); printf("--------------------------------------------------------\n"); printf("Computing COPYPRIVATE %d time\n", n); for (k=0; k<=OUTERREPS; k++){ start = getclock(); for (j=0; j<innerreps; j++){ //#pragma omp single copyprivate(btest) { delay(delaylength, btest); } } times[k] = (getclock() - start) * 1.0e6 / (double) innerreps; } // stats (&meantime, &sd); printf("COPYPRIVATE time = %10.3f microseconds +/- %10.3f\n", meantime, CONF95*sd); printf("COPYPRIVATE overhead = %10.3f microseconds +/- %10.3f\n", meantime-reftime, CONF95*(sd+refsd)); }
void privatetest() { int j,k; int i = 0 ; double start; double meantime, sd; //double a[1]; double a; // double getclock(void); printf("\n"); printf("--------------------------------------------------------\n"); printf("Computing REDUCTION time 1\n"); for (k=0; k<=OUTERREPS; k++){ start = getclock(); //#pragma acc kernels copyin(a) //#pragma acc loop independent private(a) for (j=0; j<innerreps; j++){ delay(delaylength, &a); i++; } times[k] = (getclock() - start) * 1.0e6 / (double) innerreps; } // stats (&meantime, &sd); printf("PRIVATE time = %10.3f microseconds +/- %10.3f\n", meantime, CONF95*sd); printf("PRIVATE overhead = %10.3f microseconds +/- %10.3f\n", meantime-reftime, CONF95*(sd+refsd)); reftime = meantime; refsd = sd; }
void refer() { int i,j,k; double start; double meantime, sd; double getclock(void); printf("\n"); printf("--------------------------------------------------------\n"); printf("Computing reference time\n"); for (k=0; k<=OUTERREPS; k++){ start = getclock(); for (j=0; j<innerreps; j++){ for (i=0; i<itersperthr; i++){ delay(delaylength); } } times[k] = (getclock() - start) * 1.0e6 / (double) innerreps; } stats (&meantime, &sd); printf("Reference_time_1 = %f microseconds +/- %f\n", meantime, CONF95*sd); reftime = meantime; refsd = sd; }
void refer() { int j,k; int i = 0 ; double start; double meantime, sd, hm; double a[1]; // double getclock(void); printf("\n"); printf("--------------------------------------------------------\n"); printf("Computing reference time 1\n"); for (k=0; k<=OUTERREPS; k++){ start = getclock(); for (j=0; j<innerreps; j++){ delay(delaylength, a); i++; } times[k] = (getclock() - start) * 1.0e6 / (double) innerreps; } stats (&meantime, &sd, &hm); // printf("Reference_time_1 = %10.3f microseconds +/- %10.3f\n", meantime, CONF95*sd); printf("Reference_time_1 = %10.3f microseconds +/- %10.3f\n", hm, CONF95*sd); reftime = meantime; refsd = sd; }
int getdelaylengthfromtime(double delaytime) { int i, reps; double lapsedtime, starttime; // seconds reps = 1000; lapsedtime = 0.0; delaytime = delaytime/1.0E6; // convert from microseconds to seconds // Note: delaytime is local to this function and thus the conversion // does not propagate to the main code. // Here we want to use the delaytime in microseconds to find the // delaylength in iterations. We start with delaylength=0 and // increase until we get a large enough delaytime, return delaylength // in iterations. delaylength = 0; delay(delaylength); while (lapsedtime < delaytime) { delaylength = delaylength * 1.1 + 1; starttime = getclock(); for (i = 0; i < reps; i++) { delay(delaylength); } lapsedtime = (getclock() - starttime) / (double) reps; } return delaylength; }
/* * This routine calculates the differences between successive calls to * gettimeofday(). If a difference is less than zero, the us field * has rolled over to the next second, so we add a second in us. If * the difference is greater than zero and less than MINSTEP, the * clock has been advanced by a small amount to avoid standing still. * If the clock has advanced by a greater amount, then a timer interrupt * has occurred and this amount represents the precision of the clock. * In order to guard against spurious values, which could occur if we * happen to hit a fat interrupt, we do this for MINLOOPS times and * keep the minimum value obtained. */ int default_get_precision(void) { struct timeval tp; struct timezone tzp; #ifdef HAVE_GETCLOCK struct timespec ts; #endif long last; int i; long diff; long val; long usec; usec = 0; val = MAXSTEP; #ifdef HAVE_GETCLOCK (void) getclock(TIMEOFDAY, &ts); tp.tv_sec = ts.tv_sec; tp.tv_usec = ts.tv_nsec / 1000; #else /* not HAVE_GETCLOCK */ GETTIMEOFDAY(&tp, &tzp); #endif /* not HAVE_GETCLOCK */ last = tp.tv_usec; for (i = 0; i < MINLOOPS && usec < HUSECS;) { #ifdef HAVE_GETCLOCK (void) getclock(TIMEOFDAY, &ts); tp.tv_sec = ts.tv_sec; tp.tv_usec = ts.tv_nsec / 1000; #else /* not HAVE_GETCLOCK */ GETTIMEOFDAY(&tp, &tzp); #endif /* not HAVE_GETCLOCK */ diff = tp.tv_usec - last; last = tp.tv_usec; if (diff < 0) diff += DUSECS; usec += diff; if (diff > MINSTEP) { i++; if (diff < val) val = diff; } } printf("precision = %ld usec after %d loop%s\n", val, i, (i == 1) ? "" : "s"); if (usec >= HUSECS) { printf(" (Boy this machine is fast ! usec was %ld)\n", usec); val = MINSTEP; /* val <= MINSTEP; fast machine */ } diff = HUSECS; for (i = 0; diff > val; i--) diff >>= 1; return (i); }
int16_t wgetkey (vptype *vp, int16_t x, int16_t y, int16_t font) { char tempstr[2]; int16_t oldclock; tempstr [1]=0; while (!k_pressed()) { oldclock=getclock(); do {} while (oldclock==getclock()); cursorchar=(cursorchar&7)+1; tempstr[0]=cursorchar; wprint (vp,x,y,font,tempstr); }; wprint (vp,x,y,font," "); return (k_read()); };
static inline void get_ostime( struct timespec * tsp ) { int rc; long ticks; #if defined(HAVE_CLOCK_GETTIME) rc = clock_gettime(CLOCK_REALTIME, tsp); #elif defined(HAVE_GETCLOCK) rc = getclock(TIMEOFDAY, tsp); #else struct timeval tv; rc = GETTIMEOFDAY(&tv, NULL); tsp->tv_sec = tv.tv_sec; tsp->tv_nsec = tv.tv_usec * 1000; #endif if (rc < 0) { msyslog(LOG_ERR, "read system clock failed: %m (%d)", errno); exit(1); } if (trunc_os_clock) { ticks = (long)((tsp->tv_nsec * 1e-9) / sys_tick); tsp->tv_nsec = (long)(ticks * 1e9 * sys_tick); } }
/* -------------------------------------------------------------------- * sleep for a given time or until the wakup semaphore is tickled. */ int worker_sleep( blocking_child * c, time_t seconds ) { struct timespec until; int rc; # ifdef HAVE_CLOCK_GETTIME if (0 != clock_gettime(CLOCK_REALTIME, &until)) { msyslog(LOG_ERR, "worker_sleep: clock_gettime() failed: %m"); return -1; } # else if (0 != getclock(TIMEOFDAY, &until)) { msyslog(LOG_ERR, "worker_sleep: getclock() failed: %m"); return -1; } # endif until.tv_sec += seconds; rc = wait_for_sem(c->wake_scheduled_sleep, &until); if (0 == rc) return -1; if (-1 == rc && ETIMEDOUT == errno) return 0; msyslog(LOG_ERR, "worker_sleep: sem_timedwait: %m"); return -1; }
/*停止计时器,返回自上次调用stimer_start后所用的时间,并累积花费的总时间*/ clockval_t stimer_stop(){ clockval_t stop_time=getclock(); clockval_t elapsed_time= stop_time - start_time; start_time=stop_time; total_time +=elapsed_time; return elapsed_time; }
static double time_so_far() #endif { #ifdef Windows LARGE_INTEGER freq,counter; double wintime,bigcounter; /* For Windows the time_of_day() is useless. It increments in 55 milli second */ /* increments. By using the Win32api one can get access to the high performance */ /* measurement interfaces. With this one can get back into the 8 to 9 */ /* microsecond resolution. */ QueryPerformanceFrequency(&freq); QueryPerformanceCounter(&counter); bigcounter=(double)counter.HighPart *(double)0xffffffff + (double)counter.LowPart; wintime = (double)(bigcounter/(double)freq.LowPart); return((double)wintime); #else #if defined (OSFV4) || defined(OSFV3) || defined(OSFV5) struct timespec gp; if (getclock(TIMEOFDAY, (struct timespec *) &gp) == -1) perror("getclock"); return (( (double) (gp.tv_sec)) + ( ((float)(gp.tv_nsec)) * 0.000000001 )); #else struct timeval tp; if (gettimeofday(&tp, (struct timezone *) NULL) == -1) perror("gettimeofday"); return ((double) (tp.tv_sec)) + (((double) tp.tv_usec) * 0.000001 ); #endif #endif }
/* Calculate the reference time. */ void reference(char *name, void (*refer)(void)) { int k; double start; // Calculate the required number of innerreps innerreps = getinnerreps(refer); initreference(name); for (k = 0; k <= outerreps; k++) { start = getclock(); refer(); times[k] = (getclock() - start) * 1.0e6 / (double) innerreps; } finalisereference(name); }
/* Function to run a microbenchmark test*/ void benchmark(char *name, void (*test)(void)) { int k; double start; // Calculate the required number of innerreps innerreps = getinnerreps(test); intitest(name); for (k=0; k<=outerreps; k++) { start = getclock(); test(); times[k] = (getclock() - start) * 1.0e6 / (double) innerreps; } finalisetest(name); }
unsigned long getinnerreps(void (*test)(void)) { innerreps = 10L; // some initial value double time = 0.0; while (time < targettesttime) { double start = getclock(); test(); time = (getclock() - start) * 1.0e6; innerreps *=2; // Test to stop code if compiler is optimising reference time expressions away if (innerreps > (targettesttime*1.0e15)) { printf("Compiler has optimised reference loop away, STOP! \n"); printf("Try recompiling with lower optimisation level \n"); exit(1); } } return innerreps; }
STATUS TMhrnow(HRSYSTIME *stime) { #if defined(sqs_ptx) struct timespec cur_syst; #else SYSTIME cur_syst; #endif /* sqs_ptx */ #ifdef TMHRNOW_WRAPPED_CLOCKGETTIME return clock_gettime( CLOCK_REALTIME, stime ); #endif #ifndef WRAPPED if ( !initialized ) { initialized = TRUE; #ifdef OS_THREADS_USED CS_synch_init(&nanomutex); #endif /* OS_THREADS_USED */ } #ifdef sqs_ptx getclock(TIMEOFDAY, &cur_syst); stime->tv_sec = cur_syst.tv_sec; stime->tv_nsec = cur_syst.tv_nsec; #else TMet(&cur_syst); stime->tv_sec = cur_syst.TM_secs; stime->tv_nsec = cur_syst.TM_msecs * NANO_PER_MILLI; #endif /* sqs_ptx */ /* ** if we have been called twice within the same ** interval, increment the time by one nanosecond. */ #ifdef OS_THREADS_USED CS_synch_lock(&nanomutex); #endif /* OS_THREADS_USED */ if ( stime->tv_sec == lasttime.tv_sec && stime->tv_nsec <= lasttime.tv_nsec ) { stime->tv_nsec = lasttime.tv_nsec + 1; } lasttime.tv_sec = stime->tv_sec; lasttime.tv_nsec = stime->tv_nsec; #ifdef OS_THREADS_USED CS_synch_unlock(&nanomutex); #endif /* OS_THREADS_USED */ return OK; #endif /* WRAPPED */ }
/* * get_systime - return the system time in timestamp format biased by * the current time offset. */ void get_systime( l_fp *now ) { #if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_GETCLOCK) struct timespec ts; #else struct timeval tv; #endif double dtemp; /* * We use nanosecond time if we can get it. Watch out for * rounding wiggles, which may overflow the fraction. */ #if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_GETCLOCK) # ifdef HAVE_CLOCK_GETTIME (void) clock_gettime(CLOCK_REALTIME, &ts); # else (void) getclock(TIMEOFDAY, &ts); # endif now->l_i = ts.tv_sec + JAN_1970; dtemp = ts.tv_nsec * FRAC / 1e9; if (dtemp >= FRAC) now->l_i++; now->l_uf = (u_int32)dtemp; #else /* HAVE_CLOCK_GETTIME */ (void) GETTIMEOFDAY(&tv, (struct timezone *)0); now->l_i = tv.tv_sec + JAN_1970; #if defined RELIANTUNIX_CLOCK || defined SCO5_CLOCK if (systime_10ms_ticks) { /* fake better than 10ms resolution by interpolating accumulated residual (in adj_systime(), see below) */ dtemp = tv.tv_usec / 1e6; if (sys_residual < 5000e-6 && sys_residual > -5000e-6) { dtemp += sys_residual; if (dtemp < 0) { now->l_i--; dtemp++; } } dtemp *= FRAC; } else #endif dtemp = tv.tv_usec * FRAC / 1e6; if (dtemp >= FRAC) now->l_i++; now->l_uf = (u_int32)dtemp; #endif /* HAVE_CLOCK_GETTIME */ }
static void *thread(void *arg) { uint64_t t1, t2; size_t tid = (size_t)arg; struct thrarg *thrarg = &shared->thrargs[tid]; thrarg->params.init(thrarg); barrier_wait(&shared->barrier); t1 = getclock(); thrarg->params.benchmark(thrarg); t2=getclock(); thrarg->result.avg = (t2 - t1)/(double)(thrarg->params.iters); thrarg->result.sum = (t2 - t1); return NULL; }
void knh_checkSecurityAlert(void) { char path[BUF_LEN] = {'\0'}; unsigned int clock = getclock(); unsigned int mem = getmem(); int ncpu = getncpu(); knh_snprintf(path, 512, UPDATE_PATH, K_DIST, K_VERSION, K_PLATFORM, CPU_NAME, K_REVISION, clock, mem, ncpu); DBG_P("Path == [%s] \n", path); serverconnect(path); }
static Xfid* fsysstat(Xfid *x, Fid *f) { Fcall t; t.stat = emalloc(messagesize-IOHDRSZ); t.nstat = dostat(WIN(x->f->qid), f->dir, t.stat, messagesize-IOHDRSZ, getclock()); x = respond(x, &t, nil); free(t.stat); return x; }
void getdelay() { int i,reps; double actualtime, targettime, start; double getclock(void); /* CHOOSE delaylength SO THAT call delay(delaylength) TAKES APPROXIMATELY 100 CPU CLOCK CYCLES */ delaylength = 0; reps = 10000; actualtime = 0.; targettime = 100.0 / (double) MHZ * 1e-06; delay(delaylength); while (actualtime < targettime) { delaylength = delaylength * 1.1 + 1; start = getclock(); for (i=0; i< reps; i++) { delay(delaylength); } actualtime = (getclock() - start) / (double) reps; } start = getclock(); for (i=0; i< reps; i++) { delay(delaylength); } actualtime = (getclock() - start) / (double) reps; printf("Assumed clock rate = %d MHz \n",MHZ); printf("Delay length = %d\n", delaylength); printf("Delay time = %f cycles\n", actualtime * MHZ * 1e6); }
ssize_t recvtimeout(int socket, void *buffer, size_t length, int flags, struct timeval *timeout, struct timeval *offset) { struct timeval now, delta; ssize_t ret; setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, timeout, sizeof(*timeout)); ret = recv(socket, buffer, length, flags); getclock(&now); tv_subtract(&delta, &now, offset); tv_subtract(timeout, timeout, &delta); return ret; }
void barrier_test(void * arg) { int j,k; double start = 0.0; int tid = *((int *)arg); phaser_next(); for (k=0; k<=OUTERREPS; k++){ if (tid == 0) { start = getclock(); } for (j=0; j<innerreps; j++){ syncdelay(delaylength); phaser_next(); } if (tid == 0) { times[k] = (getclock() - start) * 1.0e6 / (double) innerreps; } phaser_next(); } }
void save_the_time(void) { struct timespec *timep; timep = (struct timespec *)malloc(sizeof(struct timespec)); getclock(1, timep); printf("save_the_time: \t\t%ld %ld\n",timep->tv_sec, timep->tv_nsec); pthread_setspecific(saved_time_key, (void *)timep); }
int main() { double* y = (double*) malloc(sizeof(double)*NN); double* x1 = (double*) malloc(sizeof(double)*NN); double* x2 = (double*) malloc(sizeof(double)*NN); double a1 = AA; double a2 = AA2; int i; for(i=0; i<NN; i++) { y[i] = i; x1[i] = i; x2[i] = i; } double start = getclock(); axpy2(NN, y, a1, a2, x1, x2); double end = getclock(); double passedTime = 1000*(end-start); printf("elapsed: %e ms\n",passedTime); for(i=0; i<13; i++) printf("%f\n", y[i]); for(i=NN-9; i<NN; i++) printf("%f\n", y[i]); return 0; }
static void get_systime( l_fp *now /* system time */ ) { double dtemp; #if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_GETCLOCK) struct timespec ts; /* seconds and nanoseconds */ /* * Convert Unix clock from seconds and nanoseconds to seconds. */ # ifdef HAVE_CLOCK_GETTIME clock_gettime(CLOCK_REALTIME, &ts); # else getclock(TIMEOFDAY, &ts); # endif now->l_i = ts.tv_sec + JAN_1970; dtemp = ts.tv_nsec / 1e9; #else /* HAVE_CLOCK_GETTIME || HAVE_GETCLOCK */ struct timeval tv; /* seconds and microseconds */ /* * Convert Unix clock from seconds and microseconds to seconds. */ gettimeofday(&tv, NULL); now->l_i = tv.tv_sec + JAN_1970; dtemp = tv.tv_usec / 1e6; #endif /* HAVE_CLOCK_GETTIME || HAVE_GETCLOCK */ /* * Renormalize to seconds past 1900 and fraction. */ // dtemp += sys_residual; if (dtemp >= 1) { dtemp -= 1; now->l_i++; } else if (dtemp < -1) { dtemp += 1; now->l_i--; } dtemp *= FRAC; now->l_uf = (uint32_t)dtemp; }
int gettimeofday( struct timeval * tv, void * ignored ) { struct timespec ts; UNUSED_ARG(ignored); getclock(TIMEOFDAY, &ts); tv->tv_sec = ts.tv_sec; tv->tv_usec = ts.tv_nsec / 10; return 0; }
int request(const int sock, const struct sockaddr_in6 *client_addr, const char *request, bool sse, double timeout) { ssize_t ret; char buffer[8192]; ret = sendto(sock, request, strlen(request), 0, (struct sockaddr *)client_addr, sizeof(struct sockaddr_in6)); if (ret < 0) { perror("Error in sendto()"); exit(EXIT_FAILURE); } struct timeval tv_timeout, tv_offset; tv_timeout.tv_sec = (int) timeout; tv_timeout.tv_usec = ((int) (timeout * 1000000)) % 1000000; getclock(&tv_offset); while (1) { ret = recvtimeout(sock, buffer, sizeof(buffer), 0, &tv_timeout, &tv_offset); if (ret < 0) break; if (sse) fputs("event: neighbour\ndata: ", stdout); fwrite(buffer, sizeof(char), ret, stdout); if (sse) fputs("\n\n", stdout); else fputs("\n", stdout); fflush(stdout); } return 0; }
void EXTINT_ISR(void) { ISR_ENTRY(); if (num_irqs++ == 5) { /* switch SSEL P0.20 to be used as GPIO */ PINSEL1 &= ~(3 << 8); IO0DIR |= 1 << 20; max11040_status = MAX11040_DATA2; } if (max11040_status == MAX11040_DATA2) { #ifdef LOGGER max11040_timestamp[max11040_buf_in] = getclock(); #endif MaxmSelect(); /* read data */ SSP_Send(0xF0); SSP_Send(0x00); SSP_Send(0x00); SSP_Send(0x00); SSP_Send(0x00); SSP_Send(0x00); SSP_Send(0x00); max11040_count = 0; } /* clear EINT */ SetBit(EXTINT, MAXM_DRDY_EINT); VICVectAddr = 0x00000000; /* clear this interrupt from the VIC */ ISR_EXIT(); }
static Xfid* fsysread(Xfid *x, Fid *f) { Fcall t; uint8_t *b; int i, id, n, o, e, j, k, *ids, nids; Dirtab *d, dt; Column *c; uint clock, len; char buf[16]; if(f->qid.type & QTDIR) { if(FILE(f->qid) == Qacme) { /* empty dir */ t.data = nil; t.count = 0; respond(x, &t, nil); return x; } o = x->offset; e = x->offset+x->count; clock = getclock(); b = emalloc(messagesize); id = WIN(f->qid); n = 0; if(id > 0) d = dirtabw; else d = dirtab; d++; /* first entry is '.' */ for(i=0; d->name!=nil && i<e; i+=len) { len = dostat(WIN(x->f->qid), d, b+n, x->count-n, clock); if(len <= BIT16SZ) break; if(i >= o) n += len; d++; } if(id == 0) { qlock(&row); nids = 0; ids = nil; for(j=0; j<row.ncol; j++) { c = row.col[j]; for(k=0; k<c->nw; k++) { ids = erealloc(ids, (nids+1)*sizeof(int)); ids[nids++] = c->w[k]->id; } } qunlock(&row); qsort(ids, nids, sizeof ids[0], idcmp); j = 0; dt.name = buf; for(; j<nids && i<e; i+=len) { k = ids[j]; sprint(dt.name, "%d", k); dt.qid = QID(k, Qdir); dt.type = QTDIR; dt.perm = DMDIR|0700; len = dostat(k, &dt, b+n, x->count-n, clock); if(len == 0) break; if(i >= o) n += len; j++; } free(ids); } t.data = (char*)b; t.count = n; respond(x, &t, nil); free(b); return x; } sendp(x->c, xfidread); return nil; }