aboutsummaryrefslogtreecommitdiff
path: root/include/odp/api/spec/time.h
blob: c25338a51458b8c2e6243c8979edac8ee9ab3e44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/* Copyright (c) 2013-2018, Linaro Limited
 * Copyright (c) 2020-2021, Nokia
 * All rights reserved.
 *
 * SPDX-License-Identifier:     BSD-3-Clause
 */

/**
 * @file
 *
 * ODP time
 */

#ifndef ODP_API_SPEC_TIME_H_
#define ODP_API_SPEC_TIME_H_
#include <odp/visibility_begin.h>

#ifdef __cplusplus
extern "C" {
#endif

/** @defgroup odp_time ODP TIME
 *  Chip and CPU level wall clock time.
 *  @{
 */

/** A microsecond in nanoseconds */
#define ODP_TIME_USEC_IN_NS  1000ULL

/** A millisecond in nanoseconds */
#define ODP_TIME_MSEC_IN_NS  1000000ULL

/** A second in nanoseconds */
#define ODP_TIME_SEC_IN_NS   1000000000ULL

/** A minute in nanoseconds */
#define ODP_TIME_MIN_IN_NS   60000000000ULL

/** An hour in nanoseconds */
#define ODP_TIME_HOUR_IN_NS  3600000000000ULL

/**
 * @typedef odp_time_t
 * ODP time stamp. Time stamp can represent a time stamp from local or global
 * time source. A local time stamp must not be shared between threads. API calls
 * work correctly only when all time stamps for input are from the same time
 * source.
 */

/**
 * @def ODP_TIME_NULL
 * Zero time stamp
 */

/**
 * Current local time
 *
 * Returns current local time stamp value. The local time source provides high
 * resolution time, it is initialized to zero during ODP startup and will not
 * wrap around in at least 10 years.
 * Local time stamps are local to the calling thread and must not be shared
 * with other threads.
 *
 * @return Local time stamp.
 */
odp_time_t odp_time_local(void);

/**
 * Current local time in nanoseconds
 *
 * Like odp_time_local(), but the time stamp value is converted into nanoseconds.
 *
 * @return Local time stamp in nanoseconds
 */
uint64_t odp_time_local_ns(void);

/**
 * Current local time (strict)
 *
 * Like odp_time_local(), but reads the time stamp value more strictly in the program order.
 * The function may decrease CPU performance around the call, as it may include additional
 * barrier instructions or otherwise limit out-of-order execution.
 *
 * @return Local time stamp
 */
odp_time_t odp_time_local_strict(void);

/**
 * Current local time in nanoseconds (strict)
 *
 * Like odp_time_local_strict(), but the time stamp value is converted into nanoseconds.
 *
 * @return Local time stamp in nanoseconds
 */
uint64_t odp_time_local_strict_ns(void);

/**
 * Current global time
 *
 * Returns current global time stamp value. The global time source provides high
 * resolution time, it is initialized to zero during ODP startup and will not
 * wrap around in at least 10 years.
 * Global time stamps can be shared between threads.
 *
 * @return Global time stamp.
 */
odp_time_t odp_time_global(void);

/**
 * Current global time in nanoseconds
 *
 * Like odp_time_global(), but the time stamp value is converted into nanoseconds.
 *
 * @return Global time stamp in nanoseconds
 */
uint64_t odp_time_global_ns(void);

/**
 * Current global time (strict)
 *
 * Like odp_time_global(), but reads the time stamp value more strictly (see
 * odp_time_local_strict() documentation) in the program order.
 *
 * @return Global time stamp
 */
odp_time_t odp_time_global_strict(void);

/**
 * Current global time in nanoseconds (strict)
 *
 * Like odp_time_global_strict(), but the time stamp value is converted into nanoseconds.
 *
 * @return Global time stamp in nanoseconds
 */
uint64_t odp_time_global_strict_ns(void);

/**
 * Time difference
 *
 * @param t2    Second time stamp
 * @param t1    First time stamp
 *
 * @return Difference of time stamps
 */
odp_time_t odp_time_diff(odp_time_t t2, odp_time_t t1);

/**
 * Time difference in nanoseconds
 *
 * @param t2    Second time stamp
 * @param t1    First time stamp
 *
 * @return Difference of time stamps (t2 - t1) in nanoseconds
 */
uint64_t odp_time_diff_ns(odp_time_t t2, odp_time_t t1);

/**
 * Time sum
 *
 * @param t1    Time stamp
 * @param t2    Time stamp
 *
 * @return Sum of time stamps
 */
odp_time_t odp_time_sum(odp_time_t t1, odp_time_t t2);

/**
 * Convert time to nanoseconds
 *
 * @param time  Time
 *
 * @return Time in nanoseconds
 */
uint64_t odp_time_to_ns(odp_time_t time);

/**
 * Convert nanoseconds to local time
 *
 * @param ns    Time in nanoseconds
 *
 * @return Local time stamp
 */
odp_time_t odp_time_local_from_ns(uint64_t ns);

/**
 * Convert nanoseconds to global time
 *
 * @param ns    Time in nanoseconds
 *
 * @return Global time stamp
 */
odp_time_t odp_time_global_from_ns(uint64_t ns);

/**
 * Compare two times
 *
 * @param t2    Second time
 * @param t1    First time
 *
 * @retval <0 when t2 < t1
 * @retval  0 when t2 == t1
 * @retval >0 when t2 > t1
 */
int odp_time_cmp(odp_time_t t2, odp_time_t t1);

/**
 * Local time resolution in hertz
 *
 * @return      Local time resolution in hertz
 */
uint64_t odp_time_local_res(void);

/**
 * Global time resolution in hertz
 *
 * @return      Global time resolution in hertz
 */
uint64_t odp_time_global_res(void);

/**
 * Wait until the specified (wall clock) time has been reached
 *
 * The thread potentially busy loop the entire wait time.
 *
 * @param time  Time to reach before continue
 */
void odp_time_wait_until(odp_time_t time);

/**
 * Wait the specified number of nanoseconds
 *
 * The thread potentially busy loop the entire wait time.
 *
 * @param ns    Time in nanoseconds to wait
 */
void odp_time_wait_ns(uint64_t ns);

/**
 * @}
 */

#ifdef __cplusplus
}
#endif

#include <odp/visibility_end.h>
#endif