char msg[ZLOGGER_MSG_MAX];
char *buffer;
size_t buffer_len;
+ uint64_t last_ts;
};
/* --zlogger file channel */
return -ENOMEM;
}
zlog_file_data->buffer_len = LOG_BUFFER_SIZE;
+ zlog_file_data->last_ts = 0;
filep->private_data = (void *)zlog_file_data;
return 0;
}
return 0;
}
-static int _zlog_write(const unsigned char prio, const char *tag, const char *msg)
+static int _zlog_write(const unsigned char prio, const char *tag, const char *msg, uint64_t *last_ts)
{
uint64_t ts = ktime_get_ns();
uint16_t *slt = (uint16_t *)&ts;
return -EFAULT;
}
+ /* Ensure that the timestamp is increasing, as opposed to
+ * merely not decreasing. This is done to make sure that
+ * logs can be sorted (which can be ambiguous if there are
+ * multiple valid logs with the same timestamp). */
+ if (*last_ts >= ts)
+ ts = *last_ts + 1;
+ *last_ts = ts;
+
tmp.time = ts;
tmp.CRC = slt[0] + slt[1] + slt[2] + slt[3];
tmp.len = (uint16_t)entry_size - hd_size;
{
char *cb = (char *)zlog_file_data->buffer;
char *buffer = (char *)zlog_file_data->buffer;
+ uint64_t *last_ts = &zlog_file_data->last_ts;
endl_to_zero(zlog_file_data, len);
cb++;
continue;
}
- res = _zlog_write((const unsigned char)zlog_file_data->prio, (const char *)&zlog_file_data->tag, (const char *)cb);
+ res = _zlog_write((const unsigned char)zlog_file_data->prio, (const char *)&zlog_file_data->tag, (const char *)cb, last_ts);
if (res < 0) {
pr_err("_zlog_write failed\n");
return -EFAULT;