From: maximilian attems <janitor@sternwelten.at>
To: Jeff Garzik <jgarzik@pobox.com>
Cc: netdev@oss.sgi.com, Margit Schubert-While <margitsw@t-online.de>,
kernel-janitors@lists.osdl.org, mcgrof@studorgs.rutgers.edu,
Domen Puncer <domen@coderock.org>,
linux-kernel@vger.kernel.org, hvr@gnu.org
Subject: [KJ] [patch 1/6] back port msleep(), msleep_interruptible()
Date: Sun, 31 Oct 2004 15:44:24 +0100 [thread overview]
Message-ID: <20041031144424.GB28667@stro.at> (raw)
In-Reply-To: <41841886.2080609@pobox.com>
[-- Attachment #1: Type: text/plain, Size: 4536 bytes --]
Backport suggested by prism54 folks. idea acked by Jeff.
thanks for Domen Puncer at helping out.
Belows patch adds msleep() and msleep_interruptible() as found
in current 2.6 to 2.4.
therefor adds the helper functions ssleep(), jiffies_to_msecs(),
jiffies_to_usecs(), msecs_to_jiffies().
The namespace clashes for msleep() and msecs_to_jiffies()
are cleanup by the next 5 patches.
Signed-off-by: Maximilian Attems <janitor@sternwelten.at>
---
linux-2.4.28-rc1-max/include/linux/delay.h | 8 +++++
linux-2.4.28-rc1-max/include/linux/time.h | 41 +++++++++++++++++++++++++++++
linux-2.4.28-rc1-max/kernel/Makefile | 3 +-
linux-2.4.28-rc1-max/kernel/timer.c | 33 +++++++++++++++++++++++
4 files changed, 84 insertions(+), 1 deletion(-)
diff -puN kernel/Makefile~add-msleep-2.4 kernel/Makefile
--- linux-2.4.28-rc1/kernel/Makefile~add-msleep-2.4 2004-10-30 22:48:46.000000000 +0200
+++ linux-2.4.28-rc1-max/kernel/Makefile 2004-10-30 22:50:45.000000000 +0200
@@ -9,7 +9,8 @@
O_TARGET := kernel.o
-export-objs = signal.o sys.o kmod.o context.o ksyms.o pm.o exec_domain.o printk.o
+export-objs = signal.o sys.o kmod.o context.o ksyms.o pm.o exec_domain.o \
+ printk.o timer.o
obj-y = sched.o dma.o fork.o exec_domain.o panic.o printk.o \
module.o exit.o itimer.o info.o time.o softirq.o resource.o \
diff -puN kernel/timer.c~add-msleep-2.4 kernel/timer.c
--- linux-2.4.28-rc1/kernel/timer.c~add-msleep-2.4 2004-10-30 22:48:46.000000000 +0200
+++ linux-2.4.28-rc1-max/kernel/timer.c 2004-10-30 22:50:09.000000000 +0200
@@ -22,6 +22,7 @@
#include <linux/smp_lock.h>
#include <linux/interrupt.h>
#include <linux/kernel_stat.h>
+#include <linux/module.h>
#include <asm/uaccess.h>
@@ -874,3 +875,35 @@ asmlinkage long sys_nanosleep(struct tim
return 0;
}
+/**
+ * msleep - sleep safely even with waitqueue interruptions
+ * @msecs: Time in milliseconds to sleep for
+ */
+void msleep(unsigned int msecs)
+{
+ unsigned long timeout = msecs_to_jiffies(msecs) + 1;
+
+ while (timeout) {
+ set_current_state(TASK_UNINTERRUPTIBLE);
+ timeout = schedule_timeout(timeout);
+ }
+}
+
+EXPORT_SYMBOL(msleep);
+
+/**
+ * msleep_interruptible - sleep waiting for waitqueue interruptions
+ * @msecs: Time in milliseconds to sleep for
+ */
+unsigned long msleep_interruptible(unsigned int msecs)
+{
+ unsigned long timeout = msecs_to_jiffies(msecs) + 1;
+
+ while (timeout && !signal_pending(current)) {
+ set_current_state(TASK_INTERRUPTIBLE);
+ timeout = schedule_timeout(timeout);
+ }
+ return jiffies_to_msecs(timeout);
+}
+
+EXPORT_SYMBOL(msleep_interruptible);
diff -puN include/linux/delay.h~add-msleep-2.4 include/linux/delay.h
--- linux-2.4.28-rc1/include/linux/delay.h~add-msleep-2.4 2004-10-30 22:48:46.000000000 +0200
+++ linux-2.4.28-rc1-max/include/linux/delay.h 2004-10-30 22:48:46.000000000 +0200
@@ -34,4 +34,12 @@ extern unsigned long loops_per_jiffy;
({unsigned long msec=(n); while (msec--) udelay(1000);}))
#endif
+void msleep(unsigned int msecs);
+unsigned long msleep_interruptible(unsigned int msecs);
+
+static inline void ssleep(unsigned int seconds)
+{
+ msleep(seconds * 1000);
+}
+
#endif /* defined(_LINUX_DELAY_H) */
diff -puN include/linux/time.h~add-msleep-2.4 include/linux/time.h
--- linux-2.4.28-rc1/include/linux/time.h~add-msleep-2.4 2004-10-30 22:48:46.000000000 +0200
+++ linux-2.4.28-rc1-max/include/linux/time.h 2004-10-30 22:57:44.000000000 +0200
@@ -126,4 +126,45 @@ struct itimerval {
struct timeval it_value; /* current value */
};
+/*
+ * Convert jiffies to milliseconds and back.
+ *
+ * Avoid unnecessary multiplications/divisions in the
+ * two most common HZ cases:
+ */
+static inline unsigned int jiffies_to_msecs(const 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 int jiffies_to_usecs(const unsigned long j)
+{
+#if HZ <= 1000 && !(1000 % HZ)
+ return (1000000 / HZ) * j;
+#elif HZ > 1000 && !(HZ % 1000)
+ return (j*1000 + (HZ - 1000))/(HZ / 1000);
+#else
+ return (j * 1000000) / HZ;
+#endif
+}
+
+static inline unsigned long msecs_to_jiffies(const unsigned int m)
+{
+ if (m > jiffies_to_msecs(MAX_JIFFY_OFFSET))
+ return MAX_JIFFY_OFFSET;
+#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
+}
+
#endif
_
[-- Attachment #2: Type: text/plain, Size: 167 bytes --]
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
http://lists.osdl.org/mailman/listinfo/kernel-janitors
next prev parent reply other threads:[~2004-10-31 14:44 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20040923221303.GB13244@us.ibm.com>
2004-09-23 22:55 ` [PATCH 2.6.9-rc2 17/38] net/islpci_dev: replace schedule_timeout() with msleep() Luis R. Rodriguez
2004-09-24 7:43 ` Margit Schubert-While
2004-09-24 16:34 ` [Kernel-janitors] " maximilian attems
2004-10-01 4:15 ` Jeff Garzik
2004-10-01 7:04 ` Margit Schubert-While
2004-10-01 16:55 ` [Kernel-janitors] " Greg KH
2004-10-02 9:07 ` Margit Schubert-While
2004-10-04 21:04 ` Jeff Garzik
2004-10-30 22:22 ` [KJ] [patch 2.4] back port msleep(), msleep_interruptible() maximilian attems
2004-10-30 22:41 ` Jeff Garzik
2004-10-30 22:59 ` [KJ] " Nish Aravamudan
2004-10-30 22:59 ` Nish Aravamudan
[not found] ` <29495f1d041030155953a9a776@mail.gmail.com>
2004-10-30 23:19 ` maximilian attems
2004-10-30 23:19 ` maximilian attems
2004-10-31 14:43 ` maximilian attems
2004-10-31 14:43 ` maximilian attems
2004-10-31 14:44 ` maximilian attems [this message]
2004-10-31 14:44 ` [patch 2/6] libata remove duplicate definition msecs_to_jiffies() maximilian attems
2004-10-31 14:44 ` [patch 3/6] sx8 remove duplicate definition msleep(), msecs_to_jiffies() maximilian attems
2004-10-31 14:45 ` [patch 4/6] char/shwdt remove duplicate msecs_to_jiffies() maximilian attems
2004-10-31 14:45 ` [patch 5/6] sata_promise remove duplicate msleep() definition maximilian attems
2004-10-31 14:45 ` [patch 6/6] libata remove msleep_libata() maximilian attems
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20041031144424.GB28667@stro.at \
--to=janitor@sternwelten.at \
--cc=domen@coderock.org \
--cc=hvr@gnu.org \
--cc=jgarzik@pobox.com \
--cc=kernel-janitors@lists.osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=margitsw@t-online.de \
--cc=mcgrof@studorgs.rutgers.edu \
--cc=netdev@oss.sgi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).