Blame SOURCES/0007-Move-the-initialization-of-boot_date-to-task_init.patch

e039e7
From fa0b6453a05c5600849e4e531c94594ed9c90270 Mon Sep 17 00:00:00 2001
e039e7
From: Lianbo Jiang <lijiang@redhat.com>
e039e7
Date: Mon, 17 Jan 2022 15:14:00 +0800
e039e7
Subject: [PATCH 07/11] Move the initialization of "boot_date" to task_init()
e039e7
e039e7
The "boot_date" is initialized conditionally in the cmd_log(), which may
e039e7
display incorrect "boot_date" value with the following command before
e039e7
running the "log -T" command:
e039e7
e039e7
crash> help -k | grep date
e039e7
          date: Wed Dec 22 13:39:29 IST 2021
e039e7
     boot_date: Thu Jan  1 05:30:00 IST 1970
e039e7
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e039e7
The calculation of "boot_date" depends on the HZ value, and the HZ will
e039e7
be calculated in task_init() at the latest, so let's move it here.
e039e7
e039e7
Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
e039e7
---
e039e7
 kernel.c | 18 +++---------------
e039e7
 task.c   | 10 ++++++++++
e039e7
 2 files changed, 13 insertions(+), 15 deletions(-)
e039e7
e039e7
diff --git a/kernel.c b/kernel.c
e039e7
index a44a9c52ace0..9afddc0c918c 100644
e039e7
--- a/kernel.c
e039e7
+++ b/kernel.c
e039e7
@@ -5026,21 +5026,9 @@ cmd_log(void)
e039e7
         if (argerrs)
e039e7
                 cmd_usage(pc->curcmd, SYNOPSIS);
e039e7
 
e039e7
-	if (msg_flags & SHOW_LOG_CTIME) {
e039e7
-		if (pc->flags & MINIMAL_MODE) {
e039e7
-			error(WARNING, "the option '-T' is not available in minimal mode\n");
e039e7
-			return;
e039e7
-		}
e039e7
-
e039e7
-		if (kt->boot_date.tv_sec == 0) {
e039e7
-			ulonglong uptime_jiffies;
e039e7
-			ulong  uptime_sec;
e039e7
-
e039e7
-			get_uptime(NULL, &uptime_jiffies);
e039e7
-			uptime_sec = (uptime_jiffies)/(ulonglong)machdep->hz;
e039e7
-			kt->boot_date.tv_sec = kt->date.tv_sec - uptime_sec;
e039e7
-			kt->boot_date.tv_nsec = 0;
e039e7
-		}
e039e7
+	if (msg_flags & SHOW_LOG_CTIME && pc->flags & MINIMAL_MODE) {
e039e7
+		error(WARNING, "the option '-T' is not available in minimal mode\n");
e039e7
+		return;
e039e7
 	}
e039e7
 
e039e7
 	if (msg_flags & SHOW_LOG_AUDIT) {
e039e7
diff --git a/task.c b/task.c
e039e7
index 76e184ae70b1..263a8344dd94 100644
e039e7
--- a/task.c
e039e7
+++ b/task.c
e039e7
@@ -692,6 +692,16 @@ task_init(void)
e039e7
 
e039e7
 	stack_overflow_check_init();
e039e7
 
e039e7
+	if (machdep->hz) {
e039e7
+		ulonglong uptime_jiffies;
e039e7
+		ulong  uptime_sec;
e039e7
+
e039e7
+		get_uptime(NULL, &uptime_jiffies);
e039e7
+		uptime_sec = (uptime_jiffies)/(ulonglong)machdep->hz;
e039e7
+		kt->boot_date.tv_sec = kt->date.tv_sec - uptime_sec;
e039e7
+		kt->boot_date.tv_nsec = 0;
e039e7
+	}
e039e7
+
e039e7
 	tt->flags |= TASK_INIT_DONE;
e039e7
 }
e039e7
 
e039e7
-- 
e039e7
2.20.1
e039e7