From: Nishanth Aravamudan <nacc@us.ibm.com>
To: Arjan van de Ven <arjan@infradead.org>
Cc: Andrew Morton <akpm@osdl.org>,
domen@coderock.org, linux-kernel@vger.kernel.org,
clucas@rotomalug.org
Subject: [UPDATE PATCH] Add schedule_timeout_{interruptible,uninterruptible}_msecs() interfaces
Date: Fri, 22 Jul 2005 18:08:01 -0700 [thread overview]
Message-ID: <20050723010801.GA4366@us.ibm.com> (raw)
In-Reply-To: <1122078715.5734.15.camel@localhost.localdomain>
On 22.07.2005 [20:31:55 -0400], Arjan van de Ven wrote:
>
> > How does something like this look? If this looks ok, I'll send out
> > bunches of patches to add users of the new interfaces.
>
> I'd drop the FASTCALL stuff... nowadays with regparm that's automatic
> and the cost of register-vs-stack isn't too big anyway
>
>
> Also I'd rather not add the non-msec ones... either you're raw and use
> HZ, or you are "cooked" and use the msec variant.. I dont' see the point
> of adding an "in the middle" one. (Yes this means that several users
> need to be transformed to msecs but... I consider that progress ;)
Thanks for the feedback! Does this look better? I will be more than
happy to convert those users to msecs which should, btw :) I've been
waiting to add this interface so that the ones that couldn't use
msleep{,_interruptible}() because of wait-queues, can also be changed to
use milliseconds.
Hrm, I also noticed I typo'd the externs in sched.h. Fixed in the new
patch.
Description: Add schedule_timeout_msecs() and add wrappers for
interruptible/uninterruptible schedule_timeout_msecs() callers.
Signed-off-by: Nishanth Aravamudan <nacc@us.ibm.com>
---
include/linux/sched.h | 7 +++
kernel/timer.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 100 insertions(+), 1 deletion(-)
diff -urpN 2.6.13-rc3/include/linux/sched.h 2.6.13-rc3-new_interfaces/include/linux/sched.h
--- 2.6.13-rc3/include/linux/sched.h 2005-07-13 15:52:14.000000000 -0700
+++ 2.6.13-rc3-new_interfaces/include/linux/sched.h 2005-07-22 18:06:36.000000000 -0700
@@ -181,8 +181,13 @@ extern void scheduler_tick(void);
/* Is this address in the __sched functions? */
extern int in_sched_functions(unsigned long addr);
-#define MAX_SCHEDULE_TIMEOUT LONG_MAX
+#define MAX_SCHEDULE_TIMEOUT LONG_MAX
+#define MAX_SCHEDULE_TIMEOUT_MSECS UINT_MAX
extern signed long FASTCALL(schedule_timeout(signed long timeout));
+extern unsigned int schedule_timeout_msecs_interruptible
+ (unsigned int timeout_msecs);
+extern unsigned int schedule_timeout_msecs_uninterruptible
+ (unsigned int timeout_msecs);
asmlinkage void schedule(void);
struct namespace;
diff -urpN 2.6.13-rc3/kernel/timer.c 2.6.13-rc3-new_interfaces/kernel/timer.c
--- 2.6.13-rc3/kernel/timer.c 2005-07-13 15:52:14.000000000 -0700
+++ 2.6.13-rc3-new_interfaces/kernel/timer.c 2005-07-22 18:00:46.000000000 -0700
@@ -1153,6 +1153,100 @@ fastcall signed long __sched schedule_ti
EXPORT_SYMBOL(schedule_timeout);
+/*
+ * schedule_timeout_msecs - sleep until timeout
+ * @timeout_msecs: timeout value in milliseconds
+ *
+ * A human-time (but otherwise identical) alternative to
+ * schedule_timeout() The state, therefore, *does* need to be set before
+ * calling this function, but this function should *never* be called
+ * directly. Use the nice wrappers, schedule_{interruptible,
+ * uninterruptible}_timeout_msecs().
+ *
+ * See the comment for schedule_timeout() for details.
+ */
+inline unsigned int __sched schedule_timeout_msecs(unsigned int timeout_msecs)
+{
+ struct timer_list timer;
+ unsigned long expire_jifs;
+ signed long remaining_jifs;
+
+ if (timeout_msecs == MAX_SCHEDULE_TIMEOUT_MSECS) {
+ schedule();
+ goto out;
+ }
+
+ /*
+ * msecs_to_jiffies() is a unit conversion, which truncates
+ * (rounds down), so we need to add 1.
+ */
+ expire_jifs = jiffies + msecs_to_jiffies(timeout_msecs) + 1;
+
+ init_timer(&timer);
+ timer.expires = expire_jifs;
+ timer.data = (unsigned long) current;
+ timer.function = process_timeout;
+
+ add_timer(&timer);
+ schedule();
+ del_singleshot_timer_sync(&timer);
+
+ remaining_jifs = expire_jifs - jiffies;
+ /* if we have woken up *before* we have requested */
+ if (remaining_jifs > 0)
+ /*
+ * don't need to add 1 here, even though there is
+ * truncation, because we will add 1 if/when the value
+ * is sent back in
+ */
+ timeout_msecs = jiffies_to_msecs(remaining_jifs);
+ else
+ timeout_msecs = 0;
+
+ out:
+ return timeout_msecs;
+}
+
+/**
+ * schedule_timeout_msecs_interruptible - sleep until timeout,
+ * wait-queue event, or signal
+ * @timeout_msecs: timeout value in milliseconds
+ *
+ * A nice wrapper for the common
+ * set_current_state()/schedule_timeout_msecs() usage. The state,
+ * therefore, does *not* need to be set before calling this function.
+ *
+ * See the comment for schedule_timeout() for details.
+ */
+unsigned int __sched schedule_timeout_msecs_interruptible
+ (unsigned int timeout_msecs)
+{
+ set_current_state(TASK_INTERRUPTIBLE);
+ return schedule_timeout_msecs(timeout_msecs);
+}
+
+EXPORT_SYMBOL_GPL(schedule_timeout_msecs_interruptible);
+
+/**
+ * schedule_timeout_msecs_uninterrutible - sleep until timeout or
+ * wait-queue event
+ * @timeout_msecs: timeout value in milliseconds
+ *
+ * A nice wrapper for the common
+ * set_current_state()/schedule_timeout_msecs() usage. The state,
+ * therefore, does *not* need to be set before calling this function.
+ *
+ * See the comment for schedule_timeout() for details.
+ */
+unsigned int __sched schedule_timeout_msecs_uninterruptible
+ (unsigned int timeout_msecs)
+{
+ set_current_state(TASK_UNINTERRUPTIBLE);
+ return schedule_timeout_msecs(timeout_msecs);
+}
+
+EXPORT_SYMBOL_GPL(schedule_timeout_msecs_uninterruptible);
+
/* Thread ID - the internal kernel "pid" */
asmlinkage long sys_gettid(void)
{
next prev parent reply other threads:[~2005-07-23 1:09 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-07-07 21:31 [patch 1/4] drivers/char/ip2/i2lib.c: replace direct assignment with set_current_state() domen
2005-07-08 23:08 ` Andrew Morton
2005-07-08 23:22 ` Nish Aravamudan
2005-07-23 0:27 ` [PATCH] Add schedule_timeout_{interruptible,uninterruptible}{,_msecs}() interfaces Nishanth Aravamudan
2005-07-23 0:31 ` Arjan van de Ven
2005-07-23 1:08 ` Nishanth Aravamudan [this message]
2005-07-23 2:30 ` [UPDATE PATCH] Add schedule_timeout_{interruptible,uninterruptible}_msecs() interfaces Andrew Morton
2005-07-23 16:23 ` Nishanth Aravamudan
2005-07-23 10:50 ` [PATCH] Add schedule_timeout_{interruptible,uninterruptible}{,_msecs}() interfaces Roman Zippel
2005-07-23 11:09 ` Arjan van de Ven
2005-07-23 11:55 ` Roman Zippel
2005-07-23 12:51 ` Arjan van de Ven
2005-07-23 13:04 ` Roman Zippel
2005-07-23 13:12 ` Arjan van de Ven
2005-07-23 13:29 ` Roman Zippel
2005-07-23 13:32 ` Arjan van de Ven
2005-07-23 15:56 ` Roman Zippel
2005-07-23 16:44 ` Nishanth Aravamudan
2005-07-23 16:43 ` Nishanth Aravamudan
2005-07-23 17:17 ` Roman Zippel
2005-07-23 19:10 ` Nishanth Aravamudan
2005-07-23 20:12 ` Roman Zippel
2005-07-27 22:29 ` Nishanth Aravamudan
2005-07-30 23:35 ` Roman Zippel
2005-08-01 19:35 ` [UPDATE PATCH] Add schedule_timeout_{intr,unintr}{,_msecs}() interfaces Nishanth Aravamudan
2005-08-03 14:20 ` Roman Zippel
2005-08-04 0:51 ` [PATCH] push rounding up of relative request to schedule_timeout() Nishanth Aravamudan
2005-08-04 5:14 ` [UPDATE PATCH] " Nishanth Aravamudan
2005-08-04 16:45 ` George Anzinger
2005-08-04 18:48 ` Nish Aravamudan
2005-08-16 23:05 ` Nishanth Aravamudan
2005-08-17 0:39 ` George Anzinger
2005-08-17 5:56 ` Nishanth Aravamudan
2005-08-17 19:51 ` George Anzinger
2005-08-17 22:24 ` Nishanth Aravamudan
2005-08-04 17:05 ` George Anzinger
2005-08-04 18:49 ` Nish Aravamudan
2005-08-04 9:38 ` [PATCH] " Roman Zippel
2005-08-04 14:33 ` Nishanth Aravamudan
2005-08-04 18:59 ` Roman Zippel
2005-08-04 19:11 ` Nishanth Aravamudan
2005-08-04 23:20 ` Roman Zippel
2005-08-04 17:08 ` Andrew Morton
2005-08-04 19:00 ` [PATCH] add schedule_timeout_{,un}intr() interfaces Nishanth Aravamudan
2005-08-05 7:38 ` Andrew Morton
2005-07-23 16:37 ` [PATCH] Add schedule_timeout_{interruptible,uninterruptible}{,_msecs}() interfaces Nishanth Aravamudan
2005-07-23 17:01 ` Roman Zippel
2005-07-23 19:06 ` Nishanth Aravamudan
2005-07-23 20:22 ` Roman Zippel
2005-07-23 16:30 ` Nishanth Aravamudan
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=20050723010801.GA4366@us.ibm.com \
--to=nacc@us.ibm.com \
--cc=akpm@osdl.org \
--cc=arjan@infradead.org \
--cc=clucas@rotomalug.org \
--cc=domen@coderock.org \
--cc=linux-kernel@vger.kernel.org \
/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