2011-02-01 13:52:00

by Thomas Gleixner

[permalink] [raw]
Subject: [patch 12/28] posix-timers: Convert clock_gettime() to clockid_to_kclock()

Use the new kclock decoding mechanism and rename the misnomed
common_clock_get() to posix_clock_realtime_get().

Signed-off-by: Thomas Gleixner <[email protected]>
Cc: John Stultz <[email protected]>
Cc: Richard Cochran <[email protected]>
---
kernel/posix-timers.c | 28 +++++++++++++++-------------
1 file changed, 15 insertions(+), 13 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
@@ -190,15 +190,6 @@ static inline int common_clock_getres(co
return 0;
}

-/*
- * Get real time for posix timers
- */
-static int common_clock_get(clockid_t which_clock, struct timespec *tp)
-{
- ktime_get_real_ts(tp);
- return 0;
-}
-
static int common_timer_create(struct k_itimer *new_timer)
{
hrtimer_init(&new_timer->it.real.timer, new_timer->it_clock, 0);
@@ -226,6 +217,13 @@ static inline int invalid_clockid(const
return 1;
}

+/* Get clock_realtime */
+static int posix_clock_realtime_get(clockid_t which_clock, struct timespec *tp)
+{
+ ktime_get_real_ts(tp);
+ return 0;
+}
+
/* Set clock_realtime */
static inline int posix_clock_realtime_set(const clockid_t which_clock,
const struct timespec *tp)
@@ -277,6 +275,7 @@ static __init int init_posix_timers(void
{
struct k_clock clock_realtime = {
.clock_getres = hrtimer_get_res,
+ .clock_get = posix_clock_realtime_get,
.clock_set = posix_clock_realtime_set,
.nsleep = common_nsleep,
.nsleep_restart = hrtimer_nanosleep_restart,
@@ -956,18 +955,21 @@ SYSCALL_DEFINE2(clock_settime, const clo
SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
struct timespec __user *,tp)
{
+ struct k_clock *kc = clockid_to_kclock(which_clock);
struct timespec kernel_tp;
int error;

- if (invalid_clockid(which_clock))
+ if (!kc)
return -EINVAL;
- error = CLOCK_DISPATCH(which_clock, clock_get,
- (which_clock, &kernel_tp));
+ if (!kc->clock_get)
+ return -EOPNOTSUPP;
+
+ error = kc->clock_get(which_clock, &kernel_tp);
+
if (!error && copy_to_user(tp, &kernel_tp, sizeof (kernel_tp)))
error = -EFAULT;

return error;
-
}

SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock,


2011-02-01 21:17:04

by john stultz

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

On Tue, 2011-02-01 at 13:51 +0000, Thomas Gleixner wrote:
> plain text document attachment (posix-timers-convert-clock-get.patch)
> Use the new kclock decoding mechanism and rename the misnomed
> common_clock_get() to posix_clock_realtime_get().
>
> 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 09:09:33

by Richard Cochran

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

On Tue, Feb 01, 2011 at 01:51:50PM -0000, Thomas Gleixner wrote:
> --- linux-2.6-tip.orig/kernel/posix-timers.c
> +++ linux-2.6-tip/kernel/posix-timers.c

> @@ -956,18 +955,21 @@ SYSCALL_DEFINE2(clock_settime, const clo
> SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
> struct timespec __user *,tp)
> {
> + struct k_clock *kc = clockid_to_kclock(which_clock);
> struct timespec kernel_tp;
> int error;
>
> - if (invalid_clockid(which_clock))
> + if (!kc)
> return -EINVAL;
> - error = CLOCK_DISPATCH(which_clock, clock_get,
> - (which_clock, &kernel_tp));
> + if (!kc->clock_get)
> + return -EOPNOTSUPP;

An unreadable clock?

I would think that we can require k_clocks to provide the read
function. This could be checked and enforced in register_posix_clock().

> +
> + error = kc->clock_get(which_clock, &kernel_tp);
> +
> if (!error && copy_to_user(tp, &kernel_tp, sizeof (kernel_tp)))
> error = -EFAULT;
>
> return error;
> -
> }

Thanks,
Richard

2011-02-02 09:55:22

by Thomas Gleixner

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

On Wed, 2 Feb 2011, Richard Cochran wrote:

> On Tue, Feb 01, 2011 at 01:51:50PM -0000, Thomas Gleixner wrote:
> > --- linux-2.6-tip.orig/kernel/posix-timers.c
> > +++ linux-2.6-tip/kernel/posix-timers.c
>
> > @@ -956,18 +955,21 @@ SYSCALL_DEFINE2(clock_settime, const clo
> > SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
> > struct timespec __user *,tp)
> > {
> > + struct k_clock *kc = clockid_to_kclock(which_clock);
> > struct timespec kernel_tp;
> > int error;
> >
> > - if (invalid_clockid(which_clock))
> > + if (!kc)
> > return -EINVAL;
> > - error = CLOCK_DISPATCH(which_clock, clock_get,
> > - (which_clock, &kernel_tp));
> > + if (!kc->clock_get)
> > + return -EOPNOTSUPP;
>
> An unreadable clock?
>
> I would think that we can require k_clocks to provide the read
> function. This could be checked and enforced in register_posix_clock().

Fair enough. Though, we should do that in a separate step.

Thanks,

tglx

2011-02-02 21:59:51

by Thomas Gleixner

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

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

posix-timers: Convert clock_gettime() to clockid_to_kclock()

Use the new kclock decoding mechanism and rename the misnomed
common_clock_get() to posix_clock_realtime_get().

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 | 28 +++++++++++++++-------------
1 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index 49f358c..d9e5edf 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -190,15 +190,6 @@ static inline int common_clock_getres(const clockid_t which_clock,
return 0;
}

-/*
- * Get real time for posix timers
- */
-static int common_clock_get(clockid_t which_clock, struct timespec *tp)
-{
- ktime_get_real_ts(tp);
- return 0;
-}
-
static int common_timer_create(struct k_itimer *new_timer)
{
hrtimer_init(&new_timer->it.real.timer, new_timer->it_clock, 0);
@@ -226,6 +217,13 @@ static inline int invalid_clockid(const clockid_t which_clock)
return 1;
}

+/* Get clock_realtime */
+static int posix_clock_realtime_get(clockid_t which_clock, struct timespec *tp)
+{
+ ktime_get_real_ts(tp);
+ return 0;
+}
+
/* Set clock_realtime */
static int posix_clock_realtime_set(const clockid_t which_clock,
const struct timespec *tp)
@@ -277,6 +275,7 @@ static __init int init_posix_timers(void)
{
struct k_clock clock_realtime = {
.clock_getres = hrtimer_get_res,
+ .clock_get = posix_clock_realtime_get,
.clock_set = posix_clock_realtime_set,
.nsleep = common_nsleep,
.nsleep_restart = hrtimer_nanosleep_restart,
@@ -956,18 +955,21 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
struct timespec __user *,tp)
{
+ struct k_clock *kc = clockid_to_kclock(which_clock);
struct timespec kernel_tp;
int error;

- if (invalid_clockid(which_clock))
+ if (!kc)
return -EINVAL;
- error = CLOCK_DISPATCH(which_clock, clock_get,
- (which_clock, &kernel_tp));
+ if (!kc->clock_get)
+ return -EOPNOTSUPP;
+
+ error = kc->clock_get(which_clock, &kernel_tp);
+
if (!error && copy_to_user(tp, &kernel_tp, sizeof (kernel_tp)))
error = -EFAULT;

return error;
-
}

SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock,