From: Michal Sojka Date: Thu, 13 Aug 2009 15:37:25 +0000 (+0200) Subject: wme_test: Send timing reworked X-Git-Url: http://rtime.felk.cvut.cz/gitweb/frescor/fwp.git/commitdiff_plain/aeec8a8fbb71689aba3c9adff5e5428b3d308a95?ds=sidebyside wme_test: Send timing reworked The new implementation allows delays > 1 second and skip packets when the program is stopped for some time (suspend to *, or Ctrl-S when there is some debugging output in TX path). --- diff --git a/wme_test/wclient.c b/wme_test/wclient.c index 708c28e..6d87d31 100644 --- a/wme_test/wclient.c +++ b/wme_test/wclient.c @@ -549,22 +549,28 @@ static inline void wait_for_next_send(struct stream* stream, struct timespec *last_send_time) { struct timespec time_to_wait, current_time, period, interval; - unsigned period_usec = stream->period_usec; + unsigned delay_usec, period_usec = stream->period_usec; /* |~~~+~~~| jitter interval (width = 2*stream->jitter percentage from period)*/ /* |-------------| nominal period*/ if (stream->jitter) { - period.tv_nsec = USEC_TO_NSEC*(period_usec*(100-stream->jitter)/100 - + rand() % (2*period_usec*stream->jitter/100)); + delay_usec = period_usec*(100-stream->jitter)/100 + + rand() % (2*period_usec*stream->jitter/100); } else { - period.tv_nsec = USEC_TO_NSEC*(period_usec); + delay_usec = period_usec; } - period.tv_sec = 0; + period.tv_nsec = USEC_TO_NSEC*(delay_usec%SEC_TO_USEC); + period.tv_sec = delay_usec/SEC_TO_USEC; timespec_add(&time_to_wait, last_send_time, &period); - clock_gettime(CLOCK_REALTIME,¤t_time); + clock_gettime(CLOCK_MONOTONIC,¤t_time); timespec_sub(&interval,&time_to_wait,¤t_time); - nanosleep(&interval,NULL); + if (interval.tv_sec >= 0) { + nanosleep(&interval,NULL); + *last_send_time = time_to_wait; + } else { + *last_send_time = current_time; + } } @@ -573,7 +579,7 @@ void* sender(void* arg) union msg_buff buff; unsigned long int seqn; struct stream* stream = (struct stream*) arg; - struct timespec ts; + struct timespec timer = { 0, 0 }, ts; int ret; if (!opt_gui) { @@ -590,6 +596,7 @@ void* sender(void* arg) set_rt_prio(90-stream->ac); while (!exit_flag) { + wait_for_next_send(stream, &timer); /* buff.msg.seqn = seqn++; */ /* buff.msg.tos = ac_to_tos[stream->ac]; */ @@ -615,7 +622,6 @@ void* sender(void* arg) fflush(stdout); #endif - wait_for_next_send(stream, &ts); } out: sem_post(&sem_thread_finished); @@ -1054,11 +1060,7 @@ int main(int argc, char *argv[]) opt_interface = optarg; break; case 'j': - #ifdef WITH_FWP - error(1, 0, "-j is not allowd when compiled with FWP"); - #else opt_jitter = atoi(optarg); - #endif break; #ifdef WITH_FWP case 'l':