From: Hannes Gredler Date: Wed, 30 Jan 2008 15:13:30 +0000 (+0100) Subject: From Andreas Jacobs : bugfix for scheduler X-Git-Tag: OLSRD_0_5_5~4 X-Git-Url: http://olsr.org/git/?p=olsrd.git;a=commitdiff_plain;h=9178cb7922d841a5dd1be95e9432a4845511aabb From Andreas Jacobs : bugfix for scheduler After each iteration of the scheduler's main loop the scheduler calculates, how much time this iteration took, and then sleeps for the rest of the scheduler interval. The bug lies in the calculation of the elapsed time, which is converted from a tick count to a 'struct timeval' which consists of a seconds value and a microseconds value. The seconds are filled in correctly, but the microseconds field is filled a milliseconds value instead of a microseconds value. Consequently the elapsed time is always underestimated and afterwards the scheduler sleeps too long. --- diff --git a/src/scheduler.c b/src/scheduler.c index e5bdcfd9..8f3d07a2 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -116,6 +116,7 @@ scheduler(void) * Used to calculate sleep time */ clock_t end_of_loop; + clock_t milliseconds_used; struct timeval time_used; struct event_entry *entry; struct timeout_entry *time_out_entry; @@ -188,8 +189,9 @@ scheduler(void) end_of_loop = times(&tms_buf); //printf("Tick diff: %d\n", end_of_loop - now_times); - time_used.tv_sec = ((end_of_loop - now_times) * olsr_cnf->system_tick_divider) / 1000; - time_used.tv_usec = ((end_of_loop - now_times) * olsr_cnf->system_tick_divider) % 1000; + milliseconds_used = (end_of_loop - now_times) * olsr_cnf->system_tick_divider; + time_used.tv_sec = milliseconds_used / 1000; + time_used.tv_usec = (milliseconds_used % 1000) * 1000; //printf("Time used: %d.%04d\n", time_used.tv_sec, time_used.tv_usec);