diff options
-rw-r--r-- | platform/linux-generic/include/odp_global_data.h | 2 | ||||
-rw-r--r-- | platform/linux-generic/include/odp_timer_internal.h | 13 | ||||
-rw-r--r-- | platform/linux-generic/odp_init.c | 2 | ||||
-rw-r--r-- | platform/linux-generic/odp_timer.c | 35 |
4 files changed, 37 insertions, 15 deletions
diff --git a/platform/linux-generic/include/odp_global_data.h b/platform/linux-generic/include/odp_global_data.h index f1be1502c..a12d12973 100644 --- a/platform/linux-generic/include/odp_global_data.h +++ b/platform/linux-generic/include/odp_global_data.h @@ -40,6 +40,7 @@ typedef struct { /* Read-only global data. Members should not be modified after global init * to enable process more support. */ struct odp_global_data_ro_t { + odp_init_t init_param; /* directory for odp mmaped files */ char *shm_dir; /* overload default with env */ @@ -69,6 +70,7 @@ struct odp_global_data_rw_t { pthread_t inotify_thread; int inotify_pcapng_is_running; odp_bool_t dpdk_initialized; + odp_bool_t inline_timers; }; extern struct odp_global_data_ro_t odp_global_ro; diff --git a/platform/linux-generic/include/odp_timer_internal.h b/platform/linux-generic/include/odp_timer_internal.h index 8dda9e6ff..02ba92e0d 100644 --- a/platform/linux-generic/include/odp_timer_internal.h +++ b/platform/linux-generic/include/odp_timer_internal.h @@ -19,6 +19,7 @@ #include <odp_buffer_internal.h> #include <odp_pool_internal.h> #include <odp/api/timer.h> +#include <odp_global_data.h> /* Minimum number of scheduling rounds between checking timer pools. */ #define CONFIG_TIMER_RUN_RATELIMIT_ROUNDS 1 @@ -38,22 +39,12 @@ typedef struct { odp_timer_t timer; } odp_timeout_hdr_t; -/* - * Whether to run timer pool processing 'inline' (on worker cores) or in - * background threads (thread-per-timerpool). - * - * If the application will use both scheduler and timer this flag is set - * to true, otherwise false. This application conveys this information via - * the 'not_used' bits in odp_init_t which are passed to odp_global_init(). - */ -extern odp_bool_t inline_timers; - unsigned _timer_run(void); /* Static inline wrapper to minimize modification of schedulers. */ static inline unsigned timer_run(void) { - return inline_timers ? _timer_run() : 0; + return odp_global_rw->inline_timers ? _timer_run() : 0; } #endif diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c index dca06641a..0f7e0df28 100644 --- a/platform/linux-generic/odp_init.c +++ b/platform/linux-generic/odp_init.c @@ -268,6 +268,8 @@ int odp_init_global(odp_instance_t *instance, odp_global_ro.abort_fn = odp_override_abort; if (params != NULL) { + odp_global_ro.init_param = *params; + if (params->log_fn != NULL) odp_global_ro.log_fn = params->log_fn; if (params->abort_fn != NULL) diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c index eeb863530..507226580 100644 --- a/platform/linux-generic/odp_timer.c +++ b/platform/linux-generic/odp_timer.c @@ -68,8 +68,6 @@ * for checking the freshness of received timeouts */ #define TMO_INACTIVE ((uint64_t)0x8000000000000000) -odp_bool_t inline_timers = false; - /****************************************************************************** * Mutual exclusion in the absence of CAS16 *****************************************************************************/ @@ -333,8 +331,26 @@ static odp_timer_pool_t timer_pool_new(const char *name, odp_spinlock_init(&tp->lock); odp_ticketlock_lock(&timer_global->lock); timer_global->timer_pool[tp_idx] = tp; + + if (timer_global->num_timer_pools == 1) { + odp_bool_t inline_tim; + + /* + * Whether to run timer pool processing 'inline' (on worker + * cores) or in background threads (thread-per-timerpool). + * + * If the application will use scheduler this flag is set to + * true, otherwise false. This application conveys this + * information via the 'not_used' bits in odp_init_t which are + * passed to odp_global_init(). + */ + inline_tim = !odp_global_ro.init_param.not_used.feat.schedule; + + odp_global_rw->inline_timers = inline_tim; + } + odp_ticketlock_unlock(&timer_global->lock); - if (!inline_timers) { + if (!odp_global_rw->inline_timers) { if (tp->param.clk_src == ODP_CLOCK_CPU) itimer_init(tp); } @@ -368,7 +384,7 @@ static void odp_timer_pool_del(timer_pool_t *tp) odp_spinlock_lock(&tp->lock); - if (!inline_timers) { + if (!odp_global_rw->inline_timers) { /* Stop POSIX itimer signals */ if (tp->param.clk_src == ODP_CLOCK_CPU) itimer_fini(tp); @@ -390,6 +406,11 @@ static void odp_timer_pool_del(timer_pool_t *tp) timer_global->timer_pool[tp->tp_idx] = NULL; timer_global->timer_pool_used[tp->tp_idx] = 0; timer_global->num_timer_pools--; + + /* Disable inline timer polling */ + if (timer_global->num_timer_pools == 0) + odp_global_rw->inline_timers = false; + odp_ticketlock_unlock(&timer_global->lock); rc = odp_shm_free(shm); @@ -1093,6 +1114,11 @@ int odp_timer_capability(odp_timer_clk_src_t clk_src, odp_timer_pool_t odp_timer_pool_create(const char *name, const odp_timer_pool_param_t *param) { + if (odp_global_ro.init_param.not_used.feat.timer) { + ODP_ERR("Trying to use disabled ODP feature.\n"); + return ODP_TIMER_POOL_INVALID; + } + if (param->res_ns < timer_global->highest_res_ns) { __odp_errno = EINVAL; return ODP_TIMER_POOL_INVALID; @@ -1295,6 +1321,7 @@ void odp_timeout_free(odp_timeout_t tmo) int odp_timer_init_global(const odp_init_t *params) { odp_shm_t shm; + odp_bool_t inline_timers = false; shm = odp_shm_reserve("_odp_timer", sizeof(timer_global_t), ODP_CACHE_LINE_SIZE, 0); |