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