]> rtime.felk.cvut.cz Git - frescor/fwp.git/commitdiff
wme_test: Send timing reworked
authorMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 13 Aug 2009 15:37:25 +0000 (17:37 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 13 Aug 2009 15:54:22 +0000 (17:54 +0200)
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).

wme_test/wclient.c

index 708c28e5dc8db449654350fdb7e22251fd8b4fd1..6d87d317569ada0c57beac674a819c5d7361641e 100644 (file)
@@ -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,&current_time);
+       clock_gettime(CLOCK_MONOTONIC,&current_time);
        timespec_sub(&interval,&time_to_wait,&current_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':