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-pre.h"
15 #include <babeltrace2/babeltrace.h>
16 #include "lib/trace-ir/utils.h"
18 bt_util_clock_cycles_to_ns_from_origin_status
19 bt_util_clock_cycles_to_ns_from_origin(uint64_t cycles
,
20 uint64_t frequency
, int64_t offset_seconds
,
21 uint64_t offset_cycles
, int64_t *ns
)
24 int64_t base_offset_ns
;
25 bt_util_clock_cycles_to_ns_from_origin_status status
=
29 BT_ASSERT_PRE_NO_ERROR();
30 BT_ASSERT_PRE_NON_NULL(ns
, "Nanoseconds (output)");
31 BT_ASSERT_PRE(frequency
!= UINT64_C(-1) && frequency
!= 0,
32 "Invalid frequency: freq=%" PRIu64
, frequency
);
33 BT_ASSERT_PRE(offset_cycles
< frequency
,
34 "Offset (cycles) is greater than frequency: "
35 "offset-cycles=%" PRIu64
", freq=%" PRIu64
,
36 offset_cycles
, frequency
);
38 overflows
= bt_util_get_base_offset_ns(offset_seconds
, offset_cycles
,
39 frequency
, &base_offset_ns
);
41 status
= BT_FUNC_STATUS_OVERFLOW_ERROR
;
45 ret
= bt_util_ns_from_origin_inline(base_offset_ns
,
46 offset_seconds
, offset_cycles
,
47 frequency
, cycles
, ns
);
49 status
= BT_FUNC_STATUS_OVERFLOW_ERROR
;