2 * SPDX-License-Identifier: MIT
4 * Copyright (c) 2015-2018 Philippe Proulx <pproulx@efficios.com>
7 #define BT_LOG_TAG "LIB/UTIL"
8 #include "lib/logging.h"
10 #include "lib/assert-cond.h"
15 #include <babeltrace2/babeltrace.h>
16 #include "lib/trace-ir/utils.h"
19 bt_util_clock_cycles_to_ns_from_origin_status
20 bt_util_clock_cycles_to_ns_from_origin(uint64_t cycles
,
21 uint64_t frequency
, int64_t offset_seconds
,
22 uint64_t offset_cycles
, int64_t *ns
)
25 int64_t base_offset_ns
;
26 bt_util_clock_cycles_to_ns_from_origin_status status
=
30 BT_ASSERT_PRE_NO_ERROR();
31 BT_ASSERT_PRE_NON_NULL("nanoseconds-output", ns
,
32 "Nanoseconds (output)");
33 BT_ASSERT_PRE("valid-frequency",
34 frequency
!= UINT64_C(-1) && frequency
!= 0,
35 "Invalid frequency: freq=%" PRIu64
, frequency
);
36 BT_ASSERT_PRE("offset-cycles-lt-frequency",
37 offset_cycles
< frequency
,
38 "Offset (cycles) is greater than frequency: "
39 "offset-cycles=%" PRIu64
", freq=%" PRIu64
,
40 offset_cycles
, frequency
);
42 overflows
= bt_util_get_base_offset_ns(offset_seconds
, offset_cycles
,
43 frequency
, &base_offset_ns
);
45 status
= BT_FUNC_STATUS_OVERFLOW_ERROR
;
49 ret
= bt_util_ns_from_origin_inline(base_offset_ns
,
50 offset_seconds
, offset_cycles
,
51 frequency
, cycles
, ns
);
53 status
= BT_FUNC_STATUS_OVERFLOW_ERROR
;