1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation.
3 * Copyright(c) 2013 6WIND S.A.
12 * Simple Time Reference Functions (Cycles and HPET).
16 #include <rte_debug.h>
17 #include <rte_atomic.h>
20 #define US_PER_S 1000000
21 #define NS_PER_S 1000000000
27 extern enum timer_source eal_timer_source;
30 * Get the measured frequency of the RDTSC counter
33 * The TSC frequency for this lcore
39 * Return the number of TSC cycles since boot
42 * the number of cycles
44 static inline uint64_t
45 rte_get_tsc_cycles(void);
47 #ifdef RTE_LIBEAL_USE_HPET
49 * Return the number of HPET cycles since boot
51 * This counter is global for all execution units. The number of
52 * cycles in one second can be retrieved using rte_get_hpet_hz().
55 * the number of cycles
58 rte_get_hpet_cycles(void);
61 * Get the number of HPET cycles in one second.
64 * The number of cycles in one second.
67 rte_get_hpet_hz(void);
70 * Initialise the HPET for use. This must be called before the rte_get_hpet_hz
71 * and rte_get_hpet_cycles APIs are called. If this function does not succeed,
72 * then the HPET functions are unavailable and should not be called.
75 * If set, the hpet timer becomes the default timer whose values are
76 * returned by the rte_get_timer_hz/cycles API calls
80 * -1 on error, and the make_default parameter is ignored.
82 int rte_eal_hpet_init(int make_default);
87 * Get the number of cycles since boot from the default timer.
90 * The number of cycles
92 static inline uint64_t
93 rte_get_timer_cycles(void)
95 #ifdef RTE_LIBEAL_USE_HPET
96 switch(eal_timer_source) {
99 return rte_get_tsc_cycles();
100 #ifdef RTE_LIBEAL_USE_HPET
102 return rte_get_hpet_cycles();
103 default: rte_panic("Invalid timer source specified\n");
109 * Get the number of cycles in one second for the default timer.
112 * The number of cycles in one second.
114 static inline uint64_t
115 rte_get_timer_hz(void)
117 #ifdef RTE_LIBEAL_USE_HPET
118 switch(eal_timer_source) {
121 return rte_get_tsc_hz();
122 #ifdef RTE_LIBEAL_USE_HPET
124 return rte_get_hpet_hz();
125 default: rte_panic("Invalid timer source specified\n");
130 * Wait at least us microseconds.
131 * This function can be replaced with user-defined function.
132 * @see rte_delay_us_callback_register
135 * The number of microseconds to wait.
138 (*rte_delay_us)(unsigned int us);
141 * Wait at least ms milliseconds.
144 * The number of milliseconds to wait.
147 rte_delay_ms(unsigned ms)
149 rte_delay_us(ms * 1000);
153 * Blocking delay function.
156 * Number of microseconds to wait.
158 void rte_delay_us_block(unsigned int us);
161 * Replace rte_delay_us with user defined function.
164 * User function which replaces rte_delay_us. rte_delay_us_block restores
165 * buildin block delay function.
167 void rte_delay_us_callback_register(void(*userfunc)(unsigned int));
169 #endif /* _RTE_CYCLES_H_ */