xref: /dpdk/lib/eal/loongarch/include/rte_cycles.h (revision 719834a6849e1daf4a70ff7742bbcc3ae7e25607)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2022 Loongson Technology Corporation Limited
3  */
4 
5 #ifndef RTE_CYCLES_LOONGARCH_H
6 #define RTE_CYCLES_LOONGARCH_H
7 
8 #include "generic/rte_cycles.h"
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 /**
15  * Read the time base register.
16  *
17  * @return
18  *   The time base for this lcore.
19  */
20 static inline uint64_t
21 rte_rdtsc(void)
22 {
23 	uint64_t count;
24 
25 	__asm__ __volatile__ (
26 		"rdtime.d %[cycles], $zero\n"
27 		: [cycles] "=r" (count)
28 		::
29 		);
30 	return count;
31 }
32 
33 static inline uint64_t
34 rte_rdtsc_precise(void)
35 {
36 	rte_mb();
37 	return rte_rdtsc();
38 }
39 
40 static inline uint64_t
41 rte_get_tsc_cycles(void) { return rte_rdtsc(); }
42 
43 #ifdef __cplusplus
44 }
45 #endif
46 
47 #endif /* RTE_CYCLES_LOONGARCH_H */
48