linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] printk: add sleep time into timestamp
@ 2014-04-01  3:20 Neil Zhang
  2014-04-05  0:58 ` John Stultz
  0 siblings, 1 reply; 2+ messages in thread
From: Neil Zhang @ 2014-04-01  3:20 UTC (permalink / raw)
  To: akpm; +Cc: john.stultz, linux-kernel, Neil Zhang

Add sleep time into timestamp to reflect the actual time since
sched_clock will be stopped during suspend.

Thanks John Stultz for suggestion to use monotonic_to_bootbased.

Signed-off-by: Neil Zhang <zhangwm@marvell.com>
---
 kernel/printk/printk.c |   16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 4dae9cb..121f792 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -250,6 +250,18 @@ static char __log_buf[__LOG_BUF_LEN] __aligned(LOG_ALIGN);
 static char *log_buf = __log_buf;
 static u32 log_buf_len = __LOG_BUF_LEN;
 
+static u64 print_clock(void)
+{
+	struct timespec	ts;
+	u64 ts_nsec = local_clock();
+
+	ts = ns_to_timespec(ts_nsec);
+	monotonic_to_bootbased(&ts);
+	ts_nsec = timespec_to_ns(&ts);
+
+	return ts_nsec;
+}
+
 /* cpu currently holding logbuf_lock */
 static volatile unsigned int logbuf_cpu = UINT_MAX;
 
@@ -349,7 +361,7 @@ static void log_store(int facility, int level,
 	if (ts_nsec > 0)
 		msg->ts_nsec = ts_nsec;
 	else
-		msg->ts_nsec = local_clock();
+		msg->ts_nsec = print_clock();
 	memset(log_dict(msg) + dict_len, 0, pad_len);
 	msg->len = sizeof(struct printk_log) + text_len + dict_len + pad_len;
 
@@ -1440,7 +1452,7 @@ static bool cont_add(int facility, int level, const char *text, size_t len)
 		cont.facility = facility;
 		cont.level = level;
 		cont.owner = current;
-		cont.ts_nsec = local_clock();
+		cont.ts_nsec = print_clock();
 		cont.flags = 0;
 		cont.cons = 0;
 		cont.flushed = false;
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH V2] printk: add sleep time into timestamp
  2014-04-01  3:20 [PATCH V2] printk: add sleep time into timestamp Neil Zhang
@ 2014-04-05  0:58 ` John Stultz
  0 siblings, 0 replies; 2+ messages in thread
From: John Stultz @ 2014-04-05  0:58 UTC (permalink / raw)
  To: Neil Zhang, akpm; +Cc: linux-kernel, Lei Wen, Peter Zijlstra

On 03/31/2014 08:20 PM, Neil Zhang wrote:
> Add sleep time into timestamp to reflect the actual time since
> sched_clock will be stopped during suspend.
>
> Thanks John Stultz for suggestion to use monotonic_to_bootbased.
>
> Signed-off-by: Neil Zhang <zhangwm@marvell.com>
> ---
>  kernel/printk/printk.c |   16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index 4dae9cb..121f792 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -250,6 +250,18 @@ static char __log_buf[__LOG_BUF_LEN] __aligned(LOG_ALIGN);
>  static char *log_buf = __log_buf;
>  static u32 log_buf_len = __LOG_BUF_LEN;
>  
> +static u64 print_clock(void)
> +{
> +	struct timespec	ts;
> +	u64 ts_nsec = local_clock();
> +
> +	ts = ns_to_timespec(ts_nsec);
> +	monotonic_to_bootbased(&ts);
> +	ts_nsec = timespec_to_ns(&ts);
> +

Note that this is still problematic as monotonic_to_bootbased currently
doesn't take the required locks to ensure it reads the data atomically.

If it were fixed to take the proper locks, this would risk a deadlock
since there are places where the timekeeping code takes a write on the
seqlock and then may call printk (or WARN_ON).

I suspect if this is going to be done, we need to have the timekeeping
provide the print_clock subsystem the boottime offset when it is changed
so the print_clock logic can manage this w/o grabbing timekeeping locks.
But as I mentioned in reply to Lei's similar patches, I'm not a huge fan
of the added complexity that will be required here when userspace like
syslog can timestamps kernel messages already (so additional rational
will be needed to move this forward).

thanks
-john

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-04-05  0:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-01  3:20 [PATCH V2] printk: add sleep time into timestamp Neil Zhang
2014-04-05  0:58 ` John Stultz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).