2 * Copyright (c) 2015-2018 Philippe Proulx <pproulx@efficios.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #define BT_LOG_TAG "LIB/UTIL"
24 #include "lib/logging.h"
26 #include "lib/assert-pre.h"
31 #include <babeltrace2/babeltrace.h>
32 #include "lib/trace-ir/utils.h"
34 bt_util_clock_cycles_to_ns_from_origin_status
35 bt_util_clock_cycles_to_ns_from_origin(uint64_t cycles
,
36 uint64_t frequency
, int64_t offset_seconds
,
37 uint64_t offset_cycles
, int64_t *ns
)
40 int64_t base_offset_ns
;
41 bt_util_clock_cycles_to_ns_from_origin_status status
=
45 BT_ASSERT_PRE_NON_NULL(ns
, "Nanoseconds (output)");
46 BT_ASSERT_PRE(frequency
!= UINT64_C(-1) && frequency
!= 0,
47 "Invalid frequency: freq=%" PRIu64
, frequency
);
48 BT_ASSERT_PRE(offset_cycles
< frequency
,
49 "Offset (cycles) is greater than frequency: "
50 "offset-cycles=%" PRIu64
", freq=%" PRIu64
,
51 offset_cycles
, frequency
);
53 overflows
= bt_util_get_base_offset_ns(offset_seconds
, offset_cycles
,
54 frequency
, &base_offset_ns
);
56 status
= BT_FUNC_STATUS_OVERFLOW_ERROR
;
60 ret
= bt_util_ns_from_origin_inline(base_offset_ns
,
61 offset_seconds
, offset_cycles
,
62 frequency
, cycles
, ns
);
64 status
= BT_FUNC_STATUS_OVERFLOW_ERROR
;