improvements
authorLaurent MAZET <laurent.mazet@thalesgroup.com>
Mon, 20 Oct 2025 15:56:27 +0000 (17:56 +0200)
committerLaurent MAZET <laurent.mazet@thalesgroup.com>
Mon, 20 Oct 2025 15:56:27 +0000 (17:56 +0200)
mq_lat.c
pipe_lat.c
semaphore.c
udp_lat.c

index 45ae801e74b24ed5aa876eb568e7f47bf976198d..d0862f6287a7b5c221a14bc9eabb4fcd085c6215 100644 (file)
--- 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);
index 04e2b11b1a49c6422727a7c01a70c33275141a0e..a94d29b242a7c5e422b11c9e95cade1b1ec6c768 100644 (file)
@@ -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);
index fb3ba16cd5d902c4f7f63752d0c111b725f77cf4..bc80a8baccc09640a104daa2ee91bb957838c642 100644 (file)
@@ -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);
index 05d397be5ebb09d6db03b0e3c7d50a3cb9d8fddf..eb7a61298ad2b6186d47cef0f8f943610757ae10 100644 (file)
--- 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);