2011-02-01 13:52:09

by Thomas Gleixner

[permalink] [raw]
Subject: [patch 15/28] 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 <[email protected]>
Cc: John Stultz <[email protected]>
Cc: Richard Cochran <[email protected]>
---
kernel/posix-timers.c | 40 +++++++++++++++-------------------------
1 file changed, 15 insertions(+), 25 deletions(-)

Index: linux-2.6-tip/kernel/posix-timers.c
===================================================================
--- linux-2.6-tip.orig/kernel/posix-timers.c
+++ linux-2.6-tip/kernel/posix-timers.c
@@ -146,6 +146,7 @@ static struct k_clock posix_clocks[MAX_C
*/
static int common_nsleep(const clockid_t, int flags, struct timespec *t,
struct timespec __user *rmtp);
+static int common_timer_create(struct k_itimer *new_timer);
static void common_timer_get(struct k_itimer *, struct itimerspec *);
static int common_timer_set(struct k_itimer *, int,
struct itimerspec *, struct itimerspec *);
@@ -175,25 +176,6 @@ static inline void unlock_timer(struct k
? (*posix_clocks[clock].call) arglist : common_##call arglist))

/*
- * Default clock hook functions when the struct k_clock passed
- * to register_posix_clock leaves a function pointer null.
- *
- * The function common_CALL is the default implementation for
- * the function pointer CALL in struct k_clock.
- */
-
-static int common_timer_create(struct k_itimer *new_timer)
-{
- hrtimer_init(&new_timer->it.real.timer, new_timer->it_clock, 0);
- return 0;
-}
-
-static int no_timer_create(struct k_itimer *new_timer)
-{
- return -EOPNOTSUPP;
-}
-
-/*
* Return nonzero if we know a priori this clockid_t value is bogus.
*/
static inline int invalid_clockid(const clockid_t which_clock)
@@ -269,27 +251,26 @@ static __init int init_posix_timers(void
.clock_set = posix_clock_realtime_set,
.nsleep = common_nsleep,
.nsleep_restart = hrtimer_nanosleep_restart,
+ .timer_create = common_timer_create,
};
struct k_clock clock_monotonic = {
.clock_getres = hrtimer_get_res,
.clock_get = posix_ktime_get_ts,
.nsleep = common_nsleep,
.nsleep_restart = hrtimer_nanosleep_restart,
+ .timer_create = common_timer_create,
};
struct k_clock clock_monotonic_raw = {
.clock_getres = hrtimer_get_res,
.clock_get = posix_get_monotonic_raw,
- .timer_create = no_timer_create,
};
struct k_clock clock_realtime_coarse = {
.clock_getres = posix_get_coarse_res,
.clock_get = posix_get_realtime_coarse,
- .timer_create = no_timer_create,
};
struct k_clock clock_monotonic_coarse = {
.clock_getres = posix_get_coarse_res,
.clock_get = posix_get_monotonic_coarse,
- .timer_create = no_timer_create,
};

register_posix_clock(CLOCK_REALTIME, &clock_realtime);
@@ -523,19 +504,28 @@ static struct k_clock *clockid_to_kclock
return &posix_clocks[id];
}

+static int common_timer_create(struct k_itimer *new_timer)
+{
+ hrtimer_init(&new_timer->it.real.timer, new_timer->it_clock, 0);
+ return 0;
+}
+
/* Create a POSIX.1b interval timer. */

SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
struct sigevent __user *, timer_event_spec,
timer_t __user *, created_timer_id)
{
+ struct k_clock *kc = clockid_to_kclock(which_clock);
struct k_itimer *new_timer;
int error, new_timer_id;
sigevent_t event;
int it_id_set = IT_ID_NOT_SET;

- if (invalid_clockid(which_clock))
+ if (!kc)
return -EINVAL;
+ if (!kc->timer_create)
+ return -EOPNOTSUPP;

new_timer = alloc_posix_timer();
if (unlikely(!new_timer))
@@ -597,7 +587,7 @@ SYSCALL_DEFINE3(timer_create, const cloc
goto out;
}

- error = CLOCK_DISPATCH(which_clock, timer_create, (new_timer));
+ error = kc->timer_create(new_timer);
if (error)
goto out;

@@ -607,7 +597,7 @@ SYSCALL_DEFINE3(timer_create, const cloc
spin_unlock_irq(&current->sighand->siglock);

return 0;
- /*
+ /*
* In the case of the timer belonging to another task, after
* the task is unlocked, the timer is owned by the other task
* and may cease to exist at any time. Don't use or modify


2011-02-01 21:20:23

by john stultz

[permalink] [raw]
Subject: Re: [patch 15/28] posix-timers: Convert timer_create() to clockid_to_kclock()

On Tue, 2011-02-01 at 13:51 +0000, Thomas Gleixner wrote:
> plain text document attachment
> (posix-timers-convert-clock-timer-create.patch)
> Setup timer_create for CLOCK_MONOTONIC and CLOCK_REALTIME kclocks and
> remove the no_timer_create() implementation.
>
> Signed-off-by: Thomas Gleixner <[email protected]>
> Cc: John Stultz <[email protected]>
> Cc: Richard Cochran <[email protected]>

Acked-by: John Stultz <[email protected]>

2011-02-02 22:01:20

by Thomas Gleixner

[permalink] [raw]
Subject: [tip:timers/core] posix-timers: Convert timer_create() to clockid_to_kclock()

Commit-ID: 838394fbf989973ec7f5a0ad82cb6ff09e5c39aa
Gitweb: http://git.kernel.org/tip/838394fbf989973ec7f5a0ad82cb6ff09e5c39aa
Author: Thomas Gleixner <[email protected]>
AuthorDate: Tue, 1 Feb 2011 13:51:58 +0000
Committer: Thomas Gleixner <[email protected]>
CommitDate: Wed, 2 Feb 2011 15:28:15 +0100

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 <[email protected]>
Acked-by: John Stultz <[email protected]>
Tested-by: Richard Cochran <[email protected]>
LKML-Reference: <[email protected]>
---
kernel/posix-timers.c | 40 +++++++++++++++-------------------------
1 files changed, 15 insertions(+), 25 deletions(-)

diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index f9142a9..4f71382 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -146,6 +146,7 @@ static struct k_clock posix_clocks[MAX_CLOCKS];
*/
static int common_nsleep(const clockid_t, int flags, struct timespec *t,
struct timespec __user *rmtp);
+static int common_timer_create(struct k_itimer *new_timer);
static void common_timer_get(struct k_itimer *, struct itimerspec *);
static int common_timer_set(struct k_itimer *, int,
struct itimerspec *, struct itimerspec *);
@@ -175,25 +176,6 @@ static inline void unlock_timer(struct k_itimer *timr, unsigned long flags)
? (*posix_clocks[clock].call) arglist : common_##call arglist))

/*
- * Default clock hook functions when the struct k_clock passed
- * to register_posix_clock leaves a function pointer null.
- *
- * The function common_CALL is the default implementation for
- * the function pointer CALL in struct k_clock.
- */
-
-static int common_timer_create(struct k_itimer *new_timer)
-{
- hrtimer_init(&new_timer->it.real.timer, new_timer->it_clock, 0);
- return 0;
-}
-
-static int no_timer_create(struct k_itimer *new_timer)
-{
- return -EOPNOTSUPP;
-}
-
-/*
* Return nonzero if we know a priori this clockid_t value is bogus.
*/
static inline int invalid_clockid(const clockid_t which_clock)
@@ -269,27 +251,26 @@ static __init int init_posix_timers(void)
.clock_set = posix_clock_realtime_set,
.nsleep = common_nsleep,
.nsleep_restart = hrtimer_nanosleep_restart,
+ .timer_create = common_timer_create,
};
struct k_clock clock_monotonic = {
.clock_getres = hrtimer_get_res,
.clock_get = posix_ktime_get_ts,
.nsleep = common_nsleep,
.nsleep_restart = hrtimer_nanosleep_restart,
+ .timer_create = common_timer_create,
};
struct k_clock clock_monotonic_raw = {
.clock_getres = hrtimer_get_res,
.clock_get = posix_get_monotonic_raw,
- .timer_create = no_timer_create,
};
struct k_clock clock_realtime_coarse = {
.clock_getres = posix_get_coarse_res,
.clock_get = posix_get_realtime_coarse,
- .timer_create = no_timer_create,
};
struct k_clock clock_monotonic_coarse = {
.clock_getres = posix_get_coarse_res,
.clock_get = posix_get_monotonic_coarse,
- .timer_create = no_timer_create,
};

register_posix_clock(CLOCK_REALTIME, &clock_realtime);
@@ -534,19 +515,28 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
return &posix_clocks[id];
}

+static int common_timer_create(struct k_itimer *new_timer)
+{
+ hrtimer_init(&new_timer->it.real.timer, new_timer->it_clock, 0);
+ return 0;
+}
+
/* Create a POSIX.1b interval timer. */

SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
struct sigevent __user *, timer_event_spec,
timer_t __user *, created_timer_id)
{
+ struct k_clock *kc = clockid_to_kclock(which_clock);
struct k_itimer *new_timer;
int error, new_timer_id;
sigevent_t event;
int it_id_set = IT_ID_NOT_SET;

- if (invalid_clockid(which_clock))
+ if (!kc)
return -EINVAL;
+ if (!kc->timer_create)
+ return -EOPNOTSUPP;

new_timer = alloc_posix_timer();
if (unlikely(!new_timer))
@@ -608,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
goto out;
}

- error = CLOCK_DISPATCH(which_clock, timer_create, (new_timer));
+ error = kc->timer_create(new_timer);
if (error)
goto out;

@@ -618,7 +608,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
spin_unlock_irq(&current->sighand->siglock);

return 0;
- /*
+ /*
* In the case of the timer belonging to another task, after
* the task is unlocked, the timer is owned by the other task
* and may cease to exist at any time. Don't use or modify