--- /dev/null
+/*
+ * SPDX-License-Identifier: MIT
+ *
+ * Copyright 2022 EfficiOS, Inc.
+ */
+
+#include "normalize-clk-offset.hpp"
+
+namespace ctf {
+namespace src {
+
+/*
+ * Normalize `clkCls`'s offsets so that the part in cycles is less than the
+ * frequency.
+ */
+void normalizeClkOffset(long long& offsetSec, unsigned long long& offsetCycles,
+ unsigned long long freq) noexcept
+{
+ if (offsetCycles >= freq) {
+ const unsigned long long secInOffsetCycles = offsetCycles / freq;
+
+ offsetSec += (long long) secInOffsetCycles;
+ offsetCycles -= secInOffsetCycles * freq;
+ }
+}
+
+} /* namespace src */
+} /* namespace ctf */
#include "ctf-meta.hpp"
#include "ctf-meta-visitors.hpp"
#include "cpp-common/cfg-logging-error-reporting.hpp"
+#include "../normalize-clk-offset.hpp"
/* Bit value (left shift) */
#define _BV(_val) (1 << (_val))
return cycles;
}
-static void calibrate_clock_class_offsets(int64_t *offset_seconds, uint64_t *offset_cycles,
- uint64_t freq)
-{
- if (*offset_cycles >= freq) {
- const uint64_t s_in_offset_cycles = *offset_cycles / freq;
-
- *offset_seconds += (int64_t) s_in_offset_cycles;
- *offset_cycles -= (s_in_offset_cycles * freq);
- }
-}
-
static void apply_clock_class_is_absolute(struct ctf_visitor_generate_ir *ctx,
struct ctf_clock_class *clock)
{
uint64_t offset_ns_to_apply;
int64_t cur_offset_s;
uint64_t cur_offset_cycles;
+ long long offsetSecLL;
+ unsigned long long offsetCyclesULL;
if (ctx->decoder_config.clkClsCfg.offsetSec == 0 &&
ctx->decoder_config.clkClsCfg.offsetNanoSec == 0) {
* Recalibrate offsets because the part in cycles can be greater
* than the frequency at this point.
*/
- calibrate_clock_class_offsets(&cur_offset_s, &cur_offset_cycles, freq);
+ offsetSecLL = cur_offset_s;
+ offsetCyclesULL = cur_offset_cycles;
+ ctf::src::normalizeClkOffset(offsetSecLL, offsetCyclesULL, freq);
/* Set final offsets */
- clock->offset_seconds = cur_offset_s;
- clock->offset_cycles = cur_offset_cycles;
+ clock->offset_seconds = offsetSecLL;
+ clock->offset_cycles = offsetCyclesULL;
end:
return;
const char *clock_class_name;
int64_t offset_seconds = 0;
uint64_t offset_cycles = 0;
- uint64_t freq;
+ long long offsetSecLL;
+ unsigned long long offsetCyclesULL;
if (clock_node->visited) {
return 0;
* Adjust offsets so that the part in cycles is less than the
* frequency (move to the part in seconds).
*/
- freq = clock->frequency;
- calibrate_clock_class_offsets(&offset_seconds, &offset_cycles, freq);
- BT_ASSERT(offset_cycles < clock->frequency);
- clock->offset_seconds = offset_seconds;
- clock->offset_cycles = offset_cycles;
+ offsetSecLL = offset_seconds;
+ offsetCyclesULL = offset_cycles;
+ ctf::src::normalizeClkOffset(offsetSecLL, offsetCyclesULL, clock->frequency);
+ BT_ASSERT(offsetCyclesULL < clock->frequency);
+ clock->offset_seconds = offsetSecLL;
+ clock->offset_cycles = offsetCyclesULL;
apply_clock_class_offset(ctx, clock);
apply_clock_class_is_absolute(ctx, clock);
g_ptr_array_add(ctx->ctf_tc->clock_classes, clock);