diff options
author | Matias Elo <matias.elo@nokia.com> | 2018-08-10 13:49:20 +0300 |
---|---|---|
committer | Maxim Uvarov <maxim.uvarov@linaro.org> | 2018-11-28 17:16:37 +0300 |
commit | 97bb0f3801f2f1692a12e24d9aa4fadf0b8ce477 (patch) | |
tree | a2759ee32284508749ea558a35ad0976c526ebe7 | |
parent | 62782960967bd58553139d6b20f91a5849a2c288 (diff) |
abi: timer: use strong type for odp_timer_pool_t
Signed-off-by: Matias Elo <matias.elo@nokia.com>
Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org>
Reviewed-by: Petri Savolainen <petri.savolainen@linaro.org>
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
-rw-r--r-- | include/odp/api/abi-default/timer.h | 7 | ||||
-rw-r--r-- | platform/linux-generic/include-abi/odp/api/abi/timer.h | 4 | ||||
-rw-r--r-- | platform/linux-generic/odp_timer.c | 62 |
3 files changed, 48 insertions, 25 deletions
diff --git a/include/odp/api/abi-default/timer.h b/include/odp/api/abi-default/timer.h index a7da8ff7a..566d199e0 100644 --- a/include/odp/api/abi-default/timer.h +++ b/include/odp/api/abi-default/timer.h @@ -23,13 +23,14 @@ typedef struct { char dummy; /**< @internal Dummy */ } _odp_abi_timer_t; /** @internal Dummy type for strong typing */ typedef struct { char dummy; /**< @internal Dummy */ } _odp_abi_timeout_t; +/** @internal Dummy type for strong typing */ +typedef struct { char dummy; /**< @internal Dummy */ } _odp_abi_timer_pool_t; + /** @addtogroup odp_timer * @{ **/ -struct timer_pool_s; /**< Forward declaration */ - -typedef struct timer_pool_s *odp_timer_pool_t; +typedef _odp_abi_timer_pool_t *odp_timer_pool_t; #define ODP_TIMER_POOL_INVALID ((odp_timer_pool_t)0) diff --git a/platform/linux-generic/include-abi/odp/api/abi/timer.h b/platform/linux-generic/include-abi/odp/api/abi/timer.h index 48138f72f..c08da1ce3 100644 --- a/platform/linux-generic/include-abi/odp/api/abi/timer.h +++ b/platform/linux-generic/include-abi/odp/api/abi/timer.h @@ -24,9 +24,7 @@ extern "C" { * @{ **/ -struct timer_pool_s; /**< Forward declaration */ - -typedef struct timer_pool_s *odp_timer_pool_t; +typedef ODP_HANDLE_T(odp_timer_pool_t); #define ODP_TIMER_POOL_INVALID _odp_cast_scalar(odp_timer_pool_t, 0) diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c index 7e2848c7c..3fb50a918 100644 --- a/platform/linux-generic/odp_timer.c +++ b/platform/linux-generic/odp_timer.c @@ -224,6 +224,16 @@ typedef struct timer_global_t { static timer_global_t *timer_global; +static inline timer_pool_t *timer_pool_from_hdl(odp_timer_pool_t hdl) +{ + return (timer_pool_t *)(uintptr_t)hdl; +} + +static inline odp_timer_pool_t timer_pool_to_hdl(timer_pool_t *tp) +{ + return (odp_timer_pool_t)tp; +} + static inline timer_pool_t *handle_to_tp(odp_timer_t hdl) { uint32_t tp_idx = _odp_typeval(hdl) >> INDEX_BITS; @@ -315,8 +325,10 @@ static odp_timer_pool_t timer_pool_new(const char *name, } tp->shm = shm; tp->param = *param; - tp->min_rel_tck = odp_timer_ns_to_tick(tp, param->min_tmo); - tp->max_rel_tck = odp_timer_ns_to_tick(tp, param->max_tmo); + tp->min_rel_tck = odp_timer_ns_to_tick(timer_pool_to_hdl(tp), + param->min_tmo); + tp->max_rel_tck = odp_timer_ns_to_tick(timer_pool_to_hdl(tp), + param->max_tmo); tp->num_alloc = 0; odp_atomic_init_u32(&tp->high_wm, 0); tp->first_free = 0; @@ -349,7 +361,7 @@ static odp_timer_pool_t timer_pool_new(const char *name, if (tp->param.clk_src == ODP_CLOCK_CPU) itimer_init(tp); } - return tp; + return timer_pool_to_hdl(tp); } static void block_sigalarm(void) @@ -798,13 +810,14 @@ static unsigned timer_expire(timer_pool_t *tp, uint32_t idx, uint64_t tick) static unsigned odp_timer_pool_expire(odp_timer_pool_t tpid, uint64_t tick) { - tick_buf_t *array = &tpid->tick_buf[0]; - uint32_t high_wm = _odp_atomic_u32_load_mm(&tpid->high_wm, + timer_pool_t *tp = timer_pool_from_hdl(tpid); + tick_buf_t *array = &tp->tick_buf[0]; + uint32_t high_wm = _odp_atomic_u32_load_mm(&tp->high_wm, _ODP_MEMMODEL_ACQ); unsigned nexp = 0; uint32_t i; - ODP_ASSERT(high_wm <= tpid->param.num_timers); + ODP_ASSERT(high_wm <= tp->param.num_timers); for (i = 0; i < high_wm;) { /* As a rare occurrence, we can outsmart the HW prefetcher * and the compiler (GCC -fprefetch-loop-arrays) with some @@ -815,7 +828,7 @@ static unsigned odp_timer_pool_expire(odp_timer_pool_t tpid, uint64_t tick) uint64_t exp_tck = array[i++].exp_tck.v; if (odp_unlikely(exp_tck <= tick)) { /* Attempt to expire timer */ - nexp += timer_expire(tpid, i - 1, tick); + nexp += timer_expire(tp, i - 1, tick); } } return nexp; @@ -863,7 +876,8 @@ static unsigned process_timer_pools(void) nticks - 1, tp->name); tp->notify_overrun = 0; } - nexp += odp_timer_pool_expire(tp, tp_tick + nticks); + nexp += odp_timer_pool_expire(timer_pool_to_hdl(tp), + tp_tick + nticks); } } return nexp; @@ -924,7 +938,7 @@ static void timer_notify(timer_pool_t *tp) prev_tick = odp_atomic_fetch_inc_u64(&tp->cur_tick); /* Scan timer array, looking for timers to expire */ - (void)odp_timer_pool_expire(tp, prev_tick + 1); + (void)odp_timer_pool_expire(timer_pool_to_hdl(tp), prev_tick + 1); /* Else skip scan of timers. cur_tick was updated and next itimer * invocation will process older expiration ticks as well */ @@ -1140,32 +1154,40 @@ void odp_timer_pool_start(void) void odp_timer_pool_destroy(odp_timer_pool_t tpid) { - odp_timer_pool_del(tpid); + odp_timer_pool_del(timer_pool_from_hdl(tpid)); } uint64_t odp_timer_tick_to_ns(odp_timer_pool_t tpid, uint64_t ticks) { - return ticks * tpid->param.res_ns; + timer_pool_t *tp = timer_pool_from_hdl(tpid); + + return ticks * tp->param.res_ns; } uint64_t odp_timer_ns_to_tick(odp_timer_pool_t tpid, uint64_t ns) { - return (uint64_t)(ns / tpid->param.res_ns); + timer_pool_t *tp = timer_pool_from_hdl(tpid); + + return (uint64_t)(ns / tp->param.res_ns); } uint64_t odp_timer_current_tick(odp_timer_pool_t tpid) { + timer_pool_t *tp = timer_pool_from_hdl(tpid); + /* Relaxed atomic read for lowest overhead */ - return odp_atomic_load_u64(&tpid->cur_tick); + return odp_atomic_load_u64(&tp->cur_tick); } int odp_timer_pool_info(odp_timer_pool_t tpid, odp_timer_pool_info_t *buf) { - buf->param = tpid->param; - buf->cur_timers = tpid->num_alloc; - buf->hwm_timers = odp_atomic_load_u32(&tpid->high_wm); - buf->name = tpid->name; + timer_pool_t *tp = timer_pool_from_hdl(tpid); + + buf->param = tp->param; + buf->cur_timers = tp->num_alloc; + buf->hwm_timers = odp_atomic_load_u32(&tp->high_wm); + buf->name = tp->name; return 0; } @@ -1178,18 +1200,20 @@ odp_timer_t odp_timer_alloc(odp_timer_pool_t tpid, odp_queue_t queue, void *user_ptr) { + timer_pool_t *tp = timer_pool_from_hdl(tpid); + if (odp_unlikely(tpid == ODP_TIMER_POOL_INVALID)) { ODP_ERR("Invalid timer pool.\n"); return ODP_TIMER_INVALID; } if (odp_unlikely(queue == ODP_QUEUE_INVALID)) { - ODP_ERR("%s: Invalid queue handle\n", tpid->name); + ODP_ERR("%s: Invalid queue handle\n", tp->name); return ODP_TIMER_INVALID; } /* We don't care about the validity of user_ptr because we will not * attempt to dereference it */ - return timer_alloc(tpid, queue, user_ptr); + return timer_alloc(tp, queue, user_ptr); } odp_event_t odp_timer_free(odp_timer_t hdl) |