[Devel] [PATCH rh9 2/2] syslog: Virtualize timestamps in the data reported
Konstantin Khorenko
khorenko at virtuozzo.com
Wed Feb 8 15:20:09 MSK 2023
Internally log messages contain the timestamps relative to the Host boot
time, while Container could start much later than the Host boots and the
timestamps should be shifted accordingly.
Otherwise syslog() syscall reports incorrect timestamps.
Note:
* time_ns->offsets.boottime is (ve_uptime - host_uptime),
i.e. negative for Containers created on this Host
* ring buffer contains timestamps relative to the Host boot
=> we have to add the .boottime offset to the timestamp of Host
to get the msg entry timestamp relative to Container boottime.
Based on the vz7 commit
b44b2f8707da ("syslog: Virtualize timestamps in the data reported")
https://jira.sw.ru/browse/PSBM-145313
Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
---
kernel/printk/printk.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 9ba2fbfe8ccb..00381de5f262 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1341,7 +1341,12 @@ static size_t print_syslog(unsigned int level, char *buf)
static size_t print_time(u64 ts, char *buf)
{
- unsigned long rem_nsec = do_div(ts, 1000000000);
+ unsigned long rem_nsec;
+
+ /* shift the timestamp on the Container uptime value */
+ ts = ve_timens_add_boottime_ns(ts);
+
+ rem_nsec = do_div(ts, 1000000000);
return sprintf(buf, "[%5lu.%06lu]",
(unsigned long)ts, rem_nsec / 1000);
--
2.31.1
More information about the Devel
mailing list