DPDK  19.02.0
rte_cycles.h
Go to the documentation of this file.
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_H_
7 #define _RTE_CYCLES_H_
8 
15 #include <stdint.h>
16 #include <rte_compat.h>
17 #include <rte_debug.h>
18 #include <rte_atomic.h>
19 
20 #define MS_PER_S 1000
21 #define US_PER_S 1000000
22 #define NS_PER_S 1000000000
23 
24 enum timer_source {
25  EAL_TIMER_TSC = 0,
26  EAL_TIMER_HPET
27 };
28 extern enum timer_source eal_timer_source;
29 
36 uint64_t
37 rte_get_tsc_hz(void);
38 
45 static inline uint64_t
46 rte_get_tsc_cycles(void);
47 
48 #ifdef RTE_LIBEAL_USE_HPET
49 
58 uint64_t
59 rte_get_hpet_cycles(void);
60 
67 uint64_t
68 rte_get_hpet_hz(void);
69 
83 int rte_eal_hpet_init(int make_default);
84 
85 #endif
86 
93 static inline uint64_t
95 {
96 #ifdef RTE_LIBEAL_USE_HPET
97  switch(eal_timer_source) {
98  case EAL_TIMER_TSC:
99 #endif
100  return rte_get_tsc_cycles();
101 #ifdef RTE_LIBEAL_USE_HPET
102  case EAL_TIMER_HPET:
103  return rte_get_hpet_cycles();
104  default: rte_panic("Invalid timer source specified\n");
105  }
106 #endif
107 }
108 
115 static inline uint64_t
117 {
118 #ifdef RTE_LIBEAL_USE_HPET
119  switch(eal_timer_source) {
120  case EAL_TIMER_TSC:
121 #endif
122  return rte_get_tsc_hz();
123 #ifdef RTE_LIBEAL_USE_HPET
124  case EAL_TIMER_HPET:
125  return rte_get_hpet_hz();
126  default: rte_panic("Invalid timer source specified\n");
127  }
128 #endif
129 }
138 extern void
139 (*rte_delay_us)(unsigned int us);
140 
147 static inline void
148 rte_delay_ms(unsigned ms)
149 {
150  rte_delay_us(ms * 1000);
151 }
152 
159 void rte_delay_us_block(unsigned int us);
160 
168 void __rte_experimental
169 rte_delay_us_sleep(unsigned int us);
170 
178 void rte_delay_us_callback_register(void(*userfunc)(unsigned int));
179 
180 #endif /* _RTE_CYCLES_H_ */