From: Roman Zippel <zippel@linux-m68k.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Jonathan Corbet <corbet@lwn.net>,
linux-kernel@vger.kernel.org,
Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@elte.hu>
Subject: Re: [PATCH] msleep() with hrtimers
Date: Wed, 8 Aug 2007 05:47:02 +0200 (CEST) [thread overview]
Message-ID: <Pine.LNX.4.64.0708080535140.1817@scrub.home> (raw)
In-Reply-To: <20070807162940.74f536f8.akpm@linux-foundation.org>
On Tue, 7 Aug 2007, Andrew Morton wrote:
> On Wed, 8 Aug 2007 01:16:49 +0200 (CEST)
> Roman Zippel <zippel@linux-m68k.org> wrote:
>
> > Hi,
> >
> > On Tue, 7 Aug 2007, Andrew Morton wrote:
> >
> > > I'd be surprised if there was significant overhead - the maximum frequency
> > > at which msleep() can be called is 1000Hz. We'd need an awful lot of
> > > overhead for that to cause problems, surely?
> > >
> > > <thinks he's missing something again>
> >
> > _Anybody_ has yet to answer what's wrong with adding a nanosleep() and
> > using that instead.
> >
>
> You mean that the implementation could be simplified if msleep() were to
> simply call do_nanosleep()?
The current msleep is fine and doesn't need any "fixing".
Not all the world is i386, _please_ keep hrtimer usage where it's
required. Simple timer should be given preference unless the higher
resolution is really needed, which is not the case here.
> That would work, although a bit of refactoring would be needed so that we
> could implement the TASK_UNINTERRUPTIBLE msleep() that way.
The function is not that big, so below is a nanosleep implementation based
on Jonathan's patch. This will user give a choice, so there is no need to
force all users to use hrtimer for a simple sleep.
Please apply this patch instead.
bye, Roman
Signed-off-by: Roman Zippel <zippel@linux-m68k.org>
---
include/linux/delay.h | 5 +++++
kernel/timer.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 54 insertions(+)
Index: linux-2.6/include/linux/delay.h
===================================================================
--- linux-2.6.orig/include/linux/delay.h
+++ linux-2.6/include/linux/delay.h
@@ -9,6 +9,7 @@
extern unsigned long loops_per_jiffy;
+#include <linux/ktime.h>
#include <asm/delay.h>
/*
@@ -36,6 +37,10 @@ extern unsigned long loops_per_jiffy;
#endif
void calibrate_delay(void);
+
+void nanosleep(ktime_t time);
+int nanosleep_interruptible(ktime_t *time);
+
void msleep(unsigned int msecs);
unsigned long msleep_interruptible(unsigned int msecs);
Index: linux-2.6/kernel/timer.c
===================================================================
--- linux-2.6.orig/kernel/timer.c
+++ linux-2.6/kernel/timer.c
@@ -1377,3 +1377,52 @@ unsigned long msleep_interruptible(unsig
}
EXPORT_SYMBOL(msleep_interruptible);
+
+static int do_nanosleep(ktime_t *time, int sigs)
+{
+ enum hrtimer_mode mode = HRTIMER_MODE_REL;
+ int state = sigs ? TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE;
+ struct hrtimer_sleeper sleeper;
+
+ hrtimer_init_sleeper(&sleeper, current);
+ hrtimer_init(&sleeper.timer, CLOCK_MONOTONIC, mode);
+ sleeper.timer.expires = *time;
+
+ do {
+ set_current_state(state);
+ hrtimer_start(&sleeper.timer, sleeper.timer.expires, mode);
+ if (sleeper.task)
+ schedule();
+ hrtimer_cancel(&sleeper.timer);
+ mode = HRTIMER_MODE_ABS;
+ if (!sleeper.task)
+ return 1;
+ } while (!sigs || !signal_pending(current));
+
+ *time = sleeper.timer.expires;
+ return 0;
+}
+
+/**
+ * nanosleep - sleep safely even with waitqueue interruptions
+ * @time: Time to sleep for
+ */
+void nanosleep(ktime_t time)
+{
+ do_nanosleep(&time, 0);
+}
+EXPORT_SYMBOL(nanosleep);
+
+/**
+ * nanosleep_interruptible - sleep waiting for signals
+ * @time: Time to sleep for
+ */
+int nanosleep_interruptible(ktime_t *time)
+{
+ if (do_nanosleep(time, 1))
+ return 1;
+
+ *time = ktime_sub(*time, ktime_get());
+ return 0;
+}
+EXPORT_SYMBOL(nanosleep_interruptible);
next prev parent reply other threads:[~2007-08-08 3:46 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-03 18:37 [PATCH] msleep() with hrtimers Jonathan Corbet
2007-08-03 18:54 ` Ingo Molnar
2007-08-03 19:19 ` Roman Zippel
2007-08-03 19:46 ` Arjan van de Ven
2007-08-03 19:58 ` Roman Zippel
2007-08-03 23:53 ` Arjan van de Ven
2007-08-04 3:00 ` Roman Zippel
2007-08-04 19:19 ` Arjan van de Ven
2007-08-06 0:09 ` Roman Zippel
2007-08-06 0:43 ` Arjan van de Ven
2007-08-06 1:03 ` Roman Zippel
2007-08-06 5:39 ` Arjan van de Ven
2007-08-06 10:03 ` Roman Zippel
2007-08-06 10:20 ` Manu Abraham
2007-08-06 15:53 ` Arjan van de Ven
2007-08-07 10:40 ` Manu Abraham
2007-08-07 12:45 ` Roman Zippel
2007-08-08 4:15 ` Arjan van de Ven
2007-08-09 19:31 ` Denis Vlasenko
2007-08-09 20:01 ` Denis Vlasenko
2007-08-07 19:40 ` Andrew Morton
2007-08-07 23:16 ` Roman Zippel
2007-08-07 23:29 ` Andrew Morton
2007-08-08 3:47 ` Roman Zippel [this message]
2007-08-08 4:14 ` Andrew Morton
2007-08-09 22:31 ` Roman Zippel
2007-08-08 11:55 ` Andi Kleen
2007-08-08 11:09 ` Manu Abraham
2007-08-08 11:52 ` Andi Kleen
2007-08-08 11:59 ` Manu Abraham
2007-08-09 7:16 ` Andrew Morton
2007-08-09 15:08 ` [linux-usb-devel] " Alan Stern
2007-11-28 10:29 ` Andrew Morton
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=Pine.LNX.4.64.0708080535140.1817@scrub.home \
--to=zippel@linux-m68k.org \
--cc=akpm@linux-foundation.org \
--cc=corbet@lwn.net \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=tglx@linutronix.de \
/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).