lkml.org 
[lkml]   [1998]   [Aug]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] 498+ days uptime
Hi,

someone on IRC was very sad about the uptime of his machine wrapping from
497 days to 0. This patch enables the proc-filesystem to report uptimes
of over 100 years. It's straight forward and only modifies get_uptime()
in fs/proc/array.c.

I would call this a low priority bug fix and it should therefore be
included in the 2.1 kernel :-)

Ciao, ET.--- linux-2.1.116/fs/proc/array.c.orig Sun Aug 23 18:29:30 1998
+++ linux-2.1.116/fs/proc/array.c Sun Aug 23 19:17:02 1998
@@ -301,37 +301,42 @@
}


-static int get_uptime(char * buffer)
-{
- unsigned long uptime;
- unsigned long idle;
-
- uptime = jiffies;
- idle = task[0]->times.tms_utime + task[0]->times.tms_stime;
-
- /* The formula for the fraction parts really is ((t * 100) / HZ) % 100, but
- that would overflow about every five days at HZ == 100.
- Therefore the identity a = (a / b) * b + a % b is used so that it is
- calculated as (((t / HZ) * 100) + ((t % HZ) * 100) / HZ) % 100.
- The part in front of the '+' always evaluates as 0 (mod 100). All divisions
- in the above formulas are truncating. For HZ being a power of 10, the
- calculations simplify to the version in the #else part (if the printf
- format is adapted to the same number of digits as zeroes in HZ.
- */
-#if HZ!=100
- return sprintf(buffer,"%lu.%02lu %lu.%02lu\n",
- uptime / HZ,
- (((uptime % HZ) * 100) / HZ) % 100,
- idle / HZ,
- (((idle % HZ) * 100) / HZ) % 100);
-#else
- return sprintf(buffer,"%lu.%02lu %lu.%02lu\n",
- uptime / HZ,
- uptime % HZ,
- idle / HZ,
- idle % HZ);
-#endif
-}
+static int fmttime(char *buffer, char *fmt,
+ unsigned long curr, unsigned long *last, unsigned long *oflow)
+{
+ unsigned long sec = curr / HZ;
+ unsigned long hz = curr % HZ;
+
+ if (curr < *last)
+ (*oflow)++;
+ *last = curr;
+
+ if (*oflow)
+ {
+ sec += *oflow * (~0ul / HZ);
+ hz += *oflow * (~0ul % HZ + 1);
+ sec += hz / HZ;
+ hz = hz % HZ;
+ }
+
+ hz = (hz * 100) / HZ; /* this is optimized away if HZ == 100 */
+
+ return sprintf(buffer, fmt, sec, hz);
+}
+
+static int get_uptime(char *buffer)
+{
+ static unsigned long last_uptime = 0, oflow_uptime = 0;
+ static unsigned long last_idle = 0, oflow_idle = 0;
+ unsigned long idle;
+ char *p = buffer;
+
+ idle = task[0]->times.tms_utime + task[0]->times.tms_stime;
+
+ p += fmttime(p, "%lu.%02lu ", jiffies, &last_uptime, &oflow_uptime);
+ p += fmttime(p, "%lu.%02lu\n", idle, &last_idle, &oflow_idle);
+ return p - buffer;
+}

static int get_meminfo(char * buffer)
{
\
 
 \ /
  Last update: 2005-03-22 13:44    [W:0.091 / U:0.536 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site