On 04/19/2016 04:56 AM, Petr Mladek wrote:
> On Mon 2016-04-18 11:30:52, Prarit Bhargava wrote:

> Hmm, If you allow to change the timestamp format only at boot time, it
> will make things easier. I just wonder if it would work correctly for
> early messages. For example, are there any messages printed before
> the real time clock is initialized? Which timestamp will they use?
>
> Also note that you still need to modify the dmesg code. It must
> not add boot_time when real time timestamp is used.
>

I've got a util-linux patch in-hand that does this (sorry for the
cut-and-paste) and I've verified that ctime, delta, iso, notime and
reltime all appear to work 1) without my kernel patches applied,
2) with my kernel patches applied, and 3) with printk.time=[0-3]
as kernel parameters.

diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index cf93331..c49a202 100644
--- a/sys-utils/dmesg.c
+++ b/sys-utils/dmesg.c
@@ -1194,9 +1194,31 @@ static int which_time_format(const char *optarg)
        errx(EXIT_FAILURE, _("unknown time format: %s"), optarg);
 }

-#ifdef TEST_DMESG
+static int needs_boot_time(void)
+{
+       FILE *fd;
+       int ret = 1;
+       int val;
+
+       /*
+        * Newer kernels have /sys/modules/printk/parameter/time = [0-3]
+        * where 0 = off, 1 = local clock, 2 = boot time, and 3 = real time.
+        * If the file isn't present it means the functionality isn't there
+        * and the boot_time offset is needed.
+        */
+       fd = fopen("/sys/module/printk/parameters/time", "r");
+       if (!fd)
+               return ret;
+       fscanf(fd, "%d", &val);
+       if (val == 3)
+               ret = 0;
+       fclose(fd);
+       return ret;
+}
+
 static inline int dmesg_get_boot_time(struct timeval *tv)
 {
+#ifdef TEST_DMESG
        char *str = getenv("DMESG_TEST_BOOTIME");
        uintmax_t sec, usec;

@@ -1205,12 +1227,15 @@ static inline int dmesg_get_boot_time(struct timeval 
*tv)
                tv->tv_usec = usec;
                return tv->tv_sec >= 0 && tv->tv_usec >= 0 ? 0 : -EINVAL;
        }
+#endif
+
+       if (needs_boot_time())
+               return get_boot_time(tv);

-       return get_boot_time(tv);
+       tv->tv_sec = 0;
+       tv->tv_usec = 0;
+       return 0;
 }
-#else
-# define dmesg_get_boot_time   get_boot_time
-#endif

 int main(int argc, char *argv[])
 {
-- 
1.8.3.1

> And you need to modify also the other tools, e.g. crash.
>

I spoke with [email protected] this morning and he agrees
that no change should be necessary for crash.  A quick test shows that
the logging mechanism (dmesg or log) works after the patches are applied
and printk is in REALTIME mode.

IMO dmesg is the big one and I will modify that after I see acceptance
of this patch.

P.

Reply via email to