log -T option should not be support after system suspend

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,list


I notice a new option about "log -T",which translates the leading timestamp value of each message into human readable format.​i have checked the code,the implementation mainly consists of two steps:

1.use "kt->boot_date.tv_sec=kt->date.tv_sec - uptime_sec" to get system bootup time,uptime_sec is come from jiffies

2.use "kt->boot_date.tv_sec + nanos" to translates readable timestamp in every log entry.


This change does not take into account the system sleep,once system suspend this translation will make error,printk timestamp and jiffies won't be update during suspend,and system suspend is a common feature,so i think change is a bug.


As far as i know​ we can’t get the correct conversion time once the system sleeps.so we have to restrict​ this option only work in non-suspend state.

patch is attached.


wrong log:​
[Thu May  7 03:27:38 2020] PM: suspend entry 2020-05-06 19:22:40.481371186 UTC
[Thu May  7 03:27:38 2020] PM: suspend exit 2020-05-06 19:22:49.168938838 UTC
...
[Thu May  7 03:29:02 2020] PM: suspend entry 2020-05-06 19:28:54.366349876 UTC
[Thu May  7 03:29:03 2020] PM: suspend exit 2020-05-06 19:29:03.162471747 UTC


timestamp=utc+8


Thanks

#/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it!******/#
From 3b5702fd00b31481635575b39f90cd440e389e77 Mon Sep 17 00:00:00 2001
From: zhaoqianli <zhaoqianli@xxxxxxxxxx>
Date: Thu, 7 May 2020 19:58:30 +0800
Subject: [PATCH] bugfix for "log -T",this command only supports the case
 without suspend

Signed-off-by: zhaoqianli <zhaoqianli@xxxxxxxxxx>
---
 defs.h   |  2 ++
 kernel.c | 40 +++++++++++++++++++++++++++++++++++-----
 2 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/defs.h b/defs.h
index aba58ff..2464afc 100644
--- a/defs.h
+++ b/defs.h
@@ -2089,6 +2089,8 @@ struct offset_table {                    /* stash of commonly-used offsets */
 	long size_class_size;
 	long gendisk_private_data;
 	long zram_table_entry;
+	long timekeeper_offs_boot;
+	long timekeeper_sleep_time;
 };
 
 struct size_table {         /* stash of commonly-used sizes */
diff --git a/kernel.c b/kernel.c
index 5ed6021..0042101 100644
--- a/kernel.c
+++ b/kernel.c
@@ -95,6 +95,7 @@ static ulong __dump_audit(char *);
 static void dump_audit(void);
 static char *vmcoreinfo_read_string(const char *);
 static void check_vmcoreinfo(void);
+static uint64_t get_sleep_time(void);
 
 
 /*
@@ -222,6 +223,8 @@ kernel_init()
 	
 	MEMBER_OFFSET_INIT(timekeeper_xtime, "timekeeper", "xtime");
 	MEMBER_OFFSET_INIT(timekeeper_xtime_sec, "timekeeper", "xtime_sec");
+	MEMBER_OFFSET_INIT(timekeeper_offs_boot, "timekeeper", "offs_boot");
+	MEMBER_OFFSET_INIT(timekeeper_sleep_time, "timekeeper", "total_sleep_time");
 	get_xtime(&kt->date);
 	if (CRASHDEBUG(1))
 		fprintf(fp, "xtime timespec.tv_sec: %lx: %s\n", 
@@ -4941,11 +4944,16 @@ cmd_log(void)
 
 	if (kt->boot_date.tv_sec == 0) {
 		ulonglong uptime_jiffies;
-		ulong  uptime_sec;
-		get_uptime(NULL, &uptime_jiffies);
-		uptime_sec = (uptime_jiffies)/(ulonglong)machdep->hz;
-		kt->boot_date.tv_sec = kt->date.tv_sec - uptime_sec;
-		kt->boot_date.tv_nsec = 0;
+		ulong uptime_sec;
+		if (!get_sleep_time()) {
+			get_uptime(NULL, &uptime_jiffies);
+			uptime_sec = (uptime_jiffies)/(ulonglong)machdep->hz;
+			kt->boot_date.tv_sec = kt->date.tv_sec - uptime_sec;
+			kt->boot_date.tv_nsec = 0;
+		} else if (msg_flags & SHOW_LOG_CTIME) {
+			option_not_supported('T');
+			return;
+		}
 	}
 
 	if (msg_flags & SHOW_LOG_AUDIT) {
@@ -11476,3 +11484,25 @@ check_vmcoreinfo(void)
 		}
 	}
 }
+
+static uint64_t
+get_sleep_time(void)
+{
+	struct syment *sp;
+	struct timespec sleep_time;
+	uint64_t sleep_nsec;
+	if (VALID_MEMBER(timekeeper_offs_boot) &&
+		(sp = kernel_symbol_search("shadow_timekeeper"))) {
+			readmem(sp->value + OFFSET(timekeeper_offs_boot), KVADDR,
+				&sleep_nsec, sizeof(ulong), "shadow_timekeeper offs_boot", RETURN_ON_ERROR);
+	} else if (VALID_MEMBER(timekeeper_sleep_time) &&
+		(sp = kernel_symbol_search("timekeeper"))) {
+			readmem(sp->value + OFFSET(timekeeper_sleep_time), KVADDR,
+				&sleep_time, sizeof(struct timespec), "timekeeper total_sleep_time", RETURN_ON_ERROR);
+			sleep_nsec = (1000000000ULL*sleep_time.tv_sec) + sleep_time.tv_nsec;
+	} else if (kernel_symbol_exists("total_sleep_time")) {
+			get_symbol_data("total_sleep_time", sizeof(struct timespec), &sleep_time);
+			sleep_nsec = (1000000000ULL*sleep_time.tv_sec) + sleep_time.tv_nsec;
+	}
+	return sleep_nsec;
+}
\ No newline at end of file
-- 
2.7.4

--
Crash-utility mailing list
Crash-utility@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/crash-utility

[Index of Archives]     [Fedora Development]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]     [Fedora Tools]

 

Powered by Linux