]> git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/dpdk/lib/librte_eal/common/include/arch/x86/rte_cycles.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / seastar / dpdk / lib / librte_eal / common / include / arch / x86 / rte_cycles.h
1 /*-
2 * BSD LICENSE
3 *
4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 /* BSD LICENSE
34 *
35 * Copyright(c) 2013 6WIND.
36 *
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
39 * are met:
40 *
41 * * Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * * Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in
45 * the documentation and/or other materials provided with the
46 * distribution.
47 * * Neither the name of 6WIND S.A. nor the names of its
48 * contributors may be used to endorse or promote products derived
49 * from this software without specific prior written permission.
50 *
51 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
52 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
53 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
54 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
55 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
61 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62 */
63
64 #ifndef _RTE_CYCLES_X86_64_H_
65 #define _RTE_CYCLES_X86_64_H_
66
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70
71 #include "generic/rte_cycles.h"
72
73 #ifdef RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT
74 /* Global switch to use VMWARE mapping of TSC instead of RDTSC */
75 extern int rte_cycles_vmware_tsc_map;
76 #include <rte_branch_prediction.h>
77 #endif
78 #include <rte_common.h>
79
80 static inline uint64_t
81 rte_rdtsc(void)
82 {
83 union {
84 uint64_t tsc_64;
85 RTE_STD_C11
86 struct {
87 uint32_t lo_32;
88 uint32_t hi_32;
89 };
90 } tsc;
91
92 #ifdef RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT
93 if (unlikely(rte_cycles_vmware_tsc_map)) {
94 /* ecx = 0x10000 corresponds to the physical TSC for VMware */
95 asm volatile("rdpmc" :
96 "=a" (tsc.lo_32),
97 "=d" (tsc.hi_32) :
98 "c"(0x10000));
99 return tsc.tsc_64;
100 }
101 #endif
102
103 asm volatile("rdtsc" :
104 "=a" (tsc.lo_32),
105 "=d" (tsc.hi_32));
106 return tsc.tsc_64;
107 }
108
109 static inline uint64_t
110 rte_rdtsc_precise(void)
111 {
112 rte_mb();
113 return rte_rdtsc();
114 }
115
116 static inline uint64_t
117 rte_get_tsc_cycles(void) { return rte_rdtsc(); }
118
119 #ifdef __cplusplus
120 }
121 #endif
122
123 #endif /* _RTE_CYCLES_X86_64_H_ */