Commit 60967810 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] jiffies-to-clockt fix

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.
parent c2e48749
...@@ -2,15 +2,21 @@ ...@@ -2,15 +2,21 @@
#define _LINUX_TIMES_H #define _LINUX_TIMES_H
#ifdef __KERNEL__ #ifdef __KERNEL__
#include <linux/timex.h>
#include <asm/div64.h> #include <asm/div64.h>
#include <asm/types.h> #include <asm/types.h>
#include <asm/param.h> #include <asm/param.h>
#if (HZ % USER_HZ)==0 static inline clock_t jiffies_to_clock_t(long x)
# define jiffies_to_clock_t(x) ((x) / (HZ / USER_HZ)) {
#if (TICK_NSEC % (NSEC_PER_SEC / USER_HZ)) == 0
return x / (HZ / USER_HZ);
#else #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 #endif
}
static inline unsigned long clock_t_to_jiffies(unsigned long x) static inline unsigned long clock_t_to_jiffies(unsigned long x)
{ {
...@@ -34,7 +40,7 @@ static inline unsigned long clock_t_to_jiffies(unsigned long x) ...@@ -34,7 +40,7 @@ static inline unsigned long clock_t_to_jiffies(unsigned long x)
static inline u64 jiffies_64_to_clock_t(u64 x) 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); do_div(x, HZ / USER_HZ);
#else #else
/* /*
...@@ -42,8 +48,8 @@ static inline u64 jiffies_64_to_clock_t(u64 x) ...@@ -42,8 +48,8 @@ static inline u64 jiffies_64_to_clock_t(u64 x)
* but even this doesn't overflow in hundreds of years * but even this doesn't overflow in hundreds of years
* in 64 bits, so.. * in 64 bits, so..
*/ */
x *= USER_HZ; x *= TICK_NSEC;
do_div(x, HZ); do_div(x, (NSEC_PER_SEC / USER_HZ));
#endif #endif
return x; return x;
} }
......
...@@ -2452,7 +2452,7 @@ static void get_openreq4(struct sock *sk, struct open_request *req, ...@@ -2452,7 +2452,7 @@ static void get_openreq4(struct sock *sk, struct open_request *req,
int ttd = req->expires - jiffies; int ttd = req->expires - jiffies;
sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X" 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, i,
req->af.v4_req.loc_addr, req->af.v4_req.loc_addr,
ntohs(inet_sk(sk)->sport), ntohs(inet_sk(sk)->sport),
...@@ -2526,7 +2526,7 @@ static void get_timewait4_sock(struct tcp_tw_bucket *tw, char *tmpbuf, int i) ...@@ -2526,7 +2526,7 @@ static void get_timewait4_sock(struct tcp_tw_bucket *tw, char *tmpbuf, int i)
srcp = ntohs(tw->tw_sport); srcp = ntohs(tw->tw_sport);
sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X" 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, i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
3, jiffies_to_clock_t(ttd), 0, 0, 0, 0, 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
atomic_read(&tw->tw_refcnt), tw); atomic_read(&tw->tw_refcnt), tw);
......
...@@ -1933,7 +1933,7 @@ static void get_openreq6(struct seq_file *seq, ...@@ -1933,7 +1933,7 @@ static void get_openreq6(struct seq_file *seq,
dest = &req->af.v6_req.rmt_addr; dest = &req->af.v6_req.rmt_addr;
seq_printf(seq, seq_printf(seq,
"%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X " "%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, i,
src->s6_addr32[0], src->s6_addr32[1], src->s6_addr32[0], src->s6_addr32[1],
src->s6_addr32[2], src->s6_addr32[3], src->s6_addr32[2], src->s6_addr32[3],
...@@ -2019,7 +2019,7 @@ static void get_timewait6_sock(struct seq_file *seq, ...@@ -2019,7 +2019,7 @@ static void get_timewait6_sock(struct seq_file *seq,
seq_printf(seq, seq_printf(seq,
"%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X " "%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, i,
src->s6_addr32[0], src->s6_addr32[1], src->s6_addr32[0], src->s6_addr32[1],
src->s6_addr32[2], src->s6_addr32[3], srcp, src->s6_addr32[2], src->s6_addr32[3], srcp,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment