Print this page
11546 Track TCP round-trip time in nanoseconds
Portions contributed by: Cody Peter Mello <cody.mello@joyent.com>
Portions contributed by: Brandon Baker <bbaker@delphix.com>
Reviewed by: Jason King <jason.king@joyent.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Dan McDonald <danmcd@joyent.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/sys/time.h
+++ new/usr/src/uts/common/sys/time.h
1 1 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
2 2 /* All Rights Reserved */
3 3
4 4
5 5 /*
6 6 * Copyright (c) 1982, 1986, 1993 Regents of the University of California.
7 7 * All rights reserved. The Berkeley software License Agreement
8 8 * specifies the terms and conditions for redistribution.
9 9 */
10 10
↓ open down ↓ |
10 lines elided |
↑ open up ↑ |
11 11 /*
12 12 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
13 13 *
14 14 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
15 15 * Use is subject to license terms.
16 16 *
17 17 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
18 18 */
19 19
20 20 /*
21 - * Copyright (c) 2013, 2015 by Delphix. All rights reserved.
21 + * Copyright (c) 2013, 2016 by Delphix. All rights reserved.
22 22 */
23 23
24 24 #ifndef _SYS_TIME_H
25 25 #define _SYS_TIME_H
26 26
27 27 #include <sys/feature_tests.h>
28 28
29 29 /*
30 30 * Structure returned by gettimeofday(2) system call,
31 31 * and used in other calls.
32 32 */
33 33
34 34 #ifdef __cplusplus
35 35 extern "C" {
36 36 #endif
37 37
38 38 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
39 39 defined(__EXTENSIONS__)
40 40 #ifndef _ASM
41 41
42 42 #if !defined(_TIME_T) || __cplusplus >= 199711L
43 43 #define _TIME_T
44 44 typedef long time_t; /* time of day in seconds */
45 45 #endif /* _TIME_T */
46 46
47 47 #ifndef _SUSECONDS_T
48 48 #define _SUSECONDS_T
49 49 typedef long suseconds_t; /* signed # of microseconds */
50 50 #endif /* _SUSECONDS_T */
51 51
52 52 struct timeval {
53 53 time_t tv_sec; /* seconds */
54 54 suseconds_t tv_usec; /* and microseconds */
55 55 };
56 56
57 57 #if defined(_SYSCALL32)
58 58
59 59 #include <sys/types32.h>
60 60
61 61 #define TIMEVAL32_TO_TIMEVAL(tv, tv32) { \
62 62 (tv)->tv_sec = (time_t)(tv32)->tv_sec; \
63 63 (tv)->tv_usec = (tv32)->tv_usec; \
64 64 }
65 65
66 66 #define TIMEVAL_TO_TIMEVAL32(tv32, tv) { \
67 67 (tv32)->tv_sec = (time32_t)(tv)->tv_sec; \
68 68 (tv32)->tv_usec = (int32_t)(tv)->tv_usec; \
69 69 }
70 70
71 71 #define TIME32_MAX INT32_MAX
72 72 #define TIME32_MIN INT32_MIN
73 73
74 74 #define TIMEVAL_OVERFLOW(tv) \
75 75 ((tv)->tv_sec < TIME32_MIN || (tv)->tv_sec > TIME32_MAX)
76 76
77 77 #endif /* _SYSCALL32 */
78 78
79 79 #endif /* _ASM */
80 80 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) ... */
81 81
82 82 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
83 83 #ifndef _ASM
84 84 struct timezone {
85 85 int tz_minuteswest; /* minutes west of Greenwich */
86 86 int tz_dsttime; /* type of dst correction */
87 87 };
88 88
89 89 #endif /* _ASM */
90 90 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
91 91
92 92 #ifdef __cplusplus
93 93 }
94 94 #endif
95 95
96 96 /*
97 97 * Needed for longlong_t type. Placement of this due to <sys/types.h>
98 98 * including <sys/select.h> which relies on the presense of the itimerval
99 99 * structure.
100 100 */
101 101 #ifndef _ASM
102 102 #include <sys/types.h>
103 103 #endif /* _ASM */
104 104
105 105 #ifdef __cplusplus
106 106 extern "C" {
107 107 #endif
108 108
109 109 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
110 110
111 111 #define DST_NONE 0 /* not on dst */
112 112 #define DST_USA 1 /* USA style dst */
113 113 #define DST_AUST 2 /* Australian style dst */
114 114 #define DST_WET 3 /* Western European dst */
115 115 #define DST_MET 4 /* Middle European dst */
116 116 #define DST_EET 5 /* Eastern European dst */
117 117 #define DST_CAN 6 /* Canada */
118 118 #define DST_GB 7 /* Great Britain and Eire */
119 119 #define DST_RUM 8 /* Rumania */
120 120 #define DST_TUR 9 /* Turkey */
121 121 #define DST_AUSTALT 10 /* Australian style with shift in 1986 */
122 122
123 123 /*
124 124 * Operations on timevals.
125 125 */
126 126 #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
127 127 #define timercmp(tvp, uvp, cmp) \
128 128 (((tvp)->tv_sec == (uvp)->tv_sec) ? \
129 129 /* CSTYLED */ \
130 130 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
131 131 /* CSTYLED */ \
132 132 ((tvp)->tv_sec cmp (uvp)->tv_sec))
133 133
134 134 #define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0
135 135
136 136 #ifdef __lint
137 137 /*
138 138 * Make innocuous, lint-happy versions until do {} while (0) is acknowleged as
139 139 * lint-safe. If the compiler could know that we always make tv_usec < 1000000
140 140 * we wouldn't need a special linted version.
141 141 */
142 142 #define timeradd(tvp, uvp, vvp) \
143 143 do \
144 144 { \
145 145 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
146 146 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
147 147 if ((vvp)->tv_usec >= 1000000) \
148 148 { \
149 149 (vvp)->tv_sec++; \
150 150 (vvp)->tv_usec -= 1000000; \
151 151 } \
152 152 } while ((vvp)->tv_usec >= 1000000)
153 153 #define timersub(tvp, uvp, vvp) \
154 154 do \
155 155 { \
156 156 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
157 157 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
158 158 if ((vvp)->tv_usec < 0) \
159 159 { \
160 160 (vvp)->tv_sec--; \
161 161 (vvp)->tv_usec += 1000000; \
162 162 } \
163 163 } while ((vvp)->tv_usec >= 1000000)
164 164 #else
165 165 #define timeradd(tvp, uvp, vvp) \
166 166 do \
167 167 { \
168 168 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
169 169 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
170 170 if ((vvp)->tv_usec >= 1000000) \
171 171 { \
172 172 (vvp)->tv_sec++; \
173 173 (vvp)->tv_usec -= 1000000; \
174 174 } \
175 175 } while (0)
176 176
177 177 #define timersub(tvp, uvp, vvp) \
178 178 do \
179 179 { \
180 180 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
181 181 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
182 182 if ((vvp)->tv_usec < 0) \
183 183 { \
184 184 (vvp)->tv_sec--; \
185 185 (vvp)->tv_usec += 1000000; \
186 186 } \
187 187 } while (0)
188 188 #endif /* __lint */
189 189
190 190 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
191 191
192 192 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || defined(__EXTENSIONS__)
193 193 /*
194 194 * Names of the interval timers, and structure
195 195 * defining a timer setting.
196 196 */
197 197 #define ITIMER_REAL 0 /* Decrements in real time */
198 198 #define ITIMER_VIRTUAL 1 /* Decrements in process virtual time */
199 199 #define ITIMER_PROF 2 /* Decrements both in process virtual */
200 200 /* time and when system is running on */
201 201 /* behalf of the process. */
202 202 #define ITIMER_REALPROF 3 /* Decrements in real time for real- */
203 203 /* time profiling of multithreaded */
204 204 /* programs. */
205 205
206 206 #ifndef _ASM
207 207 struct itimerval {
208 208 struct timeval it_interval; /* timer interval */
209 209 struct timeval it_value; /* current value */
210 210 };
211 211
212 212 #if defined(_SYSCALL32)
213 213
214 214 struct itimerval32 {
215 215 struct timeval32 it_interval;
216 216 struct timeval32 it_value;
217 217 };
218 218
219 219 #define ITIMERVAL32_TO_ITIMERVAL(itv, itv32) { \
220 220 TIMEVAL32_TO_TIMEVAL(&(itv)->it_interval, &(itv32)->it_interval); \
221 221 TIMEVAL32_TO_TIMEVAL(&(itv)->it_value, &(itv32)->it_value); \
222 222 }
223 223
224 224 #define ITIMERVAL_TO_ITIMERVAL32(itv32, itv) { \
225 225 TIMEVAL_TO_TIMEVAL32(&(itv32)->it_interval, &(itv)->it_interval); \
226 226 TIMEVAL_TO_TIMEVAL32(&(itv32)->it_value, &(itv)->it_value); \
227 227 }
228 228
229 229 #define ITIMERVAL_OVERFLOW(itv) \
230 230 (TIMEVAL_OVERFLOW(&(itv)->it_interval) || \
231 231 TIMEVAL_OVERFLOW(&(itv)->it_value))
232 232
233 233 #endif /* _SYSCALL32 */
234 234 #endif /* _ASM */
235 235 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) ... */
236 236
237 237
238 238 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
239 239 /*
↓ open down ↓ |
208 lines elided |
↑ open up ↑ |
240 240 * Definitions for commonly used resolutions.
241 241 */
242 242 #define SEC 1
243 243 #define MILLISEC 1000
244 244 #define MICROSEC 1000000
245 245 #define NANOSEC 1000000000LL
246 246
247 247 #define MSEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / MILLISEC))
248 248 #define NSEC2MSEC(n) ((n) / (NANOSEC / MILLISEC))
249 249
250 -#define USEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / MICROSEC))
251 -#define NSEC2USEC(n) ((n) / (NANOSEC / MICROSEC))
250 +#define USEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / MICROSEC))
251 +#define NSEC2USEC(n) ((n) / (NANOSEC / MICROSEC))
252 252
253 253 #define NSEC2SEC(n) ((n) / (NANOSEC / SEC))
254 254 #define SEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / SEC))
255 255
256 256 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
257 257
258 258 #ifndef _ASM
259 259
260 260 /*
261 261 * Time expressed as a 64-bit nanosecond counter.
262 262 */
263 263 typedef longlong_t hrtime_t;
264 264
265 265 #if defined(_KERNEL) || defined(_FAKE_KERNEL)
266 266
267 267 #include <sys/time_impl.h>
268 268 #include <sys/mutex.h>
269 269
270 270 extern int tick_per_msec; /* clock ticks per millisecond (may be zero) */
271 271 extern int msec_per_tick; /* milliseconds per clock tick (may be zero) */
272 272 extern int usec_per_tick; /* microseconds per clock tick */
273 273 extern int nsec_per_tick; /* nanoseconds per clock tick */
274 274
275 275 /*
276 276 * Macros to convert from common units of time (sec, msec, usec, nsec,
277 277 * timeval, timestruc) to clock ticks and vice versa.
278 278 */
279 279 #define TICK_TO_SEC(tick) ((tick) / hz)
280 280 #define SEC_TO_TICK(sec) ((sec) * hz)
281 281
282 282 #define TICK_TO_MSEC(tick) \
283 283 (msec_per_tick ? (tick) * msec_per_tick : (tick) / tick_per_msec)
284 284 #define MSEC_TO_TICK(msec) \
285 285 (msec_per_tick ? (msec) / msec_per_tick : (msec) * tick_per_msec)
286 286 #define MSEC_TO_TICK_ROUNDUP(msec) \
287 287 (msec_per_tick ? \
288 288 ((msec) == 0 ? 0 : ((msec) - 1) / msec_per_tick + 1) : \
289 289 (msec) * tick_per_msec)
290 290
291 291 #define TICK_TO_USEC(tick) ((tick) * usec_per_tick)
292 292 #define USEC_TO_TICK(usec) ((usec) / usec_per_tick)
293 293 #define USEC_TO_TICK_ROUNDUP(usec) \
294 294 ((usec) == 0 ? 0 : USEC_TO_TICK((usec) - 1) + 1)
295 295
296 296 #define TICK_TO_NSEC(tick) ((hrtime_t)(tick) * nsec_per_tick)
297 297 #define NSEC_TO_TICK(nsec) ((nsec) / nsec_per_tick)
298 298 #define NSEC_TO_TICK_ROUNDUP(nsec) \
299 299 ((nsec) == 0 ? 0 : NSEC_TO_TICK((nsec) - 1) + 1)
300 300
301 301 #define TICK_TO_TIMEVAL(tick, tvp) { \
302 302 clock_t __tmptck = (tick); \
303 303 (tvp)->tv_sec = TICK_TO_SEC(__tmptck); \
304 304 (tvp)->tv_usec = TICK_TO_USEC(__tmptck - SEC_TO_TICK((tvp)->tv_sec)); \
305 305 }
306 306
307 307 #define TICK_TO_TIMEVAL32(tick, tvp) { \
308 308 clock_t __tmptck = (tick); \
309 309 time_t __tmptm = TICK_TO_SEC(__tmptck); \
310 310 (tvp)->tv_sec = (time32_t)__tmptm; \
311 311 (tvp)->tv_usec = TICK_TO_USEC(__tmptck - SEC_TO_TICK(__tmptm)); \
312 312 }
313 313
314 314 #define TICK_TO_TIMESTRUC(tick, tsp) { \
315 315 clock_t __tmptck = (tick); \
316 316 (tsp)->tv_sec = TICK_TO_SEC(__tmptck); \
317 317 (tsp)->tv_nsec = TICK_TO_NSEC(__tmptck - SEC_TO_TICK((tsp)->tv_sec)); \
318 318 }
319 319
320 320 #define TICK_TO_TIMESTRUC32(tick, tsp) { \
321 321 clock_t __tmptck = (tick); \
322 322 time_t __tmptm = TICK_TO_SEC(__tmptck); \
323 323 (tsp)->tv_sec = (time32_t)__tmptm; \
324 324 (tsp)->tv_nsec = TICK_TO_NSEC(__tmptck - SEC_TO_TICK(__tmptm)); \
325 325 }
326 326
327 327 #define TIMEVAL_TO_TICK(tvp) \
328 328 (SEC_TO_TICK((tvp)->tv_sec) + USEC_TO_TICK((tvp)->tv_usec))
329 329
330 330 #define TIMESTRUC_TO_TICK(tsp) \
331 331 (SEC_TO_TICK((tsp)->tv_sec) + NSEC_TO_TICK((tsp)->tv_nsec))
332 332
333 333 typedef struct todinfo {
334 334 int tod_sec; /* seconds 0-59 */
335 335 int tod_min; /* minutes 0-59 */
336 336 int tod_hour; /* hours 0-23 */
337 337 int tod_dow; /* day of week 1-7 */
338 338 int tod_day; /* day of month 1-31 */
339 339 int tod_month; /* month 1-12 */
340 340 int tod_year; /* year 70+ */
341 341 } todinfo_t;
342 342
343 343 extern int64_t timedelta;
344 344 extern int timechanged;
345 345 extern int tod_needsync;
346 346 extern kmutex_t tod_lock;
347 347 extern volatile timestruc_t hrestime;
348 348 extern hrtime_t hres_last_tick;
349 349 extern int64_t hrestime_adj;
350 350 extern uint_t adj_shift;
351 351
352 352 extern timestruc_t tod_get(void);
353 353 extern void tod_set(timestruc_t);
354 354 extern void set_hrestime(timestruc_t *);
355 355 extern todinfo_t utc_to_tod(time_t);
356 356 extern time_t tod_to_utc(todinfo_t);
357 357 extern int hr_clock_lock(void);
358 358 extern void hr_clock_unlock(int);
359 359 extern hrtime_t gethrtime(void);
360 360 extern hrtime_t gethrtime_unscaled(void);
361 361 extern hrtime_t gethrtime_max(void);
362 362 extern hrtime_t gethrtime_waitfree(void);
363 363 extern void scalehrtime(hrtime_t *);
364 364 extern uint64_t unscalehrtime(hrtime_t);
365 365 extern void gethrestime(timespec_t *);
366 366 extern time_t gethrestime_sec(void);
367 367 extern void gethrestime_lasttick(timespec_t *);
368 368 extern void hrt2ts(hrtime_t, timestruc_t *);
369 369 extern hrtime_t ts2hrt(const timestruc_t *);
370 370 extern void hrt2tv(hrtime_t, struct timeval *);
371 371 extern hrtime_t tv2hrt(struct timeval *);
372 372 extern int itimerfix(struct timeval *, int);
373 373 extern int itimerdecr(struct itimerval *, int);
374 374 extern void timevaladd(struct timeval *, struct timeval *);
375 375 extern void timevalsub(struct timeval *, struct timeval *);
376 376 extern void timevalfix(struct timeval *);
377 377 extern void dtrace_hres_tick(void);
378 378
379 379 extern clock_t ddi_get_lbolt(void);
380 380 extern int64_t ddi_get_lbolt64(void);
381 381
382 382 #if defined(_SYSCALL32)
383 383 extern void hrt2ts32(hrtime_t, timestruc32_t *);
384 384 #endif
385 385
386 386 #endif /* _KERNEL */
387 387
388 388 #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
389 389 int adjtime(struct timeval *, struct timeval *);
390 390 #endif /* !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) ... */
391 391
392 392 #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || \
393 393 defined(_ATFILE_SOURCE) || defined(__EXTENSIONS__)
394 394 int futimesat(int, const char *, const struct timeval *);
395 395 #endif /* defined(__ATFILE_SOURCE) */
396 396
397 397 #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
398 398 defined(__EXTENSIONS__)
399 399
400 400 int getitimer(int, struct itimerval *);
401 401 int utimes(const char *, const struct timeval *);
402 402 #if defined(_XPG4_2)
403 403 int setitimer(int, const struct itimerval *_RESTRICT_KYWD,
404 404 struct itimerval *_RESTRICT_KYWD);
405 405 #else
406 406 int setitimer(int, struct itimerval *_RESTRICT_KYWD,
407 407 struct itimerval *_RESTRICT_KYWD);
408 408 #endif /* defined(_XPG2_2) */
409 409
410 410 #endif /* !defined(_KERNEL) ... defined(_XPG4_2) */
411 411
412 412 /*
413 413 * gettimeofday() and settimeofday() were included in SVr4 due to their
414 414 * common use in BSD based applications. They were to be included exactly
415 415 * as in BSD, with two parameters. However, AT&T/USL noted that the second
416 416 * parameter was unused and deleted it, thereby making a routine included
417 417 * for compatibility, incompatible.
418 418 *
419 419 * XSH4.2 (spec 1170) defines gettimeofday and settimeofday to have two
420 420 * parameters.
421 421 *
422 422 * This has caused general disagreement in the application community as to
423 423 * the syntax of these routines. Solaris defaults to the XSH4.2 definition.
424 424 * The flag _SVID_GETTOD may be used to force the SVID version.
425 425 */
426 426 #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
427 427
428 428 #if defined(_SVID_GETTOD)
429 429 int settimeofday(struct timeval *);
430 430 #else
431 431 int settimeofday(struct timeval *, void *);
432 432 #endif
433 433 hrtime_t gethrtime(void);
434 434 hrtime_t gethrvtime(void);
435 435
436 436 #endif /* !(defined _KERNEL) && !defined(__XOPEN_OR_POSIX) ... */
437 437
438 438 #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
439 439 defined(__EXTENSIONS__)
440 440
441 441 #if defined(_SVID_GETTOD)
442 442 int gettimeofday(struct timeval *);
443 443 #else
444 444 int gettimeofday(struct timeval *_RESTRICT_KYWD, void *_RESTRICT_KYWD);
445 445 #endif
446 446
447 447 #endif /* !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) ... */
448 448
449 449 /*
450 450 * The inclusion of <time.h> is historical and was added for
451 451 * backward compatibility in delta 1.2 when a number of definitions
452 452 * were moved out of <sys/time.h>. More recently, the timespec and
453 453 * itimerspec structure definitions, along with the _CLOCK_*, CLOCK_*,
454 454 * _TIMER_*, and TIMER_* symbols were moved to <sys/time_impl.h>,
455 455 * which is now included by <time.h>. This change was due to POSIX
456 456 * 1003.1b-1993 and X/Open UNIX 98 requirements. For non-POSIX and
457 457 * non-X/Open applications, including this header will still make
458 458 * visible these definitions.
459 459 */
460 460 #if !defined(_BOOT) && !defined(_KERNEL) && !defined(_FAKE_KERNEL) && \
461 461 !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
462 462 #include <time.h>
463 463 #endif
464 464
465 465 /*
466 466 * The inclusion of <sys/select.h> is needed for the FD_CLR,
467 467 * FD_ISSET, FD_SET, and FD_SETSIZE macros as well as the
468 468 * select() prototype defined in the XOpen specifications
469 469 * beginning with XSH4v2. Placement required after definition
470 470 * for itimerval.
471 471 */
472 472 #if !defined(_KERNEL) && !defined(_FAKE_KERNEL) && \
473 473 !defined(__XOPEN_OR_POSIX) || \
474 474 defined(_XPG4_2) || defined(__EXTENSIONS__)
475 475 #include <sys/select.h>
476 476 #endif
477 477
478 478 #endif /* _ASM */
479 479
480 480 #ifdef __cplusplus
481 481 }
482 482 #endif
483 483
484 484 #endif /* _SYS_TIME_H */
↓ open down ↓ |
223 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX