From c59479faa8eb20d4d5139d7621fd179004680d3b Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Wed, 22 Nov 2017 09:26:02 +0100 Subject: 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 3bbaab0c4f..a1b0440c73 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 #include +#include 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); -- cgit v1.2.3