Bug #1351 » 0001-babeltrace2-Handle-negative-clock-offset.patch
include/babeltrace2/trace-ir/clock-class.h | ||
---|---|---|
Returns the offset of a clock class.
|
||
*/
|
||
extern void bt_clock_class_set_offset(bt_clock_class *clock_class,
|
||
int64_t offset_seconds, uint64_t offset_cycles);
|
||
int64_t offset_seconds, int64_t offset_cycles);
|
||
/*!
|
||
@brief
|
||
... | ... | |
Sets the offset of a clock class.
|
||
*/
|
||
extern void bt_clock_class_get_offset(const bt_clock_class *clock_class,
|
||
int64_t *offset_seconds, uint64_t *offset_cycles);
|
||
int64_t *offset_seconds, int64_t *offset_cycles);
|
||
/*!
|
||
@brief
|
include/babeltrace2/util.h | ||
---|---|---|
bt_util_clock_cycles_to_ns_from_origin_status
|
||
bt_util_clock_cycles_to_ns_from_origin(uint64_t cycles,
|
||
uint64_t frequency, int64_t offset_seconds,
|
||
uint64_t offset_cycles, int64_t *ns_from_origin);
|
||
int64_t offset_cycles, int64_t *ns_from_origin);
|
||
/*! @} */
|
||
src/common/common.h | ||
---|---|---|
static inline
|
||
int bt_common_clock_value_from_ns_from_origin(
|
||
int64_t cc_offset_seconds, uint64_t cc_offset_cycles,
|
||
int64_t cc_offset_seconds, int64_t cc_offset_cycles,
|
||
uint64_t cc_freq, int64_t ns_from_origin,
|
||
uint64_t *raw_value)
|
||
{
|
src/lib/graph/iterator.c | ||
---|---|---|
{
|
||
int64_t cc_offset_s = clock_class->offset_seconds;
|
||
uint64_t cc_offset_cycles = clock_class->offset_cycles;
|
||
int64_t cc_offset_cycles = clock_class->offset_cycles;
|
||
uint64_t cc_freq = clock_class->frequency;
|
||
return bt_common_clock_value_from_ns_from_origin(cc_offset_s,
|
src/lib/lib-logging.c | ||
---|---|---|
BUF_APPEND(", %sis-frozen=%d, %sprecision=%" PRIu64 ", "
|
||
"%soffset-s=%" PRId64 ", "
|
||
"%soffset-cycles=%" PRIu64 ", %sorigin-is-unix-epoch=%d, "
|
||
"%soffset-cycles=%" PRId64 ", %sorigin-is-unix-epoch=%d, "
|
||
"%sbase-offset-ns=%" PRId64,
|
||
PRFIELD(clock_class->frozen), PRFIELD(clock_class->precision),
|
||
PRFIELD(clock_class->offset_seconds),
|
src/lib/trace-ir/clock-class.c | ||
---|---|---|
}
|
||
void bt_clock_class_get_offset(const struct bt_clock_class *clock_class,
|
||
int64_t *seconds, uint64_t *cycles)
|
||
int64_t *seconds, int64_t *cycles)
|
||
{
|
||
BT_ASSERT_PRE_DEV_NON_NULL(clock_class, "Clock class");
|
||
BT_ASSERT_PRE_DEV_NON_NULL(seconds, "Seconds (output)");
|
||
... | ... | |
}
|
||
void bt_clock_class_set_offset(struct bt_clock_class *clock_class,
|
||
int64_t seconds, uint64_t cycles)
|
||
int64_t seconds, int64_t cycles)
|
||
{
|
||
BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class");
|
||
BT_ASSERT_PRE_DEV_CLOCK_CLASS_HOT(clock_class);
|
||
BT_ASSERT_PRE(cycles < clock_class->frequency,
|
||
BT_ASSERT_PRE(llabs(cycles) < clock_class->frequency,
|
||
"Offset (cycles) is greater than clock class's frequency: "
|
||
"%![cc-]+K, new-offset-cycles=%" PRIu64, clock_class, cycles);
|
||
clock_class->offset_seconds = seconds;
|
||
clock_class->offset_cycles = cycles;
|
||
set_base_offset(clock_class);
|
||
BT_LIB_LOGD("Set clock class's offset: %!+K", clock_class);
|
||
}
|
||
bt_bool bt_clock_class_origin_is_unix_epoch(const struct bt_clock_class *clock_class)
|
src/lib/trace-ir/clock-class.h | ||
---|---|---|
uint64_t frequency;
|
||
uint64_t precision;
|
||
int64_t offset_seconds;
|
||
uint64_t offset_cycles;
|
||
int64_t offset_cycles;
|
||
struct {
|
||
bt_uuid_t uuid;
|
src/lib/trace-ir/utils.h | ||
---|---|---|
};
|
||
static inline
|
||
uint64_t bt_util_ns_from_value(uint64_t frequency, uint64_t value_cycles)
|
||
int64_t bt_util_ns_from_value(uint64_t frequency, uint64_t value_cycles)
|
||
{
|
||
uint64_t ns;
|
||
int64_t ns;
|
||
if (frequency == UINT64_C(1000000000)) {
|
||
ns = value_cycles;
|
||
} else {
|
||
double dblres = ((1e9 * (double) value_cycles) / (double) frequency);
|
||
if (dblres >= (double) UINT64_MAX) {
|
||
/* Overflows uint64_t */
|
||
ns = UINT64_C(-1);
|
||
if (dblres >= (double) INT64_MAX) {
|
||
/* Overflows max int64_t */
|
||
ns = INT64_MAX;
|
||
} if (dblres <= (double) INT64_MIN) {
|
||
/* Overflows min int64_t */
|
||
ns = INT64_MIN;
|
||
} else {
|
||
ns = (uint64_t) dblres;
|
||
ns = (int64_t) dblres;
|
||
}
|
||
}
|
||
... | ... | |
}
|
||
static inline
|
||
bool bt_util_get_base_offset_ns(int64_t offset_seconds, uint64_t offset_cycles,
|
||
bool bt_util_get_base_offset_ns(int64_t offset_seconds, int64_t offset_cycles,
|
||
uint64_t frequency, int64_t *base_offset_ns)
|
||
{
|
||
bool overflows = false;
|
||
uint64_t offset_cycles_ns;
|
||
int64_t offset_cycles_ns;
|
||
BT_ASSERT_DBG(base_offset_ns);
|
||
... | ... | |
*base_offset_ns = offset_seconds * INT64_C(1000000000);
|
||
/* Add offset in cycles */
|
||
BT_ASSERT_DBG(offset_cycles < frequency);
|
||
BT_ASSERT_DBG(llabs(offset_cycles) < frequency);
|
||
offset_cycles_ns = bt_util_ns_from_value(frequency,
|
||
offset_cycles);
|
||
BT_ASSERT_DBG(offset_cycles_ns < 1000000000);
|
||
BT_ASSERT_DBG(llabs(offset_cycles_ns) < 1000000000);
|
||
*base_offset_ns += (int64_t) offset_cycles_ns;
|
||
end:
|
||
... | ... | |
static inline
|
||
int bt_util_ns_from_origin_inline(int64_t base_offset_ns,
|
||
int64_t offset_seconds, uint64_t offset_cycles,
|
||
int64_t offset_seconds, int64_t offset_cycles,
|
||
uint64_t frequency, uint64_t value, int64_t *ns_from_origin)
|
||
{
|
||
int ret = 0;
|
||
uint64_t value_ns_unsigned;
|
||
int64_t value_ns_signed;
|
||
/* Initialize to clock class's base offset */
|
||
*ns_from_origin = base_offset_ns;
|
||
/* Add given value in cycles */
|
||
value_ns_unsigned = bt_util_ns_from_value(frequency, value);
|
||
if (value_ns_unsigned >= (uint64_t) INT64_MAX) {
|
||
/*
|
||
* FIXME: `value_ns_unsigned` could be greater than
|
||
* `INT64_MAX` in fact: in this case, we need to
|
||
* subtract `INT64_MAX` from `value_ns_unsigned`, make
|
||
* sure that the difference is less than `INT64_MAX`,
|
||
* and try to add them one after the other to
|
||
* `*ns_from_origin`.
|
||
*/
|
||
ret = -1;
|
||
goto end;
|
||
}
|
||
value_ns_signed = (int64_t) value_ns_unsigned;
|
||
BT_ASSERT_DBG(value_ns_signed >= 0);
|
||
value_ns_signed = bt_util_ns_from_value(frequency, value);
|
||
if (*ns_from_origin <= 0) {
|
||
goto add_value;
|
src/lib/util.c | ||
---|---|---|
bt_util_clock_cycles_to_ns_from_origin_status
|
||
bt_util_clock_cycles_to_ns_from_origin(uint64_t cycles,
|
||
uint64_t frequency, int64_t offset_seconds,
|
||
uint64_t offset_cycles, int64_t *ns)
|
||
int64_t offset_cycles, int64_t *ns)
|
||
{
|
||
bool overflows;
|
||
int64_t base_offset_ns;
|
||
... | ... | |
BT_ASSERT_PRE_NON_NULL(ns, "Nanoseconds (output)");
|
||
BT_ASSERT_PRE(frequency != UINT64_C(-1) && frequency != 0,
|
||
"Invalid frequency: freq=%" PRIu64, frequency);
|
||
BT_ASSERT_PRE(offset_cycles < frequency,
|
||
BT_ASSERT_PRE(llabs(offset_cycles) < frequency,
|
||
"Offset (cycles) is greater than frequency: "
|
||
"offset-cycles=%" PRIu64 ", freq=%" PRIu64,
|
||
offset_cycles, frequency);
|
src/plugins/ctf/common/metadata/ctf-meta.h | ||
---|---|---|
uint64_t frequency;
|
||
uint64_t precision;
|
||
int64_t offset_seconds;
|
||
uint64_t offset_cycles;
|
||
int64_t offset_cycles;
|
||
bt_uuid_t uuid;
|
||
bool has_uuid;
|
||
bool is_absolute;
|
src/plugins/ctf/common/metadata/visitor-generate-ir.c | ||
---|---|---|
static
|
||
int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
|
||
struct ctf_clock_class *clock, int *set, int64_t *offset_seconds,
|
||
uint64_t *offset_cycles)
|
||
int64_t *offset_cycles)
|
||
{
|
||
int ret = 0;
|
||
char *left = NULL;
|
||
... | ... | |
goto error;
|
||
}
|
||
ret = get_unary_unsigned(ctx,
|
||
ret = get_unary_signed(
|
||
&entry_node->u.ctf_expression.right, offset_cycles);
|
||
if (ret) {
|
||
_BT_COMP_LOGE_NODE(entry_node,
|
||
... | ... | |
static
|
||
void calibrate_clock_class_offsets(int64_t *offset_seconds,
|
||
uint64_t *offset_cycles, uint64_t freq)
|
||
int64_t *offset_cycles, uint64_t freq)
|
||
{
|
||
if (*offset_cycles >= freq) {
|
||
const uint64_t s_in_offset_cycles = *offset_cycles / freq;
|
||
if (llabs(*offset_cycles) >= freq) {
|
||
const int64_t s_in_offset_cycles = *offset_cycles / freq;
|
||
*offset_seconds += (int64_t) s_in_offset_cycles;
|
||
*offset_cycles -= (s_in_offset_cycles * freq);
|
||
... | ... | |
int64_t offset_s_to_apply = ctx->decoder_config.clock_class_offset_s;
|
||
uint64_t offset_ns_to_apply;
|
||
int64_t cur_offset_s;
|
||
uint64_t cur_offset_cycles;
|
||
int64_t cur_offset_cycles;
|
||
if (ctx->decoder_config.clock_class_offset_s == 0 &&
|
||
ctx->decoder_config.clock_class_offset_ns == 0) {
|
||
... | ... | |
struct bt_list_head *decl_list = &clock_node->u.clock.declaration_list;
|
||
const char *clock_class_name;
|
||
int64_t offset_seconds = 0;
|
||
uint64_t offset_cycles = 0;
|
||
int64_t offset_cycles = 0;
|
||
uint64_t freq;
|
||
if (clock_node->visited) {
|
||
... | ... | |
*/
|
||
freq = clock->frequency;
|
||
calibrate_clock_class_offsets(&offset_seconds, &offset_cycles, freq);
|
||
BT_ASSERT(offset_cycles < clock->frequency);
|
||
BT_ASSERT(llabs(offset_cycles) < clock->frequency);
|
||
clock->offset_seconds = offset_seconds;
|
||
clock->offset_cycles = offset_cycles;
|
||
apply_clock_class_offset(ctx, clock);
|
src/plugins/ctf/fs-sink/translate-ctf-ir-to-tsdl.c | ||
---|---|---|
if (sc->default_clock_class) {
|
||
const char *descr;
|
||
int64_t offset_seconds;
|
||
uint64_t offset_cycles;
|
||
int64_t offset_cycles;
|
||
bt_uuid uuid;
|
||
append_indent(ctx);
|
||
... | ... | |
g_string_append_printf(ctx->tsdl, "offset_s = %" PRId64 ";\n",
|
||
offset_seconds);
|
||
append_indent(ctx);
|
||
g_string_append_printf(ctx->tsdl, "offset = %" PRIu64 ";\n",
|
||
g_string_append_printf(ctx->tsdl, "offset = %" PRId64 ";\n",
|
||
offset_cycles);
|
||
append_indent(ctx);
|
||
g_string_append(ctx->tsdl, "absolute = ");
|
src/plugins/lttng-utils/debug-info/trace-ir-metadata-copy.c | ||
---|---|---|
enum debug_info_trace_ir_mapping_status status;
|
||
const char *clock_class_name, *clock_class_description;
|
||
int64_t seconds;
|
||
uint64_t cycles;
|
||
int64_t cycles;
|
||
bt_uuid in_uuid;
|
||
BT_COMP_LOGD("Copying content of clock class: in-cc-addr=%p, out-cc-addr=%p",
|
src/plugins/text/details/write.c | ||
---|---|---|
const bt_clock_class *cc)
|
||
{
|
||
int64_t offset_seconds;
|
||
uint64_t offset_cycles;
|
||
int64_t offset_cycles;
|
||
const char *str;
|
||
str = bt_clock_class_get_name(cc);
|
src/plugins/utils/trimmer/trimmer.c | ||
---|---|---|
{
|
||
int64_t cc_offset_s;
|
||
uint64_t cc_offset_cycles;
|
||
int64_t cc_offset_cycles;
|
||
uint64_t cc_freq;
|
||
bt_clock_class_get_offset(clock_class, &cc_offset_s, &cc_offset_cycles);
|