On Mon, Jan 05, 2015 at 06:23:47PM +0000, Ola Liljedahl wrote:
> Signed-off-by: Ola Liljedahl <ola.liljed...@linaro.org>
> 
> (This document/code contribution attached is provided under the terms of
> agreement LES-LTM-21309)
> The timer API is updated according to
> https://docs.google.com/a/linaro.org/document/d/1bfY_J8ecLJPsFTmYftb0NVmGnB9qkEc_NpcJ87yfaD8
> A major change is that timers are allocated and freed separately from
> timeouts being set and cancelled. The life-length of a timer normally
> corresponds to the life-length of the associated stateful flow while
> the life-length of a timeout corresponds to individual packets being
> transmitted and received.
> The reference timer implementation is lock-less for platforms with
> support for 128-bit (16-byte) atomic exchange and CAS operations.
> Otherwise a lock-based implementation (using as many locks as desired)
> is used but some operations (e.g. reset reusing existing timeout buffer)
> may still be lock-less.
> Updated the example example/timer/odp_timer_test.c according to the
> updated API.
> Updated the API according to Petri's review comments.
> ---
>  example/timer/odp_timer_test.c                     |  177 ++--
>  platform/linux-generic/include/api/odp_timer.h     |  318 ++++--
>  .../linux-generic/include/odp_timer_internal.h     |   59 +-
>  platform/linux-generic/odp_timer.c                 | 1064 
> ++++++++++++++------
>  4 files changed, 1139 insertions(+), 479 deletions(-)
> 
> diff --git a/example/timer/odp_timer_test.c b/example/timer/odp_timer_test.c
> index 2acf2fc..71f72b4 100644
> --- a/example/timer/odp_timer_test.c
> +++ b/example/timer/odp_timer_test.c
> @@ -26,7 +26,6 @@
> 
> 
>  #define MAX_WORKERS           32            /**< Max worker threads */
> -#define MSG_POOL_SIZE         (4*1024*1024) /**< Message pool size */
>  #define MSG_NUM_BUFS          10000         /**< Number of timers */
> 
> 
> @@ -44,69 +43,119 @@ typedef struct {
>  /** @private Barrier for test synchronisation */
>  static odp_barrier_t test_barrier;
> 
> -/** @private Timer handle*/
> -static odp_timer_t test_timer;
> +/** @private Buffer pool handle */
> +static odp_buffer_pool_t pool;
> 
> +/** @private Timer pool handle */
> +static odp_timer_pool_t tp;
> +
> +/** @private Number of timeouts to receive */
> +static odp_atomic_u32_t remain;
> +
> +/** @private Timer set status ASCII strings */
> +static const char *timerset2str(odp_timer_set_t val)
> +{
> +       switch (val) {
> +       case ODP_TIMER_SET_SUCCESS:
> +               return "success";
> +       case ODP_TIMER_SET_TOOEARLY:
> +               return "too early";
> +       case ODP_TIMER_SET_TOOLATE:
> +               return "too late";
> +       case ODP_TIMER_SET_NOBUF:
> +               return "no buffer";
> +       default:
> +               return "?";
> +       }
> +};
> +
> +/** @private Helper struct for timers */
> +struct test_timer {
> +       odp_timer_t tim;
> +       odp_buffer_t buf;
> +};
> +
> +/** @private Array of all timer helper structs */
> +static struct test_timer tt[256];
> 
>  /** @private test timeout */
>  static void test_abs_timeouts(int thr, test_args_t *args)
>  {
> -       uint64_t tick;
>         uint64_t period;
>         uint64_t period_ns;
>         odp_queue_t queue;
> -       odp_buffer_t buf;
> -       int num;
> +       uint64_t tick;
> +       struct test_timer *ttp;
> 
>         EXAMPLE_DBG("  [%i] test_timeouts\n", thr);
> 
>         queue = odp_queue_lookup("timer_queue");
> 
>         period_ns = args->period_us*ODP_TIME_USEC;
> -       period    = odp_timer_ns_to_tick(test_timer, period_ns);
> +       period    = odp_timer_ns_to_tick(tp, period_ns);
> 
>         EXAMPLE_DBG("  [%i] period %"PRIu64" ticks,  %"PRIu64" ns\n", thr,
>                     period, period_ns);
> 
> -       tick = odp_timer_current_tick(test_timer);
> -
> -       EXAMPLE_DBG("  [%i] current tick %"PRIu64"\n", thr, tick);
> +       EXAMPLE_DBG("  [%i] current tick %"PRIu64"\n", thr,
> +                   odp_timer_current_tick(tp));
> 
> -       tick += period;
> -
> -       if (odp_timer_absolute_tmo(test_timer, tick, queue, 
> ODP_BUFFER_INVALID)
> -           == ODP_TIMER_TMO_INVALID){
> -               EXAMPLE_DBG("Timeout request failed\n");
> +       ttp = &tt[thr - 1]; /* Thread starts at 1 */
> +       ttp->tim = odp_timer_alloc(tp, queue, ttp);
> +       if (ttp->tim == ODP_TIMER_INVALID) {
> +               EXAMPLE_ERR("Failed to allocate timer\n");
>                 return;
>         }
> +       ttp->buf = odp_buffer_alloc(pool);
> +       if (ttp->buf == ODP_BUFFER_INVALID) {
> +               EXAMPLE_ERR("Failed to allocate buffer\n");
> +               return;
> +       }
> +       tick = odp_timer_current_tick(tp);
> 
> -       num = args->tmo_count;
> -
> -       while (1) {
> -               odp_timeout_t tmo;
> +       while ((int)odp_atomic_load_u32(&remain) > 0) {
> +               odp_buffer_t buf;
> +               odp_timer_set_t rc;
> 
> -               buf = odp_schedule_one(&queue, ODP_SCHED_WAIT);
> +               tick += period;
> +               rc = odp_timer_set_abs(ttp->tim, tick, &ttp->buf);
> +               if (odp_unlikely(rc != ODP_TIMER_SET_SUCCESS)) {
> +                       /* Too early or too late timeout requested */
> +                       EXAMPLE_ABORT("odp_timer_set_abs() failed: %s\n",
> +                                     timerset2str(rc));
> +               }
> 
> -               tmo  = odp_timeout_from_buffer(buf);
> +               /* Get the next expired timeout */
> +               buf = odp_schedule(&queue, ODP_SCHED_WAIT);
> +               if (odp_buffer_type(buf) != ODP_BUFFER_TYPE_TIMEOUT) {
> +                       /* Not a default timeout buffer */
> +                       EXAMPLE_ABORT("Unexpected buffer type (%u) 
> received\n",
> +                                     odp_buffer_type(buf));
> +               }
> +               odp_timeout_t tmo = odp_timeout_from_buf(buf);
>                 tick = odp_timeout_tick(tmo);
> -
> +               ttp = odp_timeout_user_ptr(tmo);
> +               ttp->buf = buf;
> +               if (!odp_timeout_fresh(tmo)) {
> +                       /* Not the expected expiration tick, timer has
> +                        * been reset or cancelled or freed */
> +                       EXAMPLE_ABORT("Unexpected timeout received (timer %x, 
> tick %"PRIu64")\n",
> +                                     ttp->tim, tick);
> +               }
>                 EXAMPLE_DBG("  [%i] timeout, tick %"PRIu64"\n", thr, tick);
> 
> -               odp_buffer_free(buf);
> -
> -               num--;
> -
> -               if (num == 0)
> -                       break;
> -
> -               tick += period;
> -
> -               odp_timer_absolute_tmo(test_timer, tick,
> -                                      queue, ODP_BUFFER_INVALID);
> +               odp_atomic_dec_u32(&remain);
>         }
> 
> -       if (odp_queue_sched_type(queue) == ODP_SCHED_SYNC_ATOMIC)
> -               odp_schedule_release_atomic();
> +       /* Cancel and free last timer used */
> +       (void)odp_timer_cancel(ttp->tim, &ttp->buf);
> +       if (ttp->buf != ODP_BUFFER_INVALID)
> +               odp_buffer_free(ttp->buf);
> +       else
> +               EXAMPLE_ERR("Lost timeout buffer at timer cancel\n");
> +       /* Since we have cancelled the timer, there is no timeout buffer to
> +        * return from odp_timer_free() */
> +       (void)odp_timer_free(ttp->tim);
>  }
> 
> 
> @@ -193,14 +242,14 @@ static void parse_args(int argc, char *argv[], 
> test_args_t *args)

I get a failure on this hunk.

>         /* defaults */
>         args->cpu_count     = 0; /* all CPU's */

Looks like this line is the problem, mainline still has this as
core_count.

--
Stuart.


_______________________________________________
lng-odp mailing list
lng-odp@lists.linaro.org
http://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to