[PATCH] Introduce jiffies_32 and related compare functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Some subsystems dont need more than 32bits timestamps.

See for example net/ipv4/inetpeer.c and include/net/tcp.h :
#define tcp_time_stamp            ((__u32)(jiffies))


Because most timeouts should work with 'normal jiffies' that are 32bits on 32bits platforms, it makes sense to be able to use only 32bits to store them and not 64 bits, to save ram.

This patch introduces jiffies_32, and related comparison functions time_after32(), time_before32(), time_after_eq32() and time_before_eq32().

I plan to use this infrastructure in network code for example (struct dst_entry comes to mind).

Signed-off-by: Eric Dumazet <[email protected]>
--- linux-2.6.19/include/linux/jiffies.h	2006-12-12 00:32:00.000000000 +0100
+++ linux-2.6.19-ed/include/linux/jiffies.h	2006-12-12 00:41:40.000000000 +0100
@@ -80,6 +80,11 @@
  */
 extern u64 __jiffy_data jiffies_64;
 extern unsigned long volatile __jiffy_data jiffies;
+/*
+ * Some subsystems need small deltas and can store 32 bits timestamps
+ * instead of 'long', to save space on 64bits platforms.
+ */
+#define jiffies_32 ((u32)jiffies)
 
 #if (BITS_PER_LONG < 64)
 u64 get_jiffies_64(void);
@@ -131,6 +136,22 @@ static inline u64 get_jiffies_64(void)
 #define time_before_eq64(a,b)	time_after_eq64(b,a)
 
 /*
+ * Same as above, but does so with 32bits types.
+ * These must be used when using jiffies_32
+ */
+#define time_after32(a,b)	\
+	(typecheck(__u32, a) &&	\
+	 typecheck(__u32, b) && \
+	 ((__s32)(b) - (__s32)(a) < 0))
+#define time_before32(a,b)	time_after32(b,a)
+
+#define time_after_eq32(a,b)	\
+	(typecheck(__u32, a) && \
+	 typecheck(__u32, b) && \
+	 ((__s32)(a) - (__s32)(b) >= 0))
+#define time_before_eq32(a,b)	time_after_eq32(b,a)
+
+/*
  * Have the 32 bit jiffies value wrap 5 minutes after boot
  * so jiffies wrap bugs show up earlier.
  */

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux