1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2014 Intel Corporation. 3 * Copyright(c) 2013 6WIND S.A. 4 */ 5 6 #ifndef _RTE_CYCLES_X86_64_H_ 7 #define _RTE_CYCLES_X86_64_H_ 8 9 #ifdef RTE_TOOLCHAIN_MSVC 10 #include <intrin.h> 11 #else 12 #include <x86intrin.h> 13 #endif 14 15 #include "generic/rte_cycles.h" 16 17 #ifdef RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT 18 /* Global switch to use VMWARE mapping of TSC instead of RDTSC */ 19 extern int rte_cycles_vmware_tsc_map; 20 #include <rte_branch_prediction.h> 21 #endif 22 #include <rte_common.h> 23 #include <rte_config.h> 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 static inline uint64_t 30 rte_rdtsc(void) 31 { 32 #ifdef RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT 33 union { 34 uint64_t tsc_64; 35 struct { 36 uint32_t lo_32; 37 uint32_t hi_32; 38 }; 39 } tsc; 40 41 if (unlikely(rte_cycles_vmware_tsc_map)) { 42 /* ecx = 0x10000 corresponds to the physical TSC for VMware */ 43 asm volatile("rdpmc" : 44 "=a" (tsc.lo_32), 45 "=d" (tsc.hi_32) : 46 "c"(0x10000)); 47 return tsc.tsc_64; 48 } 49 #endif 50 return __rdtsc(); 51 } 52 53 static inline uint64_t 54 rte_rdtsc_precise(void) 55 { 56 rte_mb(); 57 return rte_rdtsc(); 58 } 59 60 static inline uint64_t 61 rte_get_tsc_cycles(void) { return rte_rdtsc(); } 62 63 #ifdef __cplusplus 64 } 65 #endif 66 67 #endif /* _RTE_CYCLES_X86_64_H_ */ 68