[PATCH] linux-2.5.70_btime-fix_A0

[PATCH] linux-2.5.70_btime-fix_A0

Post by john stult » Thu, 05 Jun 2003 01:10:09



All,

        Since jiffies didn't necessarily start incrementing at a second
boundary, jiffies/HZ doesn't increment at the same moment as
xtime.tv_sec. This causes one second wobbles in the calculation of btime
(xtime.tv_sec - jiffies/HZ).  

This fix increases the precision of the calculation so the usec
component of xtime is used as well. Additionally it fixes some of the
non-atomic reading of time values.

This is a fix for bugme bug #764.
http://bugme.osdl.org/show_bug.cgi?id=764

Let me know if you have any comments

thanks
-john

--- 1.77/fs/proc/proc_misc.c    Sun May 25 14:08:09 2003

 {
        int i, len;
        extern unsigned long total_forks;
-       u64 jif = get_jiffies_64() - INITIAL_JIFFIES;
+       u64 jif;
        unsigned int sum = 0, user = 0, nice = 0, system = 0, idle = 0, iowait = 0;
+       struct timeval now;
+       unsigned long seq;
+
+       /* Atomically read jiffies and time of day */
+       do {
+               seq = read_seqbegin(&xtime_lock);
+
+               jif = get_jiffies_64() - INITIAL_JIFFIES;
+               do_gettimeofday(&now);
+       } while (read_seqretry(&xtime_lock, seq));
+
+       /* calc # of seconds since boot time */
+       jif = ((u64)now.tv_sec * HZ) + (now.tv_usec/(1000000/HZ)) - jif;
+       do_div(jif, HZ);

        for (i = 0 ; i < NR_CPUS; i++) {

                len += sprintf(page + len, " %u", kstat_irqs(i));
 #endif

-       do_div(jif, HZ);
        len += sprintf(page + len,
                "\nctxt %lu\n"

                "procs_running %lu\n"
                "procs_blocked %lu\n",
                nr_context_switches(),
-               xtime.tv_sec - (unsigned long) jif,
+               (unsigned long)jif,
                total_forks,
                nr_running(),
                nr_iowait());

-
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/

 
 
 

[PATCH] linux-2.5.70_btime-fix_A0

Post by jw schult » Thu, 05 Jun 2003 04:40:08



> All,

>    Since jiffies didn't necessarily start incrementing at a second
> boundary, jiffies/HZ doesn't increment at the same moment as
> xtime.tv_sec. This causes one second wobbles in the calculation of btime
> (xtime.tv_sec - jiffies/HZ).  

> This fix increases the precision of the calculation so the usec
> component of xtime is used as well. Additionally it fixes some of the
> non-atomic reading of time values.

> This is a fix for bugme bug #764.
> http://bugme.osdl.org/show_bug.cgi?id=764

> Let me know if you have any comments

Might it not be cheaper to start jiffies at the 1 second
boundary or with a value that simulates that?

--
________________________________________________________________
        J.W. Schultz            Pegasystems Technologies

                Remember Cernan and Schmitt
-
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/

 
 
 

[PATCH] linux-2.5.70_btime-fix_A0

Post by john stult » Thu, 05 Jun 2003 20:30:15




>> Since jiffies didn't necessarily start incrementing at a second
>> boundary, jiffies/HZ doesn't increment at the same moment as
>> xtime.tv_sec. This causes one second wobbles in the calculation of btime
>> (xtime.tv_sec - jiffies/HZ).

> Might it not be cheaper to start jiffies at the 1 second
> boundary or with a value that simulates that?

Ehhh... Mucking with the meaning of jiffies (# of timer ticks) just to fix a
math error in /proc/stat seems like a bit much.

But I'll look to see if I can improve the math some.

thanks
-john

-
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/

 
 
 

1. linux-2.5.70_btime-fix_A1

Andrew, All,
        Due to a math error in the calculation of /proc/stat's btime, the value
could wobble, varying by a single second. The patch fixes this wobble
described in bugme bug #764.

Reportedly Hans is seeing larger then 1 second wobbles which I have not
been able to reproduce, but that looks to be a separate issue to this
math bug.

Please consider for inclusion.

thanks
-john

diff -Nru a/fs/proc/proc_misc.c b/fs/proc/proc_misc.c
--- a/fs/proc/proc_misc.c       Thu Jun  5 15:07:14 2003

 {
        int i, len;
        extern unsigned long total_forks;
-       u64 jif = get_jiffies_64() - INITIAL_JIFFIES;
+       u64 jif;
        unsigned int sum = 0, user = 0, nice = 0, system = 0, idle = 0, iowait = 0;
+       struct timeval now;
+       unsigned long seq;
+
+       /* Atomically read jiffies and time of day */
+       do {
+               seq = read_seqbegin(&xtime_lock);
+
+               jif = get_jiffies_64();
+               do_gettimeofday(&now);
+       } while (read_seqretry(&xtime_lock, seq));
+
+       /* calc # of seconds since boot time */
+       jif -= INITIAL_JIFFIES;
+       jif = ((u64)now.tv_sec * HZ) + (now.tv_usec/(1000000/HZ)) - jif;
+       do_div(jif, HZ);

        for (i = 0 ; i < NR_CPUS; i++) {

                len += sprintf(page + len, " %u", kstat_irqs(i));
 #endif

-       do_div(jif, HZ);
        len += sprintf(page + len,
                "\nctxt %lu\n"

                "procs_running %lu\n"
                "procs_blocked %lu\n",
                nr_context_switches(),
-               xtime.tv_sec - (unsigned long) jif,
+               (unsigned long)jif,
                total_forks,
                nr_running(),
                nr_iowait());

-
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/

2. emacs-19.22 - Did I do it right?

3. [PATCH] linux-2.5.70_monotonic-seqlock_A0

4. ping script

5. [PATCH] linux-2.5.69_clear-smi-fix_A0

6. Checking slip activity?

7. linux-2.5.70_time-macro-cleanup_A0

8. New Unix Books

9. Patch: linux-2.5.7-pre1/net/ipv4/ipmr.c did not compile

10. linux-2.5.7.fix2.patch

11. linux-2.5.62_acpitable-fix_A0

12. linux-2.5.69_subarch-fix_A0.patch

13. Is the combination AlphaBIOS 5.70 and SYMC875 know not to work?