Fix: wait for initial statedump before proceeding to the main program
[lttng-ust.git] / liblttng-ust / clock.h
CommitLineData
8d8a24c8
MD
1/*
2 * Copyright (C) 2010 Pierre-Marc Fournier
3 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
518d7abb
PMF
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
8d8a24c8
MD
7 * License as published by the Free Software Foundation; version 2.1 of
8 * the License.
518d7abb
PMF
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
9c6bb081
JD
20#ifndef _UST_CLOCK_H
21#define _UST_CLOCK_H
518d7abb 22
ca4525b5 23#include <time.h>
518d7abb 24#include <sys/time.h>
9edd34bd
MD
25#include <stdint.h>
26#include <stddef.h>
939950af 27#include <stdio.h>
f9364363
MD
28#include <urcu/system.h>
29#include <urcu/arch.h>
30#include <lttng/ust-clock.h>
31
eda498b8 32#include "lttng-ust-uuid.h"
518d7abb 33
f9364363
MD
34struct lttng_trace_clock {
35 uint64_t (*read64)(void);
36 uint64_t (*freq)(void);
37 int (*uuid)(char *uuid);
38 const char *(*name)(void);
39 const char *(*description)(void);
40};
518d7abb 41
f9364363 42extern struct lttng_trace_clock *lttng_trace_clock;
518d7abb 43
f9364363
MD
44void lttng_ust_clock_init(void);
45
46/* Use the kernel MONOTONIC clock. */
518d7abb 47
28b12049 48static __inline__
f9364363 49uint64_t trace_clock_read64_monotonic(void)
9c6bb081
JD
50{
51 struct timespec ts;
9c6bb081 52
77686037
MD
53 if (caa_unlikely(clock_gettime(CLOCK_MONOTONIC, &ts))) {
54 ts.tv_sec = 0;
55 ts.tv_nsec = 0;
56 }
dc190cc1 57 return ((uint64_t) ts.tv_sec * 1000000000ULL) + ts.tv_nsec;
9c6bb081
JD
58}
59
f9364363
MD
60static __inline__
61uint64_t trace_clock_read64(void)
62{
63 struct lttng_trace_clock *ltc = CMM_LOAD_SHARED(lttng_trace_clock);
64
65 if (caa_likely(!ltc)) {
66 return trace_clock_read64_monotonic();
67 } else {
68 cmm_read_barrier_depends(); /* load ltc before content */
69 return ltc->read64();
70 }
71}
72
9c6bb081 73#endif /* _UST_CLOCK_H */
This page took 0.034419 seconds and 4 git commands to generate.