xref: /dpdk/lib/eal/arm/rte_cycles.c (revision 99a2dd955fba6e4cc23b77d590a033650ced9c45)
1*99a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
2*99a2dd95SBruce Richardson  * Copyright(c) 2015 Cavium, Inc
3*99a2dd95SBruce Richardson  */
4*99a2dd95SBruce Richardson 
5*99a2dd95SBruce Richardson #include "eal_private.h"
6*99a2dd95SBruce Richardson #include "rte_cycles.h"
7*99a2dd95SBruce Richardson 
8*99a2dd95SBruce Richardson uint64_t
get_tsc_freq_arch(void)9*99a2dd95SBruce Richardson get_tsc_freq_arch(void)
10*99a2dd95SBruce Richardson {
11*99a2dd95SBruce Richardson #if defined RTE_ARCH_ARM64 && !defined RTE_ARM_EAL_RDTSC_USE_PMU
12*99a2dd95SBruce Richardson 	return __rte_arm64_cntfrq();
13*99a2dd95SBruce Richardson #elif defined RTE_ARCH_ARM64 && defined RTE_ARM_EAL_RDTSC_USE_PMU
14*99a2dd95SBruce Richardson #define CYC_PER_1MHZ 1E6
15*99a2dd95SBruce Richardson 	/* Use the generic counter ticks to calculate the PMU
16*99a2dd95SBruce Richardson 	 * cycle frequency.
17*99a2dd95SBruce Richardson 	 */
18*99a2dd95SBruce Richardson 	uint64_t ticks;
19*99a2dd95SBruce Richardson 	uint64_t start_ticks, cur_ticks;
20*99a2dd95SBruce Richardson 	uint64_t start_pmu_cycles, end_pmu_cycles;
21*99a2dd95SBruce Richardson 
22*99a2dd95SBruce Richardson 	/* Number of ticks for 1/10 second */
23*99a2dd95SBruce Richardson 	ticks = __rte_arm64_cntfrq() / 10;
24*99a2dd95SBruce Richardson 
25*99a2dd95SBruce Richardson 	start_ticks = __rte_arm64_cntvct_precise();
26*99a2dd95SBruce Richardson 	start_pmu_cycles = rte_rdtsc_precise();
27*99a2dd95SBruce Richardson 	do {
28*99a2dd95SBruce Richardson 		cur_ticks = __rte_arm64_cntvct();
29*99a2dd95SBruce Richardson 	} while ((cur_ticks - start_ticks) < ticks);
30*99a2dd95SBruce Richardson 	end_pmu_cycles = rte_rdtsc_precise();
31*99a2dd95SBruce Richardson 
32*99a2dd95SBruce Richardson 	/* Adjust the cycles to next 1Mhz */
33*99a2dd95SBruce Richardson 	return RTE_ALIGN_MUL_CEIL(end_pmu_cycles - start_pmu_cycles,
34*99a2dd95SBruce Richardson 			CYC_PER_1MHZ) * 10;
35*99a2dd95SBruce Richardson #else
36*99a2dd95SBruce Richardson 	return 0;
37*99a2dd95SBruce Richardson #endif
38*99a2dd95SBruce Richardson }
39