void dispatcher_body() { int err, t0, t1; task_t* next; // Tarefa que ocupara o processador. enable_preemption(0); // Caso haver alguma tarefa na lista de prontas // o while eh executado. while (list_size(ready_list) > 0) { t0 = systime(); next = scheduler(); if (next) { ticks = 20; enable_preemption(1); t1 = systime(); curr_task->proc_time += t0 - t1; t0 = systime(); err = task_switch(next); t1 = systime(); next->proc_time += t1 - t0; if (err == -1) { perror("dispatcher_body: task_switch failed.\n"); return; } } } // Finaliza o dispatcher, voltando para o main. task_exit(0); }
void sleep_till(systime_t t) { sleep(t - systime()); while (systime() < t) ; }
void sched_schedule() { // find a thread to schedule. the scheduled thread is removed from the // queue, and the currently-run thread is re-added to the queue. spl_lock(&_sched_lock); thread_t* old = thr_current(); if(old) { switch(old->state) { case Runnable: // don't stop if the thread still has time! if(old->preempt_at > systime()) { goto done; } break; case Yielded: // timeslice is given up. old->state = Runnable; break; default: // not relevant here. break; } } // BUG: this algorithm will start to choose the idle thread when // only one other thread is remaining runnable. thread_t* thr = sched_choose(old); if(thr) { trace("switching: %d:%d (%d)\n", thr->parent->id, thr->id, thr->priority); thr->preempt_at = systime() + SCHED_TIMESLICE_US; thr_switch(thr); sched_remove_unlocked(thr); if(old) sched_add_unlocked(old); goto done; } // let things stay as they are if only one thread exists. if(old->state == Runnable) { goto done; } fatal("no thread left to schedule - this is bad!\n"); done: spl_unlock(&_sched_lock); }
void Body (void * arg) { int i,j ; printf ("%s INICIO em %4d ms\n", (char *) arg, systime()) ; for (i=0; i<40000; i++) for (j=0; j<40000; j++) ; printf ("%s FIM em %4d ms\n", (char *) arg, systime()) ; task_exit (0) ; }
void waitdelay(unsigned int n) { unsigned long start; start=systime(); do { #ifdef NOSYSCURSOR refresh(); #else buthit(); #endif } while((unsigned long)(systime()-start)<((unsigned long)n)); }
int component_ready(uint32_t t, enum frontend_tune_state st0, enum frontend_tune_state st1) { if (st0 == st1 || (t <= systime() && st0 > st1) || (st0 == CT_SHUTDOWN) ) return 1; return 0; }
static void avg(char *prog, char *file) { rusage_t joule; char cmd[1024]; sprintf(cmd, "luac -o %s.luac %s", file, file); system(cmd); sprintf(cmd, "%s.luac", file); char **argv; char *joule_argv[] = {prog, "-c", cmd, NULL}; char *lua_argv[] = {prog, cmd, NULL}; argv = strcmp(prog, "lua") == 0 ? lua_argv : joule_argv; long total, user, system, mem; total = user = system = mem = 0; int i; for (i = 0; i < NTIMES; i++) { systime(argv, &joule); total += USECS(&joule.ru_utime) + USECS(&joule.ru_stime); user += USECS(&joule.ru_utime); system += USECS(&joule.ru_stime); mem += joule.ru_maxrss; } unlink(cmd); printf("%27s,", file); printf("%10ld,%10ld,%10ld,%10ld\n", total/NTIMES, user/NTIMES, system/NTIMES, mem/NTIMES); }
void skynet_timer_init(void) { TI = timer_create_timer(); systime(&TI->starttime, &TI->current); uint64_t point = gettime(); TI->current_point = point; TI->origin_point = point; }
/* 初始化定时器模块, 初始工作包括构建定时器对象, 初始化时间系统的当前时间、启动时间、 * 启动时间戳和当前时间戳. */ void skynet_timer_init(void) { TI = timer_create_timer(); uint32_t current = 0; systime(&TI->starttime, ¤t); TI->current = current; TI->current_point = gettime(); }
void frontend_tune_restart(struct dibFrontend *fe, enum restart_tune_process option, struct dibChannel * ch) { struct dibChannelFEInfo *info = channel_frontend_info(ch, fe->id); fe->status = FE_STATUS_TUNE_PENDING; switch(option) { default: case FE_RESTART_TUNE_PROCESS_FROM_TUNER: info->tune_time_locked = info->tune_time_estimation[TUNE_TIME_LOCKED] = ch->context.tune_time_estimation[TUNE_TIME_LOCKED]; info->tune_time_data = info->tune_time_estimation[TUNE_TIME_DATA] = ch->context.tune_time_estimation[TUNE_TIME_DATA]; info->tune_start_time = fe->time_steady = systime(); dbgpl(NULL,"Full restart of fe %d (from TUNER)",fe->id); fe->tune_state = CT_START; if (fe->demod_info) fe->demod_info->callback_time_agc = FE_CALLBACK_TIME_NEVER; if (fe->demod_info) fe->demod_info->callback_time = FE_CALLBACK_TIME_NEVER; #ifdef CHANDEC_SH_FEC if (fe->channel_decoder_info) fe->channel_decoder_info->callback_time = FE_CALLBACK_TIME_NEVER; #endif break; case FE_RESTART_TUNE_PROCESS_FROM_AGC: dbgpl(NULL,"Partial restart of fe %d (from AGC only)",fe->id); if (fe->tune_state > CT_AGC_START) fe->tune_state = CT_AGC_START; if (fe->demod_info) fe->demod_info->callback_time = FE_CALLBACK_TIME_NEVER; #ifdef CHANDEC_SH_FEC if (fe->channel_decoder_info) fe->channel_decoder_info->callback_time = FE_CALLBACK_TIME_NEVER; #endif break; case FE_RESTART_TUNE_PROCESS_FROM_DEMOD: dbgpl(NULL,"Partial restart of fe %d (from DEMOD only)",fe->id); if (fe->tune_state > CT_DEMOD_START) fe->tune_state = CT_DEMOD_START; #ifdef CHANDEC_SH_FEC if (fe->channel_decoder_info) fe->channel_decoder_info->callback_time = FE_CALLBACK_TIME_NEVER; #endif break; case FE_SHUTDOWN: fe->tune_state = CT_SHUTDOWN; break; } }
int eztimer_init(void) { if(TI) { return E_EZTMR_ALRADY_INITED; } TI = timer_create_timer(); systime(&TI->starttime, &TI->current); uint64_t point = gettime(); TI->current_point = point; TI->origin_point = point; TI->dispather = NULL; return 0; }
int channel_decoder_tune(struct dibFrontend *fe, struct dibChannel *ch) { if (FE_CHANNEL_DECODER_FUNC_CHECK(fe, tune)) { if (component_ready(fe->channel_decoder_info->callback_time, fe->tune_state, CT_CHAN_DEC_START)) { uint32_t delay = FE_CHANNEL_DECODER_FUNC_CALL(fe, tune)(fe, ch); if (delay == FE_CALLBACK_TIME_NEVER) fe->channel_decoder_info->callback_time = FE_CALLBACK_TIME_NEVER; else fe->channel_decoder_info->callback_time = delay + systime(); //dbgpl(NULL,"fe%d->channel_decoder_info->callback_time = %d systime = %d ", fe->id, fe->channel_decoder_info->callback_time, systime()); } return DIB_RETURN_SUCCESS; } return DIB_RETURN_NOT_SUPPORTED; }
void task_exit(int exit_code) { int err, exec_time, proc_time, num_act; //enable_preemption(0); #ifdef DEBUG printf(">> task_exit()\n"); #endif curr_task->death_time = systime(); exec_time = curr_task->death_time - curr_task->birth_time; proc_time = curr_task->proc_time; num_act = curr_task->activations; printf("Task %d exit: execution time %d ms, processor time %d ms, ", curr_task->id, exec_time, proc_time); printf("%d activations\n", num_act); // Caso o dispatcher executar task_exit() o contexto // eh mudado para o main(). Caso for qualquer outra // tarefa o contexto é mudado para o dispatcher. /*if (curr_task == &dispatcher) { err = task_switch(&main_task); } else { err = task_switch(&dispatcher); }*/ if (curr_task != &dispatcher) err = task_switch(&dispatcher); if (err == -1) { perror("task_exit: task_switch failed.\n"); return; } #ifdef DEBUG printf(">> task_exit()\n"); #endif }
/* display the time on a remote box in a format ready for /bin/date */ static int net_time_system(struct net_context *c, int argc, const char **argv) { time_t t; if (c->display_usage || c->opt_host == NULL) { d_printf( "%s\n" "net time system\n" " %s\n", _("Usage:"), _("Output remote time server (-S server) " "time in a format ready for /bin/date")); return 0; } t = nettime(c, NULL); if (t == 0) return -1; printf("%s\n", systime(t)); return 0; }
std::string CommandEventHandler::info(std::vector<std::string>& args) { if (args.size() != 1) return agentWarnInvalidNumArgs(1); if (args[0].compare("id") == 0) return id(); else if (args[0].compare("os") == 0) return os(); else if (args[0].compare("systime") == 0) return systime(); else if (args[0].compare("uptime") == 0) return uptime(); else if (args[0].compare("uptimemillis") == 0) return uptimemillis(); else if (args[0].compare("screen") == 0) return screen(); else if (args[0].compare("memory") == 0) return memory(); else if (args[0].compare("power") == 0) return power(); return agentWarn("Invalid info subcommand."); }
std::ostream& Timer::print( std::ostream& o ) const { o << "user time: " << usertime() << '\n' ; o << "sys. time: " << systime() << '\n' ; return o << "real time: " << realtime() << std::endl ; }
void frontend_tune(struct dibFrontend *fe, struct dibChannel *ch) { int ret = 0; struct dibChannelFEInfo *fe_info = channel_frontend_info(ch, fe->id); uint8_t alpha = 5; int16_t current_status = frontend_get_status(fe); #ifdef WAVE_ADAPT enum frontend_tune_state *tune_state = &fe->tune_state; #endif /* start the tuning process */ if (fe->tune_state == CT_START) { frontend_wakeup(fe); fe->tune_state = CT_TUNER_START; fe->current_bw = ch->bandwidth_kHz; } /* nothing to do */ if (frontend_callback_time(fe) > systime()) { //dbgpl(NULL,"fe%d tune state = %d : nothing to do ! %x", fe->id, fe->tune_state, frontend_callback_time(fe)); return; } /* TUNER */ ret = tuner_tune_fast(fe, ch); if (ret == DIB_RETURN_NOT_SUPPORTED) if (fe->tune_state >= CT_TUNER_START && fe->tune_state < CT_DEMOD_START) fe->tune_state = CT_DEMOD_START; /* skip the TUNER */ /* AGC */ ret = demod_agc_startup_fast(fe, ch); if (ret == DIB_RETURN_NOT_SUPPORTED) if (fe->tune_state >= CT_AGC_START && fe->tune_state < CT_DEMOD_START) fe->tune_state = CT_DEMOD_START; /* directly go to DEMOD */ /* DEMOD */ ret = demod_tune_fast(fe, ch); if (ret == DIB_RETURN_NOT_SUPPORTED) if (fe->tune_state >= CT_DEMOD_START && fe->tune_state < CT_CHAN_DEC_START) #ifdef CONFIG_CORE_CHANDEC fe->tune_state = CT_CHAN_DEC_START; /* directly go to CHANDEC */ /* CHANDEC */ ret = channel_decoder_tune(fe, ch); if (ret == DIB_RETURN_NOT_SUPPORTED) if (fe->tune_state >= CT_CHAN_DEC_START && fe->tune_state < CT_DONE) #endif fe->tune_state = CT_DONE; /* done */ if(fe->status == FE_STATUS_LOCKED) fe_info->tune_time_locked = systime() - fe_info->tune_start_time; if(fe->status == FE_STATUS_DATA_LOCKED && (fe->tune_state == CT_DEMOD_STOP || fe->tune_state == CT_CHAN_DEC_STOP)) fe_info->tune_time_data = systime() - fe_info->tune_start_time; /* Increase smoothly estimated time (10ms step) if FE_STATUS_TUNE_FAILED */ if((fe->tune_state == CT_DEMOD_STOP || fe->tune_state == CT_CHAN_DEC_STEP_LOCKED) && fe->status == FE_STATUS_TUNE_FAILED) { if(fe_info->tune_time_locked < channel_get_default_tune_time(ch->type)) fe_info->tune_time_locked+= 100; if(fe_info->tune_time_data < channel_get_default_tune_time(ch->type)) fe_info->tune_time_data+= 100; } if((fe->tune_state == CT_DEMOD_STOP || fe->tune_state == CT_CHAN_DEC_STOP) && (fe->status == FE_STATUS_DATA_LOCKED || fe->status == FE_STATUS_LOCKED)) { alpha = 8; fe_info->tune_time_estimation[TUNE_TIME_LOCKED] = 400 + ((10-alpha) * fe_info->tune_time_estimation[TUNE_TIME_LOCKED] + (alpha * fe_info->tune_time_locked))/10; /* 40ms static margin */ fe_info->tune_time_estimation[TUNE_TIME_DATA] = 400 + ((10-alpha) * fe_info->tune_time_estimation[TUNE_TIME_DATA] + (alpha * fe_info->tune_time_data))/10; /* 40ms static margin */ /* saturations of tune_time_ estimation */ if(fe_info->tune_time_estimation[TUNE_TIME_LOCKED] < 300) fe_info->tune_time_estimation[TUNE_TIME_LOCKED] = 300; /* tune can not take less than 30 ms*/ if(fe_info->tune_time_estimation[TUNE_TIME_LOCKED] > 100000) fe_info->tune_time_estimation[TUNE_TIME_LOCKED] = 100000; /* tune can not take more than 10s*/ /* saturations of tune_time_ estimation */ if(fe_info->tune_time_estimation[TUNE_TIME_DATA] < fe_info->tune_time_estimation[TUNE_TIME_LOCKED]) fe_info->tune_time_estimation[TUNE_TIME_DATA] = fe_info->tune_time_estimation[TUNE_TIME_LOCKED]; /* tune can not take less than the time to lock */ if(fe_info->tune_time_estimation[TUNE_TIME_DATA] > 100000) fe_info->tune_time_estimation[TUNE_TIME_DATA] = 100000; /* tune can not take more than 10s*/ #ifdef WAVE_ADAPT WaveNetUpdate(NET_tune_time_est_locked_fe_0+fe->id, fe_info->tune_time_estimation[TUNE_TIME_LOCKED]); WaveNetUpdate(NET_tune_time_est_data_fe_0+fe->id, fe_info->tune_time_estimation[TUNE_TIME_DATA]); #endif } #ifdef WAVE_ADAPT WaveNetUpdate(NET_tune_state_fe_0+fe->id, *tune_state); #endif /* activate the next component */ if (fe->tune_state == CT_TUNER_STOP) fe->tune_state = CT_AGC_START; if (fe->tune_state == CT_AGC_STOP) fe->tune_state = CT_DEMOD_START; if (fe->tune_state == CT_DEMOD_STOP) #ifdef CONFIG_CORE_CHANDEC fe->tune_state = CT_CHAN_DEC_START; if (fe->tune_state == CT_CHAN_DEC_STOP) #endif fe->tune_state = CT_DONE; if (current_status == frontend_get_status(fe)) { fe->status_has_changed = 0; } else { //Trace2Host("status of FE%d has changed %d -> %d\n", fe->id, current_status, frontend_get_status(fe)); fe->status_has_changed = 1; } }
void busy_wait(uint32_t usec) { uint32_t stop = systime() + usec/100 + 1; while (systime() < stop); }
VI double seconds() { return systime() / 1000.0; }
void systime_stall(uint64_t us) { uint64_t start = systime(); uint64_t end = start + us; while(systime() < end); }
int initsystem(void) /* retourne 1 si initialisation reussie */ { int i; int windowW; int windowH; XSetWindowAttributes xswa; XGCValues xgcv; XSizeHints xsh; windowW=WIDTH*RATIO; windowH=HEIGHT*RATIO; display=XOpenDisplay(0); if (!display) return(0); else { mousek=0; XAutoRepeatOff(display); timestart=last=systime(); screen=XDefaultScreenOfDisplay(display); rdepth=sdepth=XDefaultDepthOfScreen(screen); if (emulmono) sdepth=1; XSynchronize(display,0); black=XBlackPixelOfScreen(screen); white=XWhitePixelOfScreen(screen); colormap=XDefaultColormapOfScreen(screen); visual=XDefaultVisualOfScreen(screen); xswa.event_mask=VisibilityChangeMask; xswa.background_pixel=black; xswa.border_pixel=white; xswa.override_redirect=0; xswa.backing_store=Always; xswa.bit_gravity=StaticGravity; xswa.win_gravity=CenterGravity; window=XCreateWindow(display,XRootWindowOfScreen(screen), randval(50),randval(100),windowW,windowH,0, XDefaultDepthOfScreen(screen),InputOutput, XDefaultVisualOfScreen(screen), CWWinGravity|CWBitGravity|CWBackingStore|CWEventMask| CWBackPixel|CWOverrideRedirect|CWBorderPixel,&xswa); if (sdepth!=1) xcolormap=XCreateColormap(display,window, visual,AllocAll); xgcv.foreground = white; xgcv.background = black; gc=XCreateGC(display,window,GCForeground | GCBackground,&xgcv); XSetGraphicsExposures(display,gc,False); /* CAPITAL!!! : evite d'accumuler sans cesse des expose events */ xsh.x=0; xsh.y=0; xsh.width=windowW; xsh.height=windowH; xsh.min_width=windowW; xsh.max_width=windowW; xsh.min_height=windowH; xsh.max_height=windowH; xsh.flags=PPosition|PSize|PMinSize|PMaxSize; XSetNormalHints(display, window, &xsh); XStoreName(display,window,""); XMapWindow(display, window); XSelectInput(display,window,PointerMotionMask|ButtonPressMask| ButtonReleaseMask|KeyPressMask|KeyReleaseMask); XFlush(display); XSync(display,0); for (i=0; i<(NBCOLORS+2); i++) { if (i&1) pixels[i]=white; else pixels[i]=black; if (i==NBCOLORS) pixels[i]=0; if (i==(NBCOLORS+1)) pixels[i]=(1<<rdepth)-1; xgcv.foreground=pixels[i]; xgcv.background=black; gctab[i]=XCreateGC(display,window, GCForeground|GCBackground,&xgcv); XSetFunction(display,gctab[i],GXcopy); XSetFillStyle(display,gctab[i],FillSolid); } ecran[0]=XCreatePixmap(display,window,windowW,windowH,rdepth); ecran[1]=XCreatePixmap(display,window,windowW,windowH,rdepth); for(i=0; i<9; i++) graypixmap[i]=XCreatePixmapFromBitmapData(display,window, &graypat[i][0],8,8,white,black,rdepth); setpalette(egapal); cls(); swap(); cls(); empty(); waitdelay(500); return(1); } }
int task_create(task_t *task, void (*start_routine), void *arg) { char *stack = NULL; int err; //enable_preemption(0); #ifdef DEBUG printf(">> task_create()\n"); #endif // Alocamento de 32kB de memoria para a pilha de // contexto. stack = (char *) malloc(STACKSIZE); err = getcontext(&(task->context)); if (err == -1) { perror("task_create: getcontext failed.\n"); return err; } if (stack != NULL) { task->context.uc_stack.ss_sp = stack; task->context.uc_stack.ss_size = STACKSIZE; task->context.uc_stack.ss_flags = 0; task->context.uc_link = 0; } else { #ifdef DEBUG perror("task_create: stack malloc failed.\n"); #endif return -1; } id_counter++; // Inicializando os atributos da tarefa. task->id = id_counter; task->priority = 0; task->age = 0; task->birth_time = systime(); task->proc_time = 0; task->activations = 0; #ifdef DEBUG printf("task_create: task %d created.\n", id_counter); #endif makecontext(&(task->context), start_routine, 1, arg); // Todas as tarefas sao adicionas a lista, menos // o dispatcher. if (task != &dispatcher) { #ifdef DEBUG printf("task_create: list_append task %d\n", task->id); #endif list_append(&ready_list, task); } #ifdef DEBUG printf("<< task_create()\n"); #endif return id_counter; }
void task_init() { int err; //enable_preemption(0); #ifdef DEBUG printf(">> task_init()\n"); #endif setvbuf(stdout, 0, _IONBF, 0); // --------- Timer -------- action.sa_handler = timer_handler; sigemptyset(&action.sa_mask); action.sa_flags = 0; if (sigaction(SIGALRM, &action, 0) < 0) { perror("sigaction error: "); exit(1); } timer.it_value.tv_usec = 1; timer.it_value.tv_sec = 0; timer.it_interval.tv_usec = 1000; timer.it_interval.tv_sec = 0; if (setitimer(ITIMER_REAL, &timer, 0) < 0) { perror("setitimer error: "); exit(1); } // ------ Fim Timer ------- main_task.id = id_counter; main_task.priority = 0; main_task.birth_time = systime(); main_task.proc_time = 0; main_task.activations = 0; err = getcontext(&(main_task.context)); if (err == -1) { perror("task_init: main getcontext failed.\n"); return; } curr_task = &main_task; #ifdef DEBUG printf("task_init: task main created.\n"); #endif err = task_create(&dispatcher, dispatcher_body, 0); if (err == -1) { perror("task_init: dispatcher task_create failed.\n"); return; } list_append(&ready_list, &main_task); #ifdef DEBUG printf("task_init: task dispatcher created.\n"); printf("<< task_init()\n"); #endif }