Since the scheduler does not guarantee fairness in scheduling, threads must
time out and check if the example is still running. If this is the case,
just restart the scheduler loop (not the whole example loop which may have
other side effects, e.g. resetting timers with some random tick value),
otherwise break out of the example loop which will terminate the example.

Signed-off-by: Ola Liljedahl <[email protected]>
---
(This document/code contribution attached is provided under the terms of
agreement LES-LTM-21309)

 example/timer/odp_timer_test.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/example/timer/odp_timer_test.c b/example/timer/odp_timer_test.c
index 5de499b..dfd6c70 100644
--- a/example/timer/odp_timer_test.c
+++ b/example/timer/odp_timer_test.c
@@ -126,13 +126,22 @@ static void test_abs_timeouts(int thr, test_args_t *args)
                }
 
                /* Get the next expired timeout */
-               /* Use 1.5 second timeout for scheduler */
-               uint64_t sched_tmo = odp_schedule_wait_time(1500000000ULL);
-               buf = odp_schedule(&queue, sched_tmo);
-               /* Check if odp_schedule() timed out, possibly there are no
-                * remaining timeouts to receive */
+               /* We invoke the scheduler in a loop with a timeout because
+                * we are not guaranteed to receive any more timeouts. The
+                * scheduler isn't guaranteeing fairness when scheduling
+                * buffers to threads */
+               do {
+                       /* Use 1.5 second timeout for scheduler */
+                       uint64_t sched_tmo =
+                               odp_schedule_wait_time(1500000000ULL);
+                       buf = odp_schedule(&queue, sched_tmo);
+                       /* Check if odp_schedule() timed out, possibly there
+                        * are no remaining timeouts to receive */
+               } while (buf == ODP_BUFFER_INVALID &&
+                        (int)odp_atomic_load_u32(&remain) > 0);
+
                if (buf == ODP_BUFFER_INVALID)
-                       continue; /* Re-check the remain counter */
+                       break; /* No more timeouts */
                if (odp_buffer_type(buf) != ODP_BUFFER_TYPE_TIMEOUT) {
                        /* Not a default timeout buffer */
                        EXAMPLE_ABORT("Unexpected buffer type (%u) received\n",
-- 
1.9.1


_______________________________________________
lng-odp mailing list
[email protected]
http://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to