All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [1/5] Only do century BCD conversion when we know the RTC is BCD
@ 2008-02-09 15:16 Andi Kleen
  2008-02-09 15:16 ` [PATCH] [2/5] Use 2000 offset for 32bit kernels Andi Kleen
                   ` (4 more replies)
  0 siblings, 5 replies; 16+ messages in thread
From: Andi Kleen @ 2008-02-09 15:16 UTC (permalink / raw)
  To: tglx, mingo, linux-kernel


Minor logic fix. The century change was previously always BCD,
even when the CMOS data would report itself not being BCD.

Signed-off-by: Andi Kleen <ak@suse.de>

---
 arch/x86/kernel/rtc.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux/arch/x86/kernel/rtc.c
===================================================================
--- linux.orig/arch/x86/kernel/rtc.c
+++ linux/arch/x86/kernel/rtc.c
@@ -130,10 +130,10 @@ unsigned long mach_get_cmos_time(void)
 		BCD_TO_BIN(day);
 		BCD_TO_BIN(mon);
 		BCD_TO_BIN(year);
+		BCD_TO_BIN(century);
 	}
 
 	if (century) {
-		BCD_TO_BIN(century);
 		year += century * 100;
 		printk(KERN_INFO "Extended CMOS year: %d\n", century * 100);
 	} else {

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

* [PATCH] [2/5] Use 2000 offset for 32bit kernels
  2008-02-09 15:16 [PATCH] [1/5] Only do century BCD conversion when we know the RTC is BCD Andi Kleen
@ 2008-02-09 15:16 ` Andi Kleen
  2008-02-16 19:24   ` Thomas Gleixner
  2008-02-09 15:16 ` [PATCH] [3/5] Add warning when RTC clock reports binary Andi Kleen
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 16+ messages in thread
From: Andi Kleen @ 2008-02-09 15:16 UTC (permalink / raw)
  To: tglx, mingo, linux-kernel


We know it is already after 2000.

This extends the effective lifetime of 32bit systems by 8 years:
from 2030 to 2038.

The only drawback is that users cannot set the cmos date to before 2000
now on 32bit with systems that don't support extended century in 
the RTC clock. 64bit systems had this limitation for some time
and nobody complained.

And they can always set it to such a date in Linux only using date -s 
if they really want.

Signed-off-by: Andi Kleen <ak@suse.de>

---
 arch/x86/kernel/rtc.c |   10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

Index: linux/arch/x86/kernel/rtc.c
===================================================================
--- linux.orig/arch/x86/kernel/rtc.c
+++ linux/arch/x86/kernel/rtc.c
@@ -9,7 +9,6 @@
 #include <asm/vsyscall.h>
 
 #ifdef CONFIG_X86_32
-# define CMOS_YEARS_OFFS 1900
 /*
  * This is a special lock that is owned by the CPU and holds the index
  * register we are working with.  It is required for NMI access to the
@@ -17,14 +16,11 @@
  */
 volatile unsigned long cmos_lock = 0;
 EXPORT_SYMBOL(cmos_lock);
-#else
-/*
- * x86-64 systems only exists since 2002.
- * This will work up to Dec 31, 2100
- */
-# define CMOS_YEARS_OFFS 2000
 #endif
 
+/* For two digit years assume time is always after that */
+#define CMOS_YEARS_OFFS 2000
+
 DEFINE_SPINLOCK(rtc_lock);
 EXPORT_SYMBOL(rtc_lock);
 

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

* [PATCH] [3/5] Add warning when RTC clock reports binary
  2008-02-09 15:16 [PATCH] [1/5] Only do century BCD conversion when we know the RTC is BCD Andi Kleen
  2008-02-09 15:16 ` [PATCH] [2/5] Use 2000 offset for 32bit kernels Andi Kleen
@ 2008-02-09 15:16 ` Andi Kleen
  2008-02-16 19:38   ` Thomas Gleixner
  2008-02-09 15:17 ` [PATCH] [4/5] Fix wrong comment Andi Kleen
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 16+ messages in thread
From: Andi Kleen @ 2008-02-09 15:16 UTC (permalink / raw)
  To: tglx, mingo, linux-kernel


We tend to assume the RTC clock is BCD, so print a warning
if it claims to be binary.

Signed-off-by: Andi Kleen <ak@suse.de>

Index: linux/arch/x86/kernel/rtc.c
===================================================================
--- linux.orig/arch/x86/kernel/rtc.c
+++ linux/arch/x86/kernel/rtc.c
@@ -94,6 +94,8 @@ int mach_set_rtc_mmss(unsigned long nowt
 
 unsigned long mach_get_cmos_time(void)
 {
+	unsigned status;
+	static int warned;
 	unsigned int year, mon, day, hour, min, sec, century = 0;
 
 	/*
@@ -119,7 +121,13 @@ unsigned long mach_get_cmos_time(void)
 		century = CMOS_READ(acpi_gbl_FADT.century);
 #endif
 
-	if (RTC_ALWAYS_BCD || !(CMOS_READ(RTC_CONTROL) & RTC_DM_BINARY)) {
+	status = CMOS_READ(RTC_CONTROL);
+	if (RTC_ALWAYS_BCD && (status & RTC_DM_BINARY) && !warned) {
+		printk(KERN_INFO "RTC clock reports binary. Ignored\n");
+		warned = 1;
+	}
+
+	if (RTC_ALWAYS_BCD || !(status & RTC_DM_BINARY)) {
 		BCD_TO_BIN(sec);
 		BCD_TO_BIN(min);
 		BCD_TO_BIN(hour);

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

* [PATCH] [4/5] Fix wrong comment
  2008-02-09 15:16 [PATCH] [1/5] Only do century BCD conversion when we know the RTC is BCD Andi Kleen
  2008-02-09 15:16 ` [PATCH] [2/5] Use 2000 offset for 32bit kernels Andi Kleen
  2008-02-09 15:16 ` [PATCH] [3/5] Add warning when RTC clock reports binary Andi Kleen
@ 2008-02-09 15:17 ` Andi Kleen
  2008-02-09 15:17 ` [PATCH] [5/5] Enable ACPI extended century handling for 32bit too v2 Andi Kleen
  2008-02-11  8:30 ` [PATCH] [1/5] Only do century BCD conversion when we know the RTC is BCD Thomas Gleixner
  4 siblings, 0 replies; 16+ messages in thread
From: Andi Kleen @ 2008-02-09 15:17 UTC (permalink / raw)
  To: tglx, mingo, linux-kernel


It should operate in BCD mode.
Signed-off-by: Andi Kleen <ak@suse.de>

Index: linux/include/asm-x86/mc146818rtc.h
===================================================================
--- linux.orig/include/asm-x86/mc146818rtc.h
+++ linux/include/asm-x86/mc146818rtc.h
@@ -11,7 +11,7 @@
 
 #ifndef RTC_PORT
 #define RTC_PORT(x)	(0x70 + (x))
-#define RTC_ALWAYS_BCD	1	/* RTC operates in binary mode */
+#define RTC_ALWAYS_BCD	1	/* RTC operates in BCD mode */
 #endif
 
 #if defined(CONFIG_X86_32) && defined(__HAVE_ARCH_CMPXCHG)

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

* [PATCH] [5/5] Enable ACPI extended century handling for 32bit too v2
  2008-02-09 15:16 [PATCH] [1/5] Only do century BCD conversion when we know the RTC is BCD Andi Kleen
                   ` (2 preceding siblings ...)
  2008-02-09 15:17 ` [PATCH] [4/5] Fix wrong comment Andi Kleen
@ 2008-02-09 15:17 ` Andi Kleen
  2008-02-16 19:38   ` Thomas Gleixner
  2008-02-11  8:30 ` [PATCH] [1/5] Only do century BCD conversion when we know the RTC is BCD Thomas Gleixner
  4 siblings, 1 reply; 16+ messages in thread
From: Andi Kleen @ 2008-02-09 15:17 UTC (permalink / raw)
  To: tglx, mingo, linux-kernel


Not that it matters much, see comment in the code.

v2: Fix compilation on !ACPI, pointed out by tglx

Signed-off-by: Andi Kleen <ak@suse.de>

---
 arch/x86/kernel/rtc.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Index: linux/arch/x86/kernel/rtc.c
===================================================================
--- linux.orig/arch/x86/kernel/rtc.c
+++ linux/arch/x86/kernel/rtc.c
@@ -112,8 +112,11 @@ unsigned long mach_get_cmos_time(void)
 	mon = CMOS_READ(RTC_MONTH);
 	year = CMOS_READ(RTC_YEAR);
 
-#if defined(CONFIG_ACPI) && defined(CONFIG_X86_64)
-	/* CHECKME: Is this really 64bit only ??? */
+#ifdef CONFIG_ACPI
+	/*
+	 * On 32bit not strictly needed because the world ends in 2038
+	 * and the code can handle that with the 2 digit heuristics.
+	 */
 	if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID &&
 	    acpi_gbl_FADT.century)
 		century = CMOS_READ(acpi_gbl_FADT.century);

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

* Re: [PATCH] [1/5] Only do century BCD conversion when we know the RTC is BCD
  2008-02-09 15:16 [PATCH] [1/5] Only do century BCD conversion when we know the RTC is BCD Andi Kleen
                   ` (3 preceding siblings ...)
  2008-02-09 15:17 ` [PATCH] [5/5] Enable ACPI extended century handling for 32bit too v2 Andi Kleen
@ 2008-02-11  8:30 ` Thomas Gleixner
  2008-02-11  8:56   ` Andi Kleen
  4 siblings, 1 reply; 16+ messages in thread
From: Thomas Gleixner @ 2008-02-11  8:30 UTC (permalink / raw)
  To: Andi Kleen; +Cc: mingo, linux-kernel

On Sat, 9 Feb 2008, Andi Kleen wrote:

> 
> Minor logic fix. The century change was previously always BCD,
> even when the CMOS data would report itself not being BCD.

I checked that whole rtc / BCD logic again. We always set RTC_ALWAYS_BCD:

#ifndef RTC_PORT
#define RTC_PORT(x)    (0x70 + (x))
#define RTC_ALWAYS_BCD 1       /* RTC operates in BCD mode */
#endif

Nothing ever defines RTC_PORT and RTC_ALWAYS_BCD

So we can get rid of that stuff completely.

> Signed-off-by: Andi Kleen <ak@suse.de>
> 
> ---
>  arch/x86/kernel/rtc.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> Index: linux/arch/x86/kernel/rtc.c
> ===================================================================
> --- linux.orig/arch/x86/kernel/rtc.c
> +++ linux/arch/x86/kernel/rtc.c
> @@ -130,10 +130,10 @@ unsigned long mach_get_cmos_time(void)
>  		BCD_TO_BIN(day);
>  		BCD_TO_BIN(mon);
>  		BCD_TO_BIN(year);
> +		BCD_TO_BIN(century);

This should probably go here:

        if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID &&
            acpi_gbl_FADT.century) {
--->
 	}

It does not matter much, because BCD_TO_BIN(0) is 0, but it makes a
lot of sense.

Thanks,

	tglx

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

* Re: [PATCH] [1/5] Only do century BCD conversion when we know the RTC is BCD
  2008-02-11  8:30 ` [PATCH] [1/5] Only do century BCD conversion when we know the RTC is BCD Thomas Gleixner
@ 2008-02-11  8:56   ` Andi Kleen
  2008-02-11 22:08     ` Thomas Gleixner
  0 siblings, 1 reply; 16+ messages in thread
From: Andi Kleen @ 2008-02-11  8:56 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: mingo, linux-kernel


> Nothing ever defines RTC_PORT and RTC_ALWAYS_BCD
>
> So we can get rid of that stuff completely.

Please see the second version of the patch series. This means I didn't drop it 
completely, but added a warning about it not agreeing with the status 
register. If this warning never triggers it can be dropped eventually,
if it triggers RTC_ALWAYS_BCD should be unset.

-Andi

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

* Re: [PATCH] [1/5] Only do century BCD conversion when we know the RTC is BCD
  2008-02-11  8:56   ` Andi Kleen
@ 2008-02-11 22:08     ` Thomas Gleixner
  2008-02-11 22:15       ` Andi Kleen
  0 siblings, 1 reply; 16+ messages in thread
From: Thomas Gleixner @ 2008-02-11 22:08 UTC (permalink / raw)
  To: Andi Kleen; +Cc: mingo, linux-kernel

On Mon, 11 Feb 2008, Andi Kleen wrote:
> > Nothing ever defines RTC_PORT and RTC_ALWAYS_BCD
> >
> > So we can get rid of that stuff completely.
> 
> Please see the second version of the patch series. This means I didn't drop it 

I'm already replying to the second version of the patch series AFAICT.

> completely, but added a warning about it not agreeing with the status 
> register. If this warning never triggers it can be dropped eventually,
> if it triggers RTC_ALWAYS_BCD should be unset.

#define RTC_ALWAYS_BCD 1 is there since Linux 1.0 and got never
changed for x86.

So the warning comes a bit late :)

Later on the #ifdef RTC_PORT was introduced to share the header in
include/linux across architectures. When the header got copied to
include/i386 and elsewhere this just was never removed.

Thanks,

	tglx

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

* Re: [PATCH] [1/5] Only do century BCD conversion when we know the RTC is BCD
  2008-02-11 22:08     ` Thomas Gleixner
@ 2008-02-11 22:15       ` Andi Kleen
  2008-02-12 20:36         ` Thomas Gleixner
  0 siblings, 1 reply; 16+ messages in thread
From: Andi Kleen @ 2008-02-11 22:15 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: Andi Kleen, mingo, linux-kernel

> So the warning comes a bit late :)

I suspect if this was wrong before it would not have been noticed
because user space hwclock would work around it. The warning
certainly won't hurt.

Anyways if you feel strongly about this (I don't) then drop
this patch, but apply the other ones in the series. The main
one I consider important is the change to the 2000 offset for 32bit
to extend the 32bit lifetime.

-Andi

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

* Re: [PATCH] [1/5] Only do century BCD conversion when we know the RTC is BCD
  2008-02-11 22:15       ` Andi Kleen
@ 2008-02-12 20:36         ` Thomas Gleixner
  2008-02-13 13:49           ` Andi Kleen
  0 siblings, 1 reply; 16+ messages in thread
From: Thomas Gleixner @ 2008-02-12 20:36 UTC (permalink / raw)
  To: Andi Kleen; +Cc: Andi Kleen, mingo, linux-kernel

On Mon, 11 Feb 2008, Andi Kleen wrote:

> > So the warning comes a bit late :)
> 
> I suspect if this was wrong before it would not have been noticed
> because user space hwclock would work around it. 

And how exaclty does it work around ? By setting the binary cmos clock
with BCD values ?

> The warning certainly won't hurt.

It won't.

> Anyways if you feel strongly about this (I don't) then drop
> this patch, but apply the other ones in the series. 

I'm not opposing the patch, I merily asked for a removal of the never
changing constant.

> The main one I consider important is the change to the 2000 offset
> for 32bit to extend the 32bit lifetime.

Picked the whole lot up.

Thanks,

	tglx

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

* Re: [PATCH] [1/5] Only do century BCD conversion when we know the RTC is BCD
  2008-02-12 20:36         ` Thomas Gleixner
@ 2008-02-13 13:49           ` Andi Kleen
  0 siblings, 0 replies; 16+ messages in thread
From: Andi Kleen @ 2008-02-13 13:49 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: Andi Kleen, mingo, linux-kernel

Thomas Gleixner wrote:
> On Mon, 11 Feb 2008, Andi Kleen wrote:
> 
>>> So the warning comes a bit late :)
>> I suspect if this was wrong before it would not have been noticed
>> because user space hwclock would work around it. 
> 
> And how exaclty does it work aroalund ? By setting the binary cmos clock
> with BCD values ?

By reading the value directly from CMOS I suppose and checking
the BCD bit and then setting the clock to the correct value [all
theoretical; i have not checked the hwclock code if
it does that or not. It might be wrong. Just a hypothesis.]

-Andi


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

* Re: [PATCH] [2/5] Use 2000 offset for 32bit kernels
  2008-02-09 15:16 ` [PATCH] [2/5] Use 2000 offset for 32bit kernels Andi Kleen
@ 2008-02-16 19:24   ` Thomas Gleixner
  2008-02-20 10:07     ` Thomas Gleixner
  0 siblings, 1 reply; 16+ messages in thread
From: Thomas Gleixner @ 2008-02-16 19:24 UTC (permalink / raw)
  To: Andi Kleen; +Cc: mingo, linux-kernel

On Sat, 9 Feb 2008, Andi Kleen wrote:

> 
> We know it is already after 2000.
> 
> This extends the effective lifetime of 32bit systems by 8 years:
> from 2030 to 2038.
> 
> The only drawback is that users cannot set the cmos date to before 2000
> now on 32bit with systems that don't support extended century in 
> the RTC clock. 64bit systems had this limitation for some time
> and nobody complained.
> 
> And they can always set it to such a date in Linux only using date -s 
> if they really want.
> 
> Signed-off-by: Andi Kleen <ak@suse.de>

Applied. Thanks,

	 tglx

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

* Re: [PATCH] [3/5] Add warning when RTC clock reports binary
  2008-02-09 15:16 ` [PATCH] [3/5] Add warning when RTC clock reports binary Andi Kleen
@ 2008-02-16 19:38   ` Thomas Gleixner
  0 siblings, 0 replies; 16+ messages in thread
From: Thomas Gleixner @ 2008-02-16 19:38 UTC (permalink / raw)
  To: Andi Kleen; +Cc: mingo, linux-kernel

On Sat, 9 Feb 2008, Andi Kleen wrote:

> 
> We tend to assume the RTC clock is BCD, so print a warning
> if it claims to be binary.
> 
> Signed-off-by: Andi Kleen <ak@suse.de>

Applied. FYI, I changed it to a WARN_ON_ONCE. That will make reports
more likely.

Thanks,

	tglx

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

* Re: [PATCH] [5/5] Enable ACPI extended century handling for 32bit too v2
  2008-02-09 15:17 ` [PATCH] [5/5] Enable ACPI extended century handling for 32bit too v2 Andi Kleen
@ 2008-02-16 19:38   ` Thomas Gleixner
  0 siblings, 0 replies; 16+ messages in thread
From: Thomas Gleixner @ 2008-02-16 19:38 UTC (permalink / raw)
  To: Andi Kleen; +Cc: mingo, linux-kernel

On Sat, 9 Feb 2008, Andi Kleen wrote:
> 
> Not that it matters much, see comment in the code.
> 
> v2: Fix compilation on !ACPI, pointed out by tglx
> 
> Signed-off-by: Andi Kleen <ak@suse.de>

Applied. Thanks,

	 tglx

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

* Re: [PATCH] [2/5] Use 2000 offset for 32bit kernels
  2008-02-16 19:24   ` Thomas Gleixner
@ 2008-02-20 10:07     ` Thomas Gleixner
  2008-02-20 10:23       ` Andi Kleen
  0 siblings, 1 reply; 16+ messages in thread
From: Thomas Gleixner @ 2008-02-20 10:07 UTC (permalink / raw)
  To: Andi Kleen; +Cc: mingo, linux-kernel

On Sat, 16 Feb 2008, Thomas Gleixner wrote:
> On Sat, 9 Feb 2008, Andi Kleen wrote:
> > 
> > We know it is already after 2000.
> > 
> > This extends the effective lifetime of 32bit systems by 8 years:
> > from 2030 to 2038.

Could you please explain what magic math does the 2030 -> 2038
extension ?

According to the code the 1970 comparison works until 2069:

	year += 1900;
	if (year < 1970)
		year += 100;

I keep the patch nevertheless as it removes ifdeffery, but I change
the commit log to something sensible and remove the year < 1970 check
as well as it is not longer necessary.

Thanks,

	tglx

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

* Re: [PATCH] [2/5] Use 2000 offset for 32bit kernels
  2008-02-20 10:07     ` Thomas Gleixner
@ 2008-02-20 10:23       ` Andi Kleen
  0 siblings, 0 replies; 16+ messages in thread
From: Andi Kleen @ 2008-02-20 10:23 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: mingo, linux-kernel

On Wednesday 20 February 2008 11:07:02 Thomas Gleixner wrote:
> On Sat, 16 Feb 2008, Thomas Gleixner wrote:
> > On Sat, 9 Feb 2008, Andi Kleen wrote:
> > > 
> > > We know it is already after 2000.
> > > 
> > > This extends the effective lifetime of 32bit systems by 8 years:
> > > from 2030 to 2038.
> 
> Could you please explain what magic math does the 2030 -> 2038
> extension ?

Hmm, yes on rechecking I also don't know how I got the original
conclusion.

-Andi


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

end of thread, other threads:[~2008-02-20 10:23 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-09 15:16 [PATCH] [1/5] Only do century BCD conversion when we know the RTC is BCD Andi Kleen
2008-02-09 15:16 ` [PATCH] [2/5] Use 2000 offset for 32bit kernels Andi Kleen
2008-02-16 19:24   ` Thomas Gleixner
2008-02-20 10:07     ` Thomas Gleixner
2008-02-20 10:23       ` Andi Kleen
2008-02-09 15:16 ` [PATCH] [3/5] Add warning when RTC clock reports binary Andi Kleen
2008-02-16 19:38   ` Thomas Gleixner
2008-02-09 15:17 ` [PATCH] [4/5] Fix wrong comment Andi Kleen
2008-02-09 15:17 ` [PATCH] [5/5] Enable ACPI extended century handling for 32bit too v2 Andi Kleen
2008-02-16 19:38   ` Thomas Gleixner
2008-02-11  8:30 ` [PATCH] [1/5] Only do century BCD conversion when we know the RTC is BCD Thomas Gleixner
2008-02-11  8:56   ` Andi Kleen
2008-02-11 22:08     ` Thomas Gleixner
2008-02-11 22:15       ` Andi Kleen
2008-02-12 20:36         ` Thomas Gleixner
2008-02-13 13:49           ` Andi Kleen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.