From: Joyce Kong <joyce.k...@arm.com>

Adjust frequency of timer pool polling by the duration
of timer. There needs to be 0 timer pool polling when
no timer pool created.

Signed-off-by: Joyce Kong <joyce.k...@arm.com>
---
/** Email created from pull request 107 (JoyceKong-arm:api-next-timer)
 ** https://github.com/Linaro/odp/pull/107
 ** Patch: https://github.com/Linaro/odp/pull/107.patch
 ** Base sha: 2394317ab247fa14b4e239aec512afee7eac4524
 ** Merge commit sha: ef0472e251ca035e6319f4785c16cd72017c5c04
 **/
 platform/linux-generic/include/odp_timer_internal.h |  3 ---
 platform/linux-generic/odp_timer.c                  | 13 ++++++++++++-
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/platform/linux-generic/include/odp_timer_internal.h 
b/platform/linux-generic/include/odp_timer_internal.h
index 67ee9fef..0759f727 100644
--- a/platform/linux-generic/include/odp_timer_internal.h
+++ b/platform/linux-generic/include/odp_timer_internal.h
@@ -20,9 +20,6 @@
 #include <odp_pool_internal.h>
 #include <odp/api/timer.h>
 
-/* Minimum number of nanoseconds between checking timer pools. */
-#define CONFIG_TIMER_RUN_RATELIMIT_NS 100
-
 /* Minimum number of scheduling rounds between checking timer pools. */
 #define CONFIG_TIMER_RUN_RATELIMIT_ROUNDS 1
 
diff --git a/platform/linux-generic/odp_timer.c 
b/platform/linux-generic/odp_timer.c
index fdb48902..b359f7c6 100644
--- a/platform/linux-generic/odp_timer.c
+++ b/platform/linux-generic/odp_timer.c
@@ -75,6 +75,7 @@ static _odp_atomic_flag_t locks[NUM_LOCKS]; /* Multiple locks 
per cache line! */
 
 /* Max timer resolution in nanoseconds */
 static uint64_t highest_res_ns;
+static uint64_t min_res_ns = INT64_MAX;
 
 /******************************************************************************
  * Translation between timeout buffer and timeout header
@@ -742,6 +743,9 @@ unsigned _timer_run(void)
                CONFIG_TIMER_RUN_RATELIMIT_ROUNDS;
        odp_time_t now;
 
+       if (odp_atomic_load_u32(&num_timer_pools) == 0)
+               return 0;
+
        /* Rate limit how often this thread checks the timer pools. */
 
        if (CONFIG_TIMER_RUN_RATELIMIT_ROUNDS > 1) {
@@ -984,6 +988,13 @@ odp_timer_pool_create(const char *name,
                __odp_errno = EINVAL;
                return ODP_TIMER_POOL_INVALID;
        }
+
+       if (min_res_ns > param->res_ns) {
+               min_res_ns = param->res_ns;
+               time_per_ratelimit_period =
+                       odp_time_global_from_ns(min_res_ns / 2);
+       }
+
        return odp_timer_pool_new(name, param);
 }
 
@@ -1188,7 +1199,7 @@ int odp_timer_init_global(const odp_init_t *params)
                        !params->not_used.feat.timer;
 
        time_per_ratelimit_period =
-               odp_time_global_from_ns(CONFIG_TIMER_RUN_RATELIMIT_NS);
+               odp_time_global_from_ns(min_res_ns / 2);
 
        if (!inline_timers) {
                timer_res_init();

Reply via email to