fix wrong uptime on non-i386 platforms

fix wrong uptime on non-i386 platforms

Post by Tim Schmiela » Sun, 22 Jun 2003 00:00:15



Here are most of the missing wall_to_monotonic initializations that the
non-i386 architectures still need to pick up.
This should fix the reported uptime inconsistencies.

Disclaimer: completely untested, since I don't have (most of) the hardware.

Tim

--- linux-2.5.72/arch/alpha/kernel/time.c       Fri Jun 20 23:25:45 2003

                year += 100;

        xtime.tv_sec = mktime(year, mon, day, hour, min, sec);
+       wall_to_monotonic.tv_sec = -xtime.tv_sec;
        xtime.tv_nsec = 0;

        if (HZ > (1<<16)) {

--- linux-2.5.72/arch/m68k/kernel/time.c        Fri Jun 20 23:25:45 2003

                        time.tm_year += 100;
                xtime.tv_sec = mktime(time.tm_year, time.tm_mon, time.tm_mday,
                                      time.tm_hour, time.tm_min, time.tm_sec);
+               wall_to_monotonic.tv_sec = -xtime.tv_sec;
                xtime.tv_nsec = 0;
        }

--- linux-2.5.72/arch/m68knommu/kernel/time.c   Sat Jun 14 21:18:24 2003

        if ((year += 1900) < 1970)
                year += 100;
        xtime.tv_sec = mktime(year, mon, day, hour, min, sec);
+       wall_to_monotonic.tv_sec = -xtime.tv_sec;
        xtime.tv_nsec = 0;

        mach_sched_init(timer_interrupt);

--- linux-2.5.72/arch/parisc/kernel/time.c      Fri Jun 20 23:25:45 2003

        if(pdc_tod_read(&tod_data) == 0) {
                write_seqlock_irq(&xtime_lock);
                xtime.tv_sec = tod_data.tod_sec;
+               wall_to_monotonic.tv_sec = -xtime.tv_sec;
                xtime.tv_nsec = tod_data.tod_usec * 1000;
+               wall_to_monotonic.tv_nsec = -xtime.tv_nsec;
                write_sequnlock_irq(&xtime_lock);
        } else {
                printk(KERN_ERR "Error reading tod clock\n");

--- linux-2.5.72/arch/ppc/kernel/time.c Fri Jun 20 23:25:45 2003

                if (sec==old_sec)
                        printk("Warning: real time clock seems stuck!\n");
                xtime.tv_sec = sec;
+               wall_to_monotonic.tv_sec = -xtime.tv_sec;
                xtime.tv_nsec = 0;
                /* No update now, we just read the time from the RTC ! */
                last_rtc_update = xtime.tv_sec;

--- linux-2.5.72/arch/ppc64/kernel/time.c       Fri Jun 20 23:25:45 2003

        write_seqlock_irqsave(&xtime_lock, flags);
        xtime.tv_sec = mktime(tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
                              tm.tm_hour, tm.tm_min, tm.tm_sec);
+       wall_to_monotonic.tv_sec = -xtime.tv_sec;
        tb_last_stamp = get_tb();
        do_gtod.tb_orig_stamp = tb_last_stamp;
        do_gtod.varp = &do_gtod.vars[0];

--- linux-2.5.72/arch/s390/kernel/time.c        Fri Jun 20 23:25:45 2003

        set_time_cc = init_timer_cc - 0x8126d60e46000000LL +
                (0x3c26700LL*1000000*4096);
         tod_to_timeval(set_time_cc, &xtime);
+       wall_to_monotonic.tv_sec = -xtime.tv_sec;
+       wall_to_monotonic.tv_nsec = -xtime.tv_nsec;

         /* request the 0x1004 external interrupt */
         if (register_early_external_interrupt(0x1004, do_comparator_interrupt,

--- linux-2.5.72/arch/sh/kernel/time.c  Fri Jun 20 23:25:45 2003

 #endif

        rtc_gettimeofday(&xtime);
+       wall_to_monotonic.tv_sec = -xtime.tv_sec;
+       wall_to_monotonic.tv_nsec = -xtime.tv_nsec;

        setup_irq(TIMER_IRQ, &irq0);

--- linux-2.5.72/arch/sparc/kernel/time.c       Fri Jun 20 23:25:45 2003

        mon = MSTK_REG_MONTH(mregs);
        year = MSTK_CVT_YEAR( MSTK_REG_YEAR(mregs) );
        xtime.tv_sec = mktime(year, mon, day, hour, min, sec);
-       wall_to_monotonic.tv_sec = -xtime.tv_sec + INITIAL_JIFFIES / HZ;
+       wall_to_monotonic.tv_sec = -xtime.tv_sec;
        xtime.tv_nsec = (INITIAL_JIFFIES % HZ) * (NSEC_PER_SEC / HZ);
-       wall_to_monotonic.tv_nsec = 0;
+       wall_to_monotonic.tv_nsec = -xtime.tv_nsec;
        mregs->creg &= ~MSTK_CREG_READ;
        spin_unlock_irq(&mostek_lock);
 #ifdef CONFIG_SUN4

--- linux-2.5.72/arch/sparc64/kernel/time.c     Fri Jun 20 23:25:45 2003

        }

        xtime.tv_sec = mktime(year, mon, day, hour, min, sec);
-       wall_to_monotonic.tv_sec = -xtime.tv_sec + INITIAL_JIFFIES / HZ;
+       wall_to_monotonic.tv_sec = -xtime.tv_sec;
        xtime.tv_nsec = (INITIAL_JIFFIES % HZ) * (NSEC_PER_SEC / HZ);
-       wall_to_monotonic.tv_nsec = 0;
+       wall_to_monotonic.tv_nsec = -xtime.tv_nsec;

        if (mregs) {
                tmp = mostek_read(mregs + MOSTEK_CREG);

--- linux-2.5.72/arch/x86_64/kernel/time.c      Fri Jun 20 23:25:45 2003

 #endif

        xtime.tv_sec = get_cmos_time();
+       wall_to_monotonic.tv_sec = -xtime.tv_sec;
        xtime.tv_nsec = 0;

        if (!hpet_init()) {

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

fix wrong uptime on non-i386 platforms

Post by george anzinge » Sun, 22 Jun 2003 01:30:14



> Here are most of the missing wall_to_monotonic initializations that the
> non-i386 architectures still need to pick up.
> This should fix the reported uptime inconsistencies.

> Disclaimer: completely untested, since I don't have (most of) the hardware.

> Tim

> --- linux-2.5.72/arch/alpha/kernel/time.c  Fri Jun 20 23:25:45 2003
> +++ linux-2.5.72-ufix/arch/alpha/kernel/time.c     Fri Jun 20 23:37:10 2003

>            year += 100;

>    xtime.tv_sec = mktime(year, mon, day, hour, min, sec);
> +  wall_to_monotonic.tv_sec = -xtime.tv_sec;
>    xtime.tv_nsec = 0;

>    if (HZ > (1<<16)) {

> --- linux-2.5.72/arch/m68k/kernel/time.c   Fri Jun 20 23:25:45 2003
> +++ linux-2.5.72-ufix/arch/m68k/kernel/time.c      Fri Jun 20 23:37:10 2003

>                    time.tm_year += 100;
>            xtime.tv_sec = mktime(time.tm_year, time.tm_mon, time.tm_mday,
>                                  time.tm_hour, time.tm_min, time.tm_sec);
> +          wall_to_monotonic.tv_sec = -xtime.tv_sec;
>            xtime.tv_nsec = 0;
>    }

> --- linux-2.5.72/arch/m68knommu/kernel/time.c      Sat Jun 14 21:18:24 2003
> +++ linux-2.5.72-ufix/arch/m68knommu/kernel/time.c Fri Jun 20 23:37:10 2003

>    if ((year += 1900) < 1970)
>            year += 100;
>    xtime.tv_sec = mktime(year, mon, day, hour, min, sec);
> +  wall_to_monotonic.tv_sec = -xtime.tv_sec;
>    xtime.tv_nsec = 0;

>    mach_sched_init(timer_interrupt);

> --- linux-2.5.72/arch/parisc/kernel/time.c Fri Jun 20 23:25:45 2003
> +++ linux-2.5.72-ufix/arch/parisc/kernel/time.c    Fri Jun 20 23:37:10 2003

>    if(pdc_tod_read(&tod_data) == 0) {
>            write_seqlock_irq(&xtime_lock);
>            xtime.tv_sec = tod_data.tod_sec;
> +          wall_to_monotonic.tv_sec = -xtime.tv_sec;
>            xtime.tv_nsec = tod_data.tod_usec * 1000;
> +          wall_to_monotonic.tv_nsec = -xtime.tv_nsec;
>            write_sequnlock_irq(&xtime_lock);
>    } else {
>            printk(KERN_ERR "Error reading tod clock\n");

This one should normalize wall_to_monotonic so that nsec >= 0 and <
NSEC_PER_SEC.

- Show quoted text -

> --- linux-2.5.72/arch/ppc/kernel/time.c    Fri Jun 20 23:25:45 2003
> +++ linux-2.5.72-ufix/arch/ppc/kernel/time.c       Fri Jun 20 23:37:10 2003

>            if (sec==old_sec)
>                    printk("Warning: real time clock seems stuck!\n");
>            xtime.tv_sec = sec;
> +          wall_to_monotonic.tv_sec = -xtime.tv_sec;
>            xtime.tv_nsec = 0;
>            /* No update now, we just read the time from the RTC ! */
>            last_rtc_update = xtime.tv_sec;

> --- linux-2.5.72/arch/ppc64/kernel/time.c  Fri Jun 20 23:25:45 2003
> +++ linux-2.5.72-ufix/arch/ppc64/kernel/time.c     Fri Jun 20 23:37:10 2003

>    write_seqlock_irqsave(&xtime_lock, flags);
>    xtime.tv_sec = mktime(tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
>                          tm.tm_hour, tm.tm_min, tm.tm_sec);
> +  wall_to_monotonic.tv_sec = -xtime.tv_sec;
>    tb_last_stamp = get_tb();
>    do_gtod.tb_orig_stamp = tb_last_stamp;
>    do_gtod.varp = &do_gtod.vars[0];

> --- linux-2.5.72/arch/s390/kernel/time.c   Fri Jun 20 23:25:45 2003
> +++ linux-2.5.72-ufix/arch/s390/kernel/time.c      Fri Jun 20 23:37:10 2003

>    set_time_cc = init_timer_cc - 0x8126d60e46000000LL +
>            (0x3c26700LL*1000000*4096);
>          tod_to_timeval(set_time_cc, &xtime);
> +  wall_to_monotonic.tv_sec = -xtime.tv_sec;
> +  wall_to_monotonic.tv_nsec = -xtime.tv_nsec;

This one also needs to normalize.
>          /* request the 0x1004 external interrupt */
>          if (register_early_external_interrupt(0x1004, do_comparator_interrupt,

> --- linux-2.5.72/arch/sh/kernel/time.c     Fri Jun 20 23:25:45 2003
> +++ linux-2.5.72-ufix/arch/sh/kernel/time.c        Fri Jun 20 23:37:10 2003

>  #endif

>    rtc_gettimeofday(&xtime);
> +  wall_to_monotonic.tv_sec = -xtime.tv_sec;
> +  wall_to_monotonic.tv_nsec = -xtime.tv_nsec;

This one also needs to normalize.

>    setup_irq(TIMER_IRQ, &irq0);

> --- linux-2.5.72/arch/sparc/kernel/time.c  Fri Jun 20 23:25:45 2003
> +++ linux-2.5.72-ufix/arch/sparc/kernel/time.c     Fri Jun 20 23:37:10 2003

>    mon = MSTK_REG_MONTH(mregs);
>    year = MSTK_CVT_YEAR( MSTK_REG_YEAR(mregs) );
>    xtime.tv_sec = mktime(year, mon, day, hour, min, sec);
> -  wall_to_monotonic.tv_sec = -xtime.tv_sec + INITIAL_JIFFIES / HZ;
> +  wall_to_monotonic.tv_sec = -xtime.tv_sec;
>    xtime.tv_nsec = (INITIAL_JIFFIES % HZ) * (NSEC_PER_SEC / HZ);
> -  wall_to_monotonic.tv_nsec = 0;
> +  wall_to_monotonic.tv_nsec = -xtime.tv_nsec;

This one also needs to normalize.
>    mregs->creg &= ~MSTK_CREG_READ;
>    spin_unlock_irq(&mostek_lock);
>  #ifdef CONFIG_SUN4

> --- linux-2.5.72/arch/sparc64/kernel/time.c        Fri Jun 20 23:25:45 2003
> +++ linux-2.5.72-ufix/arch/sparc64/kernel/time.c   Fri Jun 20 23:37:10 2003

>    }

>    xtime.tv_sec = mktime(year, mon, day, hour, min, sec);
> -  wall_to_monotonic.tv_sec = -xtime.tv_sec + INITIAL_JIFFIES / HZ;
> +  wall_to_monotonic.tv_sec = -xtime.tv_sec;
>    xtime.tv_nsec = (INITIAL_JIFFIES % HZ) * (NSEC_PER_SEC / HZ);
> -  wall_to_monotonic.tv_nsec = 0;
> +  wall_to_monotonic.tv_nsec = -xtime.tv_nsec;

This one also needs to normalize.

- Show quoted text -

>    if (mregs) {
>            tmp = mostek_read(mregs + MOSTEK_CREG);

> --- linux-2.5.72/arch/x86_64/kernel/time.c Fri Jun 20 23:25:45 2003
> +++ linux-2.5.72-ufix/arch/x86_64/kernel/time.c    Fri Jun 20 23:37:10 2003

>  #endif

>    xtime.tv_sec = get_cmos_time();
> +  wall_to_monotonic.tv_sec = -xtime.tv_sec;
>    xtime.tv_nsec = 0;

>    if (!hpet_init()) {

> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

--

High-res-timers:  http://sourceforge.net/projects/high-res-timers/
Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

fix wrong uptime on non-i386 platforms

Post by Alex Goddar » Sun, 22 Jun 2003 07:20:07



> Here are most of the missing wall_to_monotonic initializations that the
> non-i386 architectures still need to pick up.
> This should fix the reported uptime inconsistencies.

> Disclaimer: completely untested, since I don't have (most of) the hardware.

Incidently, I haven't had the absurdly high uptime bug strike again since
the first time it happened.  I'll try out your patch as soon as I get a
chance.

--
Alex Goddard

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

fix wrong uptime on non-i386 platforms

Post by Tim Schmiela » Sun, 22 Jun 2003 10:20:07


On Fri, 20 Jun 2003, george anzinger wrote:
> Tim Schmielau wrote:
> > Here are most of the missing wall_to_monotonic initializations that the
> > non-i386 architectures still need to pick up.
> > This should fix the reported uptime inconsistencies.

> > Disclaimer: completely untested, since I don't have (most of) the hardware.

[...]
> > --- linux-2.5.72/arch/parisc/kernel/time.c    Fri Jun 20 23:25:45 2003
> > +++ linux-2.5.72-ufix/arch/parisc/kernel/time.c       Fri Jun 20 23:37:10 2003
> > @@ -242,7 +242,9 @@
> >       if(pdc_tod_read(&tod_data) == 0) {
> >               write_seqlock_irq(&xtime_lock);
> >               xtime.tv_sec = tod_data.tod_sec;
> > +             wall_to_monotonic.tv_sec = -xtime.tv_sec;
> >               xtime.tv_nsec = tod_data.tod_usec * 1000;
> > +             wall_to_monotonic.tv_nsec = -xtime.tv_nsec;
> >               write_sequnlock_irq(&xtime_lock);
> >       } else {
> >               printk(KERN_ERR "Error reading tod clock\n");

> This one should normalize wall_to_monotonic so that nsec >= 0 and <
> NSEC_PER_SEC.

Valid point. Shouldn't i386 (that I blindly copied) also normalize, then?

This time I also added the missing bits to do_settimeofday() for
architectures that don't yet know about wall_to_monotonic.

Disclaimer: previous disclaimer still applies

Tim

--- linux-2.5.72/arch/i386/kernel/time.c        Sat Jun 21 08:58:54 2003
+++ linux-2.5.72-ufix/arch/i386/kernel/time.c   Sat Jun 21 09:11:36 2003
@@ -306,10 +306,13 @@
 {

        xtime.tv_sec = get_cmos_time();
-       wall_to_monotonic.tv_sec = -xtime.tv_sec;
        xtime.tv_nsec = (INITIAL_JIFFIES % HZ) * (NSEC_PER_SEC / HZ);
-       wall_to_monotonic.tv_nsec = -xtime.tv_nsec;

+       wall_to_monotonic.tv_sec = -xtime.tv_sec;
+       if (xtime.tv_nsec != 0) {
+               wall_to_monotonic.tv_nsec = NSEC_PER_SEC - xtime.tv_nsec;
+               wall_to_monotonic.tv_sec--;
+       }

        timer = select_timer();
        time_init_hook();

--- linux-2.5.72/arch/alpha/kernel/time.c       Sat Jun 21 08:56:38 2003
+++ linux-2.5.72-ufix/arch/alpha/kernel/time.c  Sat Jun 21 09:55:11 2003
@@ -371,6 +371,8 @@
        xtime.tv_sec = mktime(year, mon, day, hour, min, sec);
        xtime.tv_nsec = 0;

+       wall_to_monotonic.tv_sec = -xtime.tv_sec;
+
        if (HZ > (1<<16)) {
                extern void __you_loose (void);
                __you_loose();
@@ -478,6 +480,18 @@
                nsec += NSEC_PER_SEC;
                sec -= 1;
        }
+
+       wall_to_monotonic.tv_sec += xtime.tv_sec - tv->tv_sec;
+        wall_to_monotonic.tv_nsec += xtime.tv_nsec - tv->tv_nsec;
+
+        if (wall_to_monotonic.tv_nsec > NSEC_PER_SEC) {
+                wall_to_monotonic.tv_nsec -= NSEC_PER_SEC;
+                wall_to_monotonic.tv_sec++;
+        }
+        if (wall_to_monotonic.tv_nsec < 0) {
+                wall_to_monotonic.tv_nsec += NSEC_PER_SEC;
+                wall_to_monotonic.tv_sec--;
+        }

        xtime.tv_sec = sec;
        xtime.tv_nsec = nsec;

--- linux-2.5.72/arch/m68k/kernel/time.c        Sat Jun 21 08:56:38 2003
+++ linux-2.5.72-ufix/arch/m68k/kernel/time.c   Sat Jun 21 09:22:31 2003
@@ -102,6 +102,8 @@
                xtime.tv_sec = mktime(time.tm_year, time.tm_mon, time.tm_mday,
                                      time.tm_hour, time.tm_min, time.tm_sec);
                xtime.tv_nsec = 0;
+
+               wall_to_monotonic.tv_sec = -xtime.tv_sec;
        }

        mach_sched_init(timer_interrupt);
@@ -159,6 +161,18 @@
                tv->tv_nsec += NSEC_PER_SEC;
                tv->tv_sec--;
        }
+
+        wall_to_monotonic.tv_sec += xtime.tv_sec - tv->tv_sec;
+        wall_to_monotonic.tv_nsec += xtime.tv_nsec - tv->tv_nsec;
+
+        if (wall_to_monotonic.tv_nsec > NSEC_PER_SEC) {
+                wall_to_monotonic.tv_nsec -= NSEC_PER_SEC;
+                wall_to_monotonic.tv_sec++;
+        }
+        if (wall_to_monotonic.tv_nsec < 0) {
+                wall_to_monotonic.tv_nsec += NSEC_PER_SEC;
+                wall_to_monotonic.tv_sec--;
+        }

        xtime.tv_sec = tv->tv_sec;
        xtime.tv_nsec = tv->tv_nsec;

--- linux-2.5.72/arch/m68knommu/kernel/time.c   Sat Jun 14 21:18:24 2003
+++ linux-2.5.72-ufix/arch/m68knommu/kernel/time.c      Sat Jun 21 09:27:48 2003
@@ -131,6 +131,8 @@
        xtime.tv_sec = mktime(year, mon, day, hour, min, sec);
        xtime.tv_nsec = 0;

+       wall_to_monotonic.tv_sec = -xtime.tv_sec;
+
        mach_sched_init(timer_interrupt);
 }

@@ -178,6 +180,18 @@
                tv->tv_usec += 1000000;
                tv->tv_sec--;
        }
+
+        wall_to_monotonic.tv_sec += xtime.tv_sec - tv->tv_sec;
+        wall_to_monotonic.tv_nsec += xtime.tv_nsec - tv->tv_nsec;
+
+        if (wall_to_monotonic.tv_nsec > NSEC_PER_SEC) {
+                wall_to_monotonic.tv_nsec -= NSEC_PER_SEC;
+                wall_to_monotonic.tv_sec++;
+        }
+        if (wall_to_monotonic.tv_nsec < 0) {
+                wall_to_monotonic.tv_nsec += NSEC_PER_SEC;
+                wall_to_monotonic.tv_sec--;
+        }

        xtime.tv_sec = tv->tv_sec;
        xtime.tv_nsec = (tv->tv_usec * 1000);

--- linux-2.5.72/arch/parisc/kernel/time.c      Sat Jun 21 08:56:38 2003
+++ linux-2.5.72-ufix/arch/parisc/kernel/time.c Sat Jun 21 09:52:21 2003
@@ -210,6 +210,18 @@
                        tv->tv_sec--;
                }

+               wall_to_monotonic.tv_sec += xtime.tv_sec - tv->tv_sec;
+               wall_to_monotonic.tv_nsec += xtime.tv_nsec - tv->tv_nsec;
+
+               if (wall_to_monotonic.tv_nsec > NSEC_PER_SEC) {
+                       wall_to_monotonic.tv_nsec -= NSEC_PER_SEC;
+                       wall_to_monotonic.tv_sec++;
+               }
+               if (wall_to_monotonic.tv_nsec < 0) {
+                       wall_to_monotonic.tv_nsec += NSEC_PER_SEC;
+                       wall_to_monotonic.tv_sec--;
+               }
+
                xtime.tv_sec = tv->tv_sec;
                xtime.tv_nsec = tv->tv_nsec;
                time_adjust = 0;                /* stop active adjtime() */
@@ -241,8 +253,16 @@

        if(pdc_tod_read(&tod_data) == 0) {
                write_seqlock_irq(&xtime_lock);
+
                xtime.tv_sec = tod_data.tod_sec;
                xtime.tv_nsec = tod_data.tod_usec * 1000;
+
+               wall_to_monotonic.tv_sec = -xtime.tv_sec;
+               if (xtime.tv_nsec != 0) {
+                       wall_to_monotonic.tv_nsec = NSEC_PER_SEC-xtime.tv_nsec;
+                       wall_to_monotonic.tv_sec--;
+               }
+
                write_sequnlock_irq(&xtime_lock);
        } else {
                printk(KERN_ERR "Error reading tod clock\n");

--- linux-2.5.72/arch/ppc/kernel/time.c Sat Jun 21 08:56:38 2003
+++ linux-2.5.72-ufix/arch/ppc/kernel/time.c    Sat Jun 21 09:40:20 2003
@@ -276,6 +276,16 @@
        }
        xtime.tv_nsec = new_nsec;
        xtime.tv_sec = new_sec;
+       wall_to_monotonic.tv_sec += xtime.tv_sec - new_sec;
+        wall_to_monotonic.tv_nsec += xtime.tv_nsec - new_nsec;
+        if (wall_to_monotonic.tv_nsec > NSEC_PER_SEC) {
+                wall_to_monotonic.tv_nsec -= NSEC_PER_SEC;
+                wall_to_monotonic.tv_sec++;
+        }
+        if (wall_to_monotonic.tv_nsec < 0) {
+                wall_to_monotonic.tv_nsec += NSEC_PER_SEC;
+                wall_to_monotonic.tv_sec--;
+        }

        /* In case of a large backwards jump in time with NTP, we want the
         * clock to be updated as soon as the PLL is again in lock.
@@ -333,6 +343,7 @@
                        printk("Warning: real time clock seems stuck!\n");
                xtime.tv_sec = sec;
                xtime.tv_nsec = 0;
+               wall_to_monotonic.tv_sec = -xtime.tv_sec;
                /* No update now, we just read the time from the RTC ! */
                last_rtc_update = xtime.tv_sec;
        }

--- linux-2.5.72/arch/ppc64/kernel/time.c       Sat Jun 21 08:56:38 2003
+++ linux-2.5.72-ufix/arch/ppc64/kernel/time.c  Sat Jun 21 09:41:44 2003
@@ -372,6 +372,16 @@
        }
        xtime.tv_nsec = new_nsec;
        xtime.tv_sec = new_sec;
+       wall_to_monotonic.tv_sec += xtime.tv_sec - new_sec;
+        wall_to_monotonic.tv_nsec += xtime.tv_nsec - new_nsec;
+        if (wall_to_monotonic.tv_nsec > NSEC_PER_SEC) {
+                wall_to_monotonic.tv_nsec -= NSEC_PER_SEC;
+                wall_to_monotonic.tv_sec++;
+        }
+        if (wall_to_monotonic.tv_nsec < 0) {
+                wall_to_monotonic.tv_nsec += NSEC_PER_SEC;
+                wall_to_monotonic.tv_sec--;
+        }

        /* In case of a large backwards jump in time with NTP, we want the
         * clock to be updated as soon as the PLL is again in lock.
@@ -468,6 +478,7 @@
        write_seqlock_irqsave(&xtime_lock, flags);
        xtime.tv_sec = mktime(tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
                              tm.tm_hour, tm.tm_min, tm.tm_sec);
+       wall_to_monotonic.tv_sec = -xtime.tv_sec;
        tb_last_stamp = get_tb();
        do_gtod.tb_orig_stamp = tb_last_stamp;
        do_gtod.varp = &do_gtod.vars[0];

--- linux-2.5.72/arch/sh/kernel/time.c  Sat Jun 21 08:56:38 2003
+++ linux-2.5.72-ufix/arch/sh/kernel/time.c     Sat Jun 21 09:44:26 2003
@@ -171,6 +171,18 @@
                tv->tv_sec--;
        }

+       wall_to_monotonic.tv_sec += xtime.tv_sec - tv->tv_sec;
+        wall_to_monotonic.tv_nsec += xtime.tv_nsec - tv->tv_nsec;
+
+        if (wall_to_monotonic.tv_nsec > NSEC_PER_SEC) {
+                wall_to_monotonic.tv_nsec -= NSEC_PER_SEC;
+                wall_to_monotonic.tv_sec++;
+        }
+        if (wall_to_monotonic.tv_nsec < 0) {
+                wall_to_monotonic.tv_nsec += NSEC_PER_SEC;
+                wall_to_monotonic.tv_sec--;
+        }
+
        xtime = *tv;
        time_adjust = 0;                /* stop active adjtime() */
        time_status |= STA_UNSYNC;
@@ -367,6 +379,11 @@
 #endif

        rtc_gettimeofday(&xtime);
+       wall_to_monotonic.tv_sec = -xtime.tv_sec;
+       if (xtime.tv_nsec != 0) {
+                wall_to_monotonic.tv_nsec = NSEC_PER_SEC - xtime.tv_nsec;
+                wall_to_monotonic.tv_sec--;
+        }

        setup_irq(TIMER_IRQ, &irq0);

--- linux-2.5.72/arch/sparc/kernel/time.c       Sat Jun 21 08:56:38 2003
+++ linux-2.5.72-ufix/arch/sparc/kernel/time.c  Sat Jun 21 09:46:06 2003
@@ -408,9 +408,12 @@
        mon = MSTK_REG_MONTH(mregs);
        year = MSTK_CVT_YEAR( MSTK_REG_YEAR(mregs) );
        xtime.tv_sec = mktime(year, mon, day, hour, min, sec);
-       wall_to_monotonic.tv_sec = -xtime.tv_sec + INITIAL_JIFFIES / HZ;
        xtime.tv_nsec = (INITIAL_JIFFIES % HZ) * (NSEC_PER_SEC / HZ);
-       wall_to_monotonic.tv_nsec = 0;
+       wall_to_monotonic.tv_sec = -xtime.tv_sec;
+       if (xtime.tv_nsec != 0) {
+                wall_to_monotonic.tv_nsec = NSEC_PER_SEC - xtime.tv_nsec;
+                wall_to_monotonic.tv_sec--;
+        }
        mregs->creg &= ~MSTK_CREG_READ;
        spin_unlock_irq(&mostek_lock);
 #ifdef CONFIG_SUN4

--- linux-2.5.72/arch/sparc64/kernel/time.c     Sat Jun 21 08:56:38 2003
+++ ...

read more »

 
 
 

fix wrong uptime on non-i386 platforms

Post by george anzinge » Sun, 22 Jun 2003 14:00:11


Tim Schmielau wrote:
> On Fri, 20 Jun 2003, george anzinger wrote:

>>Tim Schmielau wrote:

>>>Here are most of the missing wall_to_monotonic initializations that the
>>>non-i386 architectures still need to pick up.
>>>This should fix the reported uptime inconsistencies.

>>>Disclaimer: completely untested, since I don't have (most of) the hardware.

> [...]

>>>--- linux-2.5.72/arch/parisc/kernel/time.c  Fri Jun 20 23:25:45 2003
>>>+++ linux-2.5.72-ufix/arch/parisc/kernel/time.c     Fri Jun 20 23:37:10 2003
>>>@@ -242,7 +242,9 @@
>>>    if(pdc_tod_read(&tod_data) == 0) {
>>>            write_seqlock_irq(&xtime_lock);
>>>            xtime.tv_sec = tod_data.tod_sec;
>>>+           wall_to_monotonic.tv_sec = -xtime.tv_sec;
>>>            xtime.tv_nsec = tod_data.tod_usec * 1000;
>>>+           wall_to_monotonic.tv_nsec = -xtime.tv_nsec;
>>>            write_sequnlock_irq(&xtime_lock);
>>>    } else {
>>>            printk(KERN_ERR "Error reading tod clock\n");

>>This one should normalize wall_to_monotonic so that nsec >= 0 and <
>>NSEC_PER_SEC.

> Valid point. Shouldn't i386 (that I blindly copied) also normalize, then?

Uh, I think I missed the initial set up.  If tv_nsec is not changed it
is not needed.

> This time I also added the missing bits to do_settimeofday() for
> architectures that don't yet know about wall_to_monotonic.

Looks like you missed the normalize on the s390 initial set up.
Otherwise it looks good.

-g

- Show quoted text -

> Disclaimer: previous disclaimer still applies

> Tim

> --- linux-2.5.72/arch/i386/kernel/time.c   Sat Jun 21 08:58:54 2003
> +++ linux-2.5.72-ufix/arch/i386/kernel/time.c      Sat Jun 21 09:11:36 2003
> @@ -306,10 +306,13 @@
>  {

>    xtime.tv_sec = get_cmos_time();
> -  wall_to_monotonic.tv_sec = -xtime.tv_sec;
>    xtime.tv_nsec = (INITIAL_JIFFIES % HZ) * (NSEC_PER_SEC / HZ);
> -  wall_to_monotonic.tv_nsec = -xtime.tv_nsec;

> +  wall_to_monotonic.tv_sec = -xtime.tv_sec;
> +  if (xtime.tv_nsec != 0) {
> +          wall_to_monotonic.tv_nsec = NSEC_PER_SEC - xtime.tv_nsec;
> +          wall_to_monotonic.tv_sec--;
> +  }

>    timer = select_timer();
>    time_init_hook();

> --- linux-2.5.72/arch/alpha/kernel/time.c  Sat Jun 21 08:56:38 2003
> +++ linux-2.5.72-ufix/arch/alpha/kernel/time.c     Sat Jun 21 09:55:11 2003
> @@ -371,6 +371,8 @@
>    xtime.tv_sec = mktime(year, mon, day, hour, min, sec);
>    xtime.tv_nsec = 0;

> +  wall_to_monotonic.tv_sec = -xtime.tv_sec;
> +
>    if (HZ > (1<<16)) {
>            extern void __you_loose (void);
>            __you_loose();
> @@ -478,6 +480,18 @@
>            nsec += NSEC_PER_SEC;
>            sec -= 1;
>    }
> +
> +  wall_to_monotonic.tv_sec += xtime.tv_sec - tv->tv_sec;
> +        wall_to_monotonic.tv_nsec += xtime.tv_nsec - tv->tv_nsec;
> +
> +        if (wall_to_monotonic.tv_nsec > NSEC_PER_SEC) {
> +                wall_to_monotonic.tv_nsec -= NSEC_PER_SEC;
> +                wall_to_monotonic.tv_sec++;
> +        }
> +        if (wall_to_monotonic.tv_nsec < 0) {
> +                wall_to_monotonic.tv_nsec += NSEC_PER_SEC;
> +                wall_to_monotonic.tv_sec--;
> +        }

>    xtime.tv_sec = sec;
>    xtime.tv_nsec = nsec;

> --- linux-2.5.72/arch/m68k/kernel/time.c   Sat Jun 21 08:56:38 2003
> +++ linux-2.5.72-ufix/arch/m68k/kernel/time.c      Sat Jun 21 09:22:31 2003
> @@ -102,6 +102,8 @@
>            xtime.tv_sec = mktime(time.tm_year, time.tm_mon, time.tm_mday,
>                                  time.tm_hour, time.tm_min, time.tm_sec);
>            xtime.tv_nsec = 0;
> +
> +          wall_to_monotonic.tv_sec = -xtime.tv_sec;
>    }

>    mach_sched_init(timer_interrupt);
> @@ -159,6 +161,18 @@
>            tv->tv_nsec += NSEC_PER_SEC;
>            tv->tv_sec--;
>    }
> +
> +        wall_to_monotonic.tv_sec += xtime.tv_sec - tv->tv_sec;
> +        wall_to_monotonic.tv_nsec += xtime.tv_nsec - tv->tv_nsec;
> +
> +        if (wall_to_monotonic.tv_nsec > NSEC_PER_SEC) {
> +                wall_to_monotonic.tv_nsec -= NSEC_PER_SEC;
> +                wall_to_monotonic.tv_sec++;
> +        }
> +        if (wall_to_monotonic.tv_nsec < 0) {
> +                wall_to_monotonic.tv_nsec += NSEC_PER_SEC;
> +                wall_to_monotonic.tv_sec--;
> +        }

>    xtime.tv_sec = tv->tv_sec;
>    xtime.tv_nsec = tv->tv_nsec;

> --- linux-2.5.72/arch/m68knommu/kernel/time.c      Sat Jun 14 21:18:24 2003
> +++ linux-2.5.72-ufix/arch/m68knommu/kernel/time.c Sat Jun 21 09:27:48 2003
> @@ -131,6 +131,8 @@
>    xtime.tv_sec = mktime(year, mon, day, hour, min, sec);
>    xtime.tv_nsec = 0;

> +  wall_to_monotonic.tv_sec = -xtime.tv_sec;
> +
>    mach_sched_init(timer_interrupt);
>  }

> @@ -178,6 +180,18 @@
>            tv->tv_usec += 1000000;
>            tv->tv_sec--;
>    }
> +
> +        wall_to_monotonic.tv_sec += xtime.tv_sec - tv->tv_sec;
> +        wall_to_monotonic.tv_nsec += xtime.tv_nsec - tv->tv_nsec;
> +
> +        if (wall_to_monotonic.tv_nsec > NSEC_PER_SEC) {
> +                wall_to_monotonic.tv_nsec -= NSEC_PER_SEC;
> +                wall_to_monotonic.tv_sec++;
> +        }
> +        if (wall_to_monotonic.tv_nsec < 0) {
> +                wall_to_monotonic.tv_nsec += NSEC_PER_SEC;
> +                wall_to_monotonic.tv_sec--;
> +        }

>    xtime.tv_sec = tv->tv_sec;
>    xtime.tv_nsec = (tv->tv_usec * 1000);

> --- linux-2.5.72/arch/parisc/kernel/time.c Sat Jun 21 08:56:38 2003
> +++ linux-2.5.72-ufix/arch/parisc/kernel/time.c    Sat Jun 21 09:52:21 2003
> @@ -210,6 +210,18 @@
>                    tv->tv_sec--;
>            }

> +          wall_to_monotonic.tv_sec += xtime.tv_sec - tv->tv_sec;
> +          wall_to_monotonic.tv_nsec += xtime.tv_nsec - tv->tv_nsec;
> +
> +          if (wall_to_monotonic.tv_nsec > NSEC_PER_SEC) {
> +                  wall_to_monotonic.tv_nsec -= NSEC_PER_SEC;
> +                  wall_to_monotonic.tv_sec++;
> +          }
> +          if (wall_to_monotonic.tv_nsec < 0) {
> +                  wall_to_monotonic.tv_nsec += NSEC_PER_SEC;
> +                  wall_to_monotonic.tv_sec--;
> +          }
> +
>            xtime.tv_sec = tv->tv_sec;
>            xtime.tv_nsec = tv->tv_nsec;
>            time_adjust = 0;                /* stop active adjtime() */
> @@ -241,8 +253,16 @@

>    if(pdc_tod_read(&tod_data) == 0) {
>            write_seqlock_irq(&xtime_lock);
> +
>            xtime.tv_sec = tod_data.tod_sec;
>            xtime.tv_nsec = tod_data.tod_usec * 1000;
> +
> +          wall_to_monotonic.tv_sec = -xtime.tv_sec;
> +          if (xtime.tv_nsec != 0) {
> +                  wall_to_monotonic.tv_nsec = NSEC_PER_SEC-xtime.tv_nsec;
> +                  wall_to_monotonic.tv_sec--;
> +          }
> +
>            write_sequnlock_irq(&xtime_lock);
>    } else {
>            printk(KERN_ERR "Error reading tod clock\n");

> --- linux-2.5.72/arch/ppc/kernel/time.c    Sat Jun 21 08:56:38 2003
> +++ linux-2.5.72-ufix/arch/ppc/kernel/time.c       Sat Jun 21 09:40:20 2003
> @@ -276,6 +276,16 @@
>    }
>    xtime.tv_nsec = new_nsec;
>    xtime.tv_sec = new_sec;
> +  wall_to_monotonic.tv_sec += xtime.tv_sec - new_sec;
> +        wall_to_monotonic.tv_nsec += xtime.tv_nsec - new_nsec;
> +        if (wall_to_monotonic.tv_nsec > NSEC_PER_SEC) {
> +                wall_to_monotonic.tv_nsec -= NSEC_PER_SEC;
> +                wall_to_monotonic.tv_sec++;
> +        }
> +        if (wall_to_monotonic.tv_nsec < 0) {
> +                wall_to_monotonic.tv_nsec += NSEC_PER_SEC;
> +                wall_to_monotonic.tv_sec--;
> +        }

>    /* In case of a large backwards jump in time with NTP, we want the
>     * clock to be updated as soon as the PLL is again in lock.
> @@ -333,6 +343,7 @@
>                    printk("Warning: real time clock seems stuck!\n");
>            xtime.tv_sec = sec;
>            xtime.tv_nsec = 0;
> +          wall_to_monotonic.tv_sec = -xtime.tv_sec;
>            /* No update now, we just read the time from the RTC ! */
>            last_rtc_update = xtime.tv_sec;
>    }

> --- linux-2.5.72/arch/ppc64/kernel/time.c  Sat Jun 21 08:56:38 2003
> +++ linux-2.5.72-ufix/arch/ppc64/kernel/time.c     Sat Jun 21 09:41:44 2003
> @@ -372,6 +372,16 @@
>    }
>    xtime.tv_nsec = new_nsec;
>    xtime.tv_sec = new_sec;
> +  wall_to_monotonic.tv_sec += xtime.tv_sec - new_sec;
> +        wall_to_monotonic.tv_nsec += xtime.tv_nsec - new_nsec;
> +        if (wall_to_monotonic.tv_nsec > NSEC_PER_SEC) {
> +                wall_to_monotonic.tv_nsec -= NSEC_PER_SEC;
> +                wall_to_monotonic.tv_sec++;
> +        }
> +        if (wall_to_monotonic.tv_nsec < 0) {
> +                wall_to_monotonic.tv_nsec += NSEC_PER_SEC;
> +                wall_to_monotonic.tv_sec--;
> +        }

>    /* In case of a large backwards jump in time with NTP, we want the
>     * clock to be updated as soon as the PLL is again in lock.
> @@ -468,6 +478,7 @@
>    write_seqlock_irqsave(&xtime_lock, flags);
>    xtime.tv_sec = mktime(tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
>                          tm.tm_hour, tm.tm_min, tm.tm_sec);
> +  wall_to_monotonic.tv_sec = -xtime.tv_sec;
>    tb_last_stamp = get_tb();
>    do_gtod.tb_orig_stamp = tb_last_stamp;
>    do_gtod.varp = &do_gtod.vars[0];

> --- linux-2.5.72/arch/sh/kernel/time.c     Sat Jun 21 08:56:38 2003
> +++ linux-2.5.72-ufix/arch/sh/kernel/time.c        Sat Jun 21 09:44:26 2003
> @@ -171,6 +171,18 @@
>            tv->tv_sec--;
>    }

> +  wall_to_monotonic.tv_sec += xtime.tv_sec - tv->tv_sec;
> +        wall_to_monotonic.tv_nsec += xtime.tv_nsec - tv->tv_nsec;
> +
> +        if (wall_to_monotonic.tv_nsec > NSEC_PER_SEC) {
> +                wall_to_monotonic.tv_nsec -= NSEC_PER_SEC;
> +                wall_to_monotonic.tv_sec++;
> +        }
> +        if (wall_to_monotonic.tv_nsec < 0) {
> +                wall_to_monotonic.tv_nsec += NSEC_PER_SEC;
> +                wall_to_monotonic.tv_sec--;
> +        }
> +
>    xtime = *tv;
>    time_adjust = 0;                /* stop active adjtime() */
>    time_status |= STA_UNSYNC;
> @@ -367,6 +379,11 @@
>  #endif

>    rtc_gettimeofday(&xtime);
> +  wall_to_monotonic.tv_sec = -xtime.tv_sec;
> +  if (xtime.tv_nsec != 0) {
> +                wall_to_monotonic.tv_nsec = NSEC_PER_SEC - xtime.tv_nsec;
> +                wall_to_monotonic.tv_sec--;
> +        }

>    setup_irq(TIMER_IRQ, &irq0);

> --- linux-2.5.72/arch/sparc/kernel/time.c  Sat Jun 21 08:56:38 2003
> +++ linux-2.5.72-ufix/arch/sparc/kernel/time.c     Sat Jun 21 09:46:06 2003

...

read more »

 
 
 

1. Porting linux to i386 but non-pc platform

Hello,

I'm trying to port linux to an i386 board.
The problem is that this board is not a PC, so not all pc-devices are
available. Most of them are, like the serial ports and the interrupt
controller, but someting like the real-time-clock is not available.
And also the timers are running from another frequency and there is no bios.

I have managed to load the kernel, do the uncompressing and starting the
kernel.
At this moment I'm stuck in init/main.c

I'm sure I will manage to go to the code step by step but it's time
consuming.
So I'm wondering if there is some document available which describes
what to change to adopt linux to my hardware.

Regards, Robert

2. Clearing a hung socket

3. rx_copybreak value for non-i386 architectures

4. Unresolved symbols since 2.4.5 ?

5. Minimal System for non-i386 Linux

6. NETSITE: running two servers on different ports sharing configuration

7. Downloading RH7...So many types: 7.0-i386...7.0-i386-respin...7.0-ja-i386

8. serial i/o, bangs, buffers, bleary eyes...

9. wrong uptime output?

10. New: uptime wrong on x86-64 (fwd)

11. wrong uptime in 2.5.72

12. uptime wrong

13. uptime wrong in 2.5.70