Google luky.org euqset.org

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

Re: [PATCH] cputime.h seems to assume HZ==1000


Linus Torvalds wrote:

On Mon, 17 Jan 2005, Roland McGrath wrote:

Shouldn't msecs mean msecs, not secs/HZ?


Hmm, sure, but why go through "msecs" at all?


--- linux-2.6/include/asm-generic/cputime.h
+++ linux-2.6/include/asm-generic/cputime.h
@@ -35,8 +35,8 @@ typedef u64 cputime64_t;
/*
 * Convert cputime to seconds and back.
 */
-#define cputime_to_secs(__ct)		(jiffies_to_msecs(__ct) / HZ)
-#define secs_to_cputime(__secs)		(msecs_to_jiffies(__secs * HZ))
+#define cputime_to_secs(__ct)		(jiffies_to_msecs(__ct) / 1000)
+#define secs_to_cputime(__secs)		(msecs_to_jiffies(__secs * 1000))


iow, why not

	#define cputime_to_secs(jif)	((jif) / HZ)
	#define secs_to_cputime(sec)	((sec) * HZ)

which avoids double rounding issues etc.

If we care, the jiffies_to_msecs() code is in include/linux/jiffies.h just prior to other conversion code that does NOT make the assumtion that HZ is exact. To be exact:


static inline long cputime_to_secs(unsigned long jif)
{
	int t;
	u64 result = (u64)jif * TICK_NSEC;
	t = do_div(result ,NSEC_PER_SEC);
	return (u32)result + t ? 1:0;      /* round up if not exact */
}
#define secs_to_cputime(sec) (((U64) sec * SEC_CONVERSION) >> SEC_JIFFIE_SC)

This last assumes sec worth of jiffies will actually fit in a long...

--
George Anzinger   george@xxxxxxxxxx
High-res-timers:  http://sourceforge.net/projects/high-res-timers/

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


$B$3$N>pJs$,$"$J$?$NC5$7$F$$?$b$N$+$I$&$+A*Br$7$F$/$@$5$!#(B
yes/$B$^$5$K$3$l$@!*(B   no/$B0c$&$J$!(B   part/$B0lIt8+$D$+$C$?(B   try/$B$3$l$G;n$7$F$_$k(B

$B$"$J$?$,C5$7$F$$?>pJs$O$I$N$h$&$J$3$H$+!"$4<+M3$K5-F~2<$5$!#FC$K!V$^$5$K$3$l$@!*!W$H8@$&>l9g$O5-F~$r$*4j$$7$^$9!#(B
$BNc(B:$B!VJ#?t$N%^%7%s$+$i(BCATV$B7PM3$G(Bipmasquerade$B$rMxMQ$7$F(BWeb$B$r;2>H$7$?$>l9g$N@_Dj$K$D$$F!W(B
References: