eal: move arch-specific C files
[dpdk.git] / lib / librte_eal / common / include / arch / ppc_64 / rte_cycles.h
1 /*
2  * SPDX-License-Identifier: BSD-3-Clause
3  * Copyright (C) IBM Corporation 2014.
4  */
5
6 #ifndef _RTE_CYCLES_PPC_64_H_
7 #define _RTE_CYCLES_PPC_64_H_
8
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12
13 #include "generic/rte_cycles.h"
14
15 #include <rte_byteorder.h>
16 #include <rte_common.h>
17
18 /**
19  * Read the time base register.
20  *
21  * @return
22  *   The time base for this lcore.
23  */
24 static inline uint64_t
25 rte_rdtsc(void)
26 {
27         union {
28                 uint64_t tsc_64;
29                 RTE_STD_C11
30                 struct {
31 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
32                         uint32_t hi_32;
33                         uint32_t lo_32;
34 #else
35                         uint32_t lo_32;
36                         uint32_t hi_32;
37 #endif
38                 };
39         } tsc;
40         uint32_t tmp;
41
42         asm volatile(
43                         "0:\n"
44                         "mftbu   %[hi32]\n"
45                         "mftb    %[lo32]\n"
46                         "mftbu   %[tmp]\n"
47                         "cmpw    %[tmp],%[hi32]\n"
48                         "bne     0b\n"
49                         : [hi32] "=r"(tsc.hi_32), [lo32] "=r"(tsc.lo_32),
50                         [tmp] "=r"(tmp)
51                     );
52         return tsc.tsc_64;
53 }
54
55 static inline uint64_t
56 rte_rdtsc_precise(void)
57 {
58         rte_mb();
59         return rte_rdtsc();
60 }
61
62 static inline uint64_t
63 rte_get_tsc_cycles(void) { return rte_rdtsc(); }
64
65 #ifdef __cplusplus
66 }
67 #endif
68
69 #endif /* _RTE_CYCLES_PPC_64_H_ */