[rtems commit] tests: Use exponential backoff in locked_vprintf()

Sebastian Huber sebh at rtems.org
Wed Nov 22 12:03:28 UTC 2017


Module:    rtems
Branch:    master
Commit:    c59479faa8eb20d4d5139d7621fd179004680d3b
Changeset: http://git.rtems.org/rtems/commit/?id=c59479faa8eb20d4d5139d7621fd179004680d3b

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Nov 22 09:26:02 2017 +0100

tests: Use exponential backoff in locked_vprintf()

Without the exponential backoff a livelock was observed on a QorIQ P2020
with test SMP 5.

---

 testsuites/support/src/locked_print.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/testsuites/support/src/locked_print.c b/testsuites/support/src/locked_print.c
index 3bbaab0..a1b0440 100644
--- a/testsuites/support/src/locked_print.c
+++ b/testsuites/support/src/locked_print.c
@@ -14,7 +14,9 @@
 #include "test_support.h"
 #include "tmacros.h"
 
+#include <unistd.h>
 #include <rtems/bspIo.h>
+#include <rtems/counter.h>
 
 static rtems_id locked_print_semaphore;      /* synchronisation semaphore */
 
@@ -62,9 +64,23 @@ int locked_vprintf(const char *fmt, va_list ap)
   locked_print_initialize();
 
   /* Lock semaphore without releasing the cpu */
-  do {
-    sc = rtems_semaphore_obtain( locked_print_semaphore, RTEMS_NO_WAIT, 0 );
-  } while (sc != RTEMS_SUCCESSFUL );
+  sc = rtems_semaphore_obtain( locked_print_semaphore, RTEMS_NO_WAIT, 0 );
+
+  if ( sc != RTEMS_SUCCESSFUL ) {
+    uint8_t e;
+    rtems_counter_ticks w;
+
+    /* Use exponential backoff to avoid a livelock */
+
+    getentropy( &e, sizeof( e ) );
+    w = e + 1;
+
+    do {
+      rtems_counter_delay_ticks( w );
+      w *= 2;
+      sc = rtems_semaphore_obtain( locked_print_semaphore, RTEMS_NO_WAIT, 0 );
+    } while (sc != RTEMS_SUCCESSFUL );
+  }
 
   rv = vprintf(fmt, ap);
 



More information about the vc mailing list