Move to kernel style SPDX license identifiers
[lttng-ust.git] / liblttng-ust / clock.h
... / ...
CommitLineData
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
22struct lttng_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
30extern struct lttng_trace_clock *lttng_trace_clock;
31
32void lttng_ust_clock_init(void);
33
34/* Use the kernel MONOTONIC clock. */
35
36static __inline__
37uint64_t trace_clock_read64_monotonic(void)
38{
39 struct timespec ts;
40
41 if (caa_unlikely(clock_gettime(CLOCK_MONOTONIC, &ts))) {
42 ts.tv_sec = 0;
43 ts.tv_nsec = 0;
44 }
45 return ((uint64_t) ts.tv_sec * 1000000000ULL) + ts.tv_nsec;
46}
47
48static __inline__
49uint64_t trace_clock_read64(void)
50{
51 struct lttng_trace_clock *ltc = CMM_LOAD_SHARED(lttng_trace_clock);
52
53 if (caa_likely(!ltc)) {
54 return trace_clock_read64_monotonic();
55 } else {
56 cmm_read_barrier_depends(); /* load ltc before content */
57 return ltc->read64();
58 }
59}
60
61#endif /* _UST_CLOCK_H */
This page took 0.022061 seconds and 4 git commands to generate.