From: john stultz <johnstul@us.ibm.com>

This patch polishes up Tim Schmielau's (tim@physik3.uni-rostock.de) fix for
jiffies_to_clock_t() and jiffies_64_to_clock_t().  The issues observed was
w/ /proc output not matching up to wall time due to accumulated error
caused by HZ not being exactly 1000 on i386 systems.  The solution is to
correct that error by using the more accurate TICK_NSEC in our calculation.

Additionally, this patch corrects 3 warnings in the TCP layer uncovered by
this change.  


---

 25-akpm/include/linux/times.h |   18 ++++++++++++------
 25-akpm/net/ipv4/tcp_ipv4.c   |    4 ++--
 25-akpm/net/ipv6/tcp_ipv6.c   |    4 ++--
 3 files changed, 16 insertions(+), 10 deletions(-)

diff -puN include/linux/times.h~jiffies-to-clockt-fix_a1 include/linux/times.h
--- 25/include/linux/times.h~jiffies-to-clockt-fix_a1	2004-05-03 19:48:03.608002624 -0700
+++ 25-akpm/include/linux/times.h	2004-05-03 19:48:03.614001712 -0700
@@ -2,15 +2,21 @@
 #define _LINUX_TIMES_H
 
 #ifdef __KERNEL__
+#include <linux/timex.h>
 #include <asm/div64.h>
 #include <asm/types.h>
 #include <asm/param.h>
 
-#if (HZ % USER_HZ)==0
-# define jiffies_to_clock_t(x) ((x) / (HZ / USER_HZ))
+static inline clock_t jiffies_to_clock_t(long x)
+{
+#if (TICK_NSEC % (NSEC_PER_SEC / USER_HZ)) == 0
+	return x / (HZ / USER_HZ);
 #else
-# define jiffies_to_clock_t(x) ((clock_t) jiffies_64_to_clock_t((u64) x))
+	u64 tmp = (u64)x * TICK_NSEC;
+	do_div(tmp, (NSEC_PER_SEC / USER_HZ));
+	return (long)tmp;
 #endif
+}
 
 static inline unsigned long clock_t_to_jiffies(unsigned long x)
 {
@@ -34,7 +40,7 @@ static inline unsigned long clock_t_to_j
 
 static inline u64 jiffies_64_to_clock_t(u64 x)
 {
-#if (HZ % USER_HZ)==0
+#if (TICK_NSEC % (NSEC_PER_SEC / USER_HZ)) == 0
 	do_div(x, HZ / USER_HZ);
 #else
 	/*
@@ -42,8 +48,8 @@ static inline u64 jiffies_64_to_clock_t(
 	 * but even this doesn't overflow in hundreds of years
 	 * in 64 bits, so..
 	 */
-	x *= USER_HZ;
-	do_div(x, HZ);
+	x *= TICK_NSEC;
+	do_div(x, (NSEC_PER_SEC / USER_HZ));
 #endif
 	return x;
 }
diff -puN net/ipv4/tcp_ipv4.c~jiffies-to-clockt-fix_a1 net/ipv4/tcp_ipv4.c
--- 25/net/ipv4/tcp_ipv4.c~jiffies-to-clockt-fix_a1	2004-05-03 19:48:03.609002472 -0700
+++ 25-akpm/net/ipv4/tcp_ipv4.c	2004-05-03 19:48:03.623000344 -0700
@@ -2452,7 +2452,7 @@ static void get_openreq4(struct sock *sk
 	int ttd = req->expires - jiffies;
 
 	sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
-		" %02X %08X:%08X %02X:%08X %08X %5d %8d %u %d %p",
+		" %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p",
 		i,
 		req->af.v4_req.loc_addr,
 		ntohs(inet_sk(sk)->sport),
@@ -2526,7 +2526,7 @@ static void get_timewait4_sock(struct tc
 	srcp  = ntohs(tw->tw_sport);
 
 	sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
-		" %02X %08X:%08X %02X:%08X %08X %5d %8d %d %d %p",
+		" %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p",
 		i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
 		3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
 		atomic_read(&tw->tw_refcnt), tw);
diff -puN net/ipv6/tcp_ipv6.c~jiffies-to-clockt-fix_a1 net/ipv6/tcp_ipv6.c
--- 25/net/ipv6/tcp_ipv6.c~jiffies-to-clockt-fix_a1	2004-05-03 19:48:03.611002168 -0700
+++ 25-akpm/net/ipv6/tcp_ipv6.c	2004-05-03 19:48:03.625000040 -0700
@@ -1933,7 +1933,7 @@ static void get_openreq6(struct seq_file
 	dest = &req->af.v6_req.rmt_addr;
 	seq_printf(seq,
 		   "%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X "
-		   "%02X %08X:%08X %02X:%08X %08X %5d %8d %d %d %p\n",
+		   "%02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p\n",
 		   i,
 		   src->s6_addr32[0], src->s6_addr32[1],
 		   src->s6_addr32[2], src->s6_addr32[3],
@@ -2019,7 +2019,7 @@ static void get_timewait6_sock(struct se
 
 	seq_printf(seq,
 		   "%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X "
-		   "%02X %08X:%08X %02X:%08X %08X %5d %8d %d %d %p\n",
+		   "%02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p\n",
 		   i,
 		   src->s6_addr32[0], src->s6_addr32[1],
 		   src->s6_addr32[2], src->s6_addr32[3], srcp,

_