From e5aa2592af7066f2696bc310ba68719c5cded54e Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Mon, 3 Aug 2009 11:30:06 +0200 Subject: [PATCH] wme_test: Make the message format independent of 32/64 bit architecture When wclient and wserver were run on different architectures (32/64-bit), the message format was different on each machine and the results were wrong. --- wme_test/common.h | 8 ++++---- wme_test/wclient.c | 38 +++++++++++++++++++++++--------------- wme_test/wserver.c | 4 +++- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/wme_test/common.h b/wme_test/common.h index 0b51da3..17ae3fc 100644 --- a/wme_test/common.h +++ b/wme_test/common.h @@ -25,14 +25,14 @@ enum ac { struct msg_t { /* unsigned int tos; */ - struct timespec send_timestamp; - struct timespec sendback_timestamp; + uint64_t send_timestamp; /* [nsec] */ + uint64_t sendback_timestamp; /* [nsec] */ /* unsigned long int seqn; */ - int stream; + uint32_t stream; #ifdef WITH_FWP uint16_t resp_port; #endif -}; +} __attribute__((packed)); union msg_buff { struct msg_t msg; diff --git a/wme_test/wclient.c b/wme_test/wclient.c index 30fb5f1..3bc9ea3 100644 --- a/wme_test/wclient.c +++ b/wme_test/wclient.c @@ -45,7 +45,7 @@ bool opt_wait_for_queue_is_full; /* Don't gather any statistics until any queue char *opt_comment = NULL; bool some_queue_is_full = false; -struct timespec reset_timestamp; +uint64_t reset_timestamp; /* [nsec] */ bool some_contract_not_accepted = false; @@ -348,6 +348,7 @@ void empty_handler() void reset_statistics() { int i; + struct timespec ts; for (i = 0; i < nr_streams; i++) { pthread_mutex_lock(&streams[i].mutex); streams[i].sent = 0; @@ -356,7 +357,8 @@ void reset_statistics() pthread_mutex_unlock(&streams[i].mutex); } pthread_mutex_lock(&delay_stats_mutex); - clock_gettime(CLOCK_REALTIME, &reset_timestamp); + clock_gettime(CLOCK_REALTIME, &ts); + reset_timestamp = ts.tv_sec*1000000000LL + ts.tv_nsec; memset(delay_stats, 0, sizeof(delay_stats)); pthread_mutex_unlock(&delay_stats_mutex); } @@ -400,8 +402,9 @@ void* receiver(void* arg) struct msg_t msg; long long int trans_time_usec, client_to_server_usec, server_to_client_usec; long long int min_trans_time; - struct timespec send_timestamp, server_timestamp, recv_timestamp; - int mlen, ret; + struct timespec ts; + uint64_t send_timestamp, server_timestamp, recv_timestamp; + int mlen; unsigned ac; min_trans_time = ~0; @@ -423,19 +426,20 @@ void* receiver(void* arg) error(0, errno, "receive_packet error"); goto out; } - clock_gettime(CLOCK_REALTIME,&recv_timestamp); + clock_gettime(CLOCK_REALTIME,&ts); + recv_timestamp = ts.tv_sec*1000000000LL + ts.tv_nsec; send_timestamp = msg.send_timestamp; server_timestamp = msg.sendback_timestamp; /* Check whether this message was sent after reset_statistics() */ - if ((ret = timespec_sub_usec(&send_timestamp, &reset_timestamp)) < 0) { + if (send_timestamp < reset_timestamp) { continue; /* If so, don't count it */ } - trans_time_usec = timespec_sub_usec(&recv_timestamp ,&send_timestamp) / 2; - client_to_server_usec = timespec_sub_usec(&server_timestamp, &send_timestamp); - server_to_client_usec = timespec_sub_usec(&recv_timestamp, &server_timestamp); + trans_time_usec = (recv_timestamp - send_timestamp) / 2 / 1000; + client_to_server_usec = (server_timestamp - send_timestamp) / 1000; + server_to_client_usec = (recv_timestamp - server_timestamp) / 1000; pthread_mutex_lock(&delay_stats_mutex); if (trans_time_usec < MAX_DELAY_US && trans_time_usec >= 0) { @@ -559,6 +563,7 @@ void* sender(void* arg) union msg_buff buff; unsigned long int seqn; struct stream* stream = (struct stream*) arg; + struct timespec ts; int ret; #ifndef WITH_FWP @@ -580,7 +585,8 @@ void* sender(void* arg) /* buff.msg.tos = ac_to_tos[stream->ac]; */ buff.msg.stream = stream-streams; - clock_gettime(CLOCK_REALTIME,&buff.msg.send_timestamp); + clock_gettime(CLOCK_REALTIME,&ts); + buff.msg.send_timestamp = ts.tv_sec*1000000000LL + ts.tv_nsec; ret = send_packet(stream, &buff); if (ret < 0) { @@ -598,7 +604,7 @@ void* sender(void* arg) fflush(stdout); #endif - wait_for_next_send(stream, &buff.msg.send_timestamp); + wait_for_next_send(stream, &ts); } out: sem_post(&sem_thread_finished); @@ -1102,11 +1108,13 @@ int main(int argc, char *argv[]) fprintf(stderr, "\nWaiting for threads to finish\n"); wait_for_all_threads_to_finish(); - struct timespec end_timestamp, measure_length; - clock_gettime(CLOCK_REALTIME,&end_timestamp); - timespec_sub(&measure_length, &end_timestamp, &reset_timestamp); + struct timespec ts; + uint64_t end_timestamp, measure_length; + clock_gettime(CLOCK_REALTIME,&ts); + end_timestamp = ts.tv_sec*1000000000LL+ts.tv_nsec; + measure_length = end_timestamp - reset_timestamp; - save_results(argc, argv, timespec2usec(&measure_length)); + save_results(argc, argv, measure_length/1000); #endif return 0; diff --git a/wme_test/wserver.c b/wme_test/wserver.c index 07b5bba..1649ed5 100644 --- a/wme_test/wserver.c +++ b/wme_test/wserver.c @@ -96,6 +96,7 @@ void* qhandler(void* queue) struct iovec iov; struct msghdr msg; struct in_pktinfo *ipi = NULL; + struct timespec ts; ac = (int) queue; rem_addr_length=sizeof(rem_addr); @@ -121,7 +122,8 @@ void* qhandler(void* queue) perror("recvmsg"); return NULL; } - clock_gettime(CLOCK_REALTIME, &buff.msg.sendback_timestamp); + clock_gettime(CLOCK_REALTIME, &ts); + buff.msg.sendback_timestamp = ts.tv_sec*1000000000 + ts.tv_nsec; if (opt_same_interface) { -- 2.39.2