Commit 7978672c authored by George Anzinger's avatar George Anzinger Committed by Linus Torvalds

[PATCH] hrtimers: cleanups and simplifications

Clean up the interface to hrtimers by changing the init code to pass the mode
as well as the clock.  This allow the init code to select the correct base and
eliminates extra timer re-init code in posix-timers.  We also simplify the
restart interface nanosleep use.
Signed-off-by: default avatarGeorge Anzinger <george@mvista.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent ff60a5dc
...@@ -101,9 +101,8 @@ struct hrtimer_base { ...@@ -101,9 +101,8 @@ struct hrtimer_base {
/* Exported timer functions: */ /* Exported timer functions: */
/* Initialize timers: */ /* Initialize timers: */
extern void hrtimer_init(struct hrtimer *timer, const clockid_t which_clock); extern void hrtimer_init(struct hrtimer *timer, clockid_t which_clock,
extern void hrtimer_rebase(struct hrtimer *timer, const clockid_t which_clock); enum hrtimer_mode mode);
/* Basic timer operations: */ /* Basic timer operations: */
extern int hrtimer_start(struct hrtimer *timer, ktime_t tim, extern int hrtimer_start(struct hrtimer *timer, ktime_t tim,
......
...@@ -802,7 +802,7 @@ static inline int copy_signal(unsigned long clone_flags, struct task_struct * ts ...@@ -802,7 +802,7 @@ static inline int copy_signal(unsigned long clone_flags, struct task_struct * ts
init_sigpending(&sig->shared_pending); init_sigpending(&sig->shared_pending);
INIT_LIST_HEAD(&sig->posix_timers); INIT_LIST_HEAD(&sig->posix_timers);
hrtimer_init(&sig->real_timer, CLOCK_MONOTONIC); hrtimer_init(&sig->real_timer, CLOCK_MONOTONIC, HRTIMER_REL);
sig->it_real_incr.tv64 = 0; sig->it_real_incr.tv64 = 0;
sig->real_timer.function = it_real_fn; sig->real_timer.function = it_real_fn;
sig->real_timer.data = tsk; sig->real_timer.data = tsk;
......
...@@ -66,6 +66,12 @@ EXPORT_SYMBOL_GPL(ktime_get_real); ...@@ -66,6 +66,12 @@ EXPORT_SYMBOL_GPL(ktime_get_real);
/* /*
* The timer bases: * The timer bases:
*
* Note: If we want to add new timer bases, we have to skip the two
* clock ids captured by the cpu-timers. We do this by holding empty
* entries rather than doing math adjustment of the clock ids.
* This ensures that we capture erroneous accesses to these clock ids
* rather than moving them into the range of valid clock id's.
*/ */
#define MAX_HRTIMER_BASES 2 #define MAX_HRTIMER_BASES 2
...@@ -483,29 +489,25 @@ ktime_t hrtimer_get_remaining(const struct hrtimer *timer) ...@@ -483,29 +489,25 @@ ktime_t hrtimer_get_remaining(const struct hrtimer *timer)
} }
/** /**
* hrtimer_rebase - rebase an initialized hrtimer to a different base * hrtimer_init - initialize a timer to the given clock
* *
* @timer: the timer to be rebased * @timer: the timer to be initialized
* @clock_id: the clock to be used * @clock_id: the clock to be used
* @mode: timer mode abs/rel
*/ */
void hrtimer_rebase(struct hrtimer *timer, const clockid_t clock_id) void hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
enum hrtimer_mode mode)
{ {
struct hrtimer_base *bases; struct hrtimer_base *bases;
memset(timer, 0, sizeof(struct hrtimer));
bases = per_cpu(hrtimer_bases, raw_smp_processor_id()); bases = per_cpu(hrtimer_bases, raw_smp_processor_id());
timer->base = &bases[clock_id];
}
/** if (clock_id == CLOCK_REALTIME && mode != HRTIMER_ABS)
* hrtimer_init - initialize a timer to the given clock clock_id = CLOCK_MONOTONIC;
*
* @timer: the timer to be initialized timer->base = &bases[clock_id];
* @clock_id: the clock to be used
*/
void hrtimer_init(struct hrtimer *timer, const clockid_t clock_id)
{
memset(timer, 0, sizeof(struct hrtimer));
hrtimer_rebase(timer, clock_id);
} }
/** /**
...@@ -643,8 +645,7 @@ schedule_hrtimer_interruptible(struct hrtimer *timer, ...@@ -643,8 +645,7 @@ schedule_hrtimer_interruptible(struct hrtimer *timer,
return schedule_hrtimer(timer, mode); return schedule_hrtimer(timer, mode);
} }
static long __sched static long __sched nanosleep_restart(struct restart_block *restart)
nanosleep_restart(struct restart_block *restart, clockid_t clockid)
{ {
struct timespec __user *rmtp; struct timespec __user *rmtp;
struct timespec tu; struct timespec tu;
...@@ -654,7 +655,7 @@ nanosleep_restart(struct restart_block *restart, clockid_t clockid) ...@@ -654,7 +655,7 @@ nanosleep_restart(struct restart_block *restart, clockid_t clockid)
restart->fn = do_no_restart_syscall; restart->fn = do_no_restart_syscall;
hrtimer_init(&timer, clockid); hrtimer_init(&timer, (clockid_t) restart->arg3, HRTIMER_ABS);
timer.expires.tv64 = ((u64)restart->arg1 << 32) | (u64) restart->arg0; timer.expires.tv64 = ((u64)restart->arg1 << 32) | (u64) restart->arg0;
...@@ -674,16 +675,6 @@ nanosleep_restart(struct restart_block *restart, clockid_t clockid) ...@@ -674,16 +675,6 @@ nanosleep_restart(struct restart_block *restart, clockid_t clockid)
return -ERESTART_RESTARTBLOCK; return -ERESTART_RESTARTBLOCK;
} }
static long __sched nanosleep_restart_mono(struct restart_block *restart)
{
return nanosleep_restart(restart, CLOCK_MONOTONIC);
}
static long __sched nanosleep_restart_real(struct restart_block *restart)
{
return nanosleep_restart(restart, CLOCK_REALTIME);
}
long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp, long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
const enum hrtimer_mode mode, const clockid_t clockid) const enum hrtimer_mode mode, const clockid_t clockid)
{ {
...@@ -692,7 +683,7 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp, ...@@ -692,7 +683,7 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
struct timespec tu; struct timespec tu;
ktime_t rem; ktime_t rem;
hrtimer_init(&timer, clockid); hrtimer_init(&timer, clockid, mode);
timer.expires = timespec_to_ktime(*rqtp); timer.expires = timespec_to_ktime(*rqtp);
...@@ -700,7 +691,7 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp, ...@@ -700,7 +691,7 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
if (rem.tv64 <= 0) if (rem.tv64 <= 0)
return 0; return 0;
/* Absolute timers do not update the rmtp value: */ /* Absolute timers do not update the rmtp value and restart: */
if (mode == HRTIMER_ABS) if (mode == HRTIMER_ABS)
return -ERESTARTNOHAND; return -ERESTARTNOHAND;
...@@ -710,11 +701,11 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp, ...@@ -710,11 +701,11 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
return -EFAULT; return -EFAULT;
restart = &current_thread_info()->restart_block; restart = &current_thread_info()->restart_block;
restart->fn = (clockid == CLOCK_MONOTONIC) ? restart->fn = nanosleep_restart;
nanosleep_restart_mono : nanosleep_restart_real;
restart->arg0 = timer.expires.tv64 & 0xFFFFFFFF; restart->arg0 = timer.expires.tv64 & 0xFFFFFFFF;
restart->arg1 = timer.expires.tv64 >> 32; restart->arg1 = timer.expires.tv64 >> 32;
restart->arg2 = (unsigned long) rmtp; restart->arg2 = (unsigned long) rmtp;
restart->arg3 = (unsigned long) timer.base->index;
return -ERESTART_RESTARTBLOCK; return -ERESTART_RESTARTBLOCK;
} }
...@@ -741,10 +732,8 @@ static void __devinit init_hrtimers_cpu(int cpu) ...@@ -741,10 +732,8 @@ static void __devinit init_hrtimers_cpu(int cpu)
struct hrtimer_base *base = per_cpu(hrtimer_bases, cpu); struct hrtimer_base *base = per_cpu(hrtimer_bases, cpu);
int i; int i;
for (i = 0; i < MAX_HRTIMER_BASES; i++) { for (i = 0; i < MAX_HRTIMER_BASES; i++, base++)
spin_lock_init(&base->lock); spin_lock_init(&base->lock);
base++;
}
} }
#ifdef CONFIG_HOTPLUG_CPU #ifdef CONFIG_HOTPLUG_CPU
......
...@@ -194,9 +194,7 @@ static inline int common_clock_set(const clockid_t which_clock, ...@@ -194,9 +194,7 @@ static inline int common_clock_set(const clockid_t which_clock,
static int common_timer_create(struct k_itimer *new_timer) static int common_timer_create(struct k_itimer *new_timer)
{ {
hrtimer_init(&new_timer->it.real.timer, new_timer->it_clock); hrtimer_init(&new_timer->it.real.timer, new_timer->it_clock, 0);
new_timer->it.real.timer.data = new_timer;
new_timer->it.real.timer.function = posix_timer_fn;
return 0; return 0;
} }
...@@ -693,6 +691,7 @@ common_timer_set(struct k_itimer *timr, int flags, ...@@ -693,6 +691,7 @@ common_timer_set(struct k_itimer *timr, int flags,
struct itimerspec *new_setting, struct itimerspec *old_setting) struct itimerspec *new_setting, struct itimerspec *old_setting)
{ {
struct hrtimer *timer = &timr->it.real.timer; struct hrtimer *timer = &timr->it.real.timer;
enum hrtimer_mode mode;
if (old_setting) if (old_setting)
common_timer_get(timr, old_setting); common_timer_get(timr, old_setting);
...@@ -714,14 +713,10 @@ common_timer_set(struct k_itimer *timr, int flags, ...@@ -714,14 +713,10 @@ common_timer_set(struct k_itimer *timr, int flags,
if (!new_setting->it_value.tv_sec && !new_setting->it_value.tv_nsec) if (!new_setting->it_value.tv_sec && !new_setting->it_value.tv_nsec)
return 0; return 0;
/* Posix madness. Only absolute CLOCK_REALTIME timers mode = flags & TIMER_ABSTIME ? HRTIMER_ABS : HRTIMER_REL;
* are affected by clock sets. So we must reiniatilize hrtimer_init(&timr->it.real.timer, timr->it_clock, mode);
* the timer. timr->it.real.timer.data = timr;
*/ timr->it.real.timer.function = posix_timer_fn;
if (timr->it_clock == CLOCK_REALTIME && (flags & TIMER_ABSTIME))
hrtimer_rebase(timer, CLOCK_REALTIME);
else
hrtimer_rebase(timer, CLOCK_MONOTONIC);
timer->expires = timespec_to_ktime(new_setting->it_value); timer->expires = timespec_to_ktime(new_setting->it_value);
...@@ -732,8 +727,7 @@ common_timer_set(struct k_itimer *timr, int flags, ...@@ -732,8 +727,7 @@ common_timer_set(struct k_itimer *timr, int flags,
if (((timr->it_sigev_notify & ~SIGEV_THREAD_ID) == SIGEV_NONE)) if (((timr->it_sigev_notify & ~SIGEV_THREAD_ID) == SIGEV_NONE))
return 0; return 0;
hrtimer_start(timer, timer->expires, (flags & TIMER_ABSTIME) ? hrtimer_start(timer, timer->expires, mode);
HRTIMER_ABS : HRTIMER_REL);
return 0; return 0;
} }
...@@ -948,21 +942,8 @@ sys_clock_getres(const clockid_t which_clock, struct timespec __user *tp) ...@@ -948,21 +942,8 @@ sys_clock_getres(const clockid_t which_clock, struct timespec __user *tp)
static int common_nsleep(const clockid_t which_clock, int flags, static int common_nsleep(const clockid_t which_clock, int flags,
struct timespec *tsave, struct timespec __user *rmtp) struct timespec *tsave, struct timespec __user *rmtp)
{ {
int mode = flags & TIMER_ABSTIME ? HRTIMER_ABS : HRTIMER_REL; return hrtimer_nanosleep(tsave, rmtp, flags & TIMER_ABSTIME ?
int clockid = which_clock; HRTIMER_ABS : HRTIMER_REL, which_clock);
switch (which_clock) {
case CLOCK_REALTIME:
/* Posix madness. Only absolute timers on clock realtime
are affected by clock set. */
if (mode != HRTIMER_ABS)
clockid = CLOCK_MONOTONIC;
case CLOCK_MONOTONIC:
break;
default:
return -EINVAL;
}
return hrtimer_nanosleep(tsave, rmtp, mode, clockid);
} }
asmlinkage long asmlinkage long
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment