summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/asm-i386/param.h2
-rw-r--r--include/linux/time.h31
-rw-r--r--include/net/irda/irda.h2
-rw-r--r--include/net/sctp/sctp.h5
4 files changed, 31 insertions, 9 deletions
diff --git a/include/asm-i386/param.h b/include/asm-i386/param.h
index 4a045ec3633d..e0a47502836d 100644
--- a/include/asm-i386/param.h
+++ b/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
diff --git a/include/linux/time.h b/include/linux/time.h
index b85d596949a3..9a92850cab4b 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -177,6 +177,37 @@ 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:
+ */
+static inline unsigned int jiffies_to_msecs(unsigned long j)
+{
+#if HZ <= 1000 && !(1000 % HZ)
+ return (1000 / HZ) * j;
+#elif HZ > 1000 && !(HZ % 1000)
+ return (j + (HZ / 1000) - 1)/(HZ / 1000);
+#else
+ return (j * 1000) / HZ;
+#endif
+}
+static inline unsigned long msecs_to_jiffies(unsigned int m)
+{
+#if HZ <= 1000 && !(1000 % HZ)
+ return (m + (1000 / HZ) - 1) / (1000 / HZ);
+#elif HZ > 1000 && !(HZ % 1000)
+ return m * (HZ / 1000);
+#else
+ return (m * HZ + 999) / 1000;
+#endif
+}
+
+#define JIFFIES_TO_MSECS(j) jiffies_to_msecs(j)
+#define MSECS_TO_JIFFIES(m) msecs_to_jiffies(m)
+
/*
* 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
diff --git a/include/net/irda/irda.h b/include/net/irda/irda.h
index 44ac1b099a3b..497f6a3977bd 100644
--- a/include/net/irda/irda.h
+++ b/include/net/irda/irda.h
@@ -83,8 +83,6 @@ if(!(expr)) do { \
#define MESSAGE(args...) printk(KERN_INFO args)
#define ERROR(args...) printk(KERN_ERR args)
-#define MSECS_TO_JIFFIES(ms) (((ms)*HZ+999)/1000)
-
/*
* Magic numbers used by Linux-IrDA. Random numbers which must be unique to
* give the best protection
diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
index efceb30d69bb..17d0f9adce09 100644
--- a/include/net/sctp/sctp.h
+++ b/include/net/sctp/sctp.h
@@ -116,11 +116,6 @@
#define SCTP_STATIC static
#endif
-#define MSECS_TO_JIFFIES(msec) \
- (((msec / 1000) * HZ) + ((msec % 1000) * HZ) / 1000)
-#define JIFFIES_TO_MSECS(jiff) \
- (((jiff / HZ) * 1000) + ((jiff % HZ) * 1000) / HZ)
-
/*
* Function declarations.
*/