[dpdk-stable] [dpdk-dev] [PATCH] eal: generic counter based loop for CPU freq calculation
Pavan Nikhilesh Bhagavatula
pbhagavatula at marvell.com
Wed Jun 24 17:09:24 CEST 2020
>Subject: [dpdk-dev] [PATCH] eal: generic counter based loop for CPU
>freq calculation
>
>get_tsc_freq uses 'nanosleep' system call to calculate the CPU
>frequency. However, 'nanosleep' results in the process getting
>un-scheduled. The kernel saves and restores the PMU state. This
>ensures that the PMU cycles are not counted towards a sleeping
>process. When RTE_ARM_EAL_RDTSC_USE_PMU is defined, this results
>in incorrect CPU frequency calculation. This logic is replaced
>with generic counter based loop.
>
>Bugzilla ID: 450
>Fixes: af75078fece3 ("first public release")
>Cc: stable at dpdk.org
>
>Signed-off-by: Honnappa Nagarahalli
><honnappa.nagarahalli at arm.com>
>Reviewed-by: Ruifeng Wang <ruifeng.wang at arm.com>
>Reviewed-by: Dharmik Thakkar <dharmik.thakkar at arm.com>
>Reviewed-by: Phil Yang <phil.yang at arm.com>
>
>---
> lib/librte_eal/arm/include/rte_cycles_64.h | 45
>+++++++++++++++++++---
> lib/librte_eal/arm/rte_cycles.c | 24 ++++++++++--
> 2 files changed, 61 insertions(+), 8 deletions(-)
>
<Snip>
>
> uint64_t
> get_tsc_freq_arch(void)
> {
> #if defined RTE_ARCH_ARM64 && !defined
>RTE_ARM_EAL_RDTSC_USE_PMU
>- uint64_t freq;
>- asm volatile("mrs %0, cntfrq_el0" : "=r" (freq));
>- return freq;
>+ return __rte_rd_generic_cntr_freq();
>+#elif defined RTE_ARCH_ARM64 && defined
>RTE_ARM_EAL_RDTSC_USE_PMU
>+ /* Use the generic counter ticks to calculate the PMU
>+ * cycle frequency.
>+ */
>+ uint64_t gcnt_ticks;
>+ uint64_t start_ticks, cur_ticks;
>+ uint64_t start_pmu_cycles, end_pmu_cycles;
>+
>+ /* Number of ticks for 1/10 second */
>+ gcnt_ticks = __rte_rd_generic_cntr_freq() / 10;
>+
>+ start_ticks = __rte_rd_generic_cntr_precise();
>+ start_pmu_cycles = rte_rdtsc_precise();
>+ do {
>+ cur_ticks = __rte_rd_generic_cntr();
>+ } while ((cur_ticks - start_ticks) < gcnt_ticks);
>+ end_pmu_cycles = rte_rdtsc_precise();
>+
>+ return ((end_pmu_cycles - start_pmu_cycles) * 10);
I think we need to round this of to the next multiple of 10.
Sometimes it is off by one
EAL: TSC frequency is ~2399999 KHz
Similar to http://git.dpdk.org/dpdk/tree/lib/librte_eal/common/eal_common_timer.c#n54
Pavan.
> #else
> return 0;
> #endif
>--
>2.17.1
More information about the stable
mailing list