aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/posix-timers.c
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2011-02-01 08:51:58 -0500
committerThomas Gleixner <tglx@linutronix.de>2011-02-02 09:28:15 -0500
commit838394fbf989973ec7f5a0ad82cb6ff09e5c39aa (patch)
treed6558c96c9e386d3e17d38d30aabc12b0def2d7b /kernel/posix-timers.c
parentebaac757acae0431e2c79c00e09f1debdabbddd7 (diff)
posix-timers: Convert timer_create() to clockid_to_kclock()
Setup timer_create for CLOCK_MONOTONIC and CLOCK_REALTIME kclocks and remove the no_timer_create() implementation. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: John Stultz <johnstul@us.ibm.com> Tested-by: Richard Cochran <richard.cochran@omicron.at> LKML-Reference: <20110201134418.903604289@linutronix.de>
Diffstat (limited to 'kernel/posix-timers.c')
-rw-r--r--kernel/posix-timers.c40
1 files changed, 15 insertions, 25 deletions
diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index f9142a99b5cb..4f71382a4ca8 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -146,6 +146,7 @@ static struct k_clock posix_clocks[MAX_CLOCKS];
146 */ 146 */
147static int common_nsleep(const clockid_t, int flags, struct timespec *t, 147static int common_nsleep(const clockid_t, int flags, struct timespec *t,
148 struct timespec __user *rmtp); 148 struct timespec __user *rmtp);
149static int common_timer_create(struct k_itimer *new_timer);
149static void common_timer_get(struct k_itimer *, struct itimerspec *); 150static void common_timer_get(struct k_itimer *, struct itimerspec *);
150static int common_timer_set(struct k_itimer *, int, 151static int common_timer_set(struct k_itimer *, int,
151 struct itimerspec *, struct itimerspec *); 152 struct itimerspec *, struct itimerspec *);
@@ -175,25 +176,6 @@ static inline void unlock_timer(struct k_itimer *timr, unsigned long flags)
175 ? (*posix_clocks[clock].call) arglist : common_##call arglist)) 176 ? (*posix_clocks[clock].call) arglist : common_##call arglist))
176 177
177/* 178/*
178 * Default clock hook functions when the struct k_clock passed
179 * to register_posix_clock leaves a function pointer null.
180 *
181 * The function common_CALL is the default implementation for
182 * the function pointer CALL in struct k_clock.
183 */
184
185static int common_timer_create(struct k_itimer *new_timer)
186{
187 hrtimer_init(&new_timer->it.real.timer, new_timer->it_clock, 0);
188 return 0;
189}
190
191static int no_timer_create(struct k_itimer *new_timer)
192{
193 return -EOPNOTSUPP;
194}
195
196/*
197 * Return nonzero if we know a priori this clockid_t value is bogus. 179 * Return nonzero if we know a priori this clockid_t value is bogus.
198 */ 180 */
199static inline int invalid_clockid(const clockid_t which_clock) 181static inline int invalid_clockid(const clockid_t which_clock)
@@ -269,27 +251,26 @@ static __init int init_posix_timers(void)
269 .clock_set = posix_clock_realtime_set, 251 .clock_set = posix_clock_realtime_set,
270 .nsleep = common_nsleep, 252 .nsleep = common_nsleep,
271 .nsleep_restart = hrtimer_nanosleep_restart, 253 .nsleep_restart = hrtimer_nanosleep_restart,
254 .timer_create = common_timer_create,
272 }; 255 };
273 struct k_clock clock_monotonic = { 256 struct k_clock clock_monotonic = {
274 .clock_getres = hrtimer_get_res, 257 .clock_getres = hrtimer_get_res,
275 .clock_get = posix_ktime_get_ts, 258 .clock_get = posix_ktime_get_ts,
276 .nsleep = common_nsleep, 259 .nsleep = common_nsleep,
277 .nsleep_restart = hrtimer_nanosleep_restart, 260 .nsleep_restart = hrtimer_nanosleep_restart,
261 .timer_create = common_timer_create,
278 }; 262 };
279 struct k_clock clock_monotonic_raw = { 263 struct k_clock clock_monotonic_raw = {
280 .clock_getres = hrtimer_get_res, 264 .clock_getres = hrtimer_get_res,
281 .clock_get = posix_get_monotonic_raw, 265 .clock_get = posix_get_monotonic_raw,
282 .timer_create = no_timer_create,
283 }; 266 };
284 struct k_clock clock_realtime_coarse = { 267 struct k_clock clock_realtime_coarse = {
285 .clock_getres = posix_get_coarse_res, 268 .clock_getres = posix_get_coarse_res,
286 .clock_get = posix_get_realtime_coarse, 269 .clock_get = posix_get_realtime_coarse,
287 .timer_create = no_timer_create,
288 }; 270 };
289 struct k_clock clock_monotonic_coarse = { 271 struct k_clock clock_monotonic_coarse = {
290 .clock_getres = posix_get_coarse_res, 272 .clock_getres = posix_get_coarse_res,
291 .clock_get = posix_get_monotonic_coarse, 273 .clock_get = posix_get_monotonic_coarse,
292 .timer_create = no_timer_create,
293 }; 274 };
294 275
295 register_posix_clock(CLOCK_REALTIME, &clock_realtime); 276 register_posix_clock(CLOCK_REALTIME, &clock_realtime);
@@ -534,19 +515,28 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
534 return &posix_clocks[id]; 515 return &posix_clocks[id];
535} 516}
536 517
518static int common_timer_create(struct k_itimer *new_timer)
519{
520 hrtimer_init(&new_timer->it.real.timer, new_timer->it_clock, 0);
521 return 0;
522}
523
537/* Create a POSIX.1b interval timer. */ 524/* Create a POSIX.1b interval timer. */
538 525
539SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock, 526SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
540 struct sigevent __user *, timer_event_spec, 527 struct sigevent __user *, timer_event_spec,
541 timer_t __user *, created_timer_id) 528 timer_t __user *, created_timer_id)
542{ 529{
530 struct k_clock *kc = clockid_to_kclock(which_clock);
543 struct k_itimer *new_timer; 531 struct k_itimer *new_timer;
544 int error, new_timer_id; 532 int error, new_timer_id;
545 sigevent_t event; 533 sigevent_t event;
546 int it_id_set = IT_ID_NOT_SET; 534 int it_id_set = IT_ID_NOT_SET;
547 535
548 if (invalid_clockid(which_clock)) 536 if (!kc)
549 return -EINVAL; 537 return -EINVAL;
538 if (!kc->timer_create)
539 return -EOPNOTSUPP;
550 540
551 new_timer = alloc_posix_timer(); 541 new_timer = alloc_posix_timer();
552 if (unlikely(!new_timer)) 542 if (unlikely(!new_timer))
@@ -608,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
608 goto out; 598 goto out;
609 } 599 }
610 600
611 error = CLOCK_DISPATCH(which_clock, timer_create, (new_timer)); 601 error = kc->timer_create(new_timer);
612 if (error) 602 if (error)
613 goto out; 603 goto out;
614 604
@@ -618,7 +608,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
618 spin_unlock_irq(&current->sighand->siglock); 608 spin_unlock_irq(&current->sighand->siglock);
619 609
620 return 0; 610 return 0;
621 /* 611 /*
622 * In the case of the timer belonging to another task, after 612 * In the case of the timer belonging to another task, after
623 * the task is unlocked, the timer is owned by the other task 613 * the task is unlocked, the timer is owned by the other task
624 * and may cease to exist at any time. Don't use or modify 614 * and may cease to exist at any time. Don't use or modify