lkml.org 
[lkml]   [2004]   [May]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: MSEC_TO_JIFFIES is messed up...

* Valdis.Kletnieks@vt.edu <Valdis.Kletnieks@vt.edu> wrote:

> The problem is that even for the i386 family, there's no inherent
> reason why the value of HZ is nailed to 1000 [...]

The code is 100% correct, but not 100% clean, and definitely not
documented. The reason for the change was to avoid unnecessary integer
multiplications and divisions in sched.c.

the attached patch (against BK-curr) cleans this up and makes the
defines generic and arch-independent.

Ingo
--- linux/include/linux/time.h.orig
+++ linux/include/linux/time.h
@@ -177,6 +177,15 @@ struct timezone {
(SH_DIV((MAX_JIFFY_OFFSET >> SEC_JIFFIE_SC) * TICK_NSEC, NSEC_PER_SEC, 1) - 1)

#endif
+
+#if HZ == 1000
+# define JIFFIES_TO_MSEC(x) (x)
+# define MSEC_TO_JIFFIES(x) (x)
+#else
+# define JIFFIES_TO_MSEC(x) ((x) * 1000 / HZ)
+# define MSEC_TO_JIFFIES(x) ((x) * HZ / 1000)
+#endif
+
/*
* The TICK_NSEC - 1 rounds up the value to the next resolution. Note
* that a remainder subtract here would not do the right thing as the
--- linux/include/asm-i386/param.h.orig
+++ linux/include/asm-i386/param.h
@@ -5,8 +5,6 @@
# define HZ 1000 /* Internal kernel timer frequency */
# define USER_HZ 100 /* .. some user interfaces are in "ticks" */
# define CLOCKS_PER_SEC (USER_HZ) /* like times() */
-# define JIFFIES_TO_MSEC(x) (x)
-# define MSEC_TO_JIFFIES(x) (x)
#endif

#ifndef HZ
--- linux/kernel/sched.c.orig
+++ linux/kernel/sched.c
@@ -75,13 +75,6 @@
#define NS_TO_JIFFIES(TIME) ((TIME) / (1000000000 / HZ))
#define JIFFIES_TO_NS(TIME) ((TIME) * (1000000000 / HZ))

-#ifndef JIFFIES_TO_MSEC
-# define JIFFIES_TO_MSEC(x) ((x) * 1000 / HZ)
-#endif
-#ifndef MSEC_TO_JIFFIES
-# define MSEC_TO_JIFFIES(x) ((x) * HZ / 1000)
-#endif
-
/*
* These are the 'tuning knobs' of the scheduler:
*
\
 
 \ /
  Last update: 2005-03-22 14:03    [W:0.183 / U:0.216 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site