DPDK  17.11.10
rte_cycles.h
Go to the documentation of this file.
1 /*-
2  * BSD LICENSE
3  *
4  * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  * Copyright(c) 2013 6WIND.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
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
17  * distribution.
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.
21  *
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.
33  */
34 
35 #ifndef _RTE_CYCLES_H_
36 #define _RTE_CYCLES_H_
37 
44 #include <stdint.h>
45 #include <rte_debug.h>
46 #include <rte_atomic.h>
47 
48 #define MS_PER_S 1000
49 #define US_PER_S 1000000
50 #define NS_PER_S 1000000000
51 
52 enum timer_source {
53  EAL_TIMER_TSC = 0,
54  EAL_TIMER_HPET
55 };
56 extern enum timer_source eal_timer_source;
57 
64 uint64_t
65 rte_get_tsc_hz(void);
66 
73 static inline uint64_t
74 rte_get_tsc_cycles(void);
75 
76 #ifdef RTE_LIBEAL_USE_HPET
77 
86 uint64_t
87 rte_get_hpet_cycles(void);
88 
95 uint64_t
96 rte_get_hpet_hz(void);
97 
111 int rte_eal_hpet_init(int make_default);
112 
113 #endif
114 
121 static inline uint64_t
123 {
124 #ifdef RTE_LIBEAL_USE_HPET
125  switch(eal_timer_source) {
126  case EAL_TIMER_TSC:
127 #endif
128  return rte_get_tsc_cycles();
129 #ifdef RTE_LIBEAL_USE_HPET
130  case EAL_TIMER_HPET:
131  return rte_get_hpet_cycles();
132  default: rte_panic("Invalid timer source specified\n");
133  }
134 #endif
135 }
136 
143 static inline uint64_t
145 {
146 #ifdef RTE_LIBEAL_USE_HPET
147  switch(eal_timer_source) {
148  case EAL_TIMER_TSC:
149 #endif
150  return rte_get_tsc_hz();
151 #ifdef RTE_LIBEAL_USE_HPET
152  case EAL_TIMER_HPET:
153  return rte_get_hpet_hz();
154  default: rte_panic("Invalid timer source specified\n");
155  }
156 #endif
157 }
166 extern void
167 (*rte_delay_us)(unsigned int us);
168 
175 static inline void
176 rte_delay_ms(unsigned ms)
177 {
178  rte_delay_us(ms * 1000);
179 }
180 
187 void rte_delay_us_block(unsigned int us);
188 
196 void rte_delay_us_callback_register(void(*userfunc)(unsigned int));
197 
198 #endif /* _RTE_CYCLES_H_ */
void rte_delay_us_block(unsigned int us)
void rte_delay_us_callback_register(void(*userfunc)(unsigned int))
static void rte_delay_ms(unsigned ms)
Definition: rte_cycles.h:176
static uint64_t rte_get_timer_hz(void)
Definition: rte_cycles.h:144
void(* rte_delay_us)(unsigned int us)
#define rte_panic(...)
Definition: rte_debug.h:79
static uint64_t rte_get_tsc_cycles(void)
uint64_t rte_get_tsc_hz(void)
static uint64_t rte_get_timer_cycles(void)
Definition: rte_cycles.h:122