Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1384219

Re: [PATCH 0/2 v6] printk, Add monotonic and real printk timestamps

From Prarit Bhargava <prarit@redhat.com>
Newsgroups linux.kernel
Subject Re: [PATCH 0/2 v6] printk, Add monotonic and real printk timestamps
Date 2016-04-21 15:30 +0200
Message-ID <rqmQb-1lx-45@gated-at.bofh.it> (permalink)
References (1 earlier) <rakSn-6EA-33@gated-at.bofh.it> <ranGy-8tF-29@gated-at.bofh.it> <rb5HA-5r7-21@gated-at.bofh.it> <rpjrk-7Ud-17@gated-at.bofh.it> <rpzFM-3WK-17@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw



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 anderson@redhat.com 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.

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: [PATCH 0/2 v6] printk, Add monotonic and real printk timestamps Prarit Bhargava <prarit@redhat.com> - 2016-04-18 17:40 +0200
  Re: [PATCH 0/2 v6] printk, Add monotonic and real printk timestamps Petr Mladek <pmladek@suse.com> - 2016-04-19 11:00 +0200
    Re: [PATCH 0/2 v6] printk, Add monotonic and real printk timestamps Prarit Bhargava <prarit@redhat.com> - 2016-04-20 19:10 +0200
    Re: [PATCH 0/2 v6] printk, Add monotonic and real printk timestamps Prarit Bhargava <prarit@redhat.com> - 2016-04-21 15:30 +0200
      Re: [PATCH 0/2 v6] printk, Add monotonic and real printk timestamps Petr Mladek <pmladek@suse.com> - 2016-04-26 15:10 +0200

csiph-web