int RUN(int argc,char **argv,FILE *out) { #ifdef OUT opt_t def = { 0, NUMBER_OF_RUN, SIZE_OF_TEST, AVAIL, NEXE, mode_random, }; opt_t d = def ; char *prog = argv[0] ; char **p = parse_opt(argc,argv,&def,&d) ; int n_exe = d.n_exe ; if (d.avail != AVAIL) n_exe = d.avail / N ; if (n_exe < 1) n_exe = 1 ; global.verbose = d.verbose; global.nexe = n_exe; global.noccs = NOCCS ; global.nruns = d.max_run; global.size = d.size_of_test; global.do_scan = d.mode == mode_scan ; if (global.verbose) { fprintf(stderr,"%s: n=%i, r=%i, s=%i, %s\n",prog,global.nexe,global.nruns,global.size,global.do_scan ? "+sp" : "+rp"); } parse_param(prog,global.parse,PARSESZ,p) ; #ifdef PRELUDE prelude(out) ; #endif tsc_t start = timeofday(); #else global.verbose = 0 ; global.nexe = NEXE ; global.noccs = NOCCS ; global.nruns = NUMBER_OF_RUN ; global.size = SIZE_OF_TEST ; global.do_scan = 0; #endif for (int id=0; id < AVAIL ; id++) { arg[id].id = id; arg[id].g = &global; } for (int id=0; id < AVAIL ; id++) launch(&th[id],zyva,&arg[id]); for (int id=0; id < AVAIL ; id++) join(&th[id]); int nexe = global.nexe ; hash_init(&global.hash) ; for (int k=0 ; k < nexe ; k++) { hash_adds(&global.hash,&global.ctx[k].t) ; } #ifdef OUT tsc_t total = timeofday()-start; count_t p_true = 0, p_false = 0; for (int k = 0 ; k < HASHSZ ; k++) { entry_t *e = &global.hash.t[k]; if (e->ok) { p_true += e->c ; } else { p_false += e->c; } } postlude(out,&global,p_true,p_false,total); #endif return EXIT_SUCCESS; }
const char * elektraTimeofdayHelper (char *t, TimeofdayInfo *ti) { struct timeval now; gettimeofday(&now, 0); timeofday (t, &ti->start, &now); t[10] = '\t'; t[11] = 'd'; t[12] = 'i'; t[13] = '\t'; timeofday(&t[14], &ti->last, &now); ti->last = now; return t; }
static double getnow(void) { register double now; #ifdef timeofday struct timeval tp; timeofday(&tp); now = tp.tv_sec + 1.e-6*tp.tv_usec; #else now = (double)time((time_t*)0); #endif /* timeofday */ return(now+.001); }
static void init_global(global_t *g,int id) { if (id == 0) { #ifdef TIMELIMIT /* Starting time */ g->start = timeofday() ; #endif /* Global barrier */ barrier_init(&g->gb,AVAIL) ; /* Align to cache line */ uintptr_t x = (uintptr_t)(g->mem) ; x += LINE-1 ; x /= LINE ; x *= LINE ; intmax_t *m = (intmax_t *)x ; /* Instance contexts */ for (int k = 0 ; k < NEXE ; k++) { instance_init(&g->ctx[k],k,m) ; m += NVARS*LINESZ ; } mbar() ; g->go = 1 ; } else { while (g->go == 0) ; mbar() ; } }
static int do_select(int n, fd_set *read, fd_set *write, fd_set *except, struct timeval *timeout) { int result, lerrno; fd_set orig_read, orig_write, orig_except; bzero(&orig_read, sizeof(fd_set)); bzero(&orig_write, sizeof(fd_set)); bzero(&orig_except, sizeof(fd_set)); #ifndef linux double limit = 0; struct timeval wait_rest; if (timeout) { limit = timeofday() + (double)timeout->tv_sec+(double)timeout->tv_usec*1e-6; wait_rest = *timeout; timeout = &wait_rest; } #endif if (read) orig_read = *read; if (write) orig_write = *write; if (except) orig_except = *except; retry: lerrno = 0; //BLOCKING_REGION({ result = select(n, read, write, except, timeout); if (result < 0) lerrno = errno; //}, ubf_select, GET_THREAD()); errno = lerrno; if (result < 0) { switch (errno) { case EINTR: #ifdef ERESTART case ERESTART: #endif if (read) *read = orig_read; if (write) *write = orig_write; if (except) *except = orig_except; #ifndef linux if (timeout) { double d = limit - timeofday(); wait_rest.tv_sec = (unsigned int)d; wait_rest.tv_usec = (long)((d-(double)wait_rest.tv_sec)*1e6); if (wait_rest.tv_sec < 0) wait_rest.tv_sec = 0; if (wait_rest.tv_usec < 0) wait_rest.tv_usec = 0; } #endif goto retry; default: break; } } return result; }
static void warm_up(int sz, tsc_t d) { pthread_t th[sz]; d += timeofday() ; for (int k = 0 ; k < sz ; k++) launch(&th[k], loop, &d) ; for (int k = 0 ; k < sz ; k++) join(&th[k]) ; }
static void* loop(void *p) { tsc_t *q = p ; tsc_t max = *q ; while (timeofday() < max) ; return NULL ; }