Re: MSEC_TO_JIFFIES is messed up...

2 messages, 2 authors, 2004-05-12 · open the first message on its own page

Re: MSEC_TO_JIFFIES is messed up...

From: <hidden>
Date: 2004-05-12 21:10:02

On Wed, 12 May 2004 22:50:28 +0200, Ingo Molnar said:
quoted hunk
Content-Disposition: attachment; filename="hz-cleanup-2.6.6-A2"
--- linux/include/linux/time.h.orig	
+++ linux/include/linux/time.h	
@@ -177,6 +177,24 @@ struct timezone {
 	(SH_DIV((MAX_JIFFY_OFFSET >> SEC_JIFFIE_SC) * TICK_NSEC, NSEC_PER_SEC, 
1) - 1)
 
 #endif
+
+/*
+ * Convert jiffies to milliseconds and back.
+ *
+ * Avoid unnecessary multiplications/divisions in the
+ * two most common HZ cases:
+ */
+#if HZ == 1000
+# define JIFFIES_TO_MSECS(x)	(x)
+# define MSECS_TO_JIFFIES(x)	(x)
+#elif HZ == 100
+# define JIFFIES_TO_MSECS(x)	((x) * 10)
+# define MSECS_TO_JIFFIES(x)	((x) / 10)
+#else
+# define JIFFIES_TO_MSECS(x)	((x) * 1000 / HZ)
+# define MSECS_TO_JIFFIES(x)	((x) * HZ / 1000)
+#endif
+
Looks good to me.. :)

Re: MSEC_TO_JIFFIES is messed up...

From: Davide Libenzi <hidden>
Date: 2004-05-12 21:36:35

On Wed, 12 May 2004 Valdis.Kletnieks@vt.edu wrote:
On Wed, 12 May 2004 22:50:28 +0200, Ingo Molnar said:
quoted
Content-Disposition: attachment; filename="hz-cleanup-2.6.6-A2"
--- linux/include/linux/time.h.orig	
+++ linux/include/linux/time.h	
@@ -177,6 +177,24 @@ struct timezone {
 	(SH_DIV((MAX_JIFFY_OFFSET >> SEC_JIFFIE_SC) * TICK_NSEC, NSEC_PER_SEC, 
1) - 1)
quoted
 
 #endif
+
+/*
+ * Convert jiffies to milliseconds and back.
+ *
+ * Avoid unnecessary multiplications/divisions in the
+ * two most common HZ cases:
+ */
+#if HZ == 1000
+# define JIFFIES_TO_MSECS(x)	(x)
+# define MSECS_TO_JIFFIES(x)	(x)
+#elif HZ == 100
+# define JIFFIES_TO_MSECS(x)	((x) * 10)
+# define MSECS_TO_JIFFIES(x)	((x) / 10)
+#else
+# define JIFFIES_TO_MSECS(x)	((x) * 1000 / HZ)
+# define MSECS_TO_JIFFIES(x)	((x) * HZ / 1000)
+#endif
+
Looks good to me.. :)
Guys, why don't you leave the compiler to do its job?



- Davide
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help