From: Nishanth Aravamudan <nacc@us.ibm.com>
To: linux-kernel@vger.kernel.org
Subject: [RFC][PATCH 4/4] convert sys_nanosleep() to use set_timer_nsecs()
Date: Thu, 14 Jul 2005 13:43:33 -0700 [thread overview]
Message-ID: <20050714204333.GH28100@us.ibm.com> (raw)
In-Reply-To: <20050714202629.GD28100@us.ibm.com>
From: Nishanth Aravamudan <nacc@us.ibm.com>
Description: Add timespec and timeval conversion functions for
nanoseconds. Convert sys_nanosleep() to use schedule_timeout_nsecs().
Signed-off-by: Nishanth Aravamudan <nacc@us.ibm.com>
---
include/linux/time.h | 33 +++++++++++++++++++++++++++++++++
kernel/timer.c | 24 ++++++++++++------------
2 files changed, 45 insertions(+), 12 deletions(-)
diff -urpN 2.6.13-rc3-base/include/linux/time.h 2.6.13-rc3-dev/include/linux/time.h
--- 2.6.13-rc3-base/include/linux/time.h 2005-07-14 12:46:46.000000000 -0700
+++ 2.6.13-rc3-dev/include/linux/time.h 2005-07-14 12:48:25.000000000 -0700
@@ -2,6 +2,7 @@
#define _LINUX_TIME_H
#include <linux/types.h>
+#include <asm/div64.h>
#ifdef __KERNEL__
#include <linux/seqlock.h>
@@ -126,6 +127,38 @@ set_normalized_timespec (struct timespec
ts->tv_nsec = nsec;
}
+/* Inline helper functions */
+static inline struct timeval nsecs_to_timeval(u64 ns)
+{
+ struct timeval tv;
+ tv.tv_sec = div_long_long_rem(ns, NSEC_PER_SEC, &tv.tv_usec);
+ tv.tv_usec = (tv.tv_usec + NSEC_PER_USEC/2) / NSEC_PER_USEC;
+ return tv;
+}
+
+static inline struct timespec nsecs_to_timespec(u64 ns)
+{
+ struct timespec ts;
+ ts.tv_sec = div_long_long_rem(ns, NSEC_PER_SEC, &ts.tv_nsec);
+ return ts;
+}
+
+static inline u64 timespec_to_nsecs(struct timespec* ts)
+{
+ u64 ret;
+ ret = ((u64)ts->tv_sec) * NSEC_PER_SEC;
+ ret += (u64)ts->tv_nsec;
+ return ret;
+}
+
+static inline u64 timeval_to_nsecs(struct timeval* tv)
+{
+ u64 ret;
+ ret = ((u64)tv->tv_sec) * NSEC_PER_SEC;
+ ret += ((u64)tv->tv_usec) * NSEC_PER_USEC;
+ return ret;
+}
+
#endif /* __KERNEL__ */
#define NFDBITS __NFDBITS
diff -urpN 2.6.13-rc3-base/kernel/timer.c 2.6.13-rc3-dev/kernel/timer.c
--- 2.6.13-rc3-base/kernel/timer.c 2005-07-14 12:46:46.000000000 -0700
+++ 2.6.13-rc3-dev/kernel/timer.c 2005-07-14 12:48:25.000000000 -0700
@@ -1481,21 +1481,21 @@ asmlinkage long sys_gettid(void)
static long __sched nanosleep_restart(struct restart_block *restart)
{
- unsigned long expire = restart->arg0, now = jiffies;
+ u64 expire = restart->arg0, now = do_monotonic_clock();
struct timespec __user *rmtp = (struct timespec __user *) restart->arg1;
long ret;
/* Did it expire while we handled signals? */
- if (!time_after(expire, now))
+ if (now > expire)
return 0;
- current->state = TASK_INTERRUPTIBLE;
- expire = schedule_timeout(expire - now);
+ set_current_state(TASK_INTERRUPTIBLE);
+ expire = schedule_timeout_nsecs(expire - now);
ret = 0;
if (expire) {
struct timespec t;
- jiffies_to_timespec(expire, &t);
+ t = nsecs_to_timespec(expire);
ret = -ERESTART_RESTARTBLOCK;
if (rmtp && copy_to_user(rmtp, &t, sizeof(t)))
@@ -1508,7 +1508,7 @@ static long __sched nanosleep_restart(st
asmlinkage long sys_nanosleep(struct timespec __user *rqtp, struct timespec __user *rmtp)
{
struct timespec t;
- unsigned long expire;
+ u64 expire;
long ret;
if (copy_from_user(&t, rqtp, sizeof(t)))
@@ -1517,20 +1517,20 @@ asmlinkage long sys_nanosleep(struct tim
if ((t.tv_nsec >= 1000000000L) || (t.tv_nsec < 0) || (t.tv_sec < 0))
return -EINVAL;
- expire = timespec_to_jiffies(&t) + (t.tv_sec || t.tv_nsec);
- current->state = TASK_INTERRUPTIBLE;
- expire = schedule_timeout(expire);
+ expire = timespec_to_nsecs(&t);
+ set_current_state(TASK_INTERRUPTIBLE);
+ expire = schedule_timeout_nsecs(expire);
ret = 0;
if (expire) {
struct restart_block *restart;
- jiffies_to_timespec(expire, &t);
+ t = nsecs_to_timespec(expire);
if (rmtp && copy_to_user(rmtp, &t, sizeof(t)))
return -EFAULT;
restart = ¤t_thread_info()->restart_block;
restart->fn = nanosleep_restart;
- restart->arg0 = jiffies + expire;
+ restart->arg0 = do_monotonic_clock() + expire;
restart->arg1 = (unsigned long) rmtp;
ret = -ERESTART_RESTARTBLOCK;
}
@@ -1642,7 +1642,7 @@ static void __devinit init_timers_cpu(in
for (j = 0; j < TVR_SIZE; j++)
INIT_LIST_HEAD(base->tv1.vec + j);
- base->timer_jiffies = jiffies;
+ base->last_timer_time = 0UL;
}
#ifdef CONFIG_HOTPLUG_CPU
next prev parent reply other threads:[~2005-07-14 20:47 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-07-14 20:26 [RFC][PATCH 0/4] new human-time soft-timer subsystem Nishanth Aravamudan
2005-07-14 20:28 ` [RFC][PATCH 1/4] add jiffies_to_nsecs() helper and fix up size of usecs Nishanth Aravamudan
2005-07-14 20:54 ` Dave Hansen
2005-07-14 21:03 ` Nishanth Aravamudan
2005-07-15 12:14 ` Pavel Machek
2005-07-17 0:44 ` Nishanth Aravamudan
2005-07-14 20:40 ` [RFC][PATCH 2/4] human-time soft-timer core changes Nishanth Aravamudan
2005-07-18 21:53 ` [RFC][UPDATE PATCH " Nishanth Aravamudan
2005-07-14 20:41 ` [RFC][PATCH 3/4] new human-time schedule_timeout() functions Nishanth Aravamudan
2005-07-14 20:43 ` Nishanth Aravamudan [this message]
2005-07-14 22:28 ` [RFC][PATCH 0/4] new human-time soft-timer subsystem Roman Zippel
2005-07-17 0:53 ` 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=20050714204333.GH28100@us.ibm.com \
--to=nacc@us.ibm.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.