From: Laurent MAZET Date: Mon, 20 Oct 2025 15:56:27 +0000 (+0200) Subject: improvements X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=3ae6d806b431856d7cf68f19b73526afb17edfc5;p=benchmarks.git improvements --- diff --git a/mq_lat.c b/mq_lat.c index 45ae801..d0862f6 100644 --- a/mq_lat.c +++ b/mq_lat.c @@ -92,6 +92,10 @@ void *pong (__attribute__((unused)) void *arg) for (int i = 0; i < nb_measurements; i++) { + pthread_mutex_lock (&mutex); + usleep (TIMER); + pthread_mutex_unlock (&mutex); + char buffer[MAXBUF] = { 0 }; if (mq_receive (mq_in, buffer, sizeof (buffer), NULL) == -1) { fprintf (stderr, "pong error: mq_receive (%d)\n", i); @@ -101,10 +105,6 @@ void *pong (__attribute__((unused)) void *arg) sys_timestamp (&ts2); deltas[i] = diff_timestamp (&ts2, &ts1); - - pthread_mutex_lock (&mutex); - usleep (TIMER); - pthread_mutex_unlock (&mutex); } mq_close (mq_in); diff --git a/pipe_lat.c b/pipe_lat.c index 04e2b11..a94d29b 100644 --- a/pipe_lat.c +++ b/pipe_lat.c @@ -80,6 +80,10 @@ void *pong (__attribute__((unused)) void *arg) for (int i = 0; i < nb_measurements; i++) { + pthread_mutex_lock (&mutex); + usleep (TIMER); + pthread_mutex_unlock (&mutex); + char buffer[MAXBUF] = { 0 }; if (read (fdin, buffer, sizeof(buffer)) == -1) { fprintf (stderr, "pong error: read (%d)\n", i); @@ -89,10 +93,6 @@ void *pong (__attribute__((unused)) void *arg) sys_timestamp (&ts2); deltas[i] = diff_timestamp (&ts2, &ts1); - - pthread_mutex_lock (&mutex); - usleep (TIMER); - pthread_mutex_unlock (&mutex); } close (fdin); diff --git a/semaphore.c b/semaphore.c index fb3ba16..bc80a8b 100644 --- a/semaphore.c +++ b/semaphore.c @@ -65,16 +65,13 @@ void *pong (__attribute__((unused)) void *arg) for (int i = 0; i < nb_measurements; i++) { - sem_wait (&sem); - sys_timestamp (&ts2); - deltas[i] = diff_timestamp (&ts2, &ts1); - if ((i == 0) && (deltas[i] > 1e9)) { - i--; - } - pthread_mutex_lock (&mutex); usleep (TIMER); pthread_mutex_unlock (&mutex); + + sem_wait (&sem); + sys_timestamp (&ts2); + deltas[i] = diff_timestamp (&ts2, &ts1); } pthread_exit (NULL); diff --git a/udp_lat.c b/udp_lat.c index 05d397b..eb7a612 100644 --- a/udp_lat.c +++ b/udp_lat.c @@ -139,6 +139,10 @@ void *pong (__attribute__((unused)) void *arg) for (int i = 0; i < nb_measurements; i++) { + pthread_mutex_lock (&mutex); + usleep (TIMER); + pthread_mutex_unlock (&mutex); + char buffer[MAXBUF] = { 0 }; struct sockaddr_in src = { 0 }; socklen_t alen = sizeof (src); @@ -149,10 +153,6 @@ void *pong (__attribute__((unused)) void *arg) } sys_timestamp (&ts2); deltas[i] = diff_timestamp (&ts2, &ts1); - - pthread_mutex_lock (&mutex); - usleep (TIMER); - pthread_mutex_unlock (&mutex); } close (sock);