From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751998AbcDUNUp (ORCPT ); Thu, 21 Apr 2016 09:20:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60115 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751340AbcDUNUn (ORCPT ); Thu, 21 Apr 2016 09:20:43 -0400 Message-ID: <5718D3A9.6070005@redhat.com> Date: Thu, 21 Apr 2016 09:20:41 -0400 From: Prarit Bhargava User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Petr Mladek CC: Thomas Gleixner , linux-kernel@vger.kernel.org, John Stultz , Xunlei Pang , Baolin Wang , Andrew Morton , Greg Kroah-Hartman , Tejun Heo , Peter Hurley , Vasily Averin , Joe Perches Subject: Re: [PATCH 0/2 v6] printk, Add monotonic and real printk timestamps References: <1456250040-22351-1-git-send-email-prarit@redhat.com> <56DEB17C.9000201@redhat.com> <20160310100012.GQ10940@pathway.suse.cz> <5714FDAC.4080208@redhat.com> <20160419085613.GJ6862@pathway.suse.cz> In-Reply-To: <20160419085613.GJ6862@pathway.suse.cz> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.