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_compat.h>
17 #include <rte_debug.h>
18 #include <rte_atomic.h>
21 #define US_PER_S 1000000
22 #define NS_PER_S 1000000000
28 extern enum timer_source eal_timer_source;
31 * Get the measured frequency of the RDTSC counter
34 * The TSC frequency for this lcore
40 * Return the number of TSC cycles since boot
43 * the number of cycles
45 static inline uint64_t
46 rte_get_tsc_cycles(void);
48 #ifdef RTE_LIBEAL_USE_HPET
50 * Return the number of HPET cycles since boot
52 * This counter is global for all execution units. The number of
53 * cycles in one second can be retrieved using rte_get_hpet_hz().
56 * the number of cycles
59 rte_get_hpet_cycles(void);
62 * Get the number of HPET cycles in one second.
65 * The number of cycles in one second.
68 rte_get_hpet_hz(void);
71 * Initialise the HPET for use. This must be called before the rte_get_hpet_hz
72 * and rte_get_hpet_cycles APIs are called. If this function does not succeed,
73 * then the HPET functions are unavailable and should not be called.
76 * If set, the hpet timer becomes the default timer whose values are
77 * returned by the rte_get_timer_hz/cycles API calls
81 * -1 on error, and the make_default parameter is ignored.
83 int rte_eal_hpet_init(int make_default);
88 * Get the number of cycles since boot from the default timer.
91 * The number of cycles
93 static inline uint64_t
94 rte_get_timer_cycles(void)
96 #ifdef RTE_LIBEAL_USE_HPET
97 switch(eal_timer_source) {
100 return rte_get_tsc_cycles();
101 #ifdef RTE_LIBEAL_USE_HPET
103 return rte_get_hpet_cycles();
104 default: rte_panic("Invalid timer source specified\n");
110 * Get the number of cycles in one second for the default timer.
113 * The number of cycles in one second.
115 static inline uint64_t
116 rte_get_timer_hz(void)
118 #ifdef RTE_LIBEAL_USE_HPET
119 switch(eal_timer_source) {
122 return rte_get_tsc_hz();
123 #ifdef RTE_LIBEAL_USE_HPET
125 return rte_get_hpet_hz();
126 default: rte_panic("Invalid timer source specified\n");
131 * Wait at least us microseconds.
132 * This function can be replaced with user-defined function.
133 * @see rte_delay_us_callback_register
136 * The number of microseconds to wait.
139 (*rte_delay_us)(unsigned int us);
142 * Wait at least ms milliseconds.
145 * The number of milliseconds to wait.
148 rte_delay_ms(unsigned ms)
150 rte_delay_us(ms * 1000);
154 * Blocking delay function.
157 * Number of microseconds to wait.
159 void rte_delay_us_block(unsigned int us);
162 * Delay function that uses system sleep.
163 * Does not block the CPU core.
166 * Number of microseconds to wait.
170 rte_delay_us_sleep(unsigned int us);
173 * Replace rte_delay_us with user defined function.
176 * User function which replaces rte_delay_us. rte_delay_us_block restores
177 * builtin block delay function.
179 void rte_delay_us_callback_register(void(*userfunc)(unsigned int));
181 #endif /* _RTE_CYCLES_H_ */