mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] use 64 bit jiffies 1/4
@ 2002-11-10  9:29 Tim Schmielau
  2002-11-10  9:33 ` [PATCH] use 64 bit jiffies 2/4 Tim Schmielau
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Tim Schmielau @ 2002-11-10  9:29 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: lkml, Tim Schmielau

Hi Linus,
 
with HZ=1000 even on 32bit platforms, we really should use the
64 bit jiffies value for exported interfaces like uptime, process start
time etc.
Otherwise innocent users might get quite surprised when ps output goes
berzerk after 49.5 days, showing processes as having started in the
future.
Note that the appended patch does not change any of the exported
interfaces, it just avoids internal overflows.
 
These changes were already discussed on lkml long ago, before George 
Anzinger introduced the current 64 bit jiffies implementation.

In its current form this patch was posted on lkml last month, and has been
in -dj (modulo the HZ=1000 change) since 2.5.20-dj3.

Tim


Part 1/4: "Infrastructure"

Provide a sane way to avoid unneccessary locking on 64 bit platforms,
and a 64 bit analogon to "jiffies_to_clock_t()".
Naming it "jiffies_64_to_user_HZ()" is the only part of these patches I 
expect to be controversial.


--- linux-2.5.46-bk4/include/linux/jiffies.h	Mon Nov  4 23:30:04 2002
+++ linux-2.5.46-bk4-j64a/include/linux/jiffies.h	Sun Nov 10 09:16:35 2002
@@ -2,14 +2,34 @@
 #define _LINUX_JIFFIES_H
 
 #include <linux/types.h>
+#include <linux/spinlock.h>
+#include <asm/system.h>
 #include <asm/param.h>			/* for HZ */
 
 /*
  * The 64-bit value is not volatile - you MUST NOT read it
- * without holding read_lock_irq(&xtime_lock)
+ * without holding read_lock_irq(&xtime_lock).
+ * get_jiffies_64() will do this for you as appropriate.
  */
 extern u64 jiffies_64;
 extern unsigned long volatile jiffies;
+
+static inline u64 get_jiffies_64(void)
+{
+#if BITS_PER_LONG < 64
+	extern rwlock_t xtime_lock;
+	unsigned long flags;
+	u64 tmp;
+
+	read_lock_irqsave(&xtime_lock, flags);
+	tmp = jiffies_64;
+	read_unlock_irqrestore(&xtime_lock, flags);
+	return tmp;
+#else
+	return (u64)jiffies;
+#endif
+}                                                                             
+
 
 /*
  *	These inlines deal with timer wrapping correctly. You are 

--- linux-2.5.46-bk4/include/linux/times.h	Mon Nov  4 23:30:06 2002
+++ linux-2.5.46-bk4-j64a/include/linux/times.h	Sun Nov 10 09:16:35 2002
@@ -2,7 +2,16 @@
 #define _LINUX_TIMES_H
 
 #ifdef __KERNEL__
+#include <asm/div64.h>
+#include <asm/types.h>
+
 # define jiffies_to_clock_t(x) ((x) / (HZ / USER_HZ))
+
+static inline u64 jiffies_64_to_user_HZ(u64 x)
+{
+	do_div(x, HZ / USER_HZ);
+	return x;
+}
 #endif
 
 struct tms {




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2002-11-12 14:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-10  9:29 [PATCH] use 64 bit jiffies 1/4 Tim Schmielau
2002-11-10  9:33 ` [PATCH] use 64 bit jiffies 2/4 Tim Schmielau
2002-11-10  9:36 ` [PATCH] use 64 bit jiffies 3/4 Tim Schmielau
2002-11-10  9:49 ` [PATCH] use 64 bit jiffies 4/4 Tim Schmielau
2002-11-11  1:46 ` [PATCH] use 64 bit jiffies 1/4 Linus Torvalds
2002-11-12 14:46   ` Tim Schmielau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome