On 15 January 2015 at 12:22, Savolainen, Petri (NSN - FI/Espoo) <petri.savolai...@nsn.com> wrote: > > >> -----Original Message----- >> From: lng-odp-boun...@lists.linaro.org [mailto:lng-odp- >> boun...@lists.linaro.org] On Behalf Of ext Ola Liljedahl >> Sent: Thursday, January 15, 2015 12:07 PM >> To: lng-odp@lists.linaro.org >> Subject: [lng-odp] [PATCH] example: odp_timer_test.c: bug 1068 - >> odp_timer_test aborts >> >> 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 <ola.liljed...@linaro.org> >> --- >> (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); > > No need to repeat wait time conversion in the loop. It's better to keep it > out side of the loop since this is an example and should demonstrate the > correct/elegant way of using the APIs. Calling odp_schedule() with a long timeout in a loop is IMO not a very elegant way of using the scheduler API. It is a brutal work-around.
-- Ola > > -Petri > >> + 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 >> lng-odp@lists.linaro.org >> http://lists.linaro.org/mailman/listinfo/lng-odp _______________________________________________ lng-odp mailing list lng-odp@lists.linaro.org http://lists.linaro.org/mailman/listinfo/lng-odp