2011-02-01 13:52:14

by Thomas Gleixner

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

Use the new kclock decoding. Fixup the fallout in mmtimer.c

Signed-off-by: Thomas Gleixner <[email protected]>
Cc: John Stultz <[email protected]>
Cc: Richard Cochran <[email protected]>
---
drivers/char/mmtimer.c | 10 ++++++++++
kernel/posix-timers.c | 17 ++++-------------
2 files changed, 14 insertions(+), 13 deletions(-)

Index: linux-2.6-tip/drivers/char/mmtimer.c
===================================================================
--- linux-2.6-tip.orig/drivers/char/mmtimer.c
+++ linux-2.6-tip/drivers/char/mmtimer.c
@@ -53,6 +53,8 @@ MODULE_LICENSE("GPL");

#define RTC_BITS 55 /* 55 bits for this implementation */

+static struct k_clock sgi_clock;
+
extern unsigned long sn_rtc_cycles_per_second;

#define RTC_COUNTER_ADDR ((long *)LOCAL_MMR_ADDR(SH_RTC))
@@ -763,10 +765,18 @@ static int sgi_timer_set(struct k_itimer
return err;
}

+static int sgi_clock_getres(const clockid_t which_clock, struct timespec *tp)
+{
+ tp->tv_sec = 0;
+ tp->tv_nsec = sgi_clock.res;
+ return 0;
+}
+
static struct k_clock sgi_clock = {
.res = 0,
.clock_set = sgi_clock_set,
.clock_get = sgi_clock_get,
+ .clock_getres = sgi_clock_getres,
.timer_create = sgi_timer_create,
.timer_set = sgi_timer_set,
.timer_del = sgi_timer_del,
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
@@ -182,14 +182,6 @@ static inline void unlock_timer(struct k
* the function pointer CALL in struct k_clock.
*/

-static inline int common_clock_getres(const clockid_t which_clock,
- struct timespec *tp)
-{
- tp->tv_sec = 0;
- tp->tv_nsec = posix_clocks[which_clock].res;
- return 0;
-}
-
static int common_timer_create(struct k_itimer *new_timer)
{
hrtimer_init(&new_timer->it.real.timer, new_timer->it_clock, 0);
@@ -975,18 +967,17 @@ SYSCALL_DEFINE2(clock_gettime, const clo
SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock,
struct timespec __user *, tp)
{
+ struct k_clock *kc = clockid_to_kclock(which_clock);
struct timespec rtn_tp;
int error;

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

- error = CLOCK_DISPATCH(which_clock, clock_getres,
- (which_clock, &rtn_tp));
+ error = kc->clock_getres(which_clock, &rtn_tp);

- if (!error && tp && copy_to_user(tp, &rtn_tp, sizeof (rtn_tp))) {
+ if (!error && tp && copy_to_user(tp, &rtn_tp, sizeof (rtn_tp)))
error = -EFAULT;
- }

return error;
}


2011-02-01 21:18:01

by john stultz

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

On Tue, 2011-02-01 at 13:51 +0000, Thomas Gleixner wrote:
> plain text document attachment
> (posix-timers-convert-clock-getres.patch)
> Use the new kclock decoding. Fixup the fallout in mmtimer.c
>
> 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:00:35

by Thomas Gleixner

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

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

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

Use the new kclock decoding. Fixup the fallout in mmtimer.c

Signed-off-by: Thomas Gleixner <[email protected]>
Acked-by: John Stultz <[email protected]>
Tested-by: Richard Cochran <[email protected]>
LKML-Reference: <[email protected]>
---
drivers/char/mmtimer.c | 10 ++++++++++
kernel/posix-timers.c | 17 ++++-------------
2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index 262d104..141ffae 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -53,6 +53,8 @@ MODULE_LICENSE("GPL");

#define RTC_BITS 55 /* 55 bits for this implementation */

+static struct k_clock sgi_clock;
+
extern unsigned long sn_rtc_cycles_per_second;

#define RTC_COUNTER_ADDR ((long *)LOCAL_MMR_ADDR(SH_RTC))
@@ -763,10 +765,18 @@ static int sgi_timer_set(struct k_itimer *timr, int flags,
return err;
}

+static int sgi_clock_getres(const clockid_t which_clock, struct timespec *tp)
+{
+ tp->tv_sec = 0;
+ tp->tv_nsec = sgi_clock.res;
+ return 0;
+}
+
static struct k_clock sgi_clock = {
.res = 0,
.clock_set = sgi_clock_set,
.clock_get = sgi_clock_get,
+ .clock_getres = sgi_clock_getres,
.timer_create = sgi_timer_create,
.timer_set = sgi_timer_set,
.timer_del = sgi_timer_del,
diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index 7f66143..748497f 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -182,14 +182,6 @@ static inline void unlock_timer(struct k_itimer *timr, unsigned long flags)
* the function pointer CALL in struct k_clock.
*/

-static inline int common_clock_getres(const clockid_t which_clock,
- struct timespec *tp)
-{
- tp->tv_sec = 0;
- tp->tv_nsec = posix_clocks[which_clock].res;
- return 0;
-}
-
static int common_timer_create(struct k_itimer *new_timer)
{
hrtimer_init(&new_timer->it.real.timer, new_timer->it_clock, 0);
@@ -984,18 +976,17 @@ SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock,
struct timespec __user *, tp)
{
+ struct k_clock *kc = clockid_to_kclock(which_clock);
struct timespec rtn_tp;
int error;

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

- error = CLOCK_DISPATCH(which_clock, clock_getres,
- (which_clock, &rtn_tp));
+ error = kc->clock_getres(which_clock, &rtn_tp);

- if (!error && tp && copy_to_user(tp, &rtn_tp, sizeof (rtn_tp))) {
+ if (!error && tp && copy_to_user(tp, &rtn_tp, sizeof (rtn_tp)))
error = -EFAULT;
- }

return error;
}