Skip to contentSkip to conversation

pm_trace displays the wrong time from the RTC

DISCUSSION Chuck Ebbert 5 participants 11 messages Jul 31, 2007 – Oct 17, 2007

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

When resuming, systems print this when booted on 07/31/07:

Date: 06/31/107

/drivers/base/power/trace.c::read_magic_time():
114 get_rtc_time(&time);
115 printk("Time: %2d:%02d:%02d Date: %02d/%02d/%02d\n",
116 time.tm_hour, time.tm_min, time.tm_sec,
117 time.tm_mon, time.tm_mday, time.tm_year);

include/asm-generic/rtc.h:
102 /*

103          * Account for differences between how the RTC uses the values
104          * and how they are defined in a struct rtc_time;
105          */

106 if (time->tm_year <= 69)
107 time->tm_year += 100;
108
109 time->tm_mon--;

#1 lore raw
Quoted 12 lines · On Tue, 31 Jul 2007 17:20:10 -0400 Chuck Ebbert wrote:

When resuming, systems print this when booted on 07/31/07:

Date: 06/31/107

/drivers/base/power/trace.c::read_magic_time():
114 get_rtc_time(&time);
115 printk("Time: %2d:%02d:%02d Date: %02d/%02d/%02d\n",
116 time.tm_hour, time.tm_min, time.tm_sec,
117 time.tm_mon, time.tm_mday, time.tm_year);

include/asm-generic/rtc.h:
102 /*

Quoted 7 lines
103          * Account for differences between how the RTC uses the values
104          * and how they are defined in a struct rtc_time;
105          */

106 if (time->tm_year <= 69)
107 time->tm_year += 100;
108
109 time->tm_mon--;

That's this config option (read all of it):

config PM_TRACE
bool "Suspend/resume event tracing"
depends on PM_DEBUG && X86 && EXPERIMENTAL
default n
---help---
This enables some cheesy code to save the last PM event point in the RTC across reboots, so that you can debug a machine that just hangs during suspend (or more commonly, during resume).

To use this debugging feature you should attempt to suspend the machine, then reboot it, then run

dmesg -s 1000000 | grep 'hash matches'

CAUTION: this option will cause your machine's real-time clock to be set to an invalid time after a resume.

---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

#2 lore raw
Quoted 24 lines · Randy Dunlap
Quoted 9 lines · On Tue, 31 Jul 2007 17:20:10 -0400 Chuck Ebbert wrote:

include/asm-generic/rtc.h:
102 /*

103          * Account for differences between how the RTC uses the values
104          * and how they are defined in a struct rtc_time;
105          */

106 if (time->tm_year <= 69)
107 time->tm_year += 100;
108
109 time->tm_mon--;

That's this config option (read all of it):

config PM_TRACE
bool "Suspend/resume event tracing"
depends on PM_DEBUG && X86 && EXPERIMENTAL
default n
---help---
This enables some cheesy code to save the last PM event point in the RTC across reboots, so that you can debug a machine that just hangs during suspend (or more commonly, during resume).

Quoted 7 lines

To use this debugging feature you should attempt to suspend the machine, then reboot it, then run

dmesg -s 1000000 | grep 'hash matches'

CAUTION: this option will cause your machine's real-time clock to be set to an invalid time after a resume.

Doesn't this only take effect if you've been poking /sys/power/pm_trace though ? Also, look at the date in the output from Chuck. It looks like only the year is wrong. I'd have expected more than just the century byte to have been corrupted.

That +100 heuristic seems really odd to me. Possibly it needs to be checking if the century byte is set/unset, or it needs additional clamping to make sure it doesn't overflow.

Dave

Signature · 1 line
http://www.codemonkey.org.uk
#3 lore raw
Quoted 28 lines · On Tue, 31 Jul 2007 17:56:09 -0400 Dave Jones wrote:
Quoted 27 lines · Randy Dunlap
Quoted 9 lines · On Tue, 31 Jul 2007 17:20:10 -0400 Chuck Ebbert wrote:

include/asm-generic/rtc.h:
102 /*

103          * Account for differences between how the RTC uses the values
104          * and how they are defined in a struct rtc_time;
105          */

106 if (time->tm_year <= 69)
107 time->tm_year += 100;
108
109 time->tm_mon--;

That's this config option (read all of it):

config PM_TRACE
bool "Suspend/resume event tracing"
depends on PM_DEBUG && X86 && EXPERIMENTAL
default n
---help---
This enables some cheesy code to save the last PM event point in the RTC across reboots, so that you can debug a machine that just hangs during suspend (or more commonly, during resume).

To use this debugging feature you should attempt to suspend the machine, then reboot it, then run

Quoted 6 lines
Quoted 4 lines

dmesg -s 1000000 | grep 'hash matches'

CAUTION: this option will cause your machine's real-time clock to be set to an invalid time after a resume.

Doesn't this only take effect if you've been poking /sys/power/pm_trace though ?

Looks like only if /sys/power/pm_trace is enabled, yes.

Quoted 3 lines

Also, look at the date in the output from Chuck. It looks like only the year is wrong. I'd have expected more than just the century byte to have been corrupted.

and month, but the code snippet that he posted accounts for that also.

Quoted 3 lines

That +100 heuristic seems really odd to me. Possibly it needs to be checking if the century byte is set/unset, or it needs additional clamping to make sure it doesn't overflow.

OK, worth looking into...

---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

#4 lore raw
In reply to Chuck Ebbert

Sorry for slow response, I've just noticed this thread.

Quoted 12 lines · Chuck Ebbert

When resuming, systems print this when booted on 07/31/07:

Date: 06/31/107

/drivers/base/power/trace.c::read_magic_time():
114 get_rtc_time(&time);
115 printk("Time: %2d:%02d:%02d Date: %02d/%02d/%02d\n",
116 time.tm_hour, time.tm_min, time.tm_sec,
117 time.tm_mon, time.tm_mday, time.tm_year);

include/asm-generic/rtc.h:
102 /*

Quoted 7 lines
103          * Account for differences between how the RTC uses the values
104          * and how they are defined in a struct rtc_time;
105          */

106 if (time->tm_year <= 69)
107 time->tm_year += 100;
108
109 time->tm_mon--;

Do you mean that systems display bad date after resuming if PM_TRACE is set, even if /sys/power/pm_trace contains 1 ?

If that's the case, are they i386 or x86_64?

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#5 lore raw
Quoted 23 lines · Rafael J. Wysocki

Sorry for slow response, I've just noticed this thread.

Quoted 12 lines · Chuck Ebbert

When resuming, systems print this when booted on 07/31/07:

Date: 06/31/107

/drivers/base/power/trace.c::read_magic_time():
114 get_rtc_time(&time);
115 printk("Time: %2d:%02d:%02d Date: %02d/%02d/%02d\n",
116 time.tm_hour, time.tm_min, time.tm_sec,
117 time.tm_mon, time.tm_mday, time.tm_year);

include/asm-generic/rtc.h:
102 /*

Quoted 7 lines
103          * Account for differences between how the RTC uses the values
104          * and how they are defined in a struct rtc_time;
105          */

106 if (time->tm_year <= 69)
107 time->tm_year += 100;
108
109 time->tm_mon--;

Quoted 2 lines

Do you mean that systems display bad date after resuming if PM_TRACE is set, even if /sys/power/pm_trace contains 1 ?

s/1/0/ (sorry)

#6 lore raw
In reply to Rafael J. Wysocki
Quoted 23 lines · Rafael J. Wysocki

Sorry for slow response, I've just noticed this thread.

Quoted 12 lines · Chuck Ebbert

When resuming, systems print this when booted on 07/31/07:

Date: 06/31/107

/drivers/base/power/trace.c::read_magic_time():
114 get_rtc_time(&time);
115 printk("Time: %2d:%02d:%02d Date: %02d/%02d/%02d\n",
116 time.tm_hour, time.tm_min, time.tm_sec,
117 time.tm_mon, time.tm_mday, time.tm_year);

include/asm-generic/rtc.h:
102 /*

Quoted 7 lines
103          * Account for differences between how the RTC uses the values
104          * and how they are defined in a struct rtc_time;
105          */

106 if (time->tm_year <= 69)
107 time->tm_year += 100;
108
109 time->tm_mon--;

Quoted 5 lines

Do you mean that systems display bad date after resuming if PM_TRACE is set, even if /sys/power/pm_trace contains 1 ?

If that's the case, are they i386 or x86_64?

i386:

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=250238

#7 lore raw
Quoted 27 lines · Chuck Ebbert
Quoted 26 lines · Rafael J. Wysocki

Sorry for slow response, I've just noticed this thread.

Quoted 12 lines · Chuck Ebbert

When resuming, systems print this when booted on 07/31/07:

Date: 06/31/107

/drivers/base/power/trace.c::read_magic_time():
114 get_rtc_time(&time);
115 printk("Time: %2d:%02d:%02d Date: %02d/%02d/%02d\n",
116 time.tm_hour, time.tm_min, time.tm_sec,
117 time.tm_mon, time.tm_mday, time.tm_year);

include/asm-generic/rtc.h:
102 /*

Quoted 7 lines
103          * Account for differences between how the RTC uses the values
104          * and how they are defined in a struct rtc_time;
105          */

106 if (time->tm_year <= 69)
107 time->tm_year += 100;
108
109 time->tm_mon--;

Do you mean that systems display bad date after resuming if PM_TRACE is set, even if /sys/power/pm_trace contains 1 ?

Quoted 6 lines
Quoted 2 lines

If that's the case, are they i386 or x86_64?

i386:

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=250238

OK, I now see what you mean.

On my x86_64 test box this also happens after a fresh boot without suspending/resuming, so I think the problem is that we just shouldn't add 100 to the year and decrease the month in get_rtc_time().

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#8 lore raw
In reply to Chuck Ebbert
Quoted 24 lines · Chuck Ebbert
Quoted 23 lines · Rafael J. Wysocki

Sorry for slow response, I've just noticed this thread.

Quoted 19 lines · Chuck Ebbert

When resuming, systems print this when booted on 07/31/07:

Date: 06/31/107

/drivers/base/power/trace.c::read_magic_time():
114 get_rtc_time(&time);
115 printk("Time: %2d:%02d:%02d Date: %02d/%02d/%02d\n",
116 time.tm_hour, time.tm_min, time.tm_sec,
117 time.tm_mon, time.tm_mday, time.tm_year);

include/asm-generic/rtc.h:
102 /*

103          * Account for differences between how the RTC uses the values
104          * and how they are defined in a struct rtc_time;
105          */

106 if (time->tm_year <= 69)
107 time->tm_year += 100;
108
109 time->tm_mon--;

Quoted 2 lines
Quoted 2 lines

Do you mean that systems display bad date after resuming if PM_TRACE is set, even if /sys/power/pm_trace contains 1 ?

s/1/0/

Quoted 6 lines
Quoted 2 lines

If that's the case, are they i386 or x86_64?

i386:

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=250238

OK, I think the appended patch is needed.

Greetings,
Rafael

---
The way in which read_magic_time() displays the date read from the RTC is apparently confusing to the users
(cf. https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=250238). Make it print dates in the standard way.

---
 drivers/base/power/trace.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/power/trace.c +1 -1
Index: linux-2.6.23-rc1/drivers/base/power/trace.c
===================================================================
@@ -114,7 +114,7 @@ static unsigned int read_magic_time(void
 	get_rtc_time(&time);
 	printk("Time: %2d:%02d:%02d  Date: %02d/%02d/%02d\n",
 		time.tm_hour, time.tm_min, time.tm_sec,
-		time.tm_mon, time.tm_mday, time.tm_year);
+		time.tm_mon + 1, time.tm_mday, time.tm_year % 100);
 	val = time.tm_year;				/* 100 years */
 	if (val > 100)
 		val -= 100;
Acked-by
#9 lore raw

The patch below seems to have got dropped on the floor. We've had it in Fedora since it was posted, and it does the right thing, so I'm happy to give this an

if it helps it into upstream.

Dave

Quoted 67 lines · Rafael J. Wysocki
Quoted 24 lines · Rafael J. Wysocki
Quoted 23 lines

Sorry for slow response, I've just noticed this thread.

Quoted 19 lines · Chuck Ebbert

When resuming, systems print this when booted on 07/31/07:

Date: 06/31/107

/drivers/base/power/trace.c::read_magic_time():
114 get_rtc_time(&time);
115 printk("Time: %2d:%02d:%02d Date: %02d/%02d/%02d\n",
116 time.tm_hour, time.tm_min, time.tm_sec,
117 time.tm_mon, time.tm_mday, time.tm_year);

include/asm-generic/rtc.h:
102 /*

103          * Account for differences between how the RTC uses the values
104          * and how they are defined in a struct rtc_time;
105          */

106 if (time->tm_year <= 69)
107 time->tm_year += 100;
108
109 time->tm_mon--;

Quoted 2 lines
Quoted 2 lines

Do you mean that systems display bad date after resuming if PM_TRACE is set, even if /sys/power/pm_trace contains 1 ?

s/1/0/

Quoted 6 lines
Quoted 2 lines

If that's the case, are they i386 or x86_64?

i386:

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=250238

OK, I think the appended patch is needed.

Greetings,
Rafael

---
The way in which read_magic_time() displays the date read from the RTC is apparently confusing to the users
(cf. https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=250238). Make it print dates in the standard way.

---
 drivers/base/power/trace.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux-2.6.23-rc1/drivers/base/power/trace.c
===================================================================

drivers/base/power/trace.c +1 -2
@@ -114,7 +114,7 @@ static unsigned int read_magic_time(void
 	get_rtc_time(&time);
 	printk("Time: %2d:%02d:%02d  Date: %02d/%02d/%02d\n",
 		time.tm_hour, time.tm_min, time.tm_sec,
-		time.tm_mon, time.tm_mday, time.tm_year);
+		time.tm_mon + 1, time.tm_mday, time.tm_year % 100);
 	val = time.tm_year;				/* 100 years */
 	if (val > 100)
 		val -= 100;
-
Quoted 4 lines

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

---end quoted text---

Signature · 1 line
http://www.codemonkey.org.uk
#10 lore raw
Quoted 7 lines · On Wed, 17 Oct 2007 15:48:40 -0400 Dave Jones <[email protected]> wrote:

The patch below seems to have got dropped on the floor. We've had it in Fedora since it was posted, and it does the right thing, so I'm happy to give this an

if it helps it into upstream.

I have it queued for 2.6.24, but the entire PM patch series is presently twiddling thumbs awaiting an acpi merge.