Commit | Line | Data |
---|---|---|
273b65be | 1 | /* |
0235b0db MJ |
2 | * SPDX-License-Identifier: MIT |
3 | * | |
e2f7325d | 4 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> |
de9dd397 | 5 | * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
273b65be JG |
6 | */ |
7 | ||
0235b0db MJ |
8 | #ifndef BABELTRACE_TRACE_IR_CLOCK_CLASS_INTERNAL_H |
9 | #define BABELTRACE_TRACE_IR_CLOCK_CLASS_INTERNAL_H | |
10 | ||
3fadfbc0 | 11 | #include <babeltrace2/trace-ir/clock-class.h> |
578e048b | 12 | #include "lib/object.h" |
91d81473 | 13 | #include "common/macros.h" |
578e048b MJ |
14 | #include "common/common.h" |
15 | #include "lib/object-pool.h" | |
6162e6b7 | 16 | #include "common/uuid.h" |
3fadfbc0 | 17 | #include <babeltrace2/types.h> |
578e048b MJ |
18 | #include "lib/property.h" |
19 | #include "common/assert.h" | |
036a7cac PP |
20 | #include <stdbool.h> |
21 | #include <stdint.h> | |
c55a9f58 | 22 | #include <glib.h> |
273b65be | 23 | |
d24d5663 PP |
24 | #include "lib/func-status.h" |
25 | ||
50842bdc | 26 | struct bt_clock_class { |
83509119 | 27 | struct bt_object base; |
44c440bc | 28 | |
c6962c96 PP |
29 | /* Owned by this */ |
30 | struct bt_value *user_attributes; | |
31 | ||
44c440bc PP |
32 | struct { |
33 | GString *str; | |
34 | ||
35 | /* NULL or `str->str` above */ | |
36 | const char *value; | |
37 | } name; | |
38 | ||
39 | struct { | |
40 | GString *str; | |
41 | ||
42 | /* NULL or `str->str` above */ | |
43 | const char *value; | |
44 | } description; | |
45 | ||
273b65be JG |
46 | uint64_t frequency; |
47 | uint64_t precision; | |
44c440bc PP |
48 | int64_t offset_seconds; |
49 | uint64_t offset_cycles; | |
50 | ||
51 | struct { | |
6162e6b7 | 52 | bt_uuid_t uuid; |
44c440bc PP |
53 | |
54 | /* NULL or `uuid` above */ | |
55 | bt_uuid value; | |
56 | } uuid; | |
57 | ||
5552377a | 58 | bool origin_is_unix_epoch; |
cfeb617e | 59 | |
273b65be | 60 | /* |
44c440bc PP |
61 | * This is computed every time you call |
62 | * bt_clock_class_set_frequency() or | |
63 | * bt_clock_class_set_offset(), as well as initially. It is the | |
64 | * base offset in nanoseconds including both `offset_seconds` | |
65 | * and `offset_cycles` above in the result. It is used to | |
66 | * accelerate future calls to | |
605e1019 | 67 | * bt_clock_snapshot_get_ns_from_origin() and |
44c440bc PP |
68 | * bt_clock_class_cycles_to_ns_from_origin(). |
69 | * | |
70 | * `overflows` is true if the base offset cannot be computed | |
71 | * because of an overflow. | |
273b65be | 72 | */ |
44c440bc PP |
73 | struct { |
74 | int64_t value_ns; | |
75 | bool overflows; | |
76 | } base_offset; | |
312c056a | 77 | |
605e1019 PP |
78 | /* Pool of `struct bt_clock_snapshot *` */ |
79 | struct bt_object_pool cs_pool; | |
44c440bc PP |
80 | |
81 | bool frozen; | |
273b65be JG |
82 | }; |
83 | ||
40f4ba76 | 84 | void _bt_clock_class_freeze(const struct bt_clock_class *clock_class); |
273b65be | 85 | |
44c440bc PP |
86 | #ifdef BT_DEV_MODE |
87 | # define bt_clock_class_freeze _bt_clock_class_freeze | |
88 | #else | |
89 | # define bt_clock_class_freeze(_cc) | |
90 | #endif | |
24626e8b | 91 | |
44c440bc | 92 | bt_bool bt_clock_class_is_valid(struct bt_clock_class *clock_class); |
93dda901 | 93 | |
5b9e151d PP |
94 | static inline |
95 | int bt_clock_class_clock_value_from_ns_from_origin( | |
96 | struct bt_clock_class *cc, int64_t ns_from_origin, | |
97 | uint64_t *raw_value) | |
98 | { | |
98b15851 | 99 | BT_ASSERT_DBG(cc); |
7de0e49a PP |
100 | return bt_common_clock_value_from_ns_from_origin(cc->offset_seconds, |
101 | cc->offset_cycles, cc->frequency, ns_from_origin, | |
520cdc82 | 102 | raw_value) ? BT_FUNC_STATUS_OVERFLOW_ERROR : BT_FUNC_STATUS_OK; |
5b9e151d PP |
103 | } |
104 | ||
56e18c4c | 105 | #endif /* BABELTRACE_TRACE_IR_CLOCK_CLASS_INTERNAL_H */ |