summaryrefslogtreecommitdiff
path: root/include/linux
diff options
context:
space:
mode:
authorTim Schmielau <tim@physik3.uni-rostock.de>2004-10-13 07:27:49 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2004-10-13 07:27:49 -0700
commitb9877c907d56b803b5b0241c2465ce768809fce9 (patch)
tree86de6ef294704e1a5a31591b157c41402fe7c897 /include/linux
parent1a9c15ac3687ec00574be4ad0f3ee1b299062ca4 (diff)
[PATCH] Fix reporting of process start times
Derive process start times from the posix_clock_monotonic notion of uptime instead of "jiffies", consistent with the earlier change to /proc/uptime itself. (http://linus.bkbits.net:8080/linux-2.5/cset@3ef4851dGg0fxX58R9Zv8SIq9fzNmQ?na%0Av=index.html|src/.|src/fs|src/fs/proc|related/fs/proc/proc_misc.c) Process start times are reported to userspace in units of 1/USER_HZ since boot, thus applications as procps need the value of "uptime" to convert them into absolute time. Currently "uptime" is derived from an ntp-corrected time base, but process start time is derived from the free-running "jiffies" counter. This results in inaccurate, drifting process start times as seen by the user, even if the exported number stays constant, because the users notion of "jiffies" changes in time. It's John Stultz's patch anyways, which I only messed up a bit, but since people started trading signed-off lines on lkml: Signed-off-by: Tim Schmielau <tim@physik3.uni-rostock.de> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/acct.h23
-rw-r--r--include/linux/sched.h2
-rw-r--r--include/linux/times.h20
3 files changed, 36 insertions, 9 deletions
diff --git a/include/linux/acct.h b/include/linux/acct.h
index b46ce1ac1c6a..a6ab17c49aa1 100644
--- a/include/linux/acct.h
+++ b/include/linux/acct.h
@@ -172,17 +172,24 @@ static inline u32 jiffies_to_AHZ(unsigned long x)
#endif
}
-static inline u64 jiffies_64_to_AHZ(u64 x)
+static inline u64 nsec_to_AHZ(u64 x)
{
-#if (TICK_NSEC % (NSEC_PER_SEC / AHZ)) == 0
-#if HZ != AHZ
- do_div(x, HZ / AHZ);
-#endif
-#else
- x *= TICK_NSEC;
+#if (NSEC_PER_SEC % AHZ) == 0
do_div(x, (NSEC_PER_SEC / AHZ));
+#elif (AHZ % 512) == 0
+ x *= AHZ/512;
+ do_div(x, (NSEC_PER_SEC / 512));
+#else
+ /*
+ * max relative error 5.7e-8 (1.8s per year) for AHZ <= 1024,
+ * overflow after 64.99 years.
+ * exact for AHZ=60, 72, 90, 120, 144, 180, 300, 600, 900, ...
+ */
+ x *= 9;
+ do_div(x, (unsigned long)((9ull * NSEC_PER_SEC + (AHZ/2))
+ / AHZ));
#endif
- return x;
+ return x;
}
#endif /* __KERNEL */
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 90f5cb645116..8810b551082a 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -508,7 +508,7 @@ struct task_struct {
struct timer_list real_timer;
unsigned long utime, stime;
unsigned long nvcsw, nivcsw; /* context switch counts */
- u64 start_time;
+ struct timespec start_time;
/* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
unsigned long min_flt, maj_flt;
/* process credentials */
diff --git a/include/linux/times.h b/include/linux/times.h
index ff00f334ffaa..0c5aa078dad4 100644
--- a/include/linux/times.h
+++ b/include/linux/times.h
@@ -55,6 +55,26 @@ static inline u64 jiffies_64_to_clock_t(u64 x)
}
#endif
+static inline u64 nsec_to_clock_t(u64 x)
+{
+#if (NSEC_PER_SEC % USER_HZ) == 0
+ do_div(x, (NSEC_PER_SEC / USER_HZ));
+#elif (USER_HZ % 512) == 0
+ x *= USER_HZ/512;
+ do_div(x, (NSEC_PER_SEC / 512));
+#else
+ /*
+ * max relative error 5.7e-8 (1.8s per year) for USER_HZ <= 1024,
+ * overflow after 64.99 years.
+ * exact for HZ=60, 72, 90, 120, 144, 180, 300, 600, 900, ...
+ */
+ x *= 9;
+ do_div(x, (unsigned long)((9ull * NSEC_PER_SEC + (USER_HZ/2))
+ / USER_HZ));
+#endif
+ return x;
+}
+
struct tms {
clock_t tms_utime;
clock_t tms_stime;