When application sets `RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES` flag
while creating adapter underlying driver is free to optimize the
resolution for best possible configuration.

Signed-off-by: Pavan Nikhilesh <pbhagavat...@caviumnetworks.com>
---
 drivers/event/octeontx/timvf_evdev.c | 48 +++++++++++++++++++++++++++++++++++-
 drivers/event/octeontx/timvf_evdev.h |  6 +++++
 2 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/drivers/event/octeontx/timvf_evdev.c 
b/drivers/event/octeontx/timvf_evdev.c
index fe4e8cd05..43ec98ce8 100644
--- a/drivers/event/octeontx/timvf_evdev.c
+++ b/drivers/event/octeontx/timvf_evdev.c
@@ -82,6 +82,45 @@ timvf_get_start_cyc(uint64_t *now, uint8_t ring_id)
        return octeontx_ssovf_mbox_send(&hdr, NULL, 0, now, sizeof(uint64_t));
 }
 
+static int
+optimize_bucket_parameters(struct timvf_ring *timr)
+{
+       uint32_t hbkts;
+       uint32_t lbkts;
+       uint64_t tck_nsec;
+
+       hbkts = rte_align32pow2(timr->meta.nb_bkts);
+       tck_nsec = RTE_ALIGN_MUL_CEIL(timr->max_tout / (hbkts - 1), 10);
+
+       if ((tck_nsec < 1000 || hbkts > TIM_MAX_BUCKETS))
+               hbkts = 0;
+
+       lbkts = rte_align32prevpow2(timr->meta.nb_bkts);
+       tck_nsec = RTE_ALIGN_MUL_CEIL((timr->max_tout / (lbkts - 1)), 10);
+
+       if ((tck_nsec < 1000 || hbkts > TIM_MAX_BUCKETS))
+               lbkts = 0;
+
+       if (!hbkts && !lbkts)
+               return 0;
+
+       if (!hbkts) {
+               timr->meta.nb_bkts = lbkts;
+               goto end;
+       } else if (!lbkts) {
+               timr->meta.nb_bkts = hbkts;
+               goto end;
+       }
+
+       timr->meta.nb_bkts = (hbkts - timr->meta.nb_bkts) <
+               (timr->meta.nb_bkts - lbkts) ? hbkts : lbkts;
+end:
+       timr->meta.get_target_bkt = bkt_and;
+       timr->tck_nsec = RTE_ALIGN_MUL_CEIL((timr->max_tout /
+                               (timr->meta.nb_bkts - 1)), 10);
+       return 1;
+}
+
 static int
 timvf_ring_start(const struct rte_event_timer_adapter *adptr)
 {
@@ -217,7 +256,7 @@ timvf_ring_create(struct rte_event_timer_adapter *adptr)
        }
 
        timr->tim_ring_id = adptr->data->id;
-       timr->tck_nsec = rcfg->timer_tick_ns;
+       timr->tck_nsec = RTE_ALIGN_MUL_CEIL(rcfg->timer_tick_ns, 10);
        timr->max_tout = rcfg->max_tmo_ns;
        timr->meta.nb_bkts = (timr->max_tout / timr->tck_nsec) + 1;
        timr->vbar0 = octeontx_timvf_bar(timr->tim_ring_id, 0);
@@ -227,6 +266,13 @@ timvf_ring_create(struct rte_event_timer_adapter *adptr)
 
        timr->nb_chunks = nb_timers / nb_chunk_slots;
 
+       /* Try to optimize the bucket parameters. */
+       if ((rcfg->flags & RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES)
+                       && !rte_is_power_of_2(timr->meta.nb_bkts)) {
+               optimize_bucket_parameters(timr);
+               timvf_log_info("Optimizing configured values");
+       }
+
        if (rcfg->flags & RTE_EVENT_TIMER_ADAPTER_F_SP_PUT) {
                mp_flags = MEMPOOL_F_SP_PUT | MEMPOOL_F_SC_GET;
                timvf_log_info("Using single producer mode");
diff --git a/drivers/event/octeontx/timvf_evdev.h 
b/drivers/event/octeontx/timvf_evdev.h
index a263ccc68..06e6a1588 100644
--- a/drivers/event/octeontx/timvf_evdev.h
+++ b/drivers/event/octeontx/timvf_evdev.h
@@ -191,6 +191,12 @@ bkt_mod(const uint32_t rel_bkt, const uint32_t nb_bkts)
        return rel_bkt % nb_bkts;
 }
 
+static __rte_always_inline uint32_t __hot
+bkt_and(uint32_t rel_bkt, uint32_t nb_bkts)
+{
+       return rel_bkt & (nb_bkts - 1);
+}
+
 int timvf_timer_adapter_caps_get(const struct rte_eventdev *dev, uint64_t 
flags,
                uint32_t *caps, const struct rte_event_timer_adapter_ops **ops);
 int timvf_timer_unreg_burst(const struct rte_event_timer_adapter *adptr,
-- 
2.16.2

Reply via email to