]> git.proxmox.com Git - ceph.git/blame - ceph/src/seastar/dpdk/lib/librte_eal/common/include/generic/rte_cycles.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / seastar / dpdk / lib / librte_eal / common / include / generic / rte_cycles.h
CommitLineData
9f95a23c
TL
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation.
3 * Copyright(c) 2013 6WIND S.A.
7c673cae
FG
4 */
5
6#ifndef _RTE_CYCLES_H_
7#define _RTE_CYCLES_H_
8
9/**
10 * @file
11 *
12 * Simple Time Reference Functions (Cycles and HPET).
13 */
14
15#include <stdint.h>
9f95a23c 16#include <rte_compat.h>
7c673cae
FG
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
24enum timer_source {
25 EAL_TIMER_TSC = 0,
26 EAL_TIMER_HPET
27};
28extern enum timer_source eal_timer_source;
29
30/**
31 * Get the measured frequency of the RDTSC counter
32 *
33 * @return
34 * The TSC frequency for this lcore
35 */
36uint64_t
37rte_get_tsc_hz(void);
38
39/**
40 * Return the number of TSC cycles since boot
41 *
42 * @return
43 * the number of cycles
44 */
45static inline uint64_t
46rte_get_tsc_cycles(void);
47
48#ifdef RTE_LIBEAL_USE_HPET
49/**
50 * Return the number of HPET cycles since boot
51 *
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().
54 *
55 * @return
56 * the number of cycles
57 */
58uint64_t
59rte_get_hpet_cycles(void);
60
61/**
62 * Get the number of HPET cycles in one second.
63 *
64 * @return
65 * The number of cycles in one second.
66 */
67uint64_t
68rte_get_hpet_hz(void);
69
70/**
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.
74 *
75 * @param make_default
76 * If set, the hpet timer becomes the default timer whose values are
77 * returned by the rte_get_timer_hz/cycles API calls
78 *
79 * @return
80 * 0 on success,
81 * -1 on error, and the make_default parameter is ignored.
82 */
83int rte_eal_hpet_init(int make_default);
84
85#endif
86
87/**
88 * Get the number of cycles since boot from the default timer.
89 *
90 * @return
91 * The number of cycles
92 */
93static inline uint64_t
94rte_get_timer_cycles(void)
95{
11fdf7f2 96#ifdef RTE_LIBEAL_USE_HPET
7c673cae
FG
97 switch(eal_timer_source) {
98 case EAL_TIMER_TSC:
11fdf7f2 99#endif
7c673cae 100 return rte_get_tsc_cycles();
7c673cae 101#ifdef RTE_LIBEAL_USE_HPET
11fdf7f2 102 case EAL_TIMER_HPET:
7c673cae 103 return rte_get_hpet_cycles();
7c673cae
FG
104 default: rte_panic("Invalid timer source specified\n");
105 }
11fdf7f2 106#endif
7c673cae
FG
107}
108
109/**
110 * Get the number of cycles in one second for the default timer.
111 *
112 * @return
113 * The number of cycles in one second.
114 */
115static inline uint64_t
116rte_get_timer_hz(void)
117{
11fdf7f2 118#ifdef RTE_LIBEAL_USE_HPET
7c673cae
FG
119 switch(eal_timer_source) {
120 case EAL_TIMER_TSC:
11fdf7f2 121#endif
7c673cae 122 return rte_get_tsc_hz();
7c673cae 123#ifdef RTE_LIBEAL_USE_HPET
11fdf7f2 124 case EAL_TIMER_HPET:
7c673cae 125 return rte_get_hpet_hz();
7c673cae
FG
126 default: rte_panic("Invalid timer source specified\n");
127 }
11fdf7f2 128#endif
7c673cae
FG
129}
130/**
131 * Wait at least us microseconds.
132 * This function can be replaced with user-defined function.
133 * @see rte_delay_us_callback_register
134 *
135 * @param us
136 * The number of microseconds to wait.
137 */
138extern void
139(*rte_delay_us)(unsigned int us);
140
141/**
142 * Wait at least ms milliseconds.
143 *
144 * @param ms
145 * The number of milliseconds to wait.
146 */
147static inline void
148rte_delay_ms(unsigned ms)
149{
150 rte_delay_us(ms * 1000);
151}
152
153/**
154 * Blocking delay function.
155 *
156 * @param us
157 * Number of microseconds to wait.
158 */
159void rte_delay_us_block(unsigned int us);
160
9f95a23c
TL
161/**
162 * Delay function that uses system sleep.
163 * Does not block the CPU core.
164 *
165 * @param us
166 * Number of microseconds to wait.
167 */
168void __rte_experimental
169rte_delay_us_sleep(unsigned int us);
170
7c673cae
FG
171/**
172 * Replace rte_delay_us with user defined function.
173 *
174 * @param userfunc
175 * User function which replaces rte_delay_us. rte_delay_us_block restores
9f95a23c 176 * builtin block delay function.
7c673cae
FG
177 */
178void rte_delay_us_callback_register(void(*userfunc)(unsigned int));
179
180#endif /* _RTE_CYCLES_H_ */