[4/4] event/octeontx2: timer always use virtual counter

Message ID 20210225122315.6350-4-pbhagavatula@marvell.com (mailing list archive)
State Superseded, archived
Delegated to: Jerin Jacob
Headers
Series [1/4] event/octeontx2: simplify timer bucket estimation |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/travis-robot fail travis build: failed
ci/github-robot success github build: passed
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-mellanox-Functional fail Functional Testing issues
ci/iol-abi-testing success Testing PASS
ci/iol-testing fail Testing issues

Commit Message

Pavan Nikhilesh Bhagavatula Feb. 25, 2021, 12:23 p.m. UTC
  From: Pavan Nikhilesh <pbhagavatula@marvell.com>

Use virtual counter for estimating current bucket as PMU cannot be
reliably used to estimate time.

Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
---
 drivers/event/octeontx2/otx2_tim_evdev.c  | 19 +++-----------
 drivers/event/octeontx2/otx2_tim_evdev.h  | 32 +++++++++++++++++++++++
 drivers/event/octeontx2/otx2_tim_worker.c |  4 +--
 drivers/event/octeontx2/otx2_tim_worker.h |  2 +-
 4 files changed, 38 insertions(+), 19 deletions(-)
  

Comments

Jerin Jacob March 20, 2021, 1:34 p.m. UTC | #1
On Thu, Feb 25, 2021 at 5:53 PM <pbhagavatula@marvell.com> wrote:
>
> From: Pavan Nikhilesh <pbhagavatula@marvell.com>
>
> Use virtual counter for estimating current bucket as PMU cannot be
> reliably used to estimate time.
>
> Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>

>
> +#ifdef RTE_ARCH_ARM64
> +static inline uint64_t
> +tim_cntvct(void)
> +{
> +       uint64_t tsc;
> +
> +       asm volatile("mrs %0, cntvct_el0" : "=r"(tsc));
> +       return tsc;


Reuse __rte_arm64_cntvct()

> +}
> +
> +static inline uint64_t
> +tim_cntfrq(void)
> +{
> +       uint64_t freq;
> +
> +       asm volatile("mrs %0, cntfrq_el0" : "=r"(freq));
> +       return freq;


Reuse __rte_arm64_cntfrq()


Please fix the following checkpatch and check format errors too.


[1]
Wrong headline case:
                        "event/octeontx2: optimize timer arm routine":
arm --> Arm

Invalid patch(es) found - checked 4 patches


[2]
total: 0 errors, 47 warnings, 272 lines checked
Warning in drivers/event/octeontx2/otx2_tim_worker.h:
Using rte_smp_[r/w]mb
Warning in drivers/event/octeontx2/otx2_tim_worker.c:
Using __atomic_thread_fence


>
  
Pavan Nikhilesh Bhagavatula March 21, 2021, 7:11 a.m. UTC | #2
>-----Original Message-----
>From: Jerin Jacob <jerinjacobk@gmail.com>
>Sent: Saturday, March 20, 2021 7:04 PM
>To: Pavan Nikhilesh Bhagavatula <pbhagavatula@marvell.com>
>Cc: Jerin Jacob Kollanukkaran <jerinj@marvell.com>; dpdk-dev
><dev@dpdk.org>
>Subject: [EXT] Re: [dpdk-dev] [PATCH 4/4] event/octeontx2: timer
>always use virtual counter
>
>External Email
>
>----------------------------------------------------------------------
>On Thu, Feb 25, 2021 at 5:53 PM <pbhagavatula@marvell.com> wrote:
>>
>> From: Pavan Nikhilesh <pbhagavatula@marvell.com>
>>
>> Use virtual counter for estimating current bucket as PMU cannot be
>> reliably used to estimate time.
>>
>> Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
>
>>
>> +#ifdef RTE_ARCH_ARM64
>> +static inline uint64_t
>> +tim_cntvct(void)
>> +{
>> +       uint64_t tsc;
>> +
>> +       asm volatile("mrs %0, cntvct_el0" : "=r"(tsc));
>> +       return tsc;
>
>
>Reuse __rte_arm64_cntvct()
>
>> +}
>> +
>> +static inline uint64_t
>> +tim_cntfrq(void)
>> +{
>> +       uint64_t freq;
>> +
>> +       asm volatile("mrs %0, cntfrq_el0" : "=r"(freq));
>> +       return freq;
>
>
>Reuse __rte_arm64_cntfrq()

Ack.

>
>
>Please fix the following checkpatch and check format errors too.
>
>
>[1]
>Wrong headline case:
>                        "event/octeontx2: optimize timer arm routine":
>arm --> Arm

I think checkpatch is interpreting this as Arm Inc. which I think we 
can ignore it in this context.

>
>Invalid patch(es) found - checked 4 patches
>
>
>[2]
>total: 0 errors, 47 warnings, 272 lines checked
>Warning in drivers/event/octeontx2/otx2_tim_worker.h:
>Using rte_smp_[r/w]mb
>Warning in drivers/event/octeontx2/otx2_tim_worker.c:
>Using __atomic_thread_fence
>

Ack.

>
>>
  

Patch

diff --git a/drivers/event/octeontx2/otx2_tim_evdev.c b/drivers/event/octeontx2/otx2_tim_evdev.c
index 4fb002ddb..926c2dce6 100644
--- a/drivers/event/octeontx2/otx2_tim_evdev.c
+++ b/drivers/event/octeontx2/otx2_tim_evdev.c
@@ -354,7 +354,7 @@  otx2_tim_calibrate_start_tsc(struct otx2_tim_ring *tim_ring)
 
 	for (icount = 0; icount < OTX2_TIM_CALIB_ITER; icount++) {
 		real_bkt = otx2_read64(tim_ring->base + TIM_LF_RING_REL) >> 44;
-		bkt_cyc = rte_rdtsc();
+		bkt_cyc = tim_cntvct();
 		bucket = (bkt_cyc - tim_ring->ring_start_cyc) /
 							tim_ring->tck_int;
 		bucket = bucket % (tim_ring->nb_bkts);
@@ -389,20 +389,8 @@  otx2_tim_ring_start(const struct rte_event_timer_adapter *adptr)
 		tim_err_desc(rc);
 		goto fail;
 	}
-#ifdef RTE_ARM_EAL_RDTSC_USE_PMU
-	uint64_t tenns_stmp, tenns_diff;
-	uint64_t pmu_stmp;
-
-	pmu_stmp = rte_rdtsc();
-	asm volatile("mrs %0, cntvct_el0" : "=r" (tenns_stmp));
-
-	tenns_diff = tenns_stmp - rsp->timestarted;
-	pmu_stmp = pmu_stmp - (NSEC2TICK(tenns_diff  * 10, rte_get_timer_hz()));
-	tim_ring->ring_start_cyc = pmu_stmp;
-#else
 	tim_ring->ring_start_cyc = rsp->timestarted;
-#endif
-	tim_ring->tck_int = NSEC2TICK(tim_ring->tck_nsec, rte_get_timer_hz());
+	tim_ring->tck_int = NSEC2TICK(tim_ring->tck_nsec, tim_cntfrq());
 	tim_ring->tot_int = tim_ring->tck_int * tim_ring->nb_bkts;
 	tim_ring->fast_div = rte_reciprocal_value_u64(tim_ring->tck_int);
 	tim_ring->fast_bkt = rte_reciprocal_value_u64(tim_ring->nb_bkts);
@@ -470,8 +458,7 @@  otx2_tim_stats_get(const struct rte_event_timer_adapter *adapter,
 		   struct rte_event_timer_adapter_stats *stats)
 {
 	struct otx2_tim_ring *tim_ring = adapter->data->adapter_priv;
-	uint64_t bkt_cyc = rte_rdtsc() - tim_ring->ring_start_cyc;
-
+	uint64_t bkt_cyc = tim_cntvct() - tim_ring->ring_start_cyc;
 
 	stats->evtim_exp_count = __atomic_load_n(&tim_ring->arm_cnt,
 						 __ATOMIC_RELAXED);
diff --git a/drivers/event/octeontx2/otx2_tim_evdev.h b/drivers/event/octeontx2/otx2_tim_evdev.h
index 2a3b84a43..a890b41dc 100644
--- a/drivers/event/octeontx2/otx2_tim_evdev.h
+++ b/drivers/event/octeontx2/otx2_tim_evdev.h
@@ -176,6 +176,38 @@  tim_priv_get(void)
 	return mz->addr;
 }
 
+#ifdef RTE_ARCH_ARM64
+static inline uint64_t
+tim_cntvct(void)
+{
+	uint64_t tsc;
+
+	asm volatile("mrs %0, cntvct_el0" : "=r"(tsc));
+	return tsc;
+}
+
+static inline uint64_t
+tim_cntfrq(void)
+{
+	uint64_t freq;
+
+	asm volatile("mrs %0, cntfrq_el0" : "=r"(freq));
+	return freq;
+}
+#else
+static inline uint64_t
+tim_cntvct(void)
+{
+	return 0;
+}
+
+static inline uint64_t
+tim_cntfrq(void)
+{
+	return 0;
+}
+#endif
+
 #define TIM_ARM_FASTPATH_MODES                                                 \
 	FP(sp, 0, 0, 0, OTX2_TIM_ENA_DFB | OTX2_TIM_SP)                        \
 	FP(mp, 0, 0, 1, OTX2_TIM_ENA_DFB | OTX2_TIM_MP)                        \
diff --git a/drivers/event/octeontx2/otx2_tim_worker.c b/drivers/event/octeontx2/otx2_tim_worker.c
index 9946be733..b2b88cad0 100644
--- a/drivers/event/octeontx2/otx2_tim_worker.c
+++ b/drivers/event/octeontx2/otx2_tim_worker.c
@@ -41,12 +41,12 @@  tim_format_event(const struct rte_event_timer * const tim,
 static inline void
 tim_sync_start_cyc(struct otx2_tim_ring *tim_ring)
 {
-	uint64_t cur_cyc = rte_rdtsc();
+	uint64_t cur_cyc = tim_cntvct();
 	uint32_t real_bkt;
 
 	if (cur_cyc - tim_ring->last_updt_cyc > tim_ring->tot_int) {
 		real_bkt = otx2_read64(tim_ring->base + TIM_LF_RING_REL) >> 44;
-		cur_cyc = rte_rdtsc();
+		cur_cyc = tim_cntvct();
 
 		tim_ring->ring_start_cyc = cur_cyc -
 						(real_bkt * tim_ring->tck_int);
diff --git a/drivers/event/octeontx2/otx2_tim_worker.h b/drivers/event/octeontx2/otx2_tim_worker.h
index 9d8bcb974..7f6d0611e 100644
--- a/drivers/event/octeontx2/otx2_tim_worker.h
+++ b/drivers/event/octeontx2/otx2_tim_worker.h
@@ -132,7 +132,7 @@  tim_get_target_bucket(struct otx2_tim_ring *const tim_ring,
 		      const uint32_t rel_bkt, struct otx2_tim_bkt **bkt,
 		      struct otx2_tim_bkt **mirr_bkt)
 {
-	const uint64_t bkt_cyc = rte_rdtsc() - tim_ring->ring_start_cyc;
+	const uint64_t bkt_cyc = tim_cntvct() - tim_ring->ring_start_cyc;
 	uint64_t bucket =
 		rte_reciprocal_divide_u64(bkt_cyc, &tim_ring->fast_div) +
 		rel_bkt;