--- linux/fs/proc/proc_misc.c.orig Tue Jun 10 11:03:31 2003 +++ linux/fs/proc/proc_misc.c Tue Jun 10 11:13:08 2003 @@ -51,6 +51,9 @@ #include #include +/* System boot time in seconds since the UNIX epoch. */ +static time_t boottime; + #define LOAD_INT(x) ((x) >> FSHIFT) #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100) /* @@ -378,23 +381,7 @@ { int i, len; extern unsigned long total_forks; - 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++) { int j; @@ -436,12 +423,12 @@ len += sprintf(page + len, "\nctxt %lu\n" - "btime %lu\n" + "btime %ld\n" "processes %lu\n" "procs_running %lu\n" "procs_blocked %lu\n", nr_context_switches(), - (unsigned long)jif, + boottime, total_forks, nr_running(), nr_iowait()); @@ -626,6 +613,9 @@ void __init proc_misc_init(void) { + u64 jif; + unsigned long seq; + struct timeval now; struct proc_dir_entry *entry; static struct { char *name; @@ -652,6 +642,24 @@ {"execdomains", execdomains_read_proc}, {NULL,} }; + + /* + * Intialise system boot time before creating /proc/stat + * entry. This way we avoid it changing whenever the system + * time is changed. 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); + boottime = (time_t)jif; + for (p = simple_ones; p->name; p++) create_proc_read_entry(p->name, 0, NULL, p->read_proc, NULL);