summaryrefslogtreecommitdiff
path: root/rootdir.c
diff options
context:
space:
mode:
authorJeremie Koenig <jk@jk.fr.eu.org>2010-08-23 20:21:52 +0000
committerJeremie Koenig <jk@jk.fr.eu.org>2010-08-30 14:31:32 +0200
commit59b3864bbd09e81df1a5934a02d8af7f4eec0b28 (patch)
tree17c9afccbde6ff09f49260301ca9e128274948e9 /rootdir.c
parentf3bac2c0691d9bd5c89de206faa809cd34d86c35 (diff)
Make sure the clock never runs backwards.
* process.c, rootdir.c: When converting timeval structures into seconds or jiffies, make sure that floating point rounding errors don't make the clock the result jump backwards on second boundaries.
Diffstat (limited to 'rootdir.c')
-rw-r--r--rootdir.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/rootdir.c b/rootdir.c
index 728008e5..c6ddd87c 100644
--- a/rootdir.c
+++ b/rootdir.c
@@ -140,8 +140,8 @@ rootdir_gc_uptime (void *hook, char **contents, ssize_t *contents_len)
return err;
timersub (&time, &boottime, &time);
- up_secs = time.tv_sec + time.tv_usec / 1000000.;
- idle_secs = idletime.tv_sec + idletime.tv_usec / 1000000.;
+ up_secs = (time.tv_sec * 1000000. + time.tv_usec) / 1000000.;
+ idle_secs = (idletime.tv_sec * 1000000. + idletime.tv_usec) / 1000000.;
/* The second field is the total idle time. As far as I know we don't
keep track of it. However, procps uses it to compute "USER_HZ", and
@@ -178,8 +178,8 @@ rootdir_gc_stat (void *hook, char **contents, ssize_t *contents_len)
return EIO;
timersub (&time, &boottime, &time);
- up_ticks = opt_clk_tck * (time.tv_sec + time.tv_usec / 1000000.);
- idle_ticks = opt_clk_tck * (idletime.tv_sec + idletime.tv_usec / 1000000.);
+ up_ticks = opt_clk_tck * (time.tv_sec * 1000000. + time.tv_usec) / 1000000.;
+ idle_ticks = opt_clk_tck * (idletime.tv_sec * 1000000. + idletime.tv_usec) / 1000000.;
*contents_len = asprintf (contents,
"cpu %lu 0 0 %lu 0 0 0 0 0\n"