From: Nishanth Aravamudan <nacc@us.ibm.com>
To: Kernel-Janitors <kernel-janitors@lists.osdl.org>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [RFC][PATCH] add schedule_timeout_msecs() interface
Date: Tue, 3 May 2005 11:58:01 -0700 [thread overview]
Message-ID: <20050503185801.GB3372@us.ibm.com> (raw)
Add a new interface, paralleling schedule_timeout(), but accepting
instead a relative millisecond value. This is part of my overall effort
to incorporate human-time units in the soft-timer subsystem.
Signed-off-by: Nishanth Aravamudan <nacc@us.ibm.com>
include/linux/sched.h | 2 +
kernel/timer.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 60 insertions(+)
--- 2.6.12-rc3/kernel/timer.c 2005-04-29 11:03:06.000000000 -0700
+++ 2.6.12-rc3-dev/kernel/timer.c 2005-05-03 11:52:43.000000000 -0700
@@ -1129,6 +1129,64 @@ fastcall signed long __sched schedule_ti
EXPORT_SYMBOL(schedule_timeout);
+/**
+ * schedule_timeout_msecs - sleep until timeout
+ * @timeout: timeout value in milliseconds
+ *
+ * Make the current task sleep until @timeout milliseconds have
+ * elapsed. The routine will return immediately unless
+ * the current task state has been set (see set_current_state()).
+ *
+ * You can set the task state as follows -
+ *
+ * %TASK_UNINTERRUPTIBLE - at least @timeout milliseconds are guaranteed
+ * to pass before the routine returns. The routine will return 0
+ *
+ * %TASK_INTERRUPTIBLE - the routine may return early if a signal is
+ * delivered to the current task. In this case the remaining time in
+ * milliseconds will be returned, or 0 if the timer expired in time
+ *
+ * The current task state is guaranteed to be TASK_RUNNING when this
+ * routine returns.
+ *
+ * Specifying a @timeout value of %MAX_SCHEDULE_TIMEOUT_MSECS will
+ * schedule the CPU away without a bound on the timeout. In this case
+ * the return value will be %MAX_SCHEDULE_TIMEOUT_MSECS.
+ *
+ * In all cases the return value is guaranteed to be non-negative.
+ */
+fastcall unsigned int __sched schedule_timeout_msecs(unsigned int timeout)
+{
+ struct timer_list timer;
+ unsigned long expires;
+
+ if (timeout == MAX_SCHEDULE_TIMEOUT_MSECS) {
+ schedule();
+ goto out;
+ }
+
+ expires = jiffies + msecs_to_jiffies(timeout);
+
+ init_timer(&timer);
+ timer.expires = expires;
+ timer.data = (unsigned long)current;
+ timer.function = process_timeout;
+
+ add_timer(&timer);
+ schedule();
+ del_singleshot_timer_sync(&timer);
+
+ if (jiffies > expires)
+ timeout = 0;
+ else
+ timeout = jiffies_to_msecs(expires - jiffies);
+
+out:
+ return timeout;
+}
+
+EXPORT_SYMBOL_GPL(schedule_timeout_msecs);
+
/* Thread ID - the internal kernel "pid" */
asmlinkage long sys_gettid(void)
{
--- 2.6.12-rc3/include/linux/sched.h 2005-04-29 11:03:06.000000000 -0700
+++ 2.6.12-rc3-dev/include/linux/sched.h 2005-05-03 11:30:25.000000000 -0700
@@ -182,7 +182,9 @@ extern void scheduler_tick(void);
extern int in_sched_functions(unsigned long addr);
#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 FASTCALL(schedule_timeout_msecs(unsigned int timeout));
asmlinkage void schedule(void);
struct namespace;
reply other threads:[~2005-05-03 18:58 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20050503185801.GB3372@us.ibm.com \
--to=nacc@us.ibm.com \
--cc=kernel-janitors@lists.osdl.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
all inboxes | Powered by JetHome®