4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5 * Copyright(c) 2013 6WIND.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * * Neither the name of Intel Corporation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #ifndef _RTE_CYCLES_H_
36 #define _RTE_CYCLES_H_
41 * Simple Time Reference Functions (Cycles and HPET).
45 #include <rte_debug.h>
46 #include <rte_atomic.h>
49 #define US_PER_S 1000000
50 #define NS_PER_S 1000000000
56 extern enum timer_source eal_timer_source;
59 * Get the measured frequency of the RDTSC counter
62 * The TSC frequency for this lcore
68 * Return the number of TSC cycles since boot
71 * the number of cycles
73 static inline uint64_t
74 rte_get_tsc_cycles(void);
76 #ifdef RTE_LIBEAL_USE_HPET
78 * Return the number of HPET cycles since boot
80 * This counter is global for all execution units. The number of
81 * cycles in one second can be retrieved using rte_get_hpet_hz().
84 * the number of cycles
87 rte_get_hpet_cycles(void);
90 * Get the number of HPET cycles in one second.
93 * The number of cycles in one second.
96 rte_get_hpet_hz(void);
99 * Initialise the HPET for use. This must be called before the rte_get_hpet_hz
100 * and rte_get_hpet_cycles APIs are called. If this function does not succeed,
101 * then the HPET functions are unavailable and should not be called.
103 * @param make_default
104 * If set, the hpet timer becomes the default timer whose values are
105 * returned by the rte_get_timer_hz/cycles API calls
109 * -1 on error, and the make_default parameter is ignored.
111 int rte_eal_hpet_init(int make_default);
116 * Get the number of cycles since boot from the default timer.
119 * The number of cycles
121 static inline uint64_t
122 rte_get_timer_cycles(void)
124 #ifdef RTE_LIBEAL_USE_HPET
125 switch(eal_timer_source) {
128 return rte_get_tsc_cycles();
129 #ifdef RTE_LIBEAL_USE_HPET
131 return rte_get_hpet_cycles();
132 default: rte_panic("Invalid timer source specified\n");
138 * Get the number of cycles in one second for the default timer.
141 * The number of cycles in one second.
143 static inline uint64_t
144 rte_get_timer_hz(void)
146 #ifdef RTE_LIBEAL_USE_HPET
147 switch(eal_timer_source) {
150 return rte_get_tsc_hz();
151 #ifdef RTE_LIBEAL_USE_HPET
153 return rte_get_hpet_hz();
154 default: rte_panic("Invalid timer source specified\n");
159 * Wait at least us microseconds.
160 * This function can be replaced with user-defined function.
161 * @see rte_delay_us_callback_register
164 * The number of microseconds to wait.
167 (*rte_delay_us)(unsigned int us);
170 * Wait at least ms milliseconds.
173 * The number of milliseconds to wait.
176 rte_delay_ms(unsigned ms)
178 rte_delay_us(ms * 1000);
182 * Blocking delay function.
185 * Number of microseconds to wait.
187 void rte_delay_us_block(unsigned int us);
190 * Replace rte_delay_us with user defined function.
193 * User function which replaces rte_delay_us. rte_delay_us_block restores
194 * buildin block delay function.
196 void rte_delay_us_callback_register(void(*userfunc)(unsigned int));
198 #endif /* _RTE_CYCLES_H_ */