[Devel] [PATCH RHEL9 COMMIT] syslog: Virtualize timestamps in the data reported

Konstantin Khorenko khorenko at virtuozzo.com
Tue Feb 21 16:47:30 MSK 2023


The commit is pushed to "branch-rh9-5.14.0-162.6.1.vz9.18.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-162.6.1.vz9.18.11
------>
commit cd67ec32fb15bec06613b619c231e928326531af
Author: Konstantin Khorenko <khorenko at virtuozzo.com>
Date:   Tue Feb 7 20:42:56 2023 +0300

    syslog: Virtualize timestamps in the data reported
    
    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>
    Reviewed-by: Alexander Atanasov <alexander.atanasov at virtuozzo.com>
    
    Feature: time: per-CT virtualization enhancements
---
 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 4db25f4e3e8c..469bc7d0577f 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);


More information about the Devel mailing list