Re: [Bug 764] New: btime in /proc/stat wobbles (even over 30 seconds)

Kingsley Cheung
2003-06-06T02:13:29Z

[-- Attachment #1: Type: text/plain, Size: 429 bytes --]

On Thu, Jun 05, 2003 at 05:19:15PM +1000, Kingsley Cheung wrote:

> I raised this earlier in March this year. See:
>
> http://marc.theaimsgroup.com/?l=linux-kernel&m=104804927502272&w=2
>
> I sent to Rusty trivial patch for the fix against 2.4.20 back then.
>

Attached is a trivial patch to fix the problem against 2.5.70. I've
also attached the trivial 2.4.20 patch I sent to Rusty back for
completeness.

--
Kingsley

[-- Attachment #2: proc_misc-2.5.70.patch --]
[-- Type: text/plain, Size: 1474 bytes --]

--- linux/fs/proc/proc_misc.c.orig Fri Jun 6 12:13:44 2003
+++ linux/fs/proc/proc_misc.c Fri Jun 6 12:14:46 2003
@@ -51,6 +51,9 @@
#include <asm/tlb.h>
#include <asm/div64.h>

+/* 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,7 +381,6 @@
{
int i, len;
extern unsigned long total_forks;
- u64 jif = get_jiffies_64() - INITIAL_JIFFIES;
unsigned int sum = 0, user = 0, nice = 0, system = 0, idle = 0, iowait = 0;

for (i = 0 ; i < NR_CPUS; i++) {
@@ -419,15 +421,14 @@
len += sprintf(page + len, " %u", kstat_irqs(i));
#endif

- do_div(jif, HZ);
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(),
- xtime.tv_sec - (unsigned long) jif,
+ boottime,
total_forks,
nr_running(),
nr_iowait());
@@ -612,6 +613,7 @@

void __init proc_misc_init(void)
{
+ u64 jif = get_jiffies_64() - INITIAL_JIFFIES;
struct proc_dir_entry *entry;
static struct {
char *name;
@@ -638,6 +640,10 @@
{"execdomains", execdomains_read_proc},
{NULL,}
};
+
+ /* Intialise system boot time before creating /proc/stat entry. */
+ do_div(jif, HZ);
+ boottime = xtime.tv_sec - (time_t)jif;
for (p = simple_ones; p->name; p++)
create_proc_read_entry(p->name, 0, NULL, p->read_proc, NULL);

[-- Attachment #3: proc_misc-2.4.20.patch --]
[-- Type: text/plain, Size: 963 bytes --]

--- linux-2.4.20/fs/proc/proc_misc.c Fri Mar 28 15:53:52 2003
+++ linux-2.4.20_boottime/fs/proc/proc_misc.c Fri Mar 28 15:34:21 2003
@@ -41,6 +41,9 @@
#include <asm/pgtable.h>
#include <asm/io.h>

+/* 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)
/*
@@ -372,10 +375,10 @@

proc_sprintf(page, &off, &len,
"\nctxt %u\n"
- "btime %lu\n"
+ "btime %ld\n"
"processes %lu\n",
kstat.context_swtch,
- xtime.tv_sec - jif / HZ,
+ boottime,
total_forks);

return proc_calc_metrics(page, start, off, count, eof, len);
@@ -580,6 +583,9 @@
{"execdomains", execdomains_read_proc},
{NULL,}
};
+
+ /* Intialise system boot time before creating /proc/stat entry. */
+ boottime = xtime.tv_sec - jiffies / HZ;
for (p = simple_ones; p->name; p++)
create_proc_read_entry(p->name, 0, NULL, p->read_proc, NULL);