Fix: pass private data to context callbacks
[lttng-ust.git] / liblttng-ust / clock.h
1 /*
2 * SPDX-License-Identifier: LGPL-2.1-only
3 *
4 * Copyright (C) 2010 Pierre-Marc Fournier
5 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 */
7
8 #ifndef _UST_CLOCK_H
9 #define _UST_CLOCK_H
10
11 #include <time.h>
12 #include <sys/time.h>
13 #include <stdint.h>
14 #include <stddef.h>
15 #include <stdio.h>
16 #include <urcu/system.h>
17 #include <urcu/arch.h>
18 #include <lttng/ust-clock.h>
19
20 #include "lttng-ust-uuid.h"
21
22 struct lttng_ust_trace_clock {
23 uint64_t (*read64)(void);
24 uint64_t (*freq)(void);
25 int (*uuid)(char *uuid);
26 const char *(*name)(void);
27 const char *(*description)(void);
28 };
29
30 extern struct lttng_ust_trace_clock *lttng_ust_trace_clock
31 __attribute__((visibility("hidden")));
32
33 void lttng_ust_clock_init(void);
34
35 /* Use the kernel MONOTONIC clock. */
36
37 static __inline__
38 uint64_t trace_clock_read64_monotonic(void)
39 {
40 struct timespec ts;
41
42 if (caa_unlikely(clock_gettime(CLOCK_MONOTONIC, &ts))) {
43 ts.tv_sec = 0;
44 ts.tv_nsec = 0;
45 }
46 return ((uint64_t) ts.tv_sec * 1000000000ULL) + ts.tv_nsec;
47 }
48
49 static __inline__
50 uint64_t trace_clock_read64(void)
51 {
52 struct lttng_ust_trace_clock *ltc = CMM_LOAD_SHARED(lttng_ust_trace_clock);
53
54 if (caa_likely(!ltc)) {
55 return trace_clock_read64_monotonic();
56 } else {
57 cmm_read_barrier_depends(); /* load ltc before content */
58 return ltc->read64();
59 }
60 }
61
62 #endif /* _UST_CLOCK_H */
This page took 0.031228 seconds and 4 git commands to generate.