diff mbox

[PATCHv2] example: odp_timer_test.c: odp_timer_test aborts

Message ID 1421404456-14002-1-git-send-email-ola.liljedahl@linaro.org
State Accepted
Commit aeff5d5d51f129a8f6a68628e84b32e0338c1e4a
Headers show

Commit Message

Ola Liljedahl Jan. 16, 2015, 10:34 a.m. UTC
Since the scheduler does not guarantee fairness in scheduling, threads must
time out and check if the example is still running. If so, just restart the
scheduling, not the whole example loop which has (undesired) side effects.
The bug was caused by restarting the example loop which then reset the last
used timer with an old tick value, this could eventually fail (because that
tick value was in the past) with the too late error message.

https://bugs.linaro.org/show_bug.cgi?id=1068

Reported-by: anders.roxell@linaro.org
Reported-by: ola.dahl@enea.com
Signed-off-by: Ola Liljedahl <ola.liljedahl@linaro.org>
---
(This document/code contribution attached is provided under the terms of
agreement LES-LTM-21309)

 example/timer/odp_timer_test.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

Comments

Bill Fischofer Jan. 16, 2015, 11:18 a.m. UTC | #1
On Fri, Jan 16, 2015 at 4:34 AM, Ola Liljedahl <ola.liljedahl@linaro.org>
wrote:

> Since the scheduler does not guarantee fairness in scheduling, threads must
> time out and check if the example is still running. If so, just restart the
> scheduling, not the whole example loop which has (undesired) side effects.
> The bug was caused by restarting the example loop which then reset the last
> used timer with an old tick value, this could eventually fail (because that
> tick value was in the past) with the too late error message.
>
> https://bugs.linaro.org/show_bug.cgi?id=1068
>
> Reported-by: anders.roxell@linaro.org
> Reported-by: ola.dahl@enea.com
> Signed-off-by: Ola Liljedahl <ola.liljedahl@linaro.org>
>

Reviewed-and-tested-by: Bill Fischofer <bill.fischofer@linaro.org>


> ---
> (This document/code contribution attached is provided under the terms of
> agreement LES-LTM-21309)
>
>  example/timer/odp_timer_test.c | 23 ++++++++++++++++-------
>  1 file changed, 16 insertions(+), 7 deletions(-)
>
> diff --git a/example/timer/odp_timer_test.c
> b/example/timer/odp_timer_test.c
> index 5de499b..d18378a 100644
> --- a/example/timer/odp_timer_test.c
> +++ b/example/timer/odp_timer_test.c
> @@ -125,14 +125,23 @@ static void test_abs_timeouts(int thr, test_args_t
> *args)
>                                       timerset2str(rc));
>                 }
>
> -               /* 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 */
> +               /* Get the next expired timeout.
> +                * 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.
> +                * Use 1.5 second timeout for scheduler */
> +               uint64_t sched_tmo =
> +                       odp_schedule_wait_time(1500000000ULL);
> +               do {
> +                       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
>
diff mbox

Patch

diff --git a/example/timer/odp_timer_test.c b/example/timer/odp_timer_test.c
index 5de499b..d18378a 100644
--- a/example/timer/odp_timer_test.c
+++ b/example/timer/odp_timer_test.c
@@ -125,14 +125,23 @@  static void test_abs_timeouts(int thr, test_args_t *args)
 				      timerset2str(rc));
 		}
 
-		/* 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 */
+		/* Get the next expired timeout.
+		 * 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.
+		 * Use 1.5 second timeout for scheduler */
+		uint64_t sched_tmo =
+			odp_schedule_wait_time(1500000000ULL);
+		do {
+			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",