/*the ticker thread function that executes the filters */ void * ms_ticker_run(void *arg) { uint64_t realtime; int64_t diff; MSTicker *s=(MSTicker*)arg; int lastlate=0; int precision=2; int late; precision = set_high_prio(s); s->ticks=1; ms_mutex_lock(&s->lock); s->orig=s->get_cur_time_ptr(s->get_cur_time_data); while(s->run){ s->ticks++; { #if TICKER_MEASUREMENTS MSTimeSpec begin,end;/*used to measure time spent in processing one tick*/ double iload; ms_get_cur_time(&begin); #endif run_graphs(s,s->execution_list,FALSE); #if TICKER_MEASUREMENTS ms_get_cur_time(&end); iload=100*((end.tv_sec-begin.tv_sec)*1000.0 + (end.tv_nsec-begin.tv_nsec)/1000000.0)/(double)s->interval; s->av_load=(smooth_coef*s->av_load)+((1.0-smooth_coef)*iload); #endif } s->time+=s->interval; while(1){ realtime=s->get_cur_time_ptr(s->get_cur_time_data)-s->orig; ms_mutex_unlock(&s->lock); diff=s->time-realtime; if (diff>0){ /* sleep until next tick */ sleepMs((int)diff); }else{ late=(int)-diff; if (late>s->interval*5 && late>lastlate){ ms_warning("%s: We are late of %d miliseconds.",s->name,late); } lastlate=late; break; /*exit the while loop */ } ms_mutex_lock(&s->lock); } ms_mutex_lock(&s->lock); } ms_mutex_unlock(&s->lock); unset_high_prio(precision); ms_message("%s thread exiting",s->name); ms_thread_exit(NULL); return NULL; }
/*the ticker thread function that executes the filters */ void * ms_ticker_run(void *arg) { MSTicker *s=(MSTicker*)arg; int lastlate=0; int precision=2; int late; precision = set_high_prio(s); s->thread_id = ms_thread_self(); s->ticks=1; s->orig=s->get_cur_time_ptr(s->get_cur_time_data); ms_mutex_lock(&s->lock); while(s->run){ uint64_t late_tick_time=0; s->ticks++; /*Step 1: run the graphs*/ { #if TICKER_MEASUREMENTS MSTimeSpec begin,end;/*used to measure time spent in processing one tick*/ double iload; ms_get_cur_time(&begin); #endif run_tasks(s); run_graphs(s,s->execution_list,FALSE); #if TICKER_MEASUREMENTS ms_get_cur_time(&end); iload=100*((end.tv_sec-begin.tv_sec)*1000.0 + (end.tv_nsec-begin.tv_nsec)/1000000.0)/(double)s->interval; s->av_load=(smooth_coef*s->av_load)+((1.0-smooth_coef)*iload); #endif } ms_mutex_unlock(&s->lock); /*Step 2: wait for next tick*/ s->time+=s->interval; late=s->wait_next_tick(s->wait_next_tick_data,s->time); if (late>s->interval*5 && late>lastlate){ ms_warning("%s: We are late of %d miliseconds.",s->name,late); late_tick_time=ms_get_cur_time_ms(); } lastlate=late; ms_mutex_lock(&s->lock); if (late_tick_time){ s->late_event.lateMs=late; s->late_event.time=late_tick_time; } s->late_event.current_late_ms = late; } ms_mutex_unlock(&s->lock); unset_high_prio(precision); ms_message("%s thread exiting",s->name); ms_thread_exit(NULL); s->thread_id = 0; return NULL; }
void ms_filter_process(MSFilter *f){ MSTimeSpec start,stop; ms_debug("Executing process of filter %s:%p",f->desc->name,f); if (f->stats) ms_get_cur_time(&start); f->desc->process(f); if (f->stats){ ms_get_cur_time(&stop); f->stats->count++; f->stats->elapsed+=(stop.tv_sec-start.tv_sec)*1000000000LL + (stop.tv_nsec-start.tv_nsec); } }
bool_t liblinphone_tester_clock_elapsed(const MSTimeSpec *start, int value_ms){ MSTimeSpec current; ms_get_cur_time(¤t); if ((((current.tv_sec-start->tv_sec)*1000LL) + ((current.tv_nsec-start->tv_nsec)/1000000LL))>=value_ms) return TRUE; return FALSE; }
void ms_filter_task_process(MSFilterTask *task){ MSTimeSpec start,stop; MSFilter *f=task->f; /*ms_message("Executing task of filter %s:%p",f->desc->name,f);*/ if (f->stats) ms_get_cur_time(&start); task->taskfunc(f); if (f->stats){ ms_get_cur_time(&stop); f->stats->count++; f->stats->elapsed+=(stop.tv_sec-start.tv_sec)*1000000000LL + (stop.tv_nsec-start.tv_nsec); } f->postponed_task--; }
void liblinphone_tester_clock_start(MSTimeSpec *start){ ms_get_cur_time(start); }
static uint64_t get_wallclock_ms(void){ MSTimeSpec ts; ms_get_cur_time(&ts); return get_ms(&ts); }
static uint64_t get_cur_time_ms(void *unused){ MSTimeSpec ts; ms_get_cur_time(&ts); return (ts.tv_sec*1000LL) + ((ts.tv_nsec+500000LL)/1000000LL); }