Skip to content

Commit a9357c2

Browse files
committed
journal: introduce _SOURCE_BOOTTIME_TIMESTAMP field
Then, fix the monotonic timestamp. The _SOURCE_MONOTONIC_TIMESTAMP field is already used in other projects. Hence, we cannot remove the field. But, let's store the correct value. The existence of the new _SOURCE_BOOTTIME_TIMESTAMP field can indicate that the monotonic timestamp field is reliable or not.
1 parent 36cb02e commit a9357c2

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/journal/journald-kmsg.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,17 @@ void dev_kmsg_record(Server *s, char *p, size_t l) {
253253
}
254254
}
255255

256-
char source_time[STRLEN("_SOURCE_MONOTONIC_TIMESTAMP=") + DECIMAL_STR_MAX(unsigned long long)];
257-
xsprintf(source_time, "_SOURCE_MONOTONIC_TIMESTAMP=%llu", usec);
258-
iovec[n++] = IOVEC_MAKE_STRING(source_time);
256+
char source_boot_time[STRLEN("_SOURCE_BOOTTIME_TIMESTAMP=") + DECIMAL_STR_MAX(unsigned long long)];
257+
xsprintf(source_boot_time, "_SOURCE_BOOTTIME_TIMESTAMP=%llu", usec);
258+
iovec[n++] = IOVEC_MAKE_STRING(source_boot_time);
259+
260+
/* Historically, we stored the timestamp 'usec' as _SOURCE_MONOTONIC_TIMESTAMP, so we cannot remove
261+
* the field as it is already used in other projects. So, let's store the correct timestamp here by
262+
* mapping the boottime to monotonic. Then, the existence of _SOURCE_BOOTTIME_TIMESTAMP indicates
263+
* the reliability of _SOURCE_MONOTONIC_TIMESTAMP field. */
264+
char source_monotonic_time[STRLEN("_SOURCE_MONOTONIC_TIMESTAMP=") + DECIMAL_STR_MAX(unsigned long long)];
265+
xsprintf(source_monotonic_time, "_SOURCE_MONOTONIC_TIMESTAMP="USEC_FMT, map_clock_usec(usec, CLOCK_BOOTTIME, CLOCK_MONOTONIC));
266+
iovec[n++] = IOVEC_MAKE_STRING(source_monotonic_time);
259267

260268
iovec[n++] = IOVEC_MAKE_STRING("_TRANSPORT=kernel");
261269

0 commit comments

Comments
 (0)