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