Commit daee4676 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] fix wobbly /proc/stat:btime

From: john stultz <johnstul@us.ibm.com>

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.
parent a4369a58
......@@ -378,8 +378,23 @@ static int kstat_read_proc(char *page, char **start, off_t off,
{
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++) {
int j;
......@@ -419,7 +434,6 @@ static int kstat_read_proc(char *page, char **start, off_t off,
len += sprintf(page + len, " %u", kstat_irqs(i));
#endif
do_div(jif, HZ);
len += sprintf(page + len,
"\nctxt %lu\n"
"btime %lu\n"
......@@ -427,7 +441,7 @@ static int kstat_read_proc(char *page, char **start, off_t off,
"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());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment