[PATCH 12/13] hrtimer: optimize hrtimer_get_remaining

From: Roman Zippel
Date: Sun Feb 12 2006 - 20:10:26 EST



hrtimer_get_remaining doesn't need to lock the hrtimer_base to read the
time. Also use hrtimer_get_remaining at two other places.

Signed-off-by: Roman Zippel <zippel@xxxxxxxxxxxxxx>

kernel/hrtimer.c | 18 +++---------------
1 file changed, 3 insertions(+), 15 deletions(-)

Index: linux-2.6-git/kernel/hrtimer.c
===================================================================
--- linux-2.6-git.orig/kernel/hrtimer.c 2006-02-13 01:39:19.000000000 +0100
+++ linux-2.6-git/kernel/hrtimer.c 2006-02-13 01:41:59.000000000 +0100
@@ -482,15 +482,7 @@ int hrtimer_cancel(struct hrtimer *timer
*/
ktime_t hrtimer_get_remaining(const struct hrtimer *timer)
{
- struct hrtimer_base *base;
- unsigned long flags;
- ktime_t rem;
-
- base = lock_hrtimer_base(timer, &flags);
- rem = ktime_sub(timer->expires, timer->base->get_time());
- unlock_hrtimer_base(timer, &flags);
-
- return rem;
+ return ktime_sub(timer->expires, timer->base->get_time());
}

/**
@@ -639,7 +631,6 @@ static long __sched nanosleep_restart(st
struct sleep_hrtimer t;
struct timespec __user *rmtp;
struct timespec tu;
- ktime_t time;

restart->fn = do_no_restart_syscall;

@@ -650,8 +641,7 @@ static long __sched nanosleep_restart(st

rmtp = (struct timespec __user *) restart->arg2;
if (rmtp) {
- time = ktime_sub(t.timer.expires, t.timer.base->get_time());
- tu = ktime_to_timespec(time);
+ tu = ktime_to_timespec(hrtimer_get_remaining(&t.timer));
if (copy_to_user(rmtp, &tu, sizeof(tu)))
return -EFAULT;
}
@@ -668,7 +658,6 @@ long hrtimer_nanosleep(struct timespec *
struct restart_block *restart;
struct sleep_hrtimer t;
struct timespec tu;
- ktime_t rem;

hrtimer_init(&t.timer, clockid, mode);
t.timer.expires = timespec_to_ktime(*rqtp);
@@ -680,8 +669,7 @@ long hrtimer_nanosleep(struct timespec *
return -ERESTARTNOHAND;

if (rmtp) {
- rem = ktime_sub(t.timer.expires, t.timer.base->get_time());
- tu = ktime_to_timespec(rem);
+ tu = ktime_to_timespec(hrtimer_get_remaining(&t.timer));
if (copy_to_user(rmtp, &tu, sizeof(tu)))
return -EFAULT;
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/