All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch 00/28]  Rework of the PTP support series core code
@ 2011-02-01 13:50 Thomas Gleixner
  2011-02-01 13:50 ` [patch 01/28] time: Correct the *settime* parameters Thomas Gleixner
                   ` (31 more replies)
  0 siblings, 32 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 13:50 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

This is a rework of Richards PTP support series core code. The PTP
driver patches are unchanged and not included in this series.

The reason for this rework is that I got scared when reviewing:
 [PATCH V10 09/15] posix clocks: cleanup the CLOCK_DISPTACH macro

The patch is really too large and the risk of wreckage too high. So
instead of whipping Richard through another round I reworked the
series in the following way:

1) Split the CLOCK_DISPATCH cleanup in fine grained steps.
   
   That allowed further cleanups and got rid of 200 lines of code and
   made a lot of functions static.
   
   It also fixes subtle changes to the error return codes which happened
   in the large all in one overhaul (EINVAL vs. ENOTSUP).
   
2) Move the patches which add new functionality after the cleanup.

   It does not make sense to add new functionality into the old scheme
   first and then clean it up.

Richard, can you please run that through your testing ? The PTP
drivers apply on top of that.

Thanks,

	tglx


^ permalink raw reply	[flat|nested] 111+ messages in thread

* [patch 01/28] time: Correct the *settime* parameters
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
@ 2011-02-01 13:50 ` Thomas Gleixner
  2011-02-01 14:22   ` Thomas Gleixner
                     ` (2 more replies)
  2011-02-01 13:51 ` [patch 02/28] posix-timers: Define nanosleep not supported error separate Thomas Gleixner
                   ` (30 subsequent siblings)
  31 siblings, 3 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 13:50 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

[-- Attachment #1: time-correct-the-settime-parameters.patch --]
[-- Type: text/plain, Size: 8119 bytes --]

Both settimeofday() and clock_settime() promise with a 'const'
attribute not to alter the arguments passed in. This patch adds the
missing 'const' attribute into the various kernel functions
implementing these calls.

Signed-off-by: Richard Cochran <richard.cochran@omicron.at>
Cc: John Stultz <john.stultz@linaro.org>
LKML-Reference: <681d9f8ba43fea01bae9f6a17a4674194a90353b.1296124770.git.richard.cochran@omicron.at>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 drivers/char/mmtimer.c       |    2 +-
 include/linux/posix-timers.h |    5 +++--
 include/linux/security.h     |    9 +++++----
 include/linux/time.h         |    5 +++--
 kernel/posix-timers.c        |    4 ++--
 kernel/time.c                |    2 +-
 kernel/time/timekeeping.c    |    2 +-
 security/commoncap.c         |    2 +-
 security/security.c          |    2 +-
 9 files changed, 18 insertions(+), 15 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
@@ -487,7 +487,7 @@ static int sgi_clock_get(clockid_t clock
 	return 0;
 };
 
-static int sgi_clock_set(clockid_t clockid, struct timespec *tp)
+static int sgi_clock_set(const clockid_t clockid, const struct timespec *tp)
 {
 
 	u64 nsec;
Index: linux-2.6-tip/include/linux/posix-timers.h
===================================================================
--- linux-2.6-tip.orig/include/linux/posix-timers.h
+++ linux-2.6-tip/include/linux/posix-timers.h
@@ -69,7 +69,8 @@ struct k_itimer {
 struct k_clock {
 	int res;		/* in nanoseconds */
 	int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
-	int (*clock_set) (const clockid_t which_clock, struct timespec * tp);
+	int (*clock_set) (const clockid_t which_clock,
+			  const struct timespec *tp);
 	int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
 	int (*timer_create) (struct k_itimer *timer);
 	int (*nsleep) (const clockid_t which_clock, int flags,
@@ -89,7 +90,7 @@ void register_posix_clock(const clockid_
 /* error handlers for timer_create, nanosleep and settime */
 int do_posix_clock_nonanosleep(const clockid_t, int flags, struct timespec *,
 			       struct timespec __user *);
-int do_posix_clock_nosettime(const clockid_t, struct timespec *tp);
+int do_posix_clock_nosettime(const clockid_t, const struct timespec *tp);
 
 /* function to call to trigger timer event */
 int posix_timer_event(struct k_itimer *timr, int si_private);
Index: linux-2.6-tip/include/linux/security.h
===================================================================
--- linux-2.6-tip.orig/include/linux/security.h
+++ linux-2.6-tip/include/linux/security.h
@@ -53,7 +53,7 @@ struct audit_krule;
  */
 extern int cap_capable(struct task_struct *tsk, const struct cred *cred,
 		       int cap, int audit);
-extern int cap_settime(struct timespec *ts, struct timezone *tz);
+extern int cap_settime(const struct timespec *ts, const struct timezone *tz);
 extern int cap_ptrace_access_check(struct task_struct *child, unsigned int mode);
 extern int cap_ptrace_traceme(struct task_struct *parent);
 extern int cap_capget(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted);
@@ -1387,7 +1387,7 @@ struct security_operations {
 	int (*quotactl) (int cmds, int type, int id, struct super_block *sb);
 	int (*quota_on) (struct dentry *dentry);
 	int (*syslog) (int type);
-	int (*settime) (struct timespec *ts, struct timezone *tz);
+	int (*settime) (const struct timespec *ts, const struct timezone *tz);
 	int (*vm_enough_memory) (struct mm_struct *mm, long pages);
 
 	int (*bprm_set_creds) (struct linux_binprm *bprm);
@@ -1669,7 +1669,7 @@ int security_sysctl(struct ctl_table *ta
 int security_quotactl(int cmds, int type, int id, struct super_block *sb);
 int security_quota_on(struct dentry *dentry);
 int security_syslog(int type);
-int security_settime(struct timespec *ts, struct timezone *tz);
+int security_settime(const struct timespec *ts, const struct timezone *tz);
 int security_vm_enough_memory(long pages);
 int security_vm_enough_memory_mm(struct mm_struct *mm, long pages);
 int security_vm_enough_memory_kern(long pages);
@@ -1904,7 +1904,8 @@ static inline int security_syslog(int ty
 	return 0;
 }
 
-static inline int security_settime(struct timespec *ts, struct timezone *tz)
+static inline int security_settime(const struct timespec *ts,
+				   const struct timezone *tz)
 {
 	return cap_settime(ts, tz);
 }
Index: linux-2.6-tip/include/linux/time.h
===================================================================
--- linux-2.6-tip.orig/include/linux/time.h
+++ linux-2.6-tip/include/linux/time.h
@@ -145,8 +145,9 @@ static inline u32 arch_gettimeoffset(voi
 #endif
 
 extern void do_gettimeofday(struct timeval *tv);
-extern int do_settimeofday(struct timespec *tv);
-extern int do_sys_settimeofday(struct timespec *tv, struct timezone *tz);
+extern int do_settimeofday(const struct timespec *tv);
+extern int do_sys_settimeofday(const struct timespec *tv,
+			       const struct timezone *tz);
 #define do_posix_clock_monotonic_gettime(ts) ktime_get_ts(ts)
 extern long do_utimes(int dfd, const char __user *filename, struct timespec *times, int flags);
 struct itimerval;
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
@@ -192,7 +192,7 @@ static int common_clock_get(clockid_t wh
 }
 
 static inline int common_clock_set(const clockid_t which_clock,
-				   struct timespec *tp)
+				   const struct timespec *tp)
 {
 	return do_sys_settimeofday(tp, NULL);
 }
@@ -928,7 +928,7 @@ void exit_itimers(struct signal_struct *
 }
 
 /* Not available / possible... functions */
-int do_posix_clock_nosettime(const clockid_t clockid, struct timespec *tp)
+int do_posix_clock_nosettime(const clockid_t clockid, const struct timespec *tp)
 {
 	return -EINVAL;
 }
Index: linux-2.6-tip/kernel/time.c
===================================================================
--- linux-2.6-tip.orig/kernel/time.c
+++ linux-2.6-tip/kernel/time.c
@@ -150,7 +150,7 @@ static inline void warp_clock(void)
  * various programs will get confused when the clock gets warped.
  */
 
-int do_sys_settimeofday(struct timespec *tv, struct timezone *tz)
+int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
 {
 	static int firsttime = 1;
 	int error = 0;
Index: linux-2.6-tip/kernel/time/timekeeping.c
===================================================================
--- linux-2.6-tip.orig/kernel/time/timekeeping.c
+++ linux-2.6-tip/kernel/time/timekeeping.c
@@ -353,7 +353,7 @@ EXPORT_SYMBOL(do_gettimeofday);
  *
  * Sets the time of day to the new time and update NTP and notify hrtimers
  */
-int do_settimeofday(struct timespec *tv)
+int do_settimeofday(const struct timespec *tv)
 {
 	struct timespec ts_delta;
 	unsigned long flags;
Index: linux-2.6-tip/security/commoncap.c
===================================================================
--- linux-2.6-tip.orig/security/commoncap.c
+++ linux-2.6-tip/security/commoncap.c
@@ -93,7 +93,7 @@ int cap_capable(struct task_struct *tsk,
  * Determine whether the current process may set the system clock and timezone
  * information, returning 0 if permission granted, -ve if denied.
  */
-int cap_settime(struct timespec *ts, struct timezone *tz)
+int cap_settime(const struct timespec *ts, const struct timezone *tz)
 {
 	if (!capable(CAP_SYS_TIME))
 		return -EPERM;
Index: linux-2.6-tip/security/security.c
===================================================================
--- linux-2.6-tip.orig/security/security.c
+++ linux-2.6-tip/security/security.c
@@ -202,7 +202,7 @@ int security_syslog(int type)
 	return security_ops->syslog(type);
 }
 
-int security_settime(struct timespec *ts, struct timezone *tz)
+int security_settime(const struct timespec *ts, const struct timezone *tz)
 {
 	return security_ops->settime(ts, tz);
 }



^ permalink raw reply	[flat|nested] 111+ messages in thread

* [patch 02/28] posix-timers: Define nanosleep not supported error separate
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
  2011-02-01 13:50 ` [patch 01/28] time: Correct the *settime* parameters Thomas Gleixner
@ 2011-02-01 13:51 ` Thomas Gleixner
  2011-02-01 20:32   ` John Stultz
  2011-02-02 21:55   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  2011-02-01 13:51 ` [patch 03/28] posix-timers: Cleanup struct initializers Thomas Gleixner
                   ` (29 subsequent siblings)
  31 siblings, 2 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 13:51 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

[-- Attachment #1: posix-clocks-splitout-nanosleep-notsup-error.patch --]
[-- Type: text/plain, Size: 1373 bytes --]

Define the conditional nanosleep not supported error value outside of
do_posix_clock_nonanosleep(). Preparatory patch for further cleanups. 

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Richard Cochran <richard.cochran@omicron.at>
---
 kernel/posix-timers.c |   14 +++++++++-----
 1 file changed, 9 insertions(+), 5 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
@@ -81,6 +81,14 @@ static DEFINE_SPINLOCK(idr_lock);
 #error "SIGEV_THREAD_ID must not share bit with other SIGEV values!"
 #endif
 
+/*
+ * parisc wants ENOTSUP instead of EOPNOTSUPP
+ */
+#ifndef ENOTSUP
+# define ENANOSLEEP_NOTSUP EOPNOTSUPP
+#else
+# define ENANOSLEEP_NOTSUP ENOTSUP
+#endif
 
 /*
  * The timer ID is turned into a timer address by idr_find().
@@ -937,11 +945,7 @@ EXPORT_SYMBOL_GPL(do_posix_clock_nosetti
 int do_posix_clock_nonanosleep(const clockid_t clock, int flags,
 			       struct timespec *t, struct timespec __user *r)
 {
-#ifndef ENOTSUP
-	return -EOPNOTSUPP;	/* aka ENOTSUP in userland for POSIX */
-#else  /*  parisc does define it separately.  */
-	return -ENOTSUP;
-#endif
+	return -ENANOSLEEP_NOTSUP;
 }
 EXPORT_SYMBOL_GPL(do_posix_clock_nonanosleep);
 



^ permalink raw reply	[flat|nested] 111+ messages in thread

* [patch 03/28] posix-timers: Cleanup struct initializers
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
  2011-02-01 13:50 ` [patch 01/28] time: Correct the *settime* parameters Thomas Gleixner
  2011-02-01 13:51 ` [patch 02/28] posix-timers: Define nanosleep not supported error separate Thomas Gleixner
@ 2011-02-01 13:51 ` Thomas Gleixner
  2011-02-01 20:33   ` john stultz
  2011-02-02 21:55   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  2011-02-01 13:51 ` [patch 04/28] posix-timers: Introduce clock_posix_cpu Thomas Gleixner
                   ` (28 subsequent siblings)
  31 siblings, 2 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 13:51 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

[-- Attachment #1: posix-timers-cleanup-struct-initializers-codingstyle.patch --]
[-- Type: text/plain, Size: 4604 bytes --]

Cosmetic. No functional change

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Richard Cochran <richard.cochran@omicron.at>
---
 drivers/char/mmtimer.c    |   14 +++++++-------
 kernel/posix-cpu-timers.c |   24 ++++++++++++------------
 kernel/posix-timers.c     |   38 +++++++++++++++++++-------------------
 3 files changed, 38 insertions(+), 38 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
@@ -765,13 +765,13 @@ static int sgi_timer_set(struct k_itimer
 
 static struct k_clock sgi_clock = {
 	.res = 0,
-	.clock_set = sgi_clock_set,
-	.clock_get = sgi_clock_get,
-	.timer_create = sgi_timer_create,
-	.nsleep = do_posix_clock_nonanosleep,
-	.timer_set = sgi_timer_set,
-	.timer_del = sgi_timer_del,
-	.timer_get = sgi_timer_get
+	.clock_set	= sgi_clock_set,
+	.clock_get	= sgi_clock_get,
+	.timer_create	= sgi_timer_create,
+	.nsleep		= do_posix_clock_nonanosleep,
+	.timer_set	= sgi_timer_set,
+	.timer_del	= sgi_timer_del,
+	.timer_get	= sgi_timer_get
 };
 
 /**
Index: linux-2.6-tip/kernel/posix-cpu-timers.c
===================================================================
--- linux-2.6-tip.orig/kernel/posix-cpu-timers.c
+++ linux-2.6-tip/kernel/posix-cpu-timers.c
@@ -1607,20 +1607,20 @@ static long thread_cpu_nsleep_restart(st
 static __init int init_posix_cpu_timers(void)
 {
 	struct k_clock process = {
-		.clock_getres = process_cpu_clock_getres,
-		.clock_get = process_cpu_clock_get,
-		.clock_set = do_posix_clock_nosettime,
-		.timer_create = process_cpu_timer_create,
-		.nsleep = process_cpu_nsleep,
-		.nsleep_restart = process_cpu_nsleep_restart,
+		.clock_getres	= process_cpu_clock_getres,
+		.clock_get	= process_cpu_clock_get,
+		.clock_set	= do_posix_clock_nosettime,
+		.timer_create	= process_cpu_timer_create,
+		.nsleep		= process_cpu_nsleep,
+		.nsleep_restart	= process_cpu_nsleep_restart,
 	};
 	struct k_clock thread = {
-		.clock_getres = thread_cpu_clock_getres,
-		.clock_get = thread_cpu_clock_get,
-		.clock_set = do_posix_clock_nosettime,
-		.timer_create = thread_cpu_timer_create,
-		.nsleep = thread_cpu_nsleep,
-		.nsleep_restart = thread_cpu_nsleep_restart,
+		.clock_getres	= thread_cpu_clock_getres,
+		.clock_get	= thread_cpu_clock_get,
+		.clock_set	= do_posix_clock_nosettime,
+		.timer_create	= thread_cpu_timer_create,
+		.nsleep		= thread_cpu_nsleep,
+		.nsleep_restart	= thread_cpu_nsleep_restart,
 	};
 	struct timespec ts;
 
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
@@ -281,33 +281,33 @@ static int posix_get_coarse_res(const cl
 static __init int init_posix_timers(void)
 {
 	struct k_clock clock_realtime = {
-		.clock_getres = hrtimer_get_res,
+		.clock_getres	= hrtimer_get_res,
 	};
 	struct k_clock clock_monotonic = {
-		.clock_getres = hrtimer_get_res,
-		.clock_get = posix_ktime_get_ts,
-		.clock_set = do_posix_clock_nosettime,
+		.clock_getres	= hrtimer_get_res,
+		.clock_get	= posix_ktime_get_ts,
+		.clock_set	= do_posix_clock_nosettime,
 	};
 	struct k_clock clock_monotonic_raw = {
-		.clock_getres = hrtimer_get_res,
-		.clock_get = posix_get_monotonic_raw,
-		.clock_set = do_posix_clock_nosettime,
-		.timer_create = no_timer_create,
-		.nsleep = no_nsleep,
+		.clock_getres	= hrtimer_get_res,
+		.clock_get	= posix_get_monotonic_raw,
+		.clock_set	= do_posix_clock_nosettime,
+		.timer_create	= no_timer_create,
+		.nsleep		= no_nsleep,
 	};
 	struct k_clock clock_realtime_coarse = {
-		.clock_getres = posix_get_coarse_res,
-		.clock_get = posix_get_realtime_coarse,
-		.clock_set = do_posix_clock_nosettime,
-		.timer_create = no_timer_create,
-		.nsleep = no_nsleep,
+		.clock_getres	= posix_get_coarse_res,
+		.clock_get	= posix_get_realtime_coarse,
+		.clock_set	= do_posix_clock_nosettime,
+		.timer_create	= no_timer_create,
+		.nsleep		= no_nsleep,
 	};
 	struct k_clock clock_monotonic_coarse = {
-		.clock_getres = posix_get_coarse_res,
-		.clock_get = posix_get_monotonic_coarse,
-		.clock_set = do_posix_clock_nosettime,
-		.timer_create = no_timer_create,
-		.nsleep = no_nsleep,
+		.clock_getres	= posix_get_coarse_res,
+		.clock_get	= posix_get_monotonic_coarse,
+		.clock_set	= do_posix_clock_nosettime,
+		.timer_create	= no_timer_create,
+		.nsleep		= no_nsleep,
 	};
 
 	register_posix_clock(CLOCK_REALTIME, &clock_realtime);



^ permalink raw reply	[flat|nested] 111+ messages in thread

* [patch 04/28] posix-timers: Introduce clock_posix_cpu
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
                   ` (2 preceding siblings ...)
  2011-02-01 13:51 ` [patch 03/28] posix-timers: Cleanup struct initializers Thomas Gleixner
@ 2011-02-01 13:51 ` Thomas Gleixner
  2011-02-01 20:34   ` john stultz
  2011-02-02 21:56   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  2011-02-01 13:51 ` [patch 05/28] posix-timers: Introduce clockid_to_kclock() Thomas Gleixner
                   ` (27 subsequent siblings)
  31 siblings, 2 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 13:51 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

[-- Attachment #1: posix-timers-introduce-local-posix-cpu-clockid.patch --]
[-- Type: text/plain, Size: 1884 bytes --]

The CLOCK_DISPATCH() macro is a horrible magic. We call common
functions if a function pointer is not set. That's just backwards.

To support dynamic file decriptor based clocks we need to cleanup that
dispatch logic.

Create a k_clock struct clock_posix_cpu which has all the
posix-cpu-timer functions filled in. After the cleanup the functions
can be made static.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Richard Cochran <richard.cochran@omicron.at>
---
 include/linux/posix-timers.h |    2 ++
 kernel/posix-cpu-timers.c    |   12 ++++++++++++
 2 files changed, 14 insertions(+)

Index: linux-2.6-tip/include/linux/posix-timers.h
===================================================================
--- linux-2.6-tip.orig/include/linux/posix-timers.h
+++ linux-2.6-tip/include/linux/posix-timers.h
@@ -85,6 +85,8 @@ struct k_clock {
 			   struct itimerspec * cur_setting);
 };
 
+extern struct k_clock clock_posix_cpu;
+
 void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock);
 
 /* error handlers for timer_create, nanosleep and settime */
Index: linux-2.6-tip/kernel/posix-cpu-timers.c
===================================================================
--- linux-2.6-tip.orig/kernel/posix-cpu-timers.c
+++ linux-2.6-tip/kernel/posix-cpu-timers.c
@@ -1604,6 +1604,18 @@ static long thread_cpu_nsleep_restart(st
 	return -EINVAL;
 }
 
+struct k_clock clock_posix_cpu = {
+	.clock_getres	= posix_cpu_clock_getres,
+	.clock_set	= posix_cpu_clock_set,
+	.clock_get	= posix_cpu_clock_get,
+	.timer_create	= posix_cpu_timer_create,
+	.nsleep		= posix_cpu_nsleep,
+	.nsleep_restart	= posix_cpu_nsleep_restart,
+	.timer_set	= posix_cpu_timer_set,
+	.timer_del	= posix_cpu_timer_del,
+	.timer_get	= posix_cpu_timer_get,
+};
+
 static __init int init_posix_cpu_timers(void)
 {
 	struct k_clock process = {



^ permalink raw reply	[flat|nested] 111+ messages in thread

* [patch 05/28] posix-timers: Introduce clockid_to_kclock()
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
                   ` (3 preceding siblings ...)
  2011-02-01 13:51 ` [patch 04/28] posix-timers: Introduce clock_posix_cpu Thomas Gleixner
@ 2011-02-01 13:51 ` Thomas Gleixner
  2011-02-01 20:37   ` john stultz
  2011-02-02 21:56   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  2011-02-01 13:51 ` [patch 06/28] posix-timers: Convert clock_nanosleep to clockid_to_kclock() Thomas Gleixner
                   ` (26 subsequent siblings)
  31 siblings, 2 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 13:51 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

[-- Attachment #1: posix-timers-introduce-clockid-to-kclock.patch --]
[-- Type: text/plain, Size: 1111 bytes --]

New function to find the kclock for a given clockid.

Returns a pointer to clock_posix_cpu if clockid < 0. If clockid >=
MAXCLOCK or if the clock_getres pointer is not set it returns
-EINVAL. For valid clocks it returns a pointer to the matching
posix_clock.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Richard Cochran <richard.cochran@omicron.at>
---
 kernel/posix-timers.c |   10 ++++++++++
 1 file changed, 10 insertions(+)

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
@@ -531,6 +531,16 @@ static void release_posix_timer(struct k
 	kmem_cache_free(posix_timers_cache, tmr);
 }
 
+static struct k_clock *clockid_to_kclock(const clockid_t id)
+{
+	if (id < 0)
+		return &clock_posix_cpu;
+
+	if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
+		return NULL;
+	return &posix_clocks[id];
+}
+
 /* Create a POSIX.1b interval timer. */
 
 SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,



^ permalink raw reply	[flat|nested] 111+ messages in thread

* [patch 06/28] posix-timers: Convert clock_nanosleep to clockid_to_kclock()
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
                   ` (4 preceding siblings ...)
  2011-02-01 13:51 ` [patch 05/28] posix-timers: Introduce clockid_to_kclock() Thomas Gleixner
@ 2011-02-01 13:51 ` Thomas Gleixner
  2011-02-01 20:41   ` john stultz
  2011-02-02 21:57   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  2011-02-01 13:51 ` [patch 07/28] posix-timers: Convert clock_nanosleep_restart " Thomas Gleixner
                   ` (25 subsequent siblings)
  31 siblings, 2 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 13:51 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

[-- Attachment #1: posix-timers-convert-nanosleep.patch --]
[-- Type: text/plain, Size: 4331 bytes --]

Use the new kclock decoding function in clock_nanosleep and cleanup all
kclocks which use the default functions.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Richard Cochran <richard.cochran@omicron.at>
---
 drivers/char/mmtimer.c       |    1 -
 include/linux/posix-timers.h |    2 --
 kernel/posix-timers.c        |   26 +++++++-------------------
 3 files changed, 7 insertions(+), 22 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
@@ -768,7 +768,6 @@ static struct k_clock sgi_clock = {
 	.clock_set	= sgi_clock_set,
 	.clock_get	= sgi_clock_get,
 	.timer_create	= sgi_timer_create,
-	.nsleep		= do_posix_clock_nonanosleep,
 	.timer_set	= sgi_timer_set,
 	.timer_del	= sgi_timer_del,
 	.timer_get	= sgi_timer_get
Index: linux-2.6-tip/include/linux/posix-timers.h
===================================================================
--- linux-2.6-tip.orig/include/linux/posix-timers.h
+++ linux-2.6-tip/include/linux/posix-timers.h
@@ -90,8 +90,6 @@ extern struct k_clock clock_posix_cpu;
 void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock);
 
 /* error handlers for timer_create, nanosleep and settime */
-int do_posix_clock_nonanosleep(const clockid_t, int flags, struct timespec *,
-			       struct timespec __user *);
 int do_posix_clock_nosettime(const clockid_t, const struct timespec *tp);
 
 /* function to call to trigger timer event */
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
@@ -216,12 +216,6 @@ static int no_timer_create(struct k_itim
 	return -EOPNOTSUPP;
 }
 
-static int no_nsleep(const clockid_t which_clock, int flags,
-		     struct timespec *tsave, struct timespec __user *rmtp)
-{
-	return -EOPNOTSUPP;
-}
-
 /*
  * Return nonzero if we know a priori this clockid_t value is bogus.
  */
@@ -282,32 +276,31 @@ static __init int init_posix_timers(void
 {
 	struct k_clock clock_realtime = {
 		.clock_getres	= hrtimer_get_res,
+		.nsleep		= common_nsleep,
 	};
 	struct k_clock clock_monotonic = {
 		.clock_getres	= hrtimer_get_res,
 		.clock_get	= posix_ktime_get_ts,
 		.clock_set	= do_posix_clock_nosettime,
+		.nsleep		= common_nsleep,
 	};
 	struct k_clock clock_monotonic_raw = {
 		.clock_getres	= hrtimer_get_res,
 		.clock_get	= posix_get_monotonic_raw,
 		.clock_set	= do_posix_clock_nosettime,
 		.timer_create	= no_timer_create,
-		.nsleep		= no_nsleep,
 	};
 	struct k_clock clock_realtime_coarse = {
 		.clock_getres	= posix_get_coarse_res,
 		.clock_get	= posix_get_realtime_coarse,
 		.clock_set	= do_posix_clock_nosettime,
 		.timer_create	= no_timer_create,
-		.nsleep		= no_nsleep,
 	};
 	struct k_clock clock_monotonic_coarse = {
 		.clock_getres	= posix_get_coarse_res,
 		.clock_get	= posix_get_monotonic_coarse,
 		.clock_set	= do_posix_clock_nosettime,
 		.timer_create	= no_timer_create,
-		.nsleep		= no_nsleep,
 	};
 
 	register_posix_clock(CLOCK_REALTIME, &clock_realtime);
@@ -952,13 +945,6 @@ int do_posix_clock_nosettime(const clock
 }
 EXPORT_SYMBOL_GPL(do_posix_clock_nosettime);
 
-int do_posix_clock_nonanosleep(const clockid_t clock, int flags,
-			       struct timespec *t, struct timespec __user *r)
-{
-	return -ENANOSLEEP_NOTSUP;
-}
-EXPORT_SYMBOL_GPL(do_posix_clock_nonanosleep);
-
 SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
 		const struct timespec __user *, tp)
 {
@@ -1023,10 +1009,13 @@ SYSCALL_DEFINE4(clock_nanosleep, const c
 		const struct timespec __user *, rqtp,
 		struct timespec __user *, rmtp)
 {
+	struct k_clock *kc = clockid_to_kclock(which_clock);
 	struct timespec t;
 
-	if (invalid_clockid(which_clock))
+	if (!kc)
 		return -EINVAL;
+	if (!kc->nsleep)
+		return -ENANOSLEEP_NOTSUP;
 
 	if (copy_from_user(&t, rqtp, sizeof (struct timespec)))
 		return -EFAULT;
@@ -1034,8 +1023,7 @@ SYSCALL_DEFINE4(clock_nanosleep, const c
 	if (!timespec_valid(&t))
 		return -EINVAL;
 
-	return CLOCK_DISPATCH(which_clock, nsleep,
-			      (which_clock, flags, &t, rmtp));
+	return kc->nsleep(which_clock, flags, &t, rmtp);
 }
 
 /*



^ permalink raw reply	[flat|nested] 111+ messages in thread

* [patch 07/28] posix-timers: Convert clock_nanosleep_restart to clockid_to_kclock()
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
                   ` (5 preceding siblings ...)
  2011-02-01 13:51 ` [patch 06/28] posix-timers: Convert clock_nanosleep to clockid_to_kclock() Thomas Gleixner
@ 2011-02-01 13:51 ` Thomas Gleixner
  2011-02-01 20:42   ` John Stultz
  2011-02-02 21:57   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  2011-02-01 13:51 ` [patch 08/28] posix-timers: Cleanup restart_block usage Thomas Gleixner
                   ` (24 subsequent siblings)
  31 siblings, 2 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 13:51 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

[-- Attachment #1: posix-timers-convert-nanosleep-restart.patch --]
[-- Type: text/plain, Size: 1913 bytes --]

Use the new kclock decoding function in clock_nanosleep_restart. No
need to check kclock here as the restart block always contains a valid
clockid. If not, we are in serious trouble anyway.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Richard Cochran <richard.cochran@omicron.at>
---
 kernel/posix-timers.c |   17 +++++------------
 1 file changed, 5 insertions(+), 12 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
@@ -277,12 +277,14 @@ static __init int init_posix_timers(void
 	struct k_clock clock_realtime = {
 		.clock_getres	= hrtimer_get_res,
 		.nsleep		= common_nsleep,
+		.nsleep_restart	= hrtimer_nanosleep_restart,
 	};
 	struct k_clock clock_monotonic = {
 		.clock_getres	= hrtimer_get_res,
 		.clock_get	= posix_ktime_get_ts,
 		.clock_set	= do_posix_clock_nosettime,
 		.nsleep		= common_nsleep,
+		.nsleep_restart	= hrtimer_nanosleep_restart,
 	};
 	struct k_clock clock_monotonic_raw = {
 		.clock_getres	= hrtimer_get_res,
@@ -1027,22 +1029,13 @@ SYSCALL_DEFINE4(clock_nanosleep, const c
 }
 
 /*
- * nanosleep_restart for monotonic and realtime clocks
- */
-static int common_nsleep_restart(struct restart_block *restart_block)
-{
-	return hrtimer_nanosleep_restart(restart_block);
-}
-
-/*
  * This will restart clock_nanosleep. This is required only by
  * compat_clock_nanosleep_restart for now.
  */
-long
-clock_nanosleep_restart(struct restart_block *restart_block)
+long clock_nanosleep_restart(struct restart_block *restart_block)
 {
 	clockid_t which_clock = restart_block->arg0;
+	struct k_clock *kc = clockid_to_kclock(which_clock);
 
-	return CLOCK_DISPATCH(which_clock, nsleep_restart,
-			      (restart_block));
+	return kc->nsleep_restart(restart_block);
 }



^ permalink raw reply	[flat|nested] 111+ messages in thread

* [patch 08/28] posix-timers: Cleanup restart_block usage
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
                   ` (6 preceding siblings ...)
  2011-02-01 13:51 ` [patch 07/28] posix-timers: Convert clock_nanosleep_restart " Thomas Gleixner
@ 2011-02-01 13:51 ` Thomas Gleixner
  2011-02-01 21:11   ` john stultz
  2011-02-02 21:57   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  2011-02-01 13:51 ` [patch 09/28] thread_info: Remove legacy arg0-3 from restart_block Thomas Gleixner
                   ` (23 subsequent siblings)
  31 siblings, 2 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 13:51 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

[-- Attachment #1: posix-timers-cleanup-restart-block.patch --]
[-- Type: text/plain, Size: 3587 bytes --]

posix timers still use the legacy arg0-arg3 members of
restart_block. Use restart_block.nanosleep instead

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Richard Cochran <richard.cochran@omicron.at>
---
 kernel/posix-cpu-timers.c |   38 +++++++++++++++-----------------------
 kernel/posix-timers.c     |    2 +-
 2 files changed, 16 insertions(+), 24 deletions(-)

Index: linux-2.6-tip/kernel/posix-cpu-timers.c
===================================================================
--- linux-2.6-tip.orig/kernel/posix-cpu-timers.c
+++ linux-2.6-tip/kernel/posix-cpu-timers.c
@@ -1485,7 +1485,7 @@ int posix_cpu_nsleep(const clockid_t whi
 		     struct timespec *rqtp, struct timespec __user *rmtp)
 {
 	struct restart_block *restart_block =
-	    &current_thread_info()->restart_block;
+		&current_thread_info()->restart_block;
 	struct itimerspec it;
 	int error;
 
@@ -1501,50 +1501,42 @@ int posix_cpu_nsleep(const clockid_t whi
 
 	if (error == -ERESTART_RESTARTBLOCK) {
 
-	       	if (flags & TIMER_ABSTIME)
+		if (flags & TIMER_ABSTIME)
 			return -ERESTARTNOHAND;
 		/*
-	 	 * Report back to the user the time still remaining.
-	 	 */
-		if (rmtp != NULL && copy_to_user(rmtp, &it.it_value, sizeof *rmtp))
+		 * Report back to the user the time still remaining.
+		 */
+		if (rmtp && copy_to_user(rmtp, &it.it_value, sizeof *rmtp))
 			return -EFAULT;
 
 		restart_block->fn = posix_cpu_nsleep_restart;
-		restart_block->arg0 = which_clock;
-		restart_block->arg1 = (unsigned long) rmtp;
-		restart_block->arg2 = rqtp->tv_sec;
-		restart_block->arg3 = rqtp->tv_nsec;
+		restart_block->nanosleep.index = which_clock;
+		restart_block->nanosleep.rmtp = rmtp;
+		restart_block->nanosleep.expires = timespec_to_ns(rqtp);
 	}
 	return error;
 }
 
 long posix_cpu_nsleep_restart(struct restart_block *restart_block)
 {
-	clockid_t which_clock = restart_block->arg0;
-	struct timespec __user *rmtp;
+	clockid_t which_clock = restart_block->nanosleep.index;
 	struct timespec t;
 	struct itimerspec it;
 	int error;
 
-	rmtp = (struct timespec __user *) restart_block->arg1;
-	t.tv_sec = restart_block->arg2;
-	t.tv_nsec = restart_block->arg3;
+	t = ns_to_timespec(restart_block->nanosleep.expires);
 
-	restart_block->fn = do_no_restart_syscall;
 	error = do_cpu_nanosleep(which_clock, TIMER_ABSTIME, &t, &it);
 
 	if (error == -ERESTART_RESTARTBLOCK) {
+		struct timespec __user *rmtp = restart_block->nanosleep.rmtp;
 		/*
-	 	 * Report back to the user the time still remaining.
-	 	 */
-		if (rmtp != NULL && copy_to_user(rmtp, &it.it_value, sizeof *rmtp))
+		 * Report back to the user the time still remaining.
+		 */
+		if (rmtp && copy_to_user(rmtp, &it.it_value, sizeof *rmtp))
 			return -EFAULT;
 
-		restart_block->fn = posix_cpu_nsleep_restart;
-		restart_block->arg0 = which_clock;
-		restart_block->arg1 = (unsigned long) rmtp;
-		restart_block->arg2 = t.tv_sec;
-		restart_block->arg3 = t.tv_nsec;
+		restart_block->nanosleep.expires = timespec_to_ns(&t);
 	}
 	return error;
 
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
@@ -1034,7 +1034,7 @@ SYSCALL_DEFINE4(clock_nanosleep, const c
  */
 long clock_nanosleep_restart(struct restart_block *restart_block)
 {
-	clockid_t which_clock = restart_block->arg0;
+	clockid_t which_clock = restart_block->nanosleep.index;
 	struct k_clock *kc = clockid_to_kclock(which_clock);
 
 	return kc->nsleep_restart(restart_block);



^ permalink raw reply	[flat|nested] 111+ messages in thread

* [patch 09/28] thread_info: Remove legacy arg0-3 from restart_block
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
                   ` (7 preceding siblings ...)
  2011-02-01 13:51 ` [patch 08/28] posix-timers: Cleanup restart_block usage Thomas Gleixner
@ 2011-02-01 13:51 ` Thomas Gleixner
  2011-02-01 21:11   ` john stultz
  2011-02-02 21:58   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  2011-02-01 13:51 ` [patch 10/28] posix-cpu-timers: Remove the stub nanosleep functions Thomas Gleixner
                   ` (22 subsequent siblings)
  31 siblings, 2 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 13:51 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

[-- Attachment #1: thread-info-remove-arg0-3.patch --]
[-- Type: text/plain, Size: 793 bytes --]

posix timers were the last users of the legacy arg0-3 members of
restart_block. Remove the cruft.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Richard Cochran <richard.cochran@omicron.at>
---
 include/linux/thread_info.h |    3 ---
 1 file changed, 3 deletions(-)

Index: linux-2.6-tip/include/linux/thread_info.h
===================================================================
--- linux-2.6-tip.orig/include/linux/thread_info.h
+++ linux-2.6-tip/include/linux/thread_info.h
@@ -18,9 +18,6 @@ struct compat_timespec;
 struct restart_block {
 	long (*fn)(struct restart_block *);
 	union {
-		struct {
-			unsigned long arg0, arg1, arg2, arg3;
-		};
 		/* For futex_wait and futex_wait_requeue_pi */
 		struct {
 			u32 __user *uaddr;



^ permalink raw reply	[flat|nested] 111+ messages in thread

* [patch 10/28] posix-cpu-timers: Remove the stub nanosleep functions
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
                   ` (8 preceding siblings ...)
  2011-02-01 13:51 ` [patch 09/28] thread_info: Remove legacy arg0-3 from restart_block Thomas Gleixner
@ 2011-02-01 13:51 ` Thomas Gleixner
  2011-02-01 21:14   ` John Stultz
  2011-02-02 21:58   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  2011-02-01 13:51 ` [patch 11/28] posix-timers: Convert clock_settime to clockid_to_kclock() Thomas Gleixner
                   ` (21 subsequent siblings)
  31 siblings, 2 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 13:51 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

[-- Attachment #1: posix-cpu-timers-use-default-nsleep-notsup.patch --]
[-- Type: text/plain, Size: 1466 bytes --]

CLOCK_THREAD_CPUTIME_ID implements stub functions for nanosleep and
nanosleep_restart, which return -EINVAL. That return value is
wrong. The correct return value is -ENOTSUP.

Remove the stubs and let the new dispatch code return the correct
error code.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Richard Cochran <richard.cochran@omicron.at>
---
 kernel/posix-cpu-timers.c |   11 -----------
 1 file changed, 11 deletions(-)

Index: linux-2.6-tip/kernel/posix-cpu-timers.c
===================================================================
--- linux-2.6-tip.orig/kernel/posix-cpu-timers.c
+++ linux-2.6-tip/kernel/posix-cpu-timers.c
@@ -1586,15 +1586,6 @@ static int thread_cpu_timer_create(struc
 	timer->it_clock = THREAD_CLOCK;
 	return posix_cpu_timer_create(timer);
 }
-static int thread_cpu_nsleep(const clockid_t which_clock, int flags,
-			      struct timespec *rqtp, struct timespec __user *rmtp)
-{
-	return -EINVAL;
-}
-static long thread_cpu_nsleep_restart(struct restart_block *restart_block)
-{
-	return -EINVAL;
-}
 
 struct k_clock clock_posix_cpu = {
 	.clock_getres	= posix_cpu_clock_getres,
@@ -1623,8 +1614,6 @@ static __init int init_posix_cpu_timers(
 		.clock_get	= thread_cpu_clock_get,
 		.clock_set	= do_posix_clock_nosettime,
 		.timer_create	= thread_cpu_timer_create,
-		.nsleep		= thread_cpu_nsleep,
-		.nsleep_restart	= thread_cpu_nsleep_restart,
 	};
 	struct timespec ts;
 



^ permalink raw reply	[flat|nested] 111+ messages in thread

* [patch 11/28] posix-timers: Convert clock_settime to clockid_to_kclock()
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
                   ` (9 preceding siblings ...)
  2011-02-01 13:51 ` [patch 10/28] posix-cpu-timers: Remove the stub nanosleep functions Thomas Gleixner
@ 2011-02-01 13:51 ` Thomas Gleixner
  2011-02-01 21:15   ` john stultz
  2011-02-02 21:59   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  2011-02-01 13:51 ` [patch 12/28] posix-timers: Convert clock_gettime() " Thomas Gleixner
                   ` (20 subsequent siblings)
  31 siblings, 2 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 13:51 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

[-- Attachment #1: posix-timers-convert-clock-set.patch --]
[-- Type: text/plain, Size: 4767 bytes --]

Use the new kclock decoding function in clock_settime and cleanup all
kclocks which use the default functions. Rename the misnomed
common_clock_set() to posix_clock_realtime_set().

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Richard Cochran <richard.cochran@omicron.at>
---
 include/linux/posix-timers.h |    3 ---
 kernel/posix-cpu-timers.c    |    2 --
 kernel/posix-timers.c        |   31 ++++++++++++-------------------
 3 files changed, 12 insertions(+), 24 deletions(-)

Index: linux-2.6-tip/include/linux/posix-timers.h
===================================================================
--- linux-2.6-tip.orig/include/linux/posix-timers.h
+++ linux-2.6-tip/include/linux/posix-timers.h
@@ -89,9 +89,6 @@ extern struct k_clock clock_posix_cpu;
 
 void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock);
 
-/* error handlers for timer_create, nanosleep and settime */
-int do_posix_clock_nosettime(const clockid_t, const struct timespec *tp);
-
 /* function to call to trigger timer event */
 int posix_timer_event(struct k_itimer *timr, int si_private);
 
Index: linux-2.6-tip/kernel/posix-cpu-timers.c
===================================================================
--- linux-2.6-tip.orig/kernel/posix-cpu-timers.c
+++ linux-2.6-tip/kernel/posix-cpu-timers.c
@@ -1604,7 +1604,6 @@ static __init int init_posix_cpu_timers(
 	struct k_clock process = {
 		.clock_getres	= process_cpu_clock_getres,
 		.clock_get	= process_cpu_clock_get,
-		.clock_set	= do_posix_clock_nosettime,
 		.timer_create	= process_cpu_timer_create,
 		.nsleep		= process_cpu_nsleep,
 		.nsleep_restart	= process_cpu_nsleep_restart,
@@ -1612,7 +1611,6 @@ static __init int init_posix_cpu_timers(
 	struct k_clock thread = {
 		.clock_getres	= thread_cpu_clock_getres,
 		.clock_get	= thread_cpu_clock_get,
-		.clock_set	= do_posix_clock_nosettime,
 		.timer_create	= thread_cpu_timer_create,
 	};
 	struct timespec ts;
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
@@ -199,12 +199,6 @@ static int common_clock_get(clockid_t wh
 	return 0;
 }
 
-static inline int common_clock_set(const clockid_t which_clock,
-				   const struct timespec *tp)
-{
-	return do_sys_settimeofday(tp, NULL);
-}
-
 static int common_timer_create(struct k_itimer *new_timer)
 {
 	hrtimer_init(&new_timer->it.real.timer, new_timer->it_clock, 0);
@@ -232,6 +226,13 @@ static inline int invalid_clockid(const 
 	return 1;
 }
 
+/* Set clock_realtime */
+static inline int posix_clock_realtime_set(const clockid_t which_clock,
+					   const struct timespec *tp)
+{
+	return do_sys_settimeofday(tp, NULL);
+}
+
 /*
  * Get monotonic time for posix timers
  */
@@ -276,32 +277,29 @@ static __init int init_posix_timers(void
 {
 	struct k_clock clock_realtime = {
 		.clock_getres	= hrtimer_get_res,
+		.clock_set	= posix_clock_realtime_set,
 		.nsleep		= common_nsleep,
 		.nsleep_restart	= hrtimer_nanosleep_restart,
 	};
 	struct k_clock clock_monotonic = {
 		.clock_getres	= hrtimer_get_res,
 		.clock_get	= posix_ktime_get_ts,
-		.clock_set	= do_posix_clock_nosettime,
 		.nsleep		= common_nsleep,
 		.nsleep_restart	= hrtimer_nanosleep_restart,
 	};
 	struct k_clock clock_monotonic_raw = {
 		.clock_getres	= hrtimer_get_res,
 		.clock_get	= posix_get_monotonic_raw,
-		.clock_set	= do_posix_clock_nosettime,
 		.timer_create	= no_timer_create,
 	};
 	struct k_clock clock_realtime_coarse = {
 		.clock_getres	= posix_get_coarse_res,
 		.clock_get	= posix_get_realtime_coarse,
-		.clock_set	= do_posix_clock_nosettime,
 		.timer_create	= no_timer_create,
 	};
 	struct k_clock clock_monotonic_coarse = {
 		.clock_getres	= posix_get_coarse_res,
 		.clock_get	= posix_get_monotonic_coarse,
-		.clock_set	= do_posix_clock_nosettime,
 		.timer_create	= no_timer_create,
 	};
 
@@ -940,24 +938,19 @@ void exit_itimers(struct signal_struct *
 	}
 }
 
-/* Not available / possible... functions */
-int do_posix_clock_nosettime(const clockid_t clockid, const struct timespec *tp)
-{
-	return -EINVAL;
-}
-EXPORT_SYMBOL_GPL(do_posix_clock_nosettime);
-
 SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
 		const struct timespec __user *, tp)
 {
+	struct k_clock *kc = clockid_to_kclock(which_clock);
 	struct timespec new_tp;
 
-	if (invalid_clockid(which_clock))
+	if (!kc || !kc->clock_set)
 		return -EINVAL;
+
 	if (copy_from_user(&new_tp, tp, sizeof (*tp)))
 		return -EFAULT;
 
-	return CLOCK_DISPATCH(which_clock, clock_set, (which_clock, &new_tp));
+	return kc->clock_set(which_clock, &new_tp);
 }
 
 SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,



^ permalink raw reply	[flat|nested] 111+ messages in thread

* [patch 12/28] posix-timers: Convert clock_gettime() to clockid_to_kclock()
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
                   ` (10 preceding siblings ...)
  2011-02-01 13:51 ` [patch 11/28] posix-timers: Convert clock_settime to clockid_to_kclock() Thomas Gleixner
@ 2011-02-01 13:51 ` Thomas Gleixner
  2011-02-01 21:16   ` john stultz
                     ` (2 more replies)
  2011-02-01 13:51 ` [patch 13/28] posix-timers: Convert clock_getres() " Thomas Gleixner
                   ` (19 subsequent siblings)
  31 siblings, 3 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 13:51 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

[-- Attachment #1: posix-timers-convert-clock-get.patch --]
[-- Type: text/plain, Size: 2286 bytes --]

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

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Richard Cochran <richard.cochran@omicron.at>
---
 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,



^ permalink raw reply	[flat|nested] 111+ messages in thread

* [patch 13/28] posix-timers: Convert clock_getres() to clockid_to_kclock()
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
                   ` (11 preceding siblings ...)
  2011-02-01 13:51 ` [patch 12/28] posix-timers: Convert clock_gettime() " Thomas Gleixner
@ 2011-02-01 13:51 ` Thomas Gleixner
  2011-02-01 21:17   ` john stultz
  2011-02-02 22:00   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  2011-02-01 13:51 ` [patch 14/28] posix-timers: Remove useless res field from k_clock Thomas Gleixner
                   ` (18 subsequent siblings)
  31 siblings, 2 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 13:51 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

[-- Attachment #1: posix-timers-convert-clock-getres.patch --]
[-- Type: text/plain, Size: 2551 bytes --]

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

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Richard Cochran <richard.cochran@omicron.at>
---
 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;
 }



^ permalink raw reply	[flat|nested] 111+ messages in thread

* [patch 14/28] posix-timers: Remove useless res field from k_clock
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
                   ` (12 preceding siblings ...)
  2011-02-01 13:51 ` [patch 13/28] posix-timers: Convert clock_getres() " Thomas Gleixner
@ 2011-02-01 13:51 ` Thomas Gleixner
  2011-02-01 21:18   ` john stultz
  2011-02-02 22:00   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  2011-02-01 13:51 ` [patch 15/28] posix-timers: Convert timer_create() to clockid_to_kclock() Thomas Gleixner
                   ` (17 subsequent siblings)
  31 siblings, 2 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 13:51 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

[-- Attachment #1: posix-timers-remove-unused-res-field.patch --]
[-- Type: text/plain, Size: 2282 bytes --]

The res member of kclock is only used by mmtimer.c, but even there it
contains redundant information. Remove the field and fixup mmtimer.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Richard Cochran <richard.cochran@omicron.at>
---
 drivers/char/mmtimer.c       |    5 ++---
 include/linux/posix-timers.h |    1 -
 kernel/posix-timers.c        |    2 --
 3 files changed, 2 insertions(+), 6 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
@@ -768,12 +768,11 @@ static int sgi_timer_set(struct k_itimer
 static int sgi_clock_getres(const clockid_t which_clock, struct timespec *tp)
 {
 	tp->tv_sec = 0;
-	tp->tv_nsec = sgi_clock.res;
+	tp->tv_nsec = sgi_clock_period;
 	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,
@@ -840,7 +839,7 @@ static int __init mmtimer_init(void)
 			(unsigned long) node);
 	}
 
-	sgi_clock_period = sgi_clock.res = NSEC_PER_SEC / sn_rtc_cycles_per_second;
+	sgi_clock_period = NSEC_PER_SEC / sn_rtc_cycles_per_second;
 	register_posix_clock(CLOCK_SGI_CYCLE, &sgi_clock);
 
 	printk(KERN_INFO "%s: v%s, %ld MHz\n", MMTIMER_DESC, MMTIMER_VERSION,
Index: linux-2.6-tip/include/linux/posix-timers.h
===================================================================
--- linux-2.6-tip.orig/include/linux/posix-timers.h
+++ linux-2.6-tip/include/linux/posix-timers.h
@@ -67,7 +67,6 @@ struct k_itimer {
 };
 
 struct k_clock {
-	int res;		/* in nanoseconds */
 	int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
 	int (*clock_set) (const clockid_t which_clock,
 			  const struct timespec *tp);
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
@@ -204,8 +204,6 @@ static inline int invalid_clockid(const 
 		return 1;
 	if (posix_clocks[which_clock].clock_getres != NULL)
 		return 0;
-	if (posix_clocks[which_clock].res != 0)
-		return 0;
 	return 1;
 }
 



^ permalink raw reply	[flat|nested] 111+ messages in thread

* [patch 15/28] posix-timers: Convert timer_create() to clockid_to_kclock()
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
                   ` (13 preceding siblings ...)
  2011-02-01 13:51 ` [patch 14/28] posix-timers: Remove useless res field from k_clock Thomas Gleixner
@ 2011-02-01 13:51 ` Thomas Gleixner
  2011-02-01 21:20   ` john stultz
  2011-02-02 22:00   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  2011-02-01 13:52 ` [patch 16/28] posix-timers: Convert timer_settime() " Thomas Gleixner
                   ` (16 subsequent siblings)
  31 siblings, 2 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 13:51 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

[-- Attachment #1: posix-timers-convert-clock-timer-create.patch --]
[-- Type: text/plain, Size: 4086 bytes --]

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>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Richard Cochran <richard.cochran@omicron.at>
---
 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



^ permalink raw reply	[flat|nested] 111+ messages in thread

* [patch 16/28] posix-timers: Convert timer_settime() to clockid_to_kclock()
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
                   ` (14 preceding siblings ...)
  2011-02-01 13:51 ` [patch 15/28] posix-timers: Convert timer_create() to clockid_to_kclock() Thomas Gleixner
@ 2011-02-01 13:52 ` Thomas Gleixner
  2011-02-01 21:22   ` John Stultz
  2011-02-02 22:01   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  2011-02-01 13:52 ` [patch 17/28] posix-timers: Convert timer_gettime() " Thomas Gleixner
                   ` (15 subsequent siblings)
  31 siblings, 2 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 13:52 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

[-- Attachment #1: posix-timers-convert-timer-set.patch --]
[-- Type: text/plain, Size: 1866 bytes --]

Set the common function for CLOCK_MONOTONIC and CLOCK_REALTIME kclocks
and use the new decoding function. No need to check for the return
value of it. If we have data corruption in the timer, we explode
somewhere else anyway. Also all kclocks which implement timer_create()
need to provide timer_settime() as well.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Richard Cochran <richard.cochran@omicron.at>
---
 kernel/posix-timers.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 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
@@ -252,6 +252,7 @@ static __init int init_posix_timers(void
 		.nsleep		= common_nsleep,
 		.nsleep_restart	= hrtimer_nanosleep_restart,
 		.timer_create	= common_timer_create,
+		.timer_set	= common_timer_set,
 	};
 	struct k_clock clock_monotonic = {
 		.clock_getres	= hrtimer_get_res,
@@ -259,6 +260,7 @@ static __init int init_posix_timers(void
 		.nsleep		= common_nsleep,
 		.nsleep_restart	= hrtimer_nanosleep_restart,
 		.timer_create	= common_timer_create,
+		.timer_set	= common_timer_set,
 	};
 	struct k_clock clock_monotonic_raw = {
 		.clock_getres	= hrtimer_get_res,
@@ -803,6 +805,7 @@ SYSCALL_DEFINE4(timer_settime, timer_t, 
 	int error = 0;
 	unsigned long flag;
 	struct itimerspec *rtn = old_setting ? &old_spec : NULL;
+	struct k_clock *kc;
 
 	if (!new_setting)
 		return -EINVAL;
@@ -818,8 +821,8 @@ retry:
 	if (!timr)
 		return -EINVAL;
 
-	error = CLOCK_DISPATCH(timr->it_clock, timer_set,
-			       (timr, flags, &new_spec, rtn));
+	kc = clockid_to_kclock(timr->it_clock);
+	error = kc->timer_set(timr, flags, &new_spec, rtn);
 
 	unlock_timer(timr, flag);
 	if (error == TIMER_RETRY) {



^ permalink raw reply	[flat|nested] 111+ messages in thread

* [patch 17/28] posix-timers: Convert timer_gettime() to clockid_to_kclock()
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
                   ` (15 preceding siblings ...)
  2011-02-01 13:52 ` [patch 16/28] posix-timers: Convert timer_settime() " Thomas Gleixner
@ 2011-02-01 13:52 ` Thomas Gleixner
  2011-02-01 21:23   ` john stultz
  2011-02-02 22:01   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  2011-02-01 13:52 ` [patch 18/28] posix-timers: Convert timer_delete() " Thomas Gleixner
                   ` (14 subsequent siblings)
  31 siblings, 2 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 13:52 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

[-- Attachment #1: posix-timers-convert-timer-get.patch --]
[-- Type: text/plain, Size: 1882 bytes --]

Set the common function for CLOCK_MONOTONIC and CLOCK_REALTIME kclocks
and use the new decoding function. No need to check for the return
value of it. If we have data corruption in the timer, we explode
somewhere else anyway. Also all kclocks which implement timer_create()
need to provide timer_gettime() as well.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Richard Cochran <richard.cochran@omicron.at>
---
 kernel/posix-timers.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 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
@@ -253,6 +253,7 @@ static __init int init_posix_timers(void
 		.nsleep_restart	= hrtimer_nanosleep_restart,
 		.timer_create	= common_timer_create,
 		.timer_set	= common_timer_set,
+		.timer_get	= common_timer_get,
 	};
 	struct k_clock clock_monotonic = {
 		.clock_getres	= hrtimer_get_res,
@@ -261,6 +262,7 @@ static __init int init_posix_timers(void
 		.nsleep_restart	= hrtimer_nanosleep_restart,
 		.timer_create	= common_timer_create,
 		.timer_set	= common_timer_set,
+		.timer_get	= common_timer_get,
 	};
 	struct k_clock clock_monotonic_raw = {
 		.clock_getres	= hrtimer_get_res,
@@ -701,15 +703,17 @@ common_timer_get(struct k_itimer *timr, 
 SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
 		struct itimerspec __user *, setting)
 {
-	struct k_itimer *timr;
 	struct itimerspec cur_setting;
+	struct k_itimer *timr;
+	struct k_clock *kc;
 	unsigned long flags;
 
 	timr = lock_timer(timer_id, &flags);
 	if (!timr)
 		return -EINVAL;
 
-	CLOCK_DISPATCH(timr->it_clock, timer_get, (timr, &cur_setting));
+	kc = clockid_to_kclock(timr->it_clock);
+	kc->timer_get(timr, &cur_setting);
 
 	unlock_timer(timr, flags);
 



^ permalink raw reply	[flat|nested] 111+ messages in thread

* [patch 18/28] posix-timers: Convert timer_delete() to clockid_to_kclock()
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
                   ` (16 preceding siblings ...)
  2011-02-01 13:52 ` [patch 17/28] posix-timers: Convert timer_gettime() " Thomas Gleixner
@ 2011-02-01 13:52 ` Thomas Gleixner
  2011-02-01 21:24   ` john stultz
                     ` (2 more replies)
  2011-02-01 13:52 ` [patch 19/28] posix-timers: Remove CLOCK_DISPATCH leftovers Thomas Gleixner
                   ` (13 subsequent siblings)
  31 siblings, 3 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 13:52 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

[-- Attachment #1: posix-timers-convert-timer-del.patch --]
[-- Type: text/plain, Size: 1638 bytes --]

Set the common function for CLOCK_MONOTONIC and CLOCK_REALTIME kclocks
and use the new decoding function. No need to check for the return
value of it. If we have data corruption in the timer, we explode
somewhere else anyway. Also all kclocks which implement timer_create()
need to provide timer_delete() as well.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Richard Cochran <richard.cochran@omicron.at>
---
 kernel/posix-timers.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

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
@@ -254,6 +254,7 @@ static __init int init_posix_timers(void
 		.timer_create	= common_timer_create,
 		.timer_set	= common_timer_set,
 		.timer_get	= common_timer_get,
+		.timer_del	= common_timer_del,
 	};
 	struct k_clock clock_monotonic = {
 		.clock_getres	= hrtimer_get_res,
@@ -263,6 +264,7 @@ static __init int init_posix_timers(void
 		.timer_create	= common_timer_create,
 		.timer_set	= common_timer_set,
 		.timer_get	= common_timer_get,
+		.timer_del	= common_timer_del,
 	};
 	struct k_clock clock_monotonic_raw = {
 		.clock_getres	= hrtimer_get_res,
@@ -852,7 +854,9 @@ static inline int common_timer_del(struc
 
 static inline int timer_delete_hook(struct k_itimer *timer)
 {
-	return CLOCK_DISPATCH(timer->it_clock, timer_del, (timer));
+	struct k_clock *kc = clockid_to_kclock(timer->it_clock);
+
+	return kc->timer_del(timer);
 }
 
 /* Delete a POSIX.1b interval timer. */



^ permalink raw reply	[flat|nested] 111+ messages in thread

* [patch 19/28] posix-timers: Remove CLOCK_DISPATCH leftovers
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
                   ` (17 preceding siblings ...)
  2011-02-01 13:52 ` [patch 18/28] posix-timers: Convert timer_delete() " Thomas Gleixner
@ 2011-02-01 13:52 ` Thomas Gleixner
  2011-02-01 21:25   ` john stultz
  2011-02-02 22:02   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  2011-02-01 13:52 ` [patch 20/28] posix-timers: Make posix-cpu-timers functions static Thomas Gleixner
                   ` (12 subsequent siblings)
  31 siblings, 2 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 13:52 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

[-- Attachment #1: posix-timers-remove-clock-dispatch-leftovers.patch --]
[-- Type: text/plain, Size: 1346 bytes --]

All users gone. Remove the cruft.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Richard Cochran <richard.cochran@omicron.at>
---
 kernel/posix-timers.c |   22 ----------------------
 1 file changed, 22 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
@@ -167,28 +167,6 @@ static inline void unlock_timer(struct k
 	spin_unlock_irqrestore(&timr->it_lock, flags);
 }
 
-/*
- * Call the k_clock hook function if non-null, or the default function.
- */
-#define CLOCK_DISPATCH(clock, call, arglist) \
- 	((clock) < 0 ? posix_cpu_##call arglist : \
- 	 (posix_clocks[clock].call != NULL \
- 	  ? (*posix_clocks[clock].call) arglist : common_##call arglist))
-
-/*
- * Return nonzero if we know a priori this clockid_t value is bogus.
- */
-static inline int invalid_clockid(const clockid_t which_clock)
-{
-	if (which_clock < 0)	/* CPU clock, posix_cpu_* will check it */
-		return 0;
-	if ((unsigned) which_clock >= MAX_CLOCKS)
-		return 1;
-	if (posix_clocks[which_clock].clock_getres != NULL)
-		return 0;
-	return 1;
-}
-
 /* Get clock_realtime */
 static int posix_clock_realtime_get(clockid_t which_clock, struct timespec *tp)
 {



^ permalink raw reply	[flat|nested] 111+ messages in thread

* [patch 20/28] posix-timers: Make posix-cpu-timers functions static
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
                   ` (18 preceding siblings ...)
  2011-02-01 13:52 ` [patch 19/28] posix-timers: Remove CLOCK_DISPATCH leftovers Thomas Gleixner
@ 2011-02-01 13:52 ` Thomas Gleixner
  2011-02-01 21:28   ` John Stultz
  2011-02-02 22:03   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  2011-02-01 13:52 ` [patch 21/28] posix-timer: Update comment Thomas Gleixner
                   ` (11 subsequent siblings)
  31 siblings, 2 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 13:52 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

[-- Attachment #1: posix-timer-make-posix-cpu-timer-functions-static.patch --]
[-- Type: text/plain, Size: 7405 bytes --]

All functions are accessed via clock_posix_cpu now. So make them static.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Richard Cochran <richard.cochran@omicron.at>
---
 include/linux/posix-timers.h |   12 -------
 kernel/posix-cpu-timers.c    |   73 +++++++++++++++++++++----------------------
 2 files changed, 37 insertions(+), 48 deletions(-)

Index: linux-2.6-tip/include/linux/posix-timers.h
===================================================================
--- linux-2.6-tip.orig/include/linux/posix-timers.h
+++ linux-2.6-tip/include/linux/posix-timers.h
@@ -91,18 +91,6 @@ void register_posix_clock(const clockid_
 /* function to call to trigger timer event */
 int posix_timer_event(struct k_itimer *timr, int si_private);
 
-int posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *ts);
-int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *ts);
-int posix_cpu_clock_set(const clockid_t which_clock, const struct timespec *ts);
-int posix_cpu_timer_create(struct k_itimer *timer);
-int posix_cpu_nsleep(const clockid_t which_clock, int flags,
-		     struct timespec *rqtp, struct timespec __user *rmtp);
-long posix_cpu_nsleep_restart(struct restart_block *restart_block);
-int posix_cpu_timer_set(struct k_itimer *timer, int flags,
-			struct itimerspec *new, struct itimerspec *old);
-int posix_cpu_timer_del(struct k_itimer *timer);
-void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp);
-
 void posix_cpu_timer_schedule(struct k_itimer *timer);
 
 void run_posix_cpu_timers(struct task_struct *task);
Index: linux-2.6-tip/kernel/posix-cpu-timers.c
===================================================================
--- linux-2.6-tip.orig/kernel/posix-cpu-timers.c
+++ linux-2.6-tip/kernel/posix-cpu-timers.c
@@ -176,7 +176,8 @@ static inline cputime_t virt_ticks(struc
 	return p->utime;
 }
 
-int posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *tp)
+static int
+posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *tp)
 {
 	int error = check_clock(which_clock);
 	if (!error) {
@@ -194,7 +195,8 @@ int posix_cpu_clock_getres(const clockid
 	return error;
 }
 
-int posix_cpu_clock_set(const clockid_t which_clock, const struct timespec *tp)
+static int
+posix_cpu_clock_set(const clockid_t which_clock, const struct timespec *tp)
 {
 	/*
 	 * You can never reset a CPU clock, but we check for other errors
@@ -317,7 +319,7 @@ static int cpu_clock_sample_group(const 
 }
 
 
-int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *tp)
+static int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *tp)
 {
 	const pid_t pid = CPUCLOCK_PID(which_clock);
 	int error = -EINVAL;
@@ -379,7 +381,7 @@ int posix_cpu_clock_get(const clockid_t 
  * This is called from sys_timer_create() and do_cpu_nanosleep() with the
  * new timer already all-zeros initialized.
  */
-int posix_cpu_timer_create(struct k_itimer *new_timer)
+static int posix_cpu_timer_create(struct k_itimer *new_timer)
 {
 	int ret = 0;
 	const pid_t pid = CPUCLOCK_PID(new_timer->it_clock);
@@ -425,7 +427,7 @@ int posix_cpu_timer_create(struct k_itim
  * If we return TIMER_RETRY, it's necessary to release the timer's lock
  * and try again.  (This happens when the timer is in the middle of firing.)
  */
-int posix_cpu_timer_del(struct k_itimer *timer)
+static int posix_cpu_timer_del(struct k_itimer *timer)
 {
 	struct task_struct *p = timer->it.cpu.task;
 	int ret = 0;
@@ -665,8 +667,8 @@ static int cpu_timer_sample_group(const 
  * If we return TIMER_RETRY, it's necessary to release the timer's lock
  * and try again.  (This happens when the timer is in the middle of firing.)
  */
-int posix_cpu_timer_set(struct k_itimer *timer, int flags,
-			struct itimerspec *new, struct itimerspec *old)
+static int posix_cpu_timer_set(struct k_itimer *timer, int flags,
+			       struct itimerspec *new, struct itimerspec *old)
 {
 	struct task_struct *p = timer->it.cpu.task;
 	union cpu_time_count old_expires, new_expires, old_incr, val;
@@ -820,7 +822,7 @@ int posix_cpu_timer_set(struct k_itimer 
 	return ret;
 }
 
-void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp)
+static void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp)
 {
 	union cpu_time_count now;
 	struct task_struct *p = timer->it.cpu.task;
@@ -1481,68 +1483,67 @@ static int do_cpu_nanosleep(const clocki
 	return error;
 }
 
-int posix_cpu_nsleep(const clockid_t which_clock, int flags,
-		     struct timespec *rqtp, struct timespec __user *rmtp)
+static long posix_cpu_nsleep_restart(struct restart_block *restart_block)
 {
-	struct restart_block *restart_block =
-		&current_thread_info()->restart_block;
+	clockid_t which_clock = restart_block->nanosleep.index;
+	struct timespec t;
 	struct itimerspec it;
 	int error;
 
-	/*
-	 * Diagnose required errors first.
-	 */
-	if (CPUCLOCK_PERTHREAD(which_clock) &&
-	    (CPUCLOCK_PID(which_clock) == 0 ||
-	     CPUCLOCK_PID(which_clock) == current->pid))
-		return -EINVAL;
+	t = ns_to_timespec(restart_block->nanosleep.expires);
 
-	error = do_cpu_nanosleep(which_clock, flags, rqtp, &it);
+	error = do_cpu_nanosleep(which_clock, TIMER_ABSTIME, &t, &it);
 
 	if (error == -ERESTART_RESTARTBLOCK) {
-
-		if (flags & TIMER_ABSTIME)
-			return -ERESTARTNOHAND;
+		struct timespec __user *rmtp = restart_block->nanosleep.rmtp;
 		/*
 		 * Report back to the user the time still remaining.
 		 */
 		if (rmtp && copy_to_user(rmtp, &it.it_value, sizeof *rmtp))
 			return -EFAULT;
 
-		restart_block->fn = posix_cpu_nsleep_restart;
-		restart_block->nanosleep.index = which_clock;
-		restart_block->nanosleep.rmtp = rmtp;
-		restart_block->nanosleep.expires = timespec_to_ns(rqtp);
+		restart_block->nanosleep.expires = timespec_to_ns(&t);
 	}
 	return error;
+
 }
 
-long posix_cpu_nsleep_restart(struct restart_block *restart_block)
+static int posix_cpu_nsleep(const clockid_t which_clock, int flags,
+			    struct timespec *rqtp, struct timespec __user *rmtp)
 {
-	clockid_t which_clock = restart_block->nanosleep.index;
-	struct timespec t;
+	struct restart_block *restart_block =
+		&current_thread_info()->restart_block;
 	struct itimerspec it;
 	int error;
 
-	t = ns_to_timespec(restart_block->nanosleep.expires);
+	/*
+	 * Diagnose required errors first.
+	 */
+	if (CPUCLOCK_PERTHREAD(which_clock) &&
+	    (CPUCLOCK_PID(which_clock) == 0 ||
+	     CPUCLOCK_PID(which_clock) == current->pid))
+		return -EINVAL;
 
-	error = do_cpu_nanosleep(which_clock, TIMER_ABSTIME, &t, &it);
+	error = do_cpu_nanosleep(which_clock, flags, rqtp, &it);
 
 	if (error == -ERESTART_RESTARTBLOCK) {
-		struct timespec __user *rmtp = restart_block->nanosleep.rmtp;
+
+		if (flags & TIMER_ABSTIME)
+			return -ERESTARTNOHAND;
 		/*
 		 * Report back to the user the time still remaining.
 		 */
 		if (rmtp && copy_to_user(rmtp, &it.it_value, sizeof *rmtp))
 			return -EFAULT;
 
-		restart_block->nanosleep.expires = timespec_to_ns(&t);
+		restart_block->fn = posix_cpu_nsleep_restart;
+		restart_block->nanosleep.index = which_clock;
+		restart_block->nanosleep.rmtp = rmtp;
+		restart_block->nanosleep.expires = timespec_to_ns(rqtp);
 	}
 	return error;
-
 }
 
-
 #define PROCESS_CLOCK	MAKE_PROCESS_CPUCLOCK(0, CPUCLOCK_SCHED)
 #define THREAD_CLOCK	MAKE_THREAD_CPUCLOCK(0, CPUCLOCK_SCHED)
 



^ permalink raw reply	[flat|nested] 111+ messages in thread

* [patch 21/28] posix-timer: Update comment
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
                   ` (19 preceding siblings ...)
  2011-02-01 13:52 ` [patch 20/28] posix-timers: Make posix-cpu-timers functions static Thomas Gleixner
@ 2011-02-01 13:52 ` Thomas Gleixner
  2011-02-01 21:28   ` john stultz
  2011-02-02 22:03   ` [tip:timers/core] " tip-bot for Richard Cochran
  2011-02-01 13:52 ` [patch 22/28] time: Introduce timekeeping_inject_offset Thomas Gleixner
                   ` (10 subsequent siblings)
  31 siblings, 2 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 13:52 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

[-- Attachment #1: posix-timer-update-comment.patch --]
[-- Type: text/plain, Size: 2792 bytes --]

From: Richard Cochran <richardcochran@gmail.com>

Pick the cleanup to the comment in posix-timers.c from Richards all in
one conversion patch.

Originally-from: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
---
 kernel/posix-timers.c |   25 +++++++------------------
 1 file changed, 7 insertions(+), 18 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
@@ -102,11 +102,7 @@ static DEFINE_SPINLOCK(idr_lock);
 /*
  * CLOCKs: The POSIX standard calls for a couple of clocks and allows us
  *	    to implement others.  This structure defines the various
- *	    clocks and allows the possibility of adding others.	 We
- *	    provide an interface to add clocks to the table and expect
- *	    the "arch" code to add at least one clock that is high
- *	    resolution.	 Here we define the standard CLOCK_REALTIME as a
- *	    1/HZ resolution clock.
+ *	    clocks.
  *
  * RESOLUTION: Clock resolution is used to round up timer and interval
  *	    times, NOT to report clock times, which are reported with as
@@ -116,20 +112,13 @@ static DEFINE_SPINLOCK(idr_lock);
  *	    necessary code is written.	The standard says we should say
  *	    something about this issue in the documentation...
  *
- * FUNCTIONS: The CLOCKs structure defines possible functions to handle
- *	    various clock functions.  For clocks that use the standard
- *	    system timer code these entries should be NULL.  This will
- *	    allow dispatch without the overhead of indirect function
- *	    calls.  CLOCKS that depend on other sources (e.g. WWV or GPS)
- *	    must supply functions here, even if the function just returns
- *	    ENOSYS.  The standard POSIX timer management code assumes the
- *	    following: 1.) The k_itimer struct (sched.h) is used for the
- *	    timer.  2.) The list, it_lock, it_clock, it_id and it_pid
- *	    fields are not modified by timer code.
+ * FUNCTIONS: The CLOCKs structure defines possible functions to
+ *	    handle various clock functions.
  *
- *          At this time all functions EXCEPT clock_nanosleep can be
- *          redirected by the CLOCKS structure.  Clock_nanosleep is in
- *          there, but the code ignores it.
+ *	    The standard POSIX timer management code assumes the
+ *	    following: 1.) The k_itimer struct (sched.h) is used for
+ *	    the timer.  2.) The list, it_lock, it_clock, it_id and
+ *	    it_pid fields are not modified by timer code.
  *
  * Permissions: It is assumed that the clock_settime() function defined
  *	    for each clock will take care of permission checks.	 Some



^ permalink raw reply	[flat|nested] 111+ messages in thread

* [patch 22/28] time: Introduce timekeeping_inject_offset
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
                   ` (20 preceding siblings ...)
  2011-02-01 13:52 ` [patch 21/28] posix-timer: Update comment Thomas Gleixner
@ 2011-02-01 13:52 ` Thomas Gleixner
  2011-02-02 22:03   ` [tip:timers/core] " tip-bot for John Stultz
  2011-02-01 13:52 ` [patch 23/28] ntp: Add ADJ_SETOFFSET mode bit Thomas Gleixner
                   ` (9 subsequent siblings)
  31 siblings, 1 reply; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 13:52 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

[-- Attachment #1: time-introduce-timekeeping_inject_offset.patch --]
[-- Type: text/plain, Size: 2563 bytes --]

From: John Stultz <john.stultz@linaro.org>

This adds a kernel-internal timekeeping interface to add or subtract
a fixed amount from CLOCK_REALTIME. This makes it so kernel users or
interfaces trying to do so do not have to read the time, then add an
offset and then call settimeofday(), which adds some extra error in
comparision to just simply adding the offset in the kernel timekeeping
core.

Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Richard Cochran <richard.cochran@omicron.at>
LKML-Reference: <6aec014551fc1d34924d6a7bcf97769867c15ba9.1296124770.git.richard.cochran@omicron.at>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 include/linux/time.h      |    1 +
 kernel/time/timekeeping.c |   36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)

Index: linux-2.6-tip/include/linux/time.h
===================================================================
--- linux-2.6-tip.orig/include/linux/time.h
+++ linux-2.6-tip/include/linux/time.h
@@ -166,6 +166,7 @@ extern struct timespec timespec_trunc(st
 extern int timekeeping_valid_for_hres(void);
 extern u64 timekeeping_max_deferment(void);
 extern void timekeeping_leap_insert(int leapsecond);
+extern int timekeeping_inject_offset(struct timespec *ts);
 
 struct tms;
 extern void do_sys_times(struct tms *);
Index: linux-2.6-tip/kernel/time/timekeeping.c
===================================================================
--- linux-2.6-tip.orig/kernel/time/timekeeping.c
+++ linux-2.6-tip/kernel/time/timekeeping.c
@@ -387,6 +387,42 @@ int do_settimeofday(const struct timespe
 
 EXPORT_SYMBOL(do_settimeofday);
 
+
+/**
+ * timekeeping_inject_offset - Adds or subtracts from the current time.
+ * @tv:		pointer to the timespec variable containing the offset
+ *
+ * Adds or subtracts an offset value from the current time.
+ */
+int timekeeping_inject_offset(struct timespec *ts)
+{
+	unsigned long flags;
+
+	if ((unsigned long)ts->tv_nsec >= NSEC_PER_SEC)
+		return -EINVAL;
+
+	write_seqlock_irqsave(&xtime_lock, flags);
+
+	timekeeping_forward_now();
+
+	xtime = timespec_add(xtime, *ts);
+	wall_to_monotonic = timespec_sub(wall_to_monotonic, *ts);
+
+	timekeeper.ntp_error = 0;
+	ntp_clear();
+
+	update_vsyscall(&xtime, &wall_to_monotonic, timekeeper.clock,
+				timekeeper.mult);
+
+	write_sequnlock_irqrestore(&xtime_lock, flags);
+
+	/* signal hrtimers about time change */
+	clock_was_set();
+
+	return 0;
+}
+EXPORT_SYMBOL(timekeeping_inject_offset);
+
 /**
  * change_clocksource - Swaps clocksources if a new one is available
  *



^ permalink raw reply	[flat|nested] 111+ messages in thread

* [patch 23/28] ntp: Add ADJ_SETOFFSET mode bit
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
                   ` (21 preceding siblings ...)
  2011-02-01 13:52 ` [patch 22/28] time: Introduce timekeeping_inject_offset Thomas Gleixner
@ 2011-02-01 13:52 ` Thomas Gleixner
  2011-02-01 21:30   ` john stultz
  2011-02-01 13:52 ` [patch 24/28] posix-clocks: Splitout compat timex accessors Thomas Gleixner
                   ` (8 subsequent siblings)
  31 siblings, 1 reply; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 13:52 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

[-- Attachment #1: ntp-add-adj_setoffset-mode-bit.patch --]
[-- Type: text/plain, Size: 2198 bytes --]

From: Richard Cochran <richardcochran@gmail.com>

This patch adds a new mode bit into the timex structure. When set, the bit
instructs the kernel to add the given time value to the current time.

Signed-off-by: Richard Cochran <richard.cochran@omicron.at>
Cc: John Stultz <john.stultz@linaro.org>
LKML-Reference: <2f7ed6bce83c23e4b7e4530794f0aa175df31a39.1296124770.git.richard.cochran@omicron.at>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 include/linux/timex.h |    3 ++-
 kernel/time/ntp.c     |   11 +++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

Index: linux-2.6-tip/include/linux/timex.h
===================================================================
--- linux-2.6-tip.orig/include/linux/timex.h
+++ linux-2.6-tip/include/linux/timex.h
@@ -73,7 +73,7 @@ struct timex {
 	long tolerance;		/* clock frequency tolerance (ppm)
 				 * (read only)
 				 */
-	struct timeval time;	/* (read only) */
+	struct timeval time;	/* (read only, except for ADJ_SETOFFSET) */
 	long tick;		/* (modified) usecs between clock ticks */
 
 	long ppsfreq;           /* pps frequency (scaled ppm) (ro) */
@@ -102,6 +102,7 @@ struct timex {
 #define ADJ_STATUS		0x0010	/* clock status */
 #define ADJ_TIMECONST		0x0020	/* pll time constant */
 #define ADJ_TAI			0x0080	/* set TAI offset */
+#define ADJ_SETOFFSET		0x0100  /* add 'time' to current time */
 #define ADJ_MICRO		0x1000	/* select microsecond resolution */
 #define ADJ_NANO		0x2000	/* select nanosecond resolution */
 #define ADJ_TICK		0x4000	/* tick value */
Index: linux-2.6-tip/kernel/time/ntp.c
===================================================================
--- linux-2.6-tip.orig/kernel/time/ntp.c
+++ linux-2.6-tip/kernel/time/ntp.c
@@ -648,6 +648,17 @@ int do_adjtimex(struct timex *txc)
 			hrtimer_cancel(&leap_timer);
 	}
 
+	if (txc->modes & ADJ_SETOFFSET) {
+		struct timespec delta;
+		if ((unsigned long)txc->time.tv_usec >= NSEC_PER_SEC)
+			return -EINVAL;
+		delta.tv_sec  = txc->time.tv_sec;
+		delta.tv_nsec = txc->time.tv_usec;
+		if (!(txc->modes & ADJ_NANO))
+			delta.tv_nsec *= 1000;
+		timekeeping_inject_offset(&delta);
+	}
+
 	getnstimeofday(&ts);
 
 	write_seqlock_irq(&xtime_lock);



^ permalink raw reply	[flat|nested] 111+ messages in thread

* [patch 24/28] posix-clocks: Splitout compat timex accessors
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
                   ` (22 preceding siblings ...)
  2011-02-01 13:52 ` [patch 23/28] ntp: Add ADJ_SETOFFSET mode bit Thomas Gleixner
@ 2011-02-01 13:52 ` Thomas Gleixner
  2011-02-01 21:31   ` john stultz
  2011-02-02 22:04   ` [tip:timers/core] time: " tip-bot for Richard Cochran
  2011-02-01 13:52 ` [patch 25/28] posix clocks: Introduce a syscall for clock tuning Thomas Gleixner
                   ` (7 subsequent siblings)
  31 siblings, 2 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 13:52 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

[-- Attachment #1: posix-clocks-splitout-compat-timex-accessors.patch --]
[-- Type: text/plain, Size: 5856 bytes --]

From: Richard Cochran <richardcochran@gmail.com>

Split out the compat timex accessors into separate
functions. Preparatory patch for a new syscall.

[ tglx: Split that patch from Richards "posix clocks: Introduce a
  	syscall for clock tuning.". Keeps the changes strictly
  	separate ]

Originally-from: Richard Cochran <richardcochran@gmail.com>
Cc: John Stultz <john.stultz@linaro.org>
LKML-Reference: <2d5e2f3e6f388aa1848d40406646aab2e26a906f.1296124770.git.richard.cochran@omicron.at>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 kernel/compat.c |  113 ++++++++++++++++++++++++++++++++------------------------
 1 file changed, 65 insertions(+), 48 deletions(-)

Index: linux-2.6-tip/kernel/compat.c
===================================================================
--- linux-2.6-tip.orig/kernel/compat.c
+++ linux-2.6-tip/kernel/compat.c
@@ -52,6 +52,64 @@ static int compat_put_timeval(struct com
 		put_user(i->tv_usec, &o->tv_usec)) ? -EFAULT : 0;
 }
 
+static int compat_get_timex(struct timex *txc, struct compat_timex __user *utp)
+{
+	memset(txc, 0, sizeof(struct timex));
+
+	if (!access_ok(VERIFY_READ, utp, sizeof(struct compat_timex)) ||
+			__get_user(txc->modes, &utp->modes) ||
+			__get_user(txc->offset, &utp->offset) ||
+			__get_user(txc->freq, &utp->freq) ||
+			__get_user(txc->maxerror, &utp->maxerror) ||
+			__get_user(txc->esterror, &utp->esterror) ||
+			__get_user(txc->status, &utp->status) ||
+			__get_user(txc->constant, &utp->constant) ||
+			__get_user(txc->precision, &utp->precision) ||
+			__get_user(txc->tolerance, &utp->tolerance) ||
+			__get_user(txc->time.tv_sec, &utp->time.tv_sec) ||
+			__get_user(txc->time.tv_usec, &utp->time.tv_usec) ||
+			__get_user(txc->tick, &utp->tick) ||
+			__get_user(txc->ppsfreq, &utp->ppsfreq) ||
+			__get_user(txc->jitter, &utp->jitter) ||
+			__get_user(txc->shift, &utp->shift) ||
+			__get_user(txc->stabil, &utp->stabil) ||
+			__get_user(txc->jitcnt, &utp->jitcnt) ||
+			__get_user(txc->calcnt, &utp->calcnt) ||
+			__get_user(txc->errcnt, &utp->errcnt) ||
+			__get_user(txc->stbcnt, &utp->stbcnt))
+		return -EFAULT;
+
+	return 0;
+}
+
+static int compat_put_timex(struct compat_timex __user *utp, struct timex *txc)
+{
+	if (!access_ok(VERIFY_WRITE, utp, sizeof(struct compat_timex)) ||
+			__put_user(txc->modes, &utp->modes) ||
+			__put_user(txc->offset, &utp->offset) ||
+			__put_user(txc->freq, &utp->freq) ||
+			__put_user(txc->maxerror, &utp->maxerror) ||
+			__put_user(txc->esterror, &utp->esterror) ||
+			__put_user(txc->status, &utp->status) ||
+			__put_user(txc->constant, &utp->constant) ||
+			__put_user(txc->precision, &utp->precision) ||
+			__put_user(txc->tolerance, &utp->tolerance) ||
+			__put_user(txc->time.tv_sec, &utp->time.tv_sec) ||
+			__put_user(txc->time.tv_usec, &utp->time.tv_usec) ||
+			__put_user(txc->tick, &utp->tick) ||
+			__put_user(txc->ppsfreq, &utp->ppsfreq) ||
+			__put_user(txc->jitter, &utp->jitter) ||
+			__put_user(txc->shift, &utp->shift) ||
+			__put_user(txc->stabil, &utp->stabil) ||
+			__put_user(txc->jitcnt, &utp->jitcnt) ||
+			__put_user(txc->calcnt, &utp->calcnt) ||
+			__put_user(txc->errcnt, &utp->errcnt) ||
+			__put_user(txc->stbcnt, &utp->stbcnt) ||
+			__put_user(txc->tai, &utp->tai))
+		return -EFAULT;
+	return 0;
+}
+
 asmlinkage long compat_sys_gettimeofday(struct compat_timeval __user *tv,
 		struct timezone __user *tz)
 {
@@ -951,58 +1009,17 @@ asmlinkage long compat_sys_rt_sigsuspend
 asmlinkage long compat_sys_adjtimex(struct compat_timex __user *utp)
 {
 	struct timex txc;
-	int ret;
+	int err, ret;
 
-	memset(&txc, 0, sizeof(struct timex));
-
-	if (!access_ok(VERIFY_READ, utp, sizeof(struct compat_timex)) ||
-			__get_user(txc.modes, &utp->modes) ||
-			__get_user(txc.offset, &utp->offset) ||
-			__get_user(txc.freq, &utp->freq) ||
-			__get_user(txc.maxerror, &utp->maxerror) ||
-			__get_user(txc.esterror, &utp->esterror) ||
-			__get_user(txc.status, &utp->status) ||
-			__get_user(txc.constant, &utp->constant) ||
-			__get_user(txc.precision, &utp->precision) ||
-			__get_user(txc.tolerance, &utp->tolerance) ||
-			__get_user(txc.time.tv_sec, &utp->time.tv_sec) ||
-			__get_user(txc.time.tv_usec, &utp->time.tv_usec) ||
-			__get_user(txc.tick, &utp->tick) ||
-			__get_user(txc.ppsfreq, &utp->ppsfreq) ||
-			__get_user(txc.jitter, &utp->jitter) ||
-			__get_user(txc.shift, &utp->shift) ||
-			__get_user(txc.stabil, &utp->stabil) ||
-			__get_user(txc.jitcnt, &utp->jitcnt) ||
-			__get_user(txc.calcnt, &utp->calcnt) ||
-			__get_user(txc.errcnt, &utp->errcnt) ||
-			__get_user(txc.stbcnt, &utp->stbcnt))
-		return -EFAULT;
+	err = compat_get_timex(&txc, utp);
+	if (err)
+		return err;
 
 	ret = do_adjtimex(&txc);
 
-	if (!access_ok(VERIFY_WRITE, utp, sizeof(struct compat_timex)) ||
-			__put_user(txc.modes, &utp->modes) ||
-			__put_user(txc.offset, &utp->offset) ||
-			__put_user(txc.freq, &utp->freq) ||
-			__put_user(txc.maxerror, &utp->maxerror) ||
-			__put_user(txc.esterror, &utp->esterror) ||
-			__put_user(txc.status, &utp->status) ||
-			__put_user(txc.constant, &utp->constant) ||
-			__put_user(txc.precision, &utp->precision) ||
-			__put_user(txc.tolerance, &utp->tolerance) ||
-			__put_user(txc.time.tv_sec, &utp->time.tv_sec) ||
-			__put_user(txc.time.tv_usec, &utp->time.tv_usec) ||
-			__put_user(txc.tick, &utp->tick) ||
-			__put_user(txc.ppsfreq, &utp->ppsfreq) ||
-			__put_user(txc.jitter, &utp->jitter) ||
-			__put_user(txc.shift, &utp->shift) ||
-			__put_user(txc.stabil, &utp->stabil) ||
-			__put_user(txc.jitcnt, &utp->jitcnt) ||
-			__put_user(txc.calcnt, &utp->calcnt) ||
-			__put_user(txc.errcnt, &utp->errcnt) ||
-			__put_user(txc.stbcnt, &utp->stbcnt) ||
-			__put_user(txc.tai, &utp->tai))
-		ret = -EFAULT;
+	err = compat_put_timex(utp, &txc);
+	if (err)
+		return err;
 
 	return ret;
 }



^ permalink raw reply	[flat|nested] 111+ messages in thread

* [patch 25/28] posix clocks: Introduce a syscall for clock tuning.
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
                   ` (23 preceding siblings ...)
  2011-02-01 13:52 ` [patch 24/28] posix-clocks: Splitout compat timex accessors Thomas Gleixner
@ 2011-02-01 13:52 ` Thomas Gleixner
  2011-02-01 21:35   ` john stultz
  2011-02-02 22:04   ` [tip:timers/core] posix-timers: " tip-bot for Richard Cochran
  2011-02-01 13:52 ` [patch 26/28] posix_clocks: Add clock_adjtime for x86 Thomas Gleixner
                   ` (6 subsequent siblings)
  31 siblings, 2 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 13:52 UTC (permalink / raw)
  To: LKML
  Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra,
	Alan Cox, Arnd Bergmann, Christoph Lameter, David Miller,
	Krzysztof Halasa, Rodolfo Giometti, Benjamin Herrenschmidt,
	Mike Frysinger, Paul Mackerras, Russell King

[-- Attachment #1: posix-clocks-introduce-a-syscall-for-clock-tuning.patch --]
[-- Type: text/plain, Size: 5079 bytes --]

From: Richard Cochran <richardcochran@gmail.com>

A new syscall is introduced that allows tuning of a POSIX clock. The
new call, clock_adjtime, takes two parameters, the clock ID and a
pointer to a struct timex. Any ADJTIMEX(2) operation may be requested
via this system call, but various POSIX clocks may or may not support
tuning.

[ tglx: Adapted to the posix-timer cleanup series. Avoid copy_to_user
  	in the error case ]

Signed-off-by: Richard Cochran <richard.cochran@omicron.at>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Christoph Lameter <cl@linux.com>
Cc: David Miller <davem@davemloft.net>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Krzysztof Halasa <khc@pm.waw.pl>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rodolfo Giometti <giometti@linux.it>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Mike Frysinger <vapier@gentoo.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Russell King <linux@arm.linux.org.uk>
LKML-Reference: <2d5e2f3e6f388aa1848d40406646aab2e26a906f.1296124770.git.richard.cochran@omicron.at>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 include/linux/posix-timers.h |    2 ++
 include/linux/syscalls.h     |    2 ++
 kernel/compat.c              |   23 +++++++++++++++++++++++
 kernel/posix-timers.c        |   30 ++++++++++++++++++++++++++++++
 4 files changed, 57 insertions(+)

Index: linux-2.6-tip/include/linux/posix-timers.h
===================================================================
--- linux-2.6-tip.orig/include/linux/posix-timers.h
+++ linux-2.6-tip/include/linux/posix-timers.h
@@ -4,6 +4,7 @@
 #include <linux/spinlock.h>
 #include <linux/list.h>
 #include <linux/sched.h>
+#include <linux/timex.h>
 
 union cpu_time_count {
 	cputime_t cpu;
@@ -71,6 +72,7 @@ struct k_clock {
 	int (*clock_set) (const clockid_t which_clock,
 			  const struct timespec *tp);
 	int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
+	int (*clock_adj) (const clockid_t which_clock, struct timex *tx);
 	int (*timer_create) (struct k_itimer *timer);
 	int (*nsleep) (const clockid_t which_clock, int flags,
 		       struct timespec *, struct timespec __user *);
Index: linux-2.6-tip/include/linux/syscalls.h
===================================================================
--- linux-2.6-tip.orig/include/linux/syscalls.h
+++ linux-2.6-tip/include/linux/syscalls.h
@@ -311,6 +311,8 @@ asmlinkage long sys_clock_settime(clocki
 				const struct timespec __user *tp);
 asmlinkage long sys_clock_gettime(clockid_t which_clock,
 				struct timespec __user *tp);
+asmlinkage long sys_clock_adjtime(clockid_t which_clock,
+				struct timex __user *tx);
 asmlinkage long sys_clock_getres(clockid_t which_clock,
 				struct timespec __user *tp);
 asmlinkage long sys_clock_nanosleep(clockid_t which_clock, int flags,
Index: linux-2.6-tip/kernel/compat.c
===================================================================
--- linux-2.6-tip.orig/kernel/compat.c
+++ linux-2.6-tip/kernel/compat.c
@@ -675,6 +675,29 @@ long compat_sys_clock_gettime(clockid_t 
 	return err;
 }
 
+long compat_sys_clock_adjtime(clockid_t which_clock,
+		struct compat_timex __user *utp)
+{
+	struct timex txc;
+	mm_segment_t oldfs;
+	int err, ret;
+
+	err = compat_get_timex(&txc, utp);
+	if (err)
+		return err;
+
+	oldfs = get_fs();
+	set_fs(KERNEL_DS);
+	ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
+	set_fs(oldfs);
+
+	err = compat_put_timex(utp, &txc);
+	if (err)
+		return err;
+
+	return ret;
+}
+
 long compat_sys_clock_getres(clockid_t which_clock,
 		struct compat_timespec __user *tp)
 {
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
@@ -170,6 +170,12 @@ static inline int posix_clock_realtime_s
 	return do_sys_settimeofday(tp, NULL);
 }
 
+static inline int posix_clock_realtime_adj(const clockid_t which_clock,
+					   struct timex *t)
+{
+	return do_adjtimex(t);
+}
+
 /*
  * Get monotonic time for posix timers
  */
@@ -216,6 +222,7 @@ static __init int init_posix_timers(void
 		.clock_getres	= hrtimer_get_res,
 		.clock_get	= posix_clock_realtime_get,
 		.clock_set	= posix_clock_realtime_set,
+		.clock_adj	= posix_clock_realtime_adj,
 		.nsleep		= common_nsleep,
 		.nsleep_restart	= hrtimer_nanosleep_restart,
 		.timer_create	= common_timer_create,
@@ -930,6 +937,29 @@ SYSCALL_DEFINE2(clock_gettime, const clo
 	return error;
 }
 
+SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock,
+		struct timex __user *, utx)
+{
+	struct k_clock *kc = clockid_to_kclock(which_clock);
+	struct timex ktx;
+	int err;
+
+	if (!kc)
+		return -EINVAL;
+	if (!kc->clock_adj)
+		return -EOPNOTSUPP;
+
+	if (copy_from_user(&ktx, utx, sizeof(ktx)))
+		return -EFAULT;
+
+	err = kc->clock_adj(which_clock, &ktx);
+
+	if (!err && copy_to_user(utx, &ktx, sizeof(ktx)))
+		return -EFAULT;
+
+	return err;
+}
+
 SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock,
 		struct timespec __user *, tp)
 {



^ permalink raw reply	[flat|nested] 111+ messages in thread

* [patch 26/28] posix_clocks: Add clock_adjtime for x86
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
                   ` (24 preceding siblings ...)
  2011-02-01 13:52 ` [patch 25/28] posix clocks: Introduce a syscall for clock tuning Thomas Gleixner
@ 2011-02-01 13:52 ` Thomas Gleixner
  2011-02-01 21:36   ` john stultz
  2011-02-02 22:05   ` [tip:timers/core] x86: " tip-bot for Richard Cochran
  2011-02-01 13:52 ` [patch 27/28] posix-timers: Add support for fd based clocks Thomas Gleixner
                   ` (5 subsequent siblings)
  31 siblings, 2 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 13:52 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

[-- Attachment #1: posix_clocks-add-clock_adjtime-for-x86.patch --]
[-- Type: text/plain, Size: 2416 bytes --]

This patch adds the clock_adjtime system call to the x86 architecture.

Signed-off-by: Richard Cochran <richard.cochran@omicron.at>
Cc: John Stultz <john.stultz@linaro.org>
LKML-Reference: <4501cddb99d555624baade4609030ca458dfa3a0.1296124770.git.richard.cochran@omicron.at>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 arch/x86/ia32/ia32entry.S          |    1 +
 arch/x86/include/asm/unistd_32.h   |    3 ++-
 arch/x86/include/asm/unistd_64.h   |    2 ++
 arch/x86/kernel/syscall_table_32.S |    1 +
 4 files changed, 6 insertions(+), 1 deletion(-)

Index: linux-2.6-tip/arch/x86/ia32/ia32entry.S
===================================================================
--- linux-2.6-tip.orig/arch/x86/ia32/ia32entry.S
+++ linux-2.6-tip/arch/x86/ia32/ia32entry.S
@@ -851,4 +851,5 @@ ia32_sys_call_table:
 	.quad sys_fanotify_init
 	.quad sys32_fanotify_mark
 	.quad sys_prlimit64		/* 340 */
+	.quad compat_sys_clock_adjtime
 ia32_syscall_end:
Index: linux-2.6-tip/arch/x86/include/asm/unistd_32.h
===================================================================
--- linux-2.6-tip.orig/arch/x86/include/asm/unistd_32.h
+++ linux-2.6-tip/arch/x86/include/asm/unistd_32.h
@@ -346,10 +346,11 @@
 #define __NR_fanotify_init	338
 #define __NR_fanotify_mark	339
 #define __NR_prlimit64		340
+#define __NR_clock_adjtime	341
 
 #ifdef __KERNEL__
 
-#define NR_syscalls 341
+#define NR_syscalls 342
 
 #define __ARCH_WANT_IPC_PARSE_VERSION
 #define __ARCH_WANT_OLD_READDIR
Index: linux-2.6-tip/arch/x86/include/asm/unistd_64.h
===================================================================
--- linux-2.6-tip.orig/arch/x86/include/asm/unistd_64.h
+++ linux-2.6-tip/arch/x86/include/asm/unistd_64.h
@@ -669,6 +669,8 @@ __SYSCALL(__NR_fanotify_init, sys_fanoti
 __SYSCALL(__NR_fanotify_mark, sys_fanotify_mark)
 #define __NR_prlimit64				302
 __SYSCALL(__NR_prlimit64, sys_prlimit64)
+#define __NR_clock_adjtime			303
+__SYSCALL(__NR_clock_adjtime, sys_clock_adjtime)
 
 #ifndef __NO_STUBS
 #define __ARCH_WANT_OLD_READDIR
Index: linux-2.6-tip/arch/x86/kernel/syscall_table_32.S
===================================================================
--- linux-2.6-tip.orig/arch/x86/kernel/syscall_table_32.S
+++ linux-2.6-tip/arch/x86/kernel/syscall_table_32.S
@@ -340,3 +340,4 @@ ENTRY(sys_call_table)
 	.long sys_fanotify_init
 	.long sys_fanotify_mark
 	.long sys_prlimit64		/* 340 */
+	.long sys_clock_adjtime



^ permalink raw reply	[flat|nested] 111+ messages in thread

* [patch 27/28] posix-timers: Add support for fd based clocks
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
                   ` (25 preceding siblings ...)
  2011-02-01 13:52 ` [patch 26/28] posix_clocks: Add clock_adjtime for x86 Thomas Gleixner
@ 2011-02-01 13:52 ` Thomas Gleixner
  2011-02-01 21:38   ` john stultz
                     ` (2 more replies)
  2011-02-01 13:52 ` [patch 28/28] posix clocks: Introduce dynamic clocks Thomas Gleixner
                   ` (4 subsequent siblings)
  31 siblings, 3 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 13:52 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

[-- Attachment #1: posix-timers-add-support-for-fd-based-clocks.patch --]
[-- Type: text/plain, Size: 2104 bytes --]

From: Richard Cochran <richard.cochran@omicron.at>

Extend the negative clockids which are currently used by posix cpu
timers to encode the PID with a file descriptor based type which
encodes the fd in the upper bits.

Originally-from: Richard Cochran <richard.cochran@omicron.at>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
---
 include/linux/posix-timers.h |   13 +++++++++++++
 kernel/posix-timers.c        |    2 +-
 2 files changed, 14 insertions(+), 1 deletion(-)

Index: linux-2.6-tip/include/linux/posix-timers.h
===================================================================
--- linux-2.6-tip.orig/include/linux/posix-timers.h
+++ linux-2.6-tip/include/linux/posix-timers.h
@@ -18,6 +18,17 @@ struct cpu_timer_list {
 	int firing;
 };
 
+/*
+ * Bit fields within a clockid:
+ *
+ * The most significant 29 bits hold either a pid or a file descriptor.
+ *
+ * Bit 2 indicates whether a cpu clock refers to a thread or a process.
+ *
+ * Bits 1 and 0 give the type: PROF=0, VIRT=1, SCHED=2, or FD=3.
+ *
+ * A clockid is invalid if bits 2, 1, and 0 all set.
+ */
 #define CPUCLOCK_PID(clock)		((pid_t) ~((clock) >> 3))
 #define CPUCLOCK_PERTHREAD(clock) \
 	(((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0)
@@ -29,6 +40,8 @@ struct cpu_timer_list {
 #define CPUCLOCK_VIRT		1
 #define CPUCLOCK_SCHED		2
 #define CPUCLOCK_MAX		3
+#define CLOCKFD			CPUCLOCK_MAX
+#define CLOCKFD_MASK		(CPUCLOCK_PERTHREAD_MASK|CPUCLOCK_CLOCK_MASK)
 
 #define MAKE_PROCESS_CPUCLOCK(pid, clock) \
 	((~(clockid_t) (pid) << 3) | (clockid_t) (clock))
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
@@ -477,7 +477,7 @@ static void release_posix_timer(struct k
 static struct k_clock *clockid_to_kclock(const clockid_t id)
 {
 	if (id < 0)
-		return &clock_posix_cpu;
+		return (id & CLOCKFD_MASK) == CLOCKFD ? NULL : &clock_posix_cpu;
 
 	if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
 		return NULL;



^ permalink raw reply	[flat|nested] 111+ messages in thread

* [patch 28/28] posix clocks: Introduce dynamic clocks
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
                   ` (26 preceding siblings ...)
  2011-02-01 13:52 ` [patch 27/28] posix-timers: Add support for fd based clocks Thomas Gleixner
@ 2011-02-01 13:52 ` Thomas Gleixner
  2011-02-01 21:49   ` john stultz
                     ` (2 more replies)
  2011-02-02  8:17 ` [patch 00/28] Rework of the PTP support series core code Richard Cochran
                   ` (3 subsequent siblings)
  31 siblings, 3 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 13:52 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

[-- Attachment #1: posix-clocks-introduce-dynamic-clocks.patch --]
[-- Type: text/plain, Size: 18876 bytes --]

From: Richard Cochran <richardcochran@gmail.com>

This patch adds support for adding and removing posix clocks. The
clock lifetime cycle is patterned after usb devices. Each clock is
represented by a standard character device. In addition, the driver
may optionally implement custom character device operations.

The posix clock and timer system calls listed below now work with
dynamic posix clocks, as well as the traditional static clocks.
The following system calls are affected:

   - clock_adjtime (brand new syscall)
   - clock_gettime
   - clock_getres
   - clock_settime
   - timer_create
   - timer_delete
   - timer_gettime
   - timer_settime

[ tglx: Adapted to the posix-timer cleanup. Moved clock_posix_dynamic
  	to posix-clock.c and made all referenced functions static ]

Signed-off-by: Richard Cochran <richard.cochran@omicron.at>
Cc: John Stultz <john.stultz@linaro.org>
LKML-Reference: <21258f45fcc5e08a595f411c7760f3ccc18964bb.1296124770.git.richard.cochran@omicron.at>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 include/linux/posix-clock.h  |  150 ++++++++++++++
 include/linux/posix-timers.h |    6 
 kernel/posix-timers.c        |    4 
 kernel/time/Makefile         |    3 
 kernel/time/posix-clock.c    |  441 +++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 601 insertions(+), 3 deletions(-)
 create mode 100644 include/linux/posix-clock.h
 create mode 100644 kernel/time/posix-clock-syscalls.h
 create mode 100644 kernel/time/posix-clock.c

Index: linux-2.6-tip/include/linux/posix-clock.h
===================================================================
--- /dev/null
+++ linux-2.6-tip/include/linux/posix-clock.h
@@ -0,0 +1,150 @@
+/*
+ * posix-clock.h - support for dynamic clock devices
+ *
+ * Copyright (C) 2010 OMICRON electronics GmbH
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+#ifndef _LINUX_POSIX_CLOCK_H_
+#define _LINUX_POSIX_CLOCK_H_
+
+#include <linux/cdev.h>
+#include <linux/fs.h>
+#include <linux/poll.h>
+#include <linux/posix-timers.h>
+
+struct posix_clock;
+
+/**
+ * struct posix_clock_operations - functional interface to the clock
+ *
+ * Every posix clock is represented by a character device. Drivers may
+ * optionally offer extended capabilities by implementing the
+ * character device methods. The character device file operations are
+ * first handled by the clock device layer, then passed on to the
+ * driver by calling these functions.
+ *
+ * @owner:          The clock driver should set to THIS_MODULE
+ * @clock_adjtime:  Adjust the clock
+ * @clock_gettime:  Read the current time
+ * @clock_getres:   Get the clock resolution
+ * @clock_settime:  Set the current time value
+ * @timer_create:   Create a new timer
+ * @timer_delete:   Remove a previously created timer
+ * @timer_gettime:  Get remaining time and interval of a timer
+ * @timer_setttime: Set a timer's initial expiration and interval
+ * @fasync:         Optional character device fasync method
+ * @mmap:           Optional character device mmap method
+ * @open:           Optional character device open method
+ * @release:        Optional character device release method
+ * @ioctl:          Optional character device ioctl method
+ * @read:           Optional character device read method
+ * @poll:           Optional character device poll method
+ */
+struct posix_clock_operations {
+	struct module *owner;
+
+	int  (*clock_adjtime)(struct posix_clock *pc, struct timex *tx);
+
+	int  (*clock_gettime)(struct posix_clock *pc, struct timespec *ts);
+
+	int  (*clock_getres) (struct posix_clock *pc, struct timespec *ts);
+
+	int  (*clock_settime)(struct posix_clock *pc,
+			      const struct timespec *ts);
+
+	int  (*timer_create) (struct posix_clock *pc, struct k_itimer *kit);
+
+	int  (*timer_delete) (struct posix_clock *pc, struct k_itimer *kit);
+
+	void (*timer_gettime)(struct posix_clock *pc,
+			      struct k_itimer *kit, struct itimerspec *tsp);
+
+	int  (*timer_settime)(struct posix_clock *pc,
+			      struct k_itimer *kit, int flags,
+			      struct itimerspec *tsp, struct itimerspec *old);
+	/*
+	 * Optional character device methods:
+	 */
+	int     (*fasync)  (struct posix_clock *pc,
+			    int fd, struct file *file, int on);
+
+	long    (*ioctl)   (struct posix_clock *pc,
+			    unsigned int cmd, unsigned long arg);
+
+	int     (*mmap)    (struct posix_clock *pc,
+			    struct vm_area_struct *vma);
+
+	int     (*open)    (struct posix_clock *pc, fmode_t f_mode);
+
+	uint    (*poll)    (struct posix_clock *pc,
+			    struct file *file, poll_table *wait);
+
+	int     (*release) (struct posix_clock *pc);
+
+	ssize_t (*read)    (struct posix_clock *pc,
+			    uint flags, char __user *buf, size_t cnt);
+};
+
+/**
+ * struct posix_clock - represents a dynamic posix clock
+ *
+ * @ops:     Functional interface to the clock
+ * @cdev:    Character device instance for this clock
+ * @kref:    Reference count.
+ * @mutex:   Protects the 'zombie' field from concurrent access.
+ * @zombie:  If 'zombie' is true, then the hardware has disappeared.
+ * @release: A function to free the structure when the reference count reaches
+ *           zero. May be NULL if structure is statically allocated.
+ *
+ * Drivers should embed their struct posix_clock within a private
+ * structure, obtaining a reference to it during callbacks using
+ * container_of().
+ */
+struct posix_clock {
+	struct posix_clock_operations ops;
+	struct cdev cdev;
+	struct kref kref;
+	struct mutex mutex;
+	bool zombie;
+	void (*release)(struct posix_clock *clk);
+};
+
+/**
+ * posix_clock_register() - register a new clock
+ * @clk:   Pointer to the clock. Caller must provide 'ops' and 'release'
+ * @devid: Allocated device id
+ *
+ * A clock driver calls this function to register itself with the
+ * clock device subsystem. If 'clk' points to dynamically allocated
+ * memory, then the caller must provide a 'release' function to free
+ * that memory.
+ *
+ * Returns zero on success, non-zero otherwise.
+ */
+int posix_clock_register(struct posix_clock *clk, dev_t devid);
+
+/**
+ * posix_clock_unregister() - unregister a clock
+ * @clk: Clock instance previously registered via posix_clock_register()
+ *
+ * A clock driver calls this function to remove itself from the clock
+ * device subsystem. The posix_clock itself will remain (in an
+ * inactive state) until its reference count drops to zero, at which
+ * point it will be deallocated with its 'release' method.
+ */
+void posix_clock_unregister(struct posix_clock *clk);
+
+#endif
Index: linux-2.6-tip/include/linux/posix-timers.h
===================================================================
--- linux-2.6-tip.orig/include/linux/posix-timers.h
+++ linux-2.6-tip/include/linux/posix-timers.h
@@ -32,7 +32,7 @@ struct cpu_timer_list {
 #define CPUCLOCK_PID(clock)		((pid_t) ~((clock) >> 3))
 #define CPUCLOCK_PERTHREAD(clock) \
 	(((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0)
-#define CPUCLOCK_PID_MASK	7
+
 #define CPUCLOCK_PERTHREAD_MASK	4
 #define CPUCLOCK_WHICH(clock)	((clock) & (clockid_t) CPUCLOCK_CLOCK_MASK)
 #define CPUCLOCK_CLOCK_MASK	3
@@ -48,6 +48,9 @@ struct cpu_timer_list {
 #define MAKE_THREAD_CPUCLOCK(tid, clock) \
 	MAKE_PROCESS_CPUCLOCK((tid), (clock) | CPUCLOCK_PERTHREAD_MASK)
 
+#define FD_TO_CLOCKID(fd)	((~(clockid_t) (fd) << 3) | CLOCKFD)
+#define CLOCKID_TO_FD(clk)	((unsigned int) ~((clk) >> 3))
+
 /* POSIX.1b interval timer structure. */
 struct k_itimer {
 	struct list_head list;		/* free/ allocate list */
@@ -100,6 +103,7 @@ struct k_clock {
 };
 
 extern struct k_clock clock_posix_cpu;
+extern struct k_clock clock_posix_dynamic;
 
 void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock);
 
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
@@ -41,6 +41,7 @@
 #include <linux/init.h>
 #include <linux/compiler.h>
 #include <linux/idr.h>
+#include <linux/posix-clock.h>
 #include <linux/posix-timers.h>
 #include <linux/syscalls.h>
 #include <linux/wait.h>
@@ -477,7 +478,8 @@ static void release_posix_timer(struct k
 static struct k_clock *clockid_to_kclock(const clockid_t id)
 {
 	if (id < 0)
-		return (id & CLOCKFD_MASK) == CLOCKFD ? NULL : &clock_posix_cpu;
+		return (id & CLOCKFD_MASK) == CLOCKFD ?
+			&clock_posix_dynamic : &clock_posix_cpu;
 
 	if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
 		return NULL;
Index: linux-2.6-tip/kernel/time/Makefile
===================================================================
--- linux-2.6-tip.orig/kernel/time/Makefile
+++ linux-2.6-tip/kernel/time/Makefile
@@ -1,4 +1,5 @@
-obj-y += timekeeping.o ntp.o clocksource.o jiffies.o timer_list.o timecompare.o timeconv.o
+obj-y += timekeeping.o ntp.o clocksource.o jiffies.o timer_list.o timecompare.o
+obj-y += timeconv.o posix-clock.o
 
 obj-$(CONFIG_GENERIC_CLOCKEVENTS_BUILD)		+= clockevents.o
 obj-$(CONFIG_GENERIC_CLOCKEVENTS)		+= tick-common.o
Index: linux-2.6-tip/kernel/time/posix-clock.c
===================================================================
--- /dev/null
+++ linux-2.6-tip/kernel/time/posix-clock.c
@@ -0,0 +1,441 @@
+/*
+ * posix-clock.c - support for dynamic clock devices
+ *
+ * Copyright (C) 2010 OMICRON electronics GmbH
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+#include <linux/device.h>
+#include <linux/file.h>
+#include <linux/mutex.h>
+#include <linux/posix-clock.h>
+#include <linux/slab.h>
+#include <linux/syscalls.h>
+#include <linux/uaccess.h>
+
+static void delete_clock(struct kref *kref);
+
+/*
+ * Returns NULL if the posix_clock instance attached to 'fp' is old and stale.
+ */
+static struct posix_clock *get_posix_clock(struct file *fp)
+{
+	struct posix_clock *clk = fp->private_data;
+
+	mutex_lock(&clk->mutex);
+
+	if (!clk->zombie)
+		return clk;
+
+	mutex_unlock(&clk->mutex);
+
+	return NULL;
+}
+
+static void put_posix_clock(struct posix_clock *clk)
+{
+	mutex_unlock(&clk->mutex);
+}
+
+static ssize_t posix_clock_read(struct file *fp, char __user *buf,
+				size_t count, loff_t *ppos)
+{
+	struct posix_clock *clk = get_posix_clock(fp);
+	int err = -EINVAL;
+
+	if (!clk)
+		return -ENODEV;
+
+	if (clk->ops.read)
+		err = clk->ops.read(clk, fp->f_flags, buf, count);
+
+	put_posix_clock(clk);
+
+	return err;
+}
+
+static unsigned int posix_clock_poll(struct file *fp, poll_table *wait)
+{
+	struct posix_clock *clk = get_posix_clock(fp);
+	int result = 0;
+
+	if (!clk)
+		return -ENODEV;
+
+	if (clk->ops.poll)
+		result = clk->ops.poll(clk, fp, wait);
+
+	put_posix_clock(clk);
+
+	return result;
+}
+
+static int posix_clock_fasync(int fd, struct file *fp, int on)
+{
+	struct posix_clock *clk = get_posix_clock(fp);
+	int err = 0;
+
+	if (!clk)
+		return -ENODEV;
+
+	if (clk->ops.fasync)
+		err = clk->ops.fasync(clk, fd, fp, on);
+
+	put_posix_clock(clk);
+
+	return err;
+}
+
+static int posix_clock_mmap(struct file *fp, struct vm_area_struct *vma)
+{
+	struct posix_clock *clk = get_posix_clock(fp);
+	int err = -ENODEV;
+
+	if (!clk)
+		return -ENODEV;
+
+	if (clk->ops.mmap)
+		err = clk->ops.mmap(clk, vma);
+
+	put_posix_clock(clk);
+
+	return err;
+}
+
+static long posix_clock_ioctl(struct file *fp,
+			      unsigned int cmd, unsigned long arg)
+{
+	struct posix_clock *clk = get_posix_clock(fp);
+	int err = -ENOTTY;
+
+	if (!clk)
+		return -ENODEV;
+
+	if (clk->ops.ioctl)
+		err = clk->ops.ioctl(clk, cmd, arg);
+
+	put_posix_clock(clk);
+
+	return err;
+}
+
+#ifdef CONFIG_COMPAT
+static long posix_clock_compat_ioctl(struct file *fp,
+				     unsigned int cmd, unsigned long arg)
+{
+	struct posix_clock *clk = get_posix_clock(fp);
+	int err = -ENOTTY;
+
+	if (!clk)
+		return -ENODEV;
+
+	if (clk->ops.ioctl)
+		err = clk->ops.ioctl(clk, cmd, arg);
+
+	put_posix_clock(clk);
+
+	return err;
+}
+#endif
+
+static int posix_clock_open(struct inode *inode, struct file *fp)
+{
+	int err;
+	struct posix_clock *clk =
+		container_of(inode->i_cdev, struct posix_clock, cdev);
+
+	mutex_lock(&clk->mutex);
+
+	if (clk->zombie) {
+		err = -ENODEV;
+		goto out;
+	}
+	if (clk->ops.open)
+		err = clk->ops.open(clk, fp->f_mode);
+	else
+		err = 0;
+
+	if (!err) {
+		kref_get(&clk->kref);
+		fp->private_data = clk;
+	}
+out:
+	mutex_unlock(&clk->mutex);
+	return err;
+}
+
+static int posix_clock_release(struct inode *inode, struct file *fp)
+{
+	struct posix_clock *clk = fp->private_data;
+	int err = 0;
+
+	if (clk->ops.release)
+		err = clk->ops.release(clk);
+
+	kref_put(&clk->kref, delete_clock);
+
+	fp->private_data = NULL;
+
+	return err;
+}
+
+static const struct file_operations posix_clock_file_operations = {
+	.owner		= THIS_MODULE,
+	.llseek		= no_llseek,
+	.read		= posix_clock_read,
+	.poll		= posix_clock_poll,
+	.unlocked_ioctl	= posix_clock_ioctl,
+	.open		= posix_clock_open,
+	.release	= posix_clock_release,
+	.fasync		= posix_clock_fasync,
+	.mmap		= posix_clock_mmap,
+#ifdef CONFIG_COMPAT
+	.compat_ioctl	= posix_clock_compat_ioctl,
+#endif
+};
+
+int posix_clock_register(struct posix_clock *clk, dev_t devid)
+{
+	int err;
+
+	kref_init(&clk->kref);
+	mutex_init(&clk->mutex);
+
+	cdev_init(&clk->cdev, &posix_clock_file_operations);
+	clk->cdev.owner = clk->ops.owner;
+	err = cdev_add(&clk->cdev, devid, 1);
+	if (err)
+		goto no_cdev;
+
+	return err;
+no_cdev:
+	mutex_destroy(&clk->mutex);
+	return err;
+}
+EXPORT_SYMBOL_GPL(posix_clock_register);
+
+static void delete_clock(struct kref *kref)
+{
+	struct posix_clock *clk = container_of(kref, struct posix_clock, kref);
+	mutex_destroy(&clk->mutex);
+	if (clk->release)
+		clk->release(clk);
+}
+
+void posix_clock_unregister(struct posix_clock *clk)
+{
+	cdev_del(&clk->cdev);
+
+	mutex_lock(&clk->mutex);
+	clk->zombie = true;
+	mutex_unlock(&clk->mutex);
+
+	kref_put(&clk->kref, delete_clock);
+}
+EXPORT_SYMBOL_GPL(posix_clock_unregister);
+
+struct posix_clock_desc {
+	struct file *fp;
+	struct posix_clock *clk;
+};
+
+static int get_clock_desc(const clockid_t id, struct posix_clock_desc *cd)
+{
+	struct file *fp = fget(CLOCKID_TO_FD(id));
+	int err = -EINVAL;
+
+	if (!fp)
+		return err;
+
+	if (fp->f_op->open != posix_clock_open || !fp->private_data)
+		goto out;
+
+	cd->fp = fp;
+	cd->clk = get_posix_clock(fp);
+
+	err = cd->clk ? 0 : -ENODEV;
+out:
+	if (err)
+		fput(fp);
+	return err;
+}
+
+static void put_clock_desc(struct posix_clock_desc *cd)
+{
+	put_posix_clock(cd->clk);
+	fput(cd->fp);
+}
+
+static int pc_clock_adjtime(clockid_t id, struct timex *tx)
+{
+	struct posix_clock_desc cd;
+	int err;
+
+	err = get_clock_desc(id, &cd);
+	if (err)
+		return err;
+
+	if (cd.clk->ops.clock_adjtime)
+		err = cd.clk->ops.clock_adjtime(cd.clk, tx);
+	else
+		err = -EOPNOTSUPP;
+
+	put_clock_desc(&cd);
+
+	return err;
+}
+
+static int pc_clock_gettime(clockid_t id, struct timespec *ts)
+{
+	struct posix_clock_desc cd;
+	int err;
+
+	err = get_clock_desc(id, &cd);
+	if (err)
+		return err;
+
+	if (cd.clk->ops.clock_gettime)
+		err = cd.clk->ops.clock_gettime(cd.clk, ts);
+	else
+		err = -EOPNOTSUPP;
+
+	put_clock_desc(&cd);
+
+	return err;
+}
+
+static int pc_clock_getres(clockid_t id, struct timespec *ts)
+{
+	struct posix_clock_desc cd;
+	int err;
+
+	err = get_clock_desc(id, &cd);
+	if (err)
+		return err;
+
+	if (cd.clk->ops.clock_getres)
+		err = cd.clk->ops.clock_getres(cd.clk, ts);
+	else
+		err = -EOPNOTSUPP;
+
+	put_clock_desc(&cd);
+
+	return err;
+}
+
+static int pc_clock_settime(clockid_t id, const struct timespec *ts)
+{
+	struct posix_clock_desc cd;
+	int err;
+
+	err = get_clock_desc(id, &cd);
+	if (err)
+		return err;
+
+	if (cd.clk->ops.clock_settime)
+		err = cd.clk->ops.clock_settime(cd.clk, ts);
+	else
+		err = -EOPNOTSUPP;
+
+	put_clock_desc(&cd);
+
+	return err;
+}
+
+static int pc_timer_create(struct k_itimer *kit)
+{
+	clockid_t id = kit->it_clock;
+	struct posix_clock_desc cd;
+	int err;
+
+	err = get_clock_desc(id, &cd);
+	if (err)
+		return err;
+
+	if (cd.clk->ops.timer_create)
+		err = cd.clk->ops.timer_create(cd.clk, kit);
+	else
+		err = -EOPNOTSUPP;
+
+	put_clock_desc(&cd);
+
+	return err;
+}
+
+static int pc_timer_delete(struct k_itimer *kit)
+{
+	clockid_t id = kit->it_clock;
+	struct posix_clock_desc cd;
+	int err;
+
+	err = get_clock_desc(id, &cd);
+	if (err)
+		return err;
+
+	if (cd.clk->ops.timer_delete)
+		err = cd.clk->ops.timer_delete(cd.clk, kit);
+	else
+		err = -EOPNOTSUPP;
+
+	put_clock_desc(&cd);
+
+	return err;
+}
+
+static void pc_timer_gettime(struct k_itimer *kit, struct itimerspec *ts)
+{
+	clockid_t id = kit->it_clock;
+	struct posix_clock_desc cd;
+
+	if (get_clock_desc(id, &cd))
+		return;
+
+	if (cd.clk->ops.timer_gettime)
+		cd.clk->ops.timer_gettime(cd.clk, kit, ts);
+
+	put_clock_desc(&cd);
+}
+
+static int pc_timer_settime(struct k_itimer *kit, int flags,
+			    struct itimerspec *ts, struct itimerspec *old)
+{
+	clockid_t id = kit->it_clock;
+	struct posix_clock_desc cd;
+	int err;
+
+	err = get_clock_desc(id, &cd);
+	if (err)
+		return err;
+
+	if (cd.clk->ops.timer_settime)
+		err = cd.clk->ops.timer_settime(cd.clk, kit, flags, ts, old);
+	else
+		err = -EOPNOTSUPP;
+
+	put_clock_desc(&cd);
+
+	return err;
+}
+
+struct k_clock clock_posix_dynamic = {
+	.clock_getres	= pc_clock_getres,
+	.clock_set	= pc_clock_settime,
+	.clock_get	= pc_clock_gettime,
+	.clock_adj	= pc_clock_adjtime,
+	.timer_create	= pc_timer_create,
+	.timer_set	= pc_timer_settime,
+	.timer_del	= pc_timer_delete,
+	.timer_get	= pc_timer_gettime,
+};



^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 01/28] time: Correct the *settime* parameters
  2011-02-01 13:50 ` [patch 01/28] time: Correct the *settime* parameters Thomas Gleixner
@ 2011-02-01 14:22   ` Thomas Gleixner
  2011-02-01 20:32   ` john stultz
  2011-02-02 21:54   ` [tip:timers/core] " tip-bot for Richard Cochran
  2 siblings, 0 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 14:22 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, 1 Feb 2011, Thomas Gleixner wrote:

That's missing a From: Richard. Fixed in my local queue.

Thanks,

	tglx

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 01/28] time: Correct the *settime* parameters
  2011-02-01 13:50 ` [patch 01/28] time: Correct the *settime* parameters Thomas Gleixner
  2011-02-01 14:22   ` Thomas Gleixner
@ 2011-02-01 20:32   ` john stultz
  2011-02-02 21:54   ` [tip:timers/core] " tip-bot for Richard Cochran
  2 siblings, 0 replies; 111+ messages in thread
From: john stultz @ 2011-02-01 20:32 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, 2011-02-01 at 13:50 +0000, Thomas Gleixner wrote:
> plain text document attachment
> (time-correct-the-settime-parameters.patch)
> Both settimeofday() and clock_settime() promise with a 'const'
> attribute not to alter the arguments passed in. This patch adds the
> missing 'const' attribute into the various kernel functions
> implementing these calls.
> 
> Signed-off-by: Richard Cochran <richard.cochran@omicron.at>
> Cc: John Stultz <john.stultz@linaro.org>
> LKML-Reference: <681d9f8ba43fea01bae9f6a17a4674194a90353b.1296124770.git.richard.cochran@omicron.at>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>


Acked-by: John Stultz <johnstul@us.ibm.com>



^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 02/28] posix-timers: Define nanosleep not supported error separate
  2011-02-01 13:51 ` [patch 02/28] posix-timers: Define nanosleep not supported error separate Thomas Gleixner
@ 2011-02-01 20:32   ` John Stultz
  2011-02-02 21:55   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: John Stultz @ 2011-02-01 20:32 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, 2011-02-01 at 13:51 +0000, Thomas Gleixner wrote:
> plain text document attachment
> (posix-clocks-splitout-nanosleep-notsup-error.patch)
> Define the conditional nanosleep not supported error value outside of
> do_posix_clock_nonanosleep(). Preparatory patch for further cleanups. 
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: John Stultz <john.stultz@linaro.org>
> Cc: Richard Cochran <richard.cochran@omicron.at>

Acked-by: John Stultz <johnstul@us.ibm.com>



^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 03/28] posix-timers: Cleanup struct initializers
  2011-02-01 13:51 ` [patch 03/28] posix-timers: Cleanup struct initializers Thomas Gleixner
@ 2011-02-01 20:33   ` john stultz
  2011-02-02 21:55   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: john stultz @ 2011-02-01 20:33 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, 2011-02-01 at 13:51 +0000, Thomas Gleixner wrote:
> plain text document attachment
> (posix-timers-cleanup-struct-initializers-codingstyle.patch)
> Cosmetic. No functional change
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: John Stultz <john.stultz@linaro.org>
> Cc: Richard Cochran <richard.cochran@omicron.at>

Acked-by: John Stultz <johnstul@us.ibm.com>

> ---
>  drivers/char/mmtimer.c    |   14 +++++++-------
>  kernel/posix-cpu-timers.c |   24 ++++++++++++------------
>  kernel/posix-timers.c     |   38 +++++++++++++++++++-------------------
>  3 files changed, 38 insertions(+), 38 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
> @@ -765,13 +765,13 @@ static int sgi_timer_set(struct k_itimer
> 
>  static struct k_clock sgi_clock = {
>  	.res = 0,
> -	.clock_set = sgi_clock_set,
> -	.clock_get = sgi_clock_get,
> -	.timer_create = sgi_timer_create,
> -	.nsleep = do_posix_clock_nonanosleep,
> -	.timer_set = sgi_timer_set,
> -	.timer_del = sgi_timer_del,
> -	.timer_get = sgi_timer_get
> +	.clock_set	= sgi_clock_set,
> +	.clock_get	= sgi_clock_get,
> +	.timer_create	= sgi_timer_create,
> +	.nsleep		= do_posix_clock_nonanosleep,
> +	.timer_set	= sgi_timer_set,
> +	.timer_del	= sgi_timer_del,
> +	.timer_get	= sgi_timer_get
>  };
> 
>  /**
> Index: linux-2.6-tip/kernel/posix-cpu-timers.c
> ===================================================================
> --- linux-2.6-tip.orig/kernel/posix-cpu-timers.c
> +++ linux-2.6-tip/kernel/posix-cpu-timers.c
> @@ -1607,20 +1607,20 @@ static long thread_cpu_nsleep_restart(st
>  static __init int init_posix_cpu_timers(void)
>  {
>  	struct k_clock process = {
> -		.clock_getres = process_cpu_clock_getres,
> -		.clock_get = process_cpu_clock_get,
> -		.clock_set = do_posix_clock_nosettime,
> -		.timer_create = process_cpu_timer_create,
> -		.nsleep = process_cpu_nsleep,
> -		.nsleep_restart = process_cpu_nsleep_restart,
> +		.clock_getres	= process_cpu_clock_getres,
> +		.clock_get	= process_cpu_clock_get,
> +		.clock_set	= do_posix_clock_nosettime,
> +		.timer_create	= process_cpu_timer_create,
> +		.nsleep		= process_cpu_nsleep,
> +		.nsleep_restart	= process_cpu_nsleep_restart,
>  	};
>  	struct k_clock thread = {
> -		.clock_getres = thread_cpu_clock_getres,
> -		.clock_get = thread_cpu_clock_get,
> -		.clock_set = do_posix_clock_nosettime,
> -		.timer_create = thread_cpu_timer_create,
> -		.nsleep = thread_cpu_nsleep,
> -		.nsleep_restart = thread_cpu_nsleep_restart,
> +		.clock_getres	= thread_cpu_clock_getres,
> +		.clock_get	= thread_cpu_clock_get,
> +		.clock_set	= do_posix_clock_nosettime,
> +		.timer_create	= thread_cpu_timer_create,
> +		.nsleep		= thread_cpu_nsleep,
> +		.nsleep_restart	= thread_cpu_nsleep_restart,
>  	};
>  	struct timespec ts;
> 
> 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
> @@ -281,33 +281,33 @@ static int posix_get_coarse_res(const cl
>  static __init int init_posix_timers(void)
>  {
>  	struct k_clock clock_realtime = {
> -		.clock_getres = hrtimer_get_res,
> +		.clock_getres	= hrtimer_get_res,
>  	};
>  	struct k_clock clock_monotonic = {
> -		.clock_getres = hrtimer_get_res,
> -		.clock_get = posix_ktime_get_ts,
> -		.clock_set = do_posix_clock_nosettime,
> +		.clock_getres	= hrtimer_get_res,
> +		.clock_get	= posix_ktime_get_ts,
> +		.clock_set	= do_posix_clock_nosettime,
>  	};
>  	struct k_clock clock_monotonic_raw = {
> -		.clock_getres = hrtimer_get_res,
> -		.clock_get = posix_get_monotonic_raw,
> -		.clock_set = do_posix_clock_nosettime,
> -		.timer_create = no_timer_create,
> -		.nsleep = no_nsleep,
> +		.clock_getres	= hrtimer_get_res,
> +		.clock_get	= posix_get_monotonic_raw,
> +		.clock_set	= do_posix_clock_nosettime,
> +		.timer_create	= no_timer_create,
> +		.nsleep		= no_nsleep,
>  	};
>  	struct k_clock clock_realtime_coarse = {
> -		.clock_getres = posix_get_coarse_res,
> -		.clock_get = posix_get_realtime_coarse,
> -		.clock_set = do_posix_clock_nosettime,
> -		.timer_create = no_timer_create,
> -		.nsleep = no_nsleep,
> +		.clock_getres	= posix_get_coarse_res,
> +		.clock_get	= posix_get_realtime_coarse,
> +		.clock_set	= do_posix_clock_nosettime,
> +		.timer_create	= no_timer_create,
> +		.nsleep		= no_nsleep,
>  	};
>  	struct k_clock clock_monotonic_coarse = {
> -		.clock_getres = posix_get_coarse_res,
> -		.clock_get = posix_get_monotonic_coarse,
> -		.clock_set = do_posix_clock_nosettime,
> -		.timer_create = no_timer_create,
> -		.nsleep = no_nsleep,
> +		.clock_getres	= posix_get_coarse_res,
> +		.clock_get	= posix_get_monotonic_coarse,
> +		.clock_set	= do_posix_clock_nosettime,
> +		.timer_create	= no_timer_create,
> +		.nsleep		= no_nsleep,
>  	};
> 
>  	register_posix_clock(CLOCK_REALTIME, &clock_realtime);
> 
> 



^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 04/28] posix-timers: Introduce clock_posix_cpu
  2011-02-01 13:51 ` [patch 04/28] posix-timers: Introduce clock_posix_cpu Thomas Gleixner
@ 2011-02-01 20:34   ` john stultz
  2011-02-02 21:56   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: john stultz @ 2011-02-01 20:34 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, 2011-02-01 at 13:51 +0000, Thomas Gleixner wrote:
> plain text document attachment
> (posix-timers-introduce-local-posix-cpu-clockid.patch)
> The CLOCK_DISPATCH() macro is a horrible magic. We call common
> functions if a function pointer is not set. That's just backwards.
> 
> To support dynamic file decriptor based clocks we need to cleanup that
> dispatch logic.
> 
> Create a k_clock struct clock_posix_cpu which has all the
> posix-cpu-timer functions filled in. After the cleanup the functions
> can be made static.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: John Stultz <john.stultz@linaro.org>
> Cc: Richard Cochran <richard.cochran@omicron.at>

Acked-by: John Stultz <johnstul@us.ibm.com>

> ---
>  include/linux/posix-timers.h |    2 ++
>  kernel/posix-cpu-timers.c    |   12 ++++++++++++
>  2 files changed, 14 insertions(+)
> 
> Index: linux-2.6-tip/include/linux/posix-timers.h
> ===================================================================
> --- linux-2.6-tip.orig/include/linux/posix-timers.h
> +++ linux-2.6-tip/include/linux/posix-timers.h
> @@ -85,6 +85,8 @@ struct k_clock {
>  			   struct itimerspec * cur_setting);
>  };
> 
> +extern struct k_clock clock_posix_cpu;
> +
>  void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock);
> 
>  /* error handlers for timer_create, nanosleep and settime */
> Index: linux-2.6-tip/kernel/posix-cpu-timers.c
> ===================================================================
> --- linux-2.6-tip.orig/kernel/posix-cpu-timers.c
> +++ linux-2.6-tip/kernel/posix-cpu-timers.c
> @@ -1604,6 +1604,18 @@ static long thread_cpu_nsleep_restart(st
>  	return -EINVAL;
>  }
> 
> +struct k_clock clock_posix_cpu = {
> +	.clock_getres	= posix_cpu_clock_getres,
> +	.clock_set	= posix_cpu_clock_set,
> +	.clock_get	= posix_cpu_clock_get,
> +	.timer_create	= posix_cpu_timer_create,
> +	.nsleep		= posix_cpu_nsleep,
> +	.nsleep_restart	= posix_cpu_nsleep_restart,
> +	.timer_set	= posix_cpu_timer_set,
> +	.timer_del	= posix_cpu_timer_del,
> +	.timer_get	= posix_cpu_timer_get,
> +};
> +
>  static __init int init_posix_cpu_timers(void)
>  {
>  	struct k_clock process = {
> 
> 



^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 05/28] posix-timers: Introduce clockid_to_kclock()
  2011-02-01 13:51 ` [patch 05/28] posix-timers: Introduce clockid_to_kclock() Thomas Gleixner
@ 2011-02-01 20:37   ` john stultz
  2011-02-02 21:56   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: john stultz @ 2011-02-01 20:37 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, 2011-02-01 at 13:51 +0000, Thomas Gleixner wrote:
> plain text document attachment
> (posix-timers-introduce-clockid-to-kclock.patch)
> New function to find the kclock for a given clockid.
> 
> Returns a pointer to clock_posix_cpu if clockid < 0. If clockid >=
> MAXCLOCK or if the clock_getres pointer is not set it returns
> -EINVAL. For valid clocks it returns a pointer to the matching
> posix_clock.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: John Stultz <john.stultz@linaro.org>
> Cc: Richard Cochran <richard.cochran@omicron.at>

Acked-by: John Stultz <johnstul@us.ibm.com>



^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 06/28] posix-timers: Convert clock_nanosleep to clockid_to_kclock()
  2011-02-01 13:51 ` [patch 06/28] posix-timers: Convert clock_nanosleep to clockid_to_kclock() Thomas Gleixner
@ 2011-02-01 20:41   ` john stultz
  2011-02-02 21:57   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: john stultz @ 2011-02-01 20:41 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, 2011-02-01 at 13:51 +0000, Thomas Gleixner wrote:
> plain text document attachment (posix-timers-convert-nanosleep.patch)
> Use the new kclock decoding function in clock_nanosleep and cleanup all
> kclocks which use the default functions.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: John Stultz <john.stultz@linaro.org>
> Cc: Richard Cochran <richard.cochran@omicron.at>

Acked-by: John Stultz <johnstul@us.ibm.com>



^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 07/28] posix-timers: Convert clock_nanosleep_restart to clockid_to_kclock()
  2011-02-01 13:51 ` [patch 07/28] posix-timers: Convert clock_nanosleep_restart " Thomas Gleixner
@ 2011-02-01 20:42   ` John Stultz
  2011-02-01 20:46     ` Thomas Gleixner
  2011-02-02 21:57   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  1 sibling, 1 reply; 111+ messages in thread
From: John Stultz @ 2011-02-01 20:42 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, 2011-02-01 at 13:51 +0000, Thomas Gleixner wrote:
> plain text document attachment
> (posix-timers-convert-nanosleep-restart.patch)
> Use the new kclock decoding function in clock_nanosleep_restart. No
> need to check kclock here as the restart block always contains a valid
> clockid. If not, we are in serious trouble anyway.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: John Stultz <john.stultz@linaro.org>
> Cc: Richard Cochran <richard.cochran@omicron.at>

One nit.

> -long
> -clock_nanosleep_restart(struct restart_block *restart_block)
> +long clock_nanosleep_restart(struct restart_block *restart_block)
>  {
>  	clockid_t which_clock = restart_block->arg0;
> +	struct k_clock *kc = clockid_to_kclock(which_clock);
> 
> -	return CLOCK_DISPATCH(which_clock, nsleep_restart,
> -			      (restart_block));
> +	return kc->nsleep_restart(restart_block);
>  }


Should you be checking if kc is null before dereferencing? Or am I being
overly paranoid?

thanks
-john



^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 07/28] posix-timers: Convert clock_nanosleep_restart to clockid_to_kclock()
  2011-02-01 20:42   ` John Stultz
@ 2011-02-01 20:46     ` Thomas Gleixner
  2011-02-01 21:08       ` Thomas Gleixner
  0 siblings, 1 reply; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 20:46 UTC (permalink / raw)
  To: John Stultz; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, 1 Feb 2011, John Stultz wrote:

> On Tue, 2011-02-01 at 13:51 +0000, Thomas Gleixner wrote:
> > plain text document attachment
> > (posix-timers-convert-nanosleep-restart.patch)
> > Use the new kclock decoding function in clock_nanosleep_restart. No
> > need to check kclock here as the restart block always contains a valid
> > clockid. If not, we are in serious trouble anyway.
> > 
> > Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> > Cc: John Stultz <john.stultz@linaro.org>
> > Cc: Richard Cochran <richard.cochran@omicron.at>
> 
> One nit.
> 
> > -long
> > -clock_nanosleep_restart(struct restart_block *restart_block)
> > +long clock_nanosleep_restart(struct restart_block *restart_block)
> >  {
> >  	clockid_t which_clock = restart_block->arg0;
> > +	struct k_clock *kc = clockid_to_kclock(which_clock);
> > 
> > -	return CLOCK_DISPATCH(which_clock, nsleep_restart,
> > -			      (restart_block));
> > +	return kc->nsleep_restart(restart_block);
> >  }
> 
> 
> Should you be checking if kc is null before dereferencing? Or am I being
> overly paranoid?

See changelog. If we get a corrupted restart_block then checking kc is
probably the least of our worries.

Thanks,

	tglx

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 07/28] posix-timers: Convert clock_nanosleep_restart to clockid_to_kclock()
  2011-02-01 20:46     ` Thomas Gleixner
@ 2011-02-01 21:08       ` Thomas Gleixner
  0 siblings, 0 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 21:08 UTC (permalink / raw)
  To: John Stultz; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, 1 Feb 2011, Thomas Gleixner wrote:
> On Tue, 1 Feb 2011, John Stultz wrote:
> 
> > On Tue, 2011-02-01 at 13:51 +0000, Thomas Gleixner wrote:
> > > plain text document attachment
> > > (posix-timers-convert-nanosleep-restart.patch)
> > > Use the new kclock decoding function in clock_nanosleep_restart. No
> > > need to check kclock here as the restart block always contains a valid
> > > clockid. If not, we are in serious trouble anyway.
> > > 
> > > Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> > > Cc: John Stultz <john.stultz@linaro.org>
> > > Cc: Richard Cochran <richard.cochran@omicron.at>
> > 
> > One nit.
> > 
> > > -long
> > > -clock_nanosleep_restart(struct restart_block *restart_block)
> > > +long clock_nanosleep_restart(struct restart_block *restart_block)
> > >  {
> > >  	clockid_t which_clock = restart_block->arg0;
> > > +	struct k_clock *kc = clockid_to_kclock(which_clock);
> > > 
> > > -	return CLOCK_DISPATCH(which_clock, nsleep_restart,
> > > -			      (restart_block));
> > > +	return kc->nsleep_restart(restart_block);
> > >  }
> > 
> > 
> > Should you be checking if kc is null before dereferencing? Or am I being
> > overly paranoid?
> 
> See changelog. If we get a corrupted restart_block then checking kc is
> probably the least of our worries.

Ok, I'll add the checks for nsleep_restart and timer_get/set/del, but
I make them a WARN_ON_ONCE() as this is serious data corruption in the
kernel.

Thanks,

	tglx

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 08/28] posix-timers: Cleanup restart_block usage
  2011-02-01 13:51 ` [patch 08/28] posix-timers: Cleanup restart_block usage Thomas Gleixner
@ 2011-02-01 21:11   ` john stultz
  2011-02-01 21:14     ` Thomas Gleixner
  2011-02-02 21:57   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  1 sibling, 1 reply; 111+ messages in thread
From: john stultz @ 2011-02-01 21:11 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, 2011-02-01 at 13:51 +0000, Thomas Gleixner wrote:
> plain text document attachment
> (posix-timers-cleanup-restart-block.patch)
> posix timers still use the legacy arg0-arg3 members of
> restart_block. Use restart_block.nanosleep instead
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: John Stultz <john.stultz@linaro.org>
> Cc: Richard Cochran <richard.cochran@omicron.at>
[snip]
>  long posix_cpu_nsleep_restart(struct restart_block *restart_block)
>  {
> -	clockid_t which_clock = restart_block->arg0;
> -	struct timespec __user *rmtp;
> +	clockid_t which_clock = restart_block->nanosleep.index;
>  	struct timespec t;
>  	struct itimerspec it;
>  	int error;
> 
> -	rmtp = (struct timespec __user *) restart_block->arg1;
> -	t.tv_sec = restart_block->arg2;
> -	t.tv_nsec = restart_block->arg3;
> +	t = ns_to_timespec(restart_block->nanosleep.expires);
> 
> -	restart_block->fn = do_no_restart_syscall;
>  	error = do_cpu_nanosleep(which_clock, TIMER_ABSTIME, &t, &it);
> 
>  	if (error == -ERESTART_RESTARTBLOCK) {
> +		struct timespec __user *rmtp = restart_block->nanosleep.rmtp;
>  		/*
> -	 	 * Report back to the user the time still remaining.
> -	 	 */
> -		if (rmtp != NULL && copy_to_user(rmtp, &it.it_value, sizeof *rmtp))
> +		 * Report back to the user the time still remaining.
> +		 */
> +		if (rmtp && copy_to_user(rmtp, &it.it_value, sizeof *rmtp))
>  			return -EFAULT;
> 
> -		restart_block->fn = posix_cpu_nsleep_restart;
> -		restart_block->arg0 = which_clock;
> -		restart_block->arg1 = (unsigned long) rmtp;
> -		restart_block->arg2 = t.tv_sec;
> -		restart_block->arg3 = t.tv_nsec;
> +		restart_block->nanosleep.expires = timespec_to_ns(&t);

The conversion back and forth from nanoseconds to timespec seems a
little extraneous, but short of reworking all of the do_nanosleep calls
to take a ktime I don't see a clean solution (since hrtimer also uses
the restart_block).

Acked-by: John Stultz <johnstul@us.ibm.com>

thanks
-john


^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 09/28] thread_info: Remove legacy arg0-3 from restart_block
  2011-02-01 13:51 ` [patch 09/28] thread_info: Remove legacy arg0-3 from restart_block Thomas Gleixner
@ 2011-02-01 21:11   ` john stultz
  2011-02-02 21:58   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: john stultz @ 2011-02-01 21:11 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, 2011-02-01 at 13:51 +0000, Thomas Gleixner wrote:
> plain text document attachment (thread-info-remove-arg0-3.patch)
> posix timers were the last users of the legacy arg0-3 members of
> restart_block. Remove the cruft.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: John Stultz <john.stultz@linaro.org>
> Cc: Richard Cochran <richard.cochran@omicron.at>
> ---

Acked-by: John Stultz <johnstul@us.ibm.com>




^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 10/28] posix-cpu-timers: Remove the stub nanosleep functions
  2011-02-01 13:51 ` [patch 10/28] posix-cpu-timers: Remove the stub nanosleep functions Thomas Gleixner
@ 2011-02-01 21:14   ` John Stultz
  2011-02-02 21:58   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: John Stultz @ 2011-02-01 21:14 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, 2011-02-01 at 13:51 +0000, Thomas Gleixner wrote:
> plain text document attachment
> (posix-cpu-timers-use-default-nsleep-notsup.patch)
> CLOCK_THREAD_CPUTIME_ID implements stub functions for nanosleep and
> nanosleep_restart, which return -EINVAL. That return value is
> wrong. The correct return value is -ENOTSUP.
> 
> Remove the stubs and let the new dispatch code return the correct
> error code.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: John Stultz <john.stultz@linaro.org>
> Cc: Richard Cochran <richard.cochran@omicron.at>
> ---

Acked-by: John Stultz <johnstul@us.ibm.com>



^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 08/28] posix-timers: Cleanup restart_block usage
  2011-02-01 21:11   ` john stultz
@ 2011-02-01 21:14     ` Thomas Gleixner
  0 siblings, 0 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 21:14 UTC (permalink / raw)
  To: john stultz; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, 1 Feb 2011, john stultz wrote:
> On Tue, 2011-02-01 at 13:51 +0000, Thomas Gleixner wrote:
> > -		restart_block->fn = posix_cpu_nsleep_restart;
> > -		restart_block->arg0 = which_clock;
> > -		restart_block->arg1 = (unsigned long) rmtp;
> > -		restart_block->arg2 = t.tv_sec;
> > -		restart_block->arg3 = t.tv_nsec;
> > +		restart_block->nanosleep.expires = timespec_to_ns(&t);
> 
> The conversion back and forth from nanoseconds to timespec seems a
> little extraneous, but short of reworking all of the do_nanosleep calls
> to take a ktime I don't see a clean solution (since hrtimer also uses
> the restart_block).

We could simply add a timespec to the nanosleep struct in the
restart_block. Could be a union with expires.
 
Thanks,

	tglx

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 11/28] posix-timers: Convert clock_settime to clockid_to_kclock()
  2011-02-01 13:51 ` [patch 11/28] posix-timers: Convert clock_settime to clockid_to_kclock() Thomas Gleixner
@ 2011-02-01 21:15   ` john stultz
  2011-02-02 21:59   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: john stultz @ 2011-02-01 21:15 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, 2011-02-01 at 13:51 +0000, Thomas Gleixner wrote:
> plain text document attachment (posix-timers-convert-clock-set.patch)
> Use the new kclock decoding function in clock_settime and cleanup all
> kclocks which use the default functions. Rename the misnomed
> common_clock_set() to posix_clock_realtime_set().
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: John Stultz <john.stultz@linaro.org>
> Cc: Richard Cochran <richard.cochran@omicron.at>

Acked-by: John Stultz <johnstul@us.ibm.com>



^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 12/28] posix-timers: Convert clock_gettime() to clockid_to_kclock()
  2011-02-01 13:51 ` [patch 12/28] posix-timers: Convert clock_gettime() " Thomas Gleixner
@ 2011-02-01 21:16   ` john stultz
  2011-02-02  9:09   ` Richard Cochran
  2011-02-02 21:59   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  2 siblings, 0 replies; 111+ messages in thread
From: john stultz @ 2011-02-01 21:16 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

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 <tglx@linutronix.de>
> Cc: John Stultz <john.stultz@linaro.org>
> Cc: Richard Cochran <richard.cochran@omicron.at>

Acked-by: John Stultz <johnstul@us.ibm.com>



^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 13/28] posix-timers: Convert clock_getres() to clockid_to_kclock()
  2011-02-01 13:51 ` [patch 13/28] posix-timers: Convert clock_getres() " Thomas Gleixner
@ 2011-02-01 21:17   ` john stultz
  2011-02-02 22:00   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: john stultz @ 2011-02-01 21:17 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

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 <tglx@linutronix.de>
> Cc: John Stultz <john.stultz@linaro.org>
> Cc: Richard Cochran <richard.cochran@omicron.at>

Acked-by: John Stultz <johnstul@us.ibm.com>



^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 14/28] posix-timers: Remove useless res field from k_clock
  2011-02-01 13:51 ` [patch 14/28] posix-timers: Remove useless res field from k_clock Thomas Gleixner
@ 2011-02-01 21:18   ` john stultz
  2011-02-02 22:00   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: john stultz @ 2011-02-01 21:18 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, 2011-02-01 at 13:51 +0000, Thomas Gleixner wrote:
> plain text document attachment
> (posix-timers-remove-unused-res-field.patch)
> The res member of kclock is only used by mmtimer.c, but even there it
> contains redundant information. Remove the field and fixup mmtimer.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: John Stultz <john.stultz@linaro.org>
> Cc: Richard Cochran <richard.cochran@omicron.at>

Acked-by: John Stultz <johnstul@us.ibm.com>



^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 15/28] posix-timers: Convert timer_create() to clockid_to_kclock()
  2011-02-01 13:51 ` [patch 15/28] posix-timers: Convert timer_create() to clockid_to_kclock() Thomas Gleixner
@ 2011-02-01 21:20   ` john stultz
  2011-02-02 22:00   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: john stultz @ 2011-02-01 21:20 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

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 <tglx@linutronix.de>
> Cc: John Stultz <john.stultz@linaro.org>
> Cc: Richard Cochran <richard.cochran@omicron.at>

Acked-by: John Stultz <johnstul@us.ibm.com>



^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 16/28] posix-timers: Convert timer_settime() to clockid_to_kclock()
  2011-02-01 13:52 ` [patch 16/28] posix-timers: Convert timer_settime() " Thomas Gleixner
@ 2011-02-01 21:22   ` John Stultz
  2011-02-02 22:01   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: John Stultz @ 2011-02-01 21:22 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, 2011-02-01 at 13:52 +0000, Thomas Gleixner wrote:
> plain text document attachment (posix-timers-convert-timer-set.patch)
> Set the common function for CLOCK_MONOTONIC and CLOCK_REALTIME kclocks
> and use the new decoding function. No need to check for the return
> value of it. If we have data corruption in the timer, we explode
> somewhere else anyway. Also all kclocks which implement timer_create()
> need to provide timer_settime() as well.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: John Stultz <john.stultz@linaro.org>
> Cc: Richard Cochran <richard.cochran@omicron.at>
[snip]
> @@ -818,8 +821,8 @@ retry:
>  	if (!timr)
>  		return -EINVAL;
> 
> -	error = CLOCK_DISPATCH(timr->it_clock, timer_set,
> -			       (timr, flags, &new_spec, rtn));
> +	kc = clockid_to_kclock(timr->it_clock);
> +	error = kc->timer_set(timr, flags, &new_spec, rtn);

Again, me being paraniod, would probably want a null check on kc here.
Also, as you suggested on irc, a WARN_ON_ONCE(), since it means kernel
data has been munged.


thanks
-john


^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 17/28] posix-timers: Convert timer_gettime() to clockid_to_kclock()
  2011-02-01 13:52 ` [patch 17/28] posix-timers: Convert timer_gettime() " Thomas Gleixner
@ 2011-02-01 21:23   ` john stultz
  2011-02-02 22:01   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: john stultz @ 2011-02-01 21:23 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, 2011-02-01 at 13:52 +0000, Thomas Gleixner wrote:
> plain text document attachment (posix-timers-convert-timer-get.patch)
> Set the common function for CLOCK_MONOTONIC and CLOCK_REALTIME kclocks
> and use the new decoding function. No need to check for the return
> value of it. If we have data corruption in the timer, we explode
> somewhere else anyway. Also all kclocks which implement timer_create()
> need to provide timer_gettime() as well.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: John Stultz <john.stultz@linaro.org>
> Cc: Richard Cochran <richard.cochran@omicron.at>
[snip]
> -	CLOCK_DISPATCH(timr->it_clock, timer_get, (timr, &cur_setting));
> +	kc = clockid_to_kclock(timr->it_clock);
> +	kc->timer_get(timr, &cur_setting);

Null check again.

thanks
-john


^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 18/28] posix-timers: Convert timer_delete() to clockid_to_kclock()
  2011-02-01 13:52 ` [patch 18/28] posix-timers: Convert timer_delete() " Thomas Gleixner
@ 2011-02-01 21:24   ` john stultz
  2011-02-02  8:29   ` Richard Cochran
  2011-02-02 22:02   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  2 siblings, 0 replies; 111+ messages in thread
From: john stultz @ 2011-02-01 21:24 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, 2011-02-01 at 13:52 +0000, Thomas Gleixner wrote:
> plain text document attachment (posix-timers-convert-timer-del.patch)
> Set the common function for CLOCK_MONOTONIC and CLOCK_REALTIME kclocks
> and use the new decoding function. No need to check for the return
> value of it. If we have data corruption in the timer, we explode
> somewhere else anyway. Also all kclocks which implement timer_create()
> need to provide timer_delete() as well.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: John Stultz <john.stultz@linaro.org>
> Cc: Richard Cochran <richard.cochran@omicron.at>
> ---
[snip]
> @@ -852,7 +854,9 @@ static inline int common_timer_del(struc
> 
>  static inline int timer_delete_hook(struct k_itimer *timer)
>  {
> -	return CLOCK_DISPATCH(timer->it_clock, timer_del, (timer));
> +	struct k_clock *kc = clockid_to_kclock(timer->it_clock);
> +
> +	return kc->timer_del(timer);
>  }

Again, kc == NULL check. 

thanks
-john


^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 19/28] posix-timers: Remove CLOCK_DISPATCH leftovers
  2011-02-01 13:52 ` [patch 19/28] posix-timers: Remove CLOCK_DISPATCH leftovers Thomas Gleixner
@ 2011-02-01 21:25   ` john stultz
  2011-02-02 22:02   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: john stultz @ 2011-02-01 21:25 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, 2011-02-01 at 13:52 +0000, Thomas Gleixner wrote:
> plain text document attachment
> (posix-timers-remove-clock-dispatch-leftovers.patch)
> All users gone. Remove the cruft.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: John Stultz <john.stultz@linaro.org>
> Cc: Richard Cochran <richard.cochran@omicron.at>
> ---
>  kernel/posix-timers.c |   22 ----------------------
>  1 file changed, 22 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
> @@ -167,28 +167,6 @@ static inline void unlock_timer(struct k
>  	spin_unlock_irqrestore(&timr->it_lock, flags);
>  }
> 
> -/*
> - * Call the k_clock hook function if non-null, or the default function.
> - */
> -#define CLOCK_DISPATCH(clock, call, arglist) \
> - 	((clock) < 0 ? posix_cpu_##call arglist : \
> - 	 (posix_clocks[clock].call != NULL \
> - 	  ? (*posix_clocks[clock].call) arglist : common_##call arglist))
> -

Big thanks to Richard and Thomas for killing this bit of ugliness!

Acked-by: John Stultz <johnstul@us.ibm.com>



^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 20/28] posix-timers: Make posix-cpu-timers functions static
  2011-02-01 13:52 ` [patch 20/28] posix-timers: Make posix-cpu-timers functions static Thomas Gleixner
@ 2011-02-01 21:28   ` John Stultz
  2011-02-01 21:33     ` Thomas Gleixner
  2011-02-02 22:03   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  1 sibling, 1 reply; 111+ messages in thread
From: John Stultz @ 2011-02-01 21:28 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, 2011-02-01 at 13:52 +0000, Thomas Gleixner wrote:
> plain text document attachment
> (posix-timer-make-posix-cpu-timer-functions-static.patch)
> All functions are accessed via clock_posix_cpu now. So make them static.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: John Stultz <john.stultz@linaro.org>
> Cc: Richard Cochran <richard.cochran@omicron.at>

This patch seems to have more then just making functions static in it.

> @@ -1481,68 +1483,67 @@ static int do_cpu_nanosleep(const clocki
>  	return error;
>  }
> 
> -int posix_cpu_nsleep(const clockid_t which_clock, int flags,
> -		     struct timespec *rqtp, struct timespec __user *rmtp)
> +static long posix_cpu_nsleep_restart(struct restart_block *restart_block)
>  {
> -	struct restart_block *restart_block =
> -		&current_thread_info()->restart_block;
> +	clockid_t which_clock = restart_block->nanosleep.index;
> +	struct timespec t;
>  	struct itimerspec it;
>  	int error;
> 
> -	/*
> -	 * Diagnose required errors first.
> -	 */
> -	if (CPUCLOCK_PERTHREAD(which_clock) &&
> -	    (CPUCLOCK_PID(which_clock) == 0 ||
> -	     CPUCLOCK_PID(which_clock) == current->pid))
> -		return -EINVAL;
> +	t = ns_to_timespec(restart_block->nanosleep.expires);
> 
> -	error = do_cpu_nanosleep(which_clock, flags, rqtp, &it);
> +	error = do_cpu_nanosleep(which_clock, TIMER_ABSTIME, &t, &it);
> 
>  	if (error == -ERESTART_RESTARTBLOCK) {
> -
> -		if (flags & TIMER_ABSTIME)
> -			return -ERESTARTNOHAND;
> +		struct timespec __user *rmtp = restart_block->nanosleep.rmtp;
>  		/*
>  		 * Report back to the user the time still remaining.
>  		 */
>  		if (rmtp && copy_to_user(rmtp, &it.it_value, sizeof *rmtp))
>  			return -EFAULT;
> 
> -		restart_block->fn = posix_cpu_nsleep_restart;
> -		restart_block->nanosleep.index = which_clock;
> -		restart_block->nanosleep.rmtp = rmtp;
> -		restart_block->nanosleep.expires = timespec_to_ns(rqtp);
> +		restart_block->nanosleep.expires = timespec_to_ns(&t);
>  	}
>  	return error;
> +
>  }
> 
> -long posix_cpu_nsleep_restart(struct restart_block *restart_block)
> +static int posix_cpu_nsleep(const clockid_t which_clock, int flags,
> +			    struct timespec *rqtp, struct timespec __user *rmtp)
>  {
> -	clockid_t which_clock = restart_block->nanosleep.index;
> -	struct timespec t;
> +	struct restart_block *restart_block =
> +		&current_thread_info()->restart_block;
>  	struct itimerspec it;
>  	int error;
> 
> -	t = ns_to_timespec(restart_block->nanosleep.expires);
> +	/*
> +	 * Diagnose required errors first.
> +	 */
> +	if (CPUCLOCK_PERTHREAD(which_clock) &&
> +	    (CPUCLOCK_PID(which_clock) == 0 ||
> +	     CPUCLOCK_PID(which_clock) == current->pid))
> +		return -EINVAL;
> 
> -	error = do_cpu_nanosleep(which_clock, TIMER_ABSTIME, &t, &it);
> +	error = do_cpu_nanosleep(which_clock, flags, rqtp, &it);
> 
>  	if (error == -ERESTART_RESTARTBLOCK) {
> -		struct timespec __user *rmtp = restart_block->nanosleep.rmtp;
> +
> +		if (flags & TIMER_ABSTIME)
> +			return -ERESTARTNOHAND;
>  		/*
>  		 * Report back to the user the time still remaining.
>  		 */
>  		if (rmtp && copy_to_user(rmtp, &it.it_value, sizeof *rmtp))
>  			return -EFAULT;
> 
> -		restart_block->nanosleep.expires = timespec_to_ns(&t);
> +		restart_block->fn = posix_cpu_nsleep_restart;
> +		restart_block->nanosleep.index = which_clock;
> +		restart_block->nanosleep.rmtp = rmtp;
> +		restart_block->nanosleep.expires = timespec_to_ns(rqtp);
>  	}
>  	return error;
> -
>  }

Maybe split that out?

thanks
-john



^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 21/28] posix-timer: Update comment
  2011-02-01 13:52 ` [patch 21/28] posix-timer: Update comment Thomas Gleixner
@ 2011-02-01 21:28   ` john stultz
  2011-02-02 22:03   ` [tip:timers/core] " tip-bot for Richard Cochran
  1 sibling, 0 replies; 111+ messages in thread
From: john stultz @ 2011-02-01 21:28 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, 2011-02-01 at 13:52 +0000, Thomas Gleixner wrote:
> plain text document attachment (posix-timer-update-comment.patch)
> From: Richard Cochran <richardcochran@gmail.com>
> 
> Pick the cleanup to the comment in posix-timers.c from Richards all in
> one conversion patch.
> 
> Originally-from: Richard Cochran <richardcochran@gmail.com>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: John Stultz <john.stultz@linaro.org>

Acked-by: John Stultz <johnstul@us.ibm.com>



^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 23/28] ntp: Add ADJ_SETOFFSET mode bit
  2011-02-01 13:52 ` [patch 23/28] ntp: Add ADJ_SETOFFSET mode bit Thomas Gleixner
@ 2011-02-01 21:30   ` john stultz
  0 siblings, 0 replies; 111+ messages in thread
From: john stultz @ 2011-02-01 21:30 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, 2011-02-01 at 13:52 +0000, Thomas Gleixner wrote:
> plain text document attachment (ntp-add-adj_setoffset-mode-bit.patch)
> From: Richard Cochran <richardcochran@gmail.com>
> 
> This patch adds a new mode bit into the timex structure. When set, the bit
> instructs the kernel to add the given time value to the current time.
> 
> Signed-off-by: Richard Cochran <richard.cochran@omicron.at>
> Cc: John Stultz <john.stultz@linaro.org>
> LKML-Reference: <2f7ed6bce83c23e4b7e4530794f0aa175df31a39.1296124770.git.richard.cochran@omicron.at>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

Acked-by: John Stultz <johnstul@us.ibm.com>



^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 24/28] posix-clocks: Splitout compat timex accessors
  2011-02-01 13:52 ` [patch 24/28] posix-clocks: Splitout compat timex accessors Thomas Gleixner
@ 2011-02-01 21:31   ` john stultz
  2011-02-02 22:04   ` [tip:timers/core] time: " tip-bot for Richard Cochran
  1 sibling, 0 replies; 111+ messages in thread
From: john stultz @ 2011-02-01 21:31 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, 2011-02-01 at 13:52 +0000, Thomas Gleixner wrote:
> plain text document attachment
> (posix-clocks-splitout-compat-timex-accessors.patch)
> From: Richard Cochran <richardcochran@gmail.com>
> 
> Split out the compat timex accessors into separate
> functions. Preparatory patch for a new syscall.
> 
> [ tglx: Split that patch from Richards "posix clocks: Introduce a
>   	syscall for clock tuning.". Keeps the changes strictly
>   	separate ]
> 
> Originally-from: Richard Cochran <richardcochran@gmail.com>
> Cc: John Stultz <john.stultz@linaro.org>
> LKML-Reference: <2d5e2f3e6f388aa1848d40406646aab2e26a906f.1296124770.git.richard.cochran@omicron.at>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

Acked-by: John Stultz <johnstul@us.ibm.com>



^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 20/28] posix-timers: Make posix-cpu-timers functions static
  2011-02-01 21:28   ` John Stultz
@ 2011-02-01 21:33     ` Thomas Gleixner
  0 siblings, 0 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 21:33 UTC (permalink / raw)
  To: John Stultz; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, 1 Feb 2011, John Stultz wrote:

> On Tue, 2011-02-01 at 13:52 +0000, Thomas Gleixner wrote:
> > plain text document attachment
> > (posix-timer-make-posix-cpu-timer-functions-static.patch)
> > All functions are accessed via clock_posix_cpu now. So make them static.
> > 
> > Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> > Cc: John Stultz <john.stultz@linaro.org>
> > Cc: Richard Cochran <richard.cochran@omicron.at>
> 
> This patch seems to have more then just making functions static in it.
> 
> > @@ -1481,68 +1483,67 @@ static int do_cpu_nanosleep(const clocki
> >  	return error;
> >  }
> > 
> > -int posix_cpu_nsleep(const clockid_t which_clock, int flags,
> > -		     struct timespec *rqtp, struct timespec __user *rmtp)
> > +static long posix_cpu_nsleep_restart(struct restart_block *restart_block)
> >  {
> > -	struct restart_block *restart_block =
> > -		&current_thread_info()->restart_block;
> > +	clockid_t which_clock = restart_block->nanosleep.index;
> > +	struct timespec t;
> >  	struct itimerspec it;
> >  	int error;
> > 
> > -	/*
> > -	 * Diagnose required errors first.
> > -	 */
> > -	if (CPUCLOCK_PERTHREAD(which_clock) &&
> > -	    (CPUCLOCK_PID(which_clock) == 0 ||
> > -	     CPUCLOCK_PID(which_clock) == current->pid))
> > -		return -EINVAL;
> > +	t = ns_to_timespec(restart_block->nanosleep.expires);
> > 
> > -	error = do_cpu_nanosleep(which_clock, flags, rqtp, &it);
> > +	error = do_cpu_nanosleep(which_clock, TIMER_ABSTIME, &t, &it);
> > 
> >  	if (error == -ERESTART_RESTARTBLOCK) {
> > -
> > -		if (flags & TIMER_ABSTIME)
> > -			return -ERESTARTNOHAND;
> > +		struct timespec __user *rmtp = restart_block->nanosleep.rmtp;
> >  		/*
> >  		 * Report back to the user the time still remaining.
> >  		 */
> >  		if (rmtp && copy_to_user(rmtp, &it.it_value, sizeof *rmtp))
> >  			return -EFAULT;
> > 
> > -		restart_block->fn = posix_cpu_nsleep_restart;
> > -		restart_block->nanosleep.index = which_clock;
> > -		restart_block->nanosleep.rmtp = rmtp;
> > -		restart_block->nanosleep.expires = timespec_to_ns(rqtp);
> > +		restart_block->nanosleep.expires = timespec_to_ns(&t);
> >  	}
> >  	return error;
> > +
> >  }
> > 
> > -long posix_cpu_nsleep_restart(struct restart_block *restart_block)
> > +static int posix_cpu_nsleep(const clockid_t which_clock, int flags,
> > +			    struct timespec *rqtp, struct timespec __user *rmtp)
> >  {
> > -	clockid_t which_clock = restart_block->nanosleep.index;
> > -	struct timespec t;
> > +	struct restart_block *restart_block =
> > +		&current_thread_info()->restart_block;
> >  	struct itimerspec it;
> >  	int error;
> > 
> > -	t = ns_to_timespec(restart_block->nanosleep.expires);
> > +	/*
> > +	 * Diagnose required errors first.
> > +	 */
> > +	if (CPUCLOCK_PERTHREAD(which_clock) &&
> > +	    (CPUCLOCK_PID(which_clock) == 0 ||
> > +	     CPUCLOCK_PID(which_clock) == current->pid))
> > +		return -EINVAL;
> > 
> > -	error = do_cpu_nanosleep(which_clock, TIMER_ABSTIME, &t, &it);
> > +	error = do_cpu_nanosleep(which_clock, flags, rqtp, &it);
> > 
> >  	if (error == -ERESTART_RESTARTBLOCK) {
> > -		struct timespec __user *rmtp = restart_block->nanosleep.rmtp;
> > +
> > +		if (flags & TIMER_ABSTIME)
> > +			return -ERESTARTNOHAND;
> >  		/*
> >  		 * Report back to the user the time still remaining.
> >  		 */
> >  		if (rmtp && copy_to_user(rmtp, &it.it_value, sizeof *rmtp))
> >  			return -EFAULT;
> > 
> > -		restart_block->nanosleep.expires = timespec_to_ns(&t);
> > +		restart_block->fn = posix_cpu_nsleep_restart;
> > +		restart_block->nanosleep.index = which_clock;
> > +		restart_block->nanosleep.rmtp = rmtp;
> > +		restart_block->nanosleep.expires = timespec_to_ns(rqtp);
> >  	}
> >  	return error;
> > -
> >  }
> 
> Maybe split that out?

I just moved the restart function above nanosleep to avoid the forward
declaration, but patch deciced to make it more complex. I'll stick
with the forward declaration.

Thanks,

	tglx

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 25/28] posix clocks: Introduce a syscall for clock tuning.
  2011-02-01 13:52 ` [patch 25/28] posix clocks: Introduce a syscall for clock tuning Thomas Gleixner
@ 2011-02-01 21:35   ` john stultz
  2011-02-02 22:04   ` [tip:timers/core] posix-timers: " tip-bot for Richard Cochran
  1 sibling, 0 replies; 111+ messages in thread
From: john stultz @ 2011-02-01 21:35 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra, Alan Cox,
	Arnd Bergmann, Christoph Lameter, David Miller, Krzysztof Halasa,
	Rodolfo Giometti, Benjamin Herrenschmidt, Mike Frysinger,
	Paul Mackerras, Russell King

On Tue, 2011-02-01 at 13:52 +0000, Thomas Gleixner wrote:
> plain text document attachment
> (posix-clocks-introduce-a-syscall-for-clock-tuning.patch)
> From: Richard Cochran <richardcochran@gmail.com>
> 
> A new syscall is introduced that allows tuning of a POSIX clock. The
> new call, clock_adjtime, takes two parameters, the clock ID and a
> pointer to a struct timex. Any ADJTIMEX(2) operation may be requested
> via this system call, but various POSIX clocks may or may not support
> tuning.
> 
> [ tglx: Adapted to the posix-timer cleanup series. Avoid copy_to_user
>   	in the error case ]

Acked-by: John Stultz <johnstul@us.ibm.com>




^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 26/28] posix_clocks: Add clock_adjtime for x86
  2011-02-01 13:52 ` [patch 26/28] posix_clocks: Add clock_adjtime for x86 Thomas Gleixner
@ 2011-02-01 21:36   ` john stultz
  2011-02-02 22:05   ` [tip:timers/core] x86: " tip-bot for Richard Cochran
  1 sibling, 0 replies; 111+ messages in thread
From: john stultz @ 2011-02-01 21:36 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, 2011-02-01 at 13:52 +0000, Thomas Gleixner wrote:
> plain text document attachment
> (posix_clocks-add-clock_adjtime-for-x86.patch)
> This patch adds the clock_adjtime system call to the x86 architecture.
> 
> Signed-off-by: Richard Cochran <richard.cochran@omicron.at>
> Cc: John Stultz <john.stultz@linaro.org>
> LKML-Reference: <4501cddb99d555624baade4609030ca458dfa3a0.1296124770.git.richard.cochran@omicron.at>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

Acked-by: John Stultz <johnstul@us.ibm.com>



^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 27/28] posix-timers: Add support for fd based clocks
  2011-02-01 13:52 ` [patch 27/28] posix-timers: Add support for fd based clocks Thomas Gleixner
@ 2011-02-01 21:38   ` john stultz
  2011-02-02  9:19   ` Richard Cochran
  2011-02-02 22:05   ` [tip:timers/core] " tip-bot for Richard Cochran
  2 siblings, 0 replies; 111+ messages in thread
From: john stultz @ 2011-02-01 21:38 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, 2011-02-01 at 13:52 +0000, Thomas Gleixner wrote:
> plain text document attachment
> (posix-timers-add-support-for-fd-based-clocks.patch)
> From: Richard Cochran <richard.cochran@omicron.at>
> 
> Extend the negative clockids which are currently used by posix cpu
> timers to encode the PID with a file descriptor based type which
> encodes the fd in the upper bits.
> 
> Originally-from: Richard Cochran <richard.cochran@omicron.at>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: John Stultz <john.stultz@linaro.org>

Acked-by: John Stultz <johnstul@us.ibm.com>



^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 28/28] posix clocks: Introduce dynamic clocks
  2011-02-01 13:52 ` [patch 28/28] posix clocks: Introduce dynamic clocks Thomas Gleixner
@ 2011-02-01 21:49   ` john stultz
  2011-02-01 22:04     ` Thomas Gleixner
  2011-02-02  7:50     ` Richard Cochran
  2011-02-02 22:06   ` [tip:timers/core] posix clocks: Introduce dynamic clocks tip-bot for Richard Cochran
  2011-03-03 14:50   ` [patch 28/28] " torbenh
  2 siblings, 2 replies; 111+ messages in thread
From: john stultz @ 2011-02-01 21:49 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, 2011-02-01 at 13:52 +0000, Thomas Gleixner wrote:
> plain text document attachment
> (posix-clocks-introduce-dynamic-clocks.patch)
> From: Richard Cochran <richardcochran@gmail.com>
> 
> This patch adds support for adding and removing posix clocks. The
> clock lifetime cycle is patterned after usb devices. Each clock is
> represented by a standard character device. In addition, the driver
> may optionally implement custom character device operations.
> 
> The posix clock and timer system calls listed below now work with
> dynamic posix clocks, as well as the traditional static clocks.
> The following system calls are affected:
> 
>    - clock_adjtime (brand new syscall)
>    - clock_gettime
>    - clock_getres
>    - clock_settime
>    - timer_create
>    - timer_delete
>    - timer_gettime
>    - timer_settime
> 
> [ tglx: Adapted to the posix-timer cleanup. Moved clock_posix_dynamic
>   	to posix-clock.c and made all referenced functions static ]

I sort of worry about the naming collision with the term posix-clock, as
this is just one type of posix clock (I suspect most folks think of a
posix clock as the clockid passed to the existing posix api).

Could we maybe use posix-dynclock or posix-fdclock or something? I know
its already been changed from clkdev, so sorry for being finicky here
and not catching this earlier.

thanks
-john



^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 28/28] posix clocks: Introduce dynamic clocks
  2011-02-01 21:49   ` john stultz
@ 2011-02-01 22:04     ` Thomas Gleixner
  2011-02-02  7:50     ` Richard Cochran
  1 sibling, 0 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-01 22:04 UTC (permalink / raw)
  To: john stultz; +Cc: LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, 1 Feb 2011, john stultz wrote:

> On Tue, 2011-02-01 at 13:52 +0000, Thomas Gleixner wrote:
> > plain text document attachment
> > (posix-clocks-introduce-dynamic-clocks.patch)
> > From: Richard Cochran <richardcochran@gmail.com>
> > 
> > This patch adds support for adding and removing posix clocks. The
> > clock lifetime cycle is patterned after usb devices. Each clock is
> > represented by a standard character device. In addition, the driver
> > may optionally implement custom character device operations.
> > 
> > The posix clock and timer system calls listed below now work with
> > dynamic posix clocks, as well as the traditional static clocks.
> > The following system calls are affected:
> > 
> >    - clock_adjtime (brand new syscall)
> >    - clock_gettime
> >    - clock_getres
> >    - clock_settime
> >    - timer_create
> >    - timer_delete
> >    - timer_gettime
> >    - timer_settime
> > 
> > [ tglx: Adapted to the posix-timer cleanup. Moved clock_posix_dynamic
> >   	to posix-clock.c and made all referenced functions static ]
> 
> I sort of worry about the naming collision with the term posix-clock, as
> this is just one type of posix clock (I suspect most folks think of a
> posix clock as the clockid passed to the existing posix api).

Well that's kernel internal and not the posix-timer syscalls.
 
> Could we maybe use posix-dynclock or posix-fdclock or something? I know
> its already been changed from clkdev, so sorry for being finicky here
> and not catching this earlier.

I'm fine with the name as is and it's well documented.

Thanks,

	tglx

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 28/28] posix clocks: Introduce dynamic clocks
  2011-02-01 21:49   ` john stultz
  2011-02-01 22:04     ` Thomas Gleixner
@ 2011-02-02  7:50     ` Richard Cochran
  2011-02-02 10:37       ` Thomas Gleixner
  1 sibling, 1 reply; 111+ messages in thread
From: Richard Cochran @ 2011-02-02  7:50 UTC (permalink / raw)
  To: john stultz
  Cc: Thomas Gleixner, LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, Feb 01, 2011 at 01:49:47PM -0800, john stultz wrote:
> I sort of worry about the naming collision with the term posix-clock, as
> this is just one type of posix clock (I suspect most folks think of a
> posix clock as the clockid passed to the existing posix api).
> 
> Could we maybe use posix-dynclock or posix-fdclock or something? I know
> its already been changed from clkdev, so sorry for being finicky here
> and not catching this earlier.

A rose by any other name...

I agree that naming (even internal APIs) is important and have no
objection to changing the name. I did spend a bit of time considering
various alternatives, and now I'm out of ideas.

So, please do change the name if you have a better one.

Thanks,
Richard

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 00/28]  Rework of the PTP support series core code
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
                   ` (27 preceding siblings ...)
  2011-02-01 13:52 ` [patch 28/28] posix clocks: Introduce dynamic clocks Thomas Gleixner
@ 2011-02-02  8:17 ` Richard Cochran
  2011-02-02 13:53 ` Richard Cochran
                   ` (2 subsequent siblings)
  31 siblings, 0 replies; 111+ messages in thread
From: Richard Cochran @ 2011-02-02  8:17 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: LKML, John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, Feb 01, 2011 at 01:50:55PM -0000, Thomas Gleixner wrote:
> The reason for this rework is that I got scared when reviewing:
>  [PATCH V10 09/15] posix clocks: cleanup the CLOCK_DISPTACH macro

I am glad that you are taking the blame/credit ;)

> The patch is really too large and the risk of wreckage too high. So
> instead of whipping Richard through another round I reworked the
> series in the following way:
> 
> 1) Split the CLOCK_DISPATCH cleanup in fine grained steps.

I didn't test or compile each of the little steps, but I have looked
the differences between where I landed with my V10 and this series.

>    That allowed further cleanups and got rid of 200 lines of code and
>    made a lot of functions static.

Yes, it looks even nicer than before, but I'll comment on a few small
points.

> Richard, can you please run that through your testing ? The PTP
> drivers apply on top of that.

I'll run my PTP tests today.

Thanks,
Richard

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 18/28] posix-timers: Convert timer_delete() to clockid_to_kclock()
  2011-02-01 13:52 ` [patch 18/28] posix-timers: Convert timer_delete() " Thomas Gleixner
  2011-02-01 21:24   ` john stultz
@ 2011-02-02  8:29   ` Richard Cochran
  2011-02-02  9:53     ` Thomas Gleixner
  2011-02-02 22:02   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  2 siblings, 1 reply; 111+ messages in thread
From: Richard Cochran @ 2011-02-02  8:29 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: LKML, John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, Feb 01, 2011 at 01:52:07PM -0000, Thomas Gleixner wrote:
> 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
> @@ -254,6 +254,7 @@ static __init int init_posix_timers(void
>  		.timer_create	= common_timer_create,
>  		.timer_set	= common_timer_set,
>  		.timer_get	= common_timer_get,
> +		.timer_del	= common_timer_del,
>  	};
>  	struct k_clock clock_monotonic = {
>  		.clock_getres	= hrtimer_get_res,
> @@ -263,6 +264,7 @@ static __init int init_posix_timers(void
>  		.timer_create	= common_timer_create,
>  		.timer_set	= common_timer_set,
>  		.timer_get	= common_timer_get,
> +		.timer_del	= common_timer_del,
>  	};
>  	struct k_clock clock_monotonic_raw = {
>  		.clock_getres	= hrtimer_get_res,

The definition of common_timer_del() should not be "inline" since the
address of the function is in these tables. The declaration is not
inline, and gcc 4.2.4 gives a warning.

(But strangly, newer versions do not).

Thanks,
Richard

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 12/28] posix-timers: Convert clock_gettime() to clockid_to_kclock()
  2011-02-01 13:51 ` [patch 12/28] posix-timers: Convert clock_gettime() " Thomas Gleixner
  2011-02-01 21:16   ` john stultz
@ 2011-02-02  9:09   ` Richard Cochran
  2011-02-02  9:55     ` Thomas Gleixner
  2011-02-02 21:59   ` [tip:timers/core] " tip-bot for Thomas Gleixner
  2 siblings, 1 reply; 111+ messages in thread
From: Richard Cochran @ 2011-02-02  9:09 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: LKML, John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

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

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 27/28] posix-timers: Add support for fd based clocks
  2011-02-01 13:52 ` [patch 27/28] posix-timers: Add support for fd based clocks Thomas Gleixner
  2011-02-01 21:38   ` john stultz
@ 2011-02-02  9:19   ` Richard Cochran
  2011-02-02 10:33     ` Thomas Gleixner
  2011-02-02 22:05   ` [tip:timers/core] " tip-bot for Richard Cochran
  2 siblings, 1 reply; 111+ messages in thread
From: Richard Cochran @ 2011-02-02  9:19 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: LKML, John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, Feb 01, 2011 at 01:52:32PM -0000, Thomas Gleixner wrote:
> --- linux-2.6-tip.orig/include/linux/posix-timers.h
> +++ linux-2.6-tip/include/linux/posix-timers.h

> +/*
> + * Bit fields within a clockid:
> + *
> + * The most significant 29 bits hold either a pid or a file descriptor.
> + *
> + * Bit 2 indicates whether a cpu clock refers to a thread or a process.
> + *
> + * Bits 1 and 0 give the type: PROF=0, VIRT=1, SCHED=2, or FD=3.
> + *
> + * A clockid is invalid if bits 2, 1, and 0 all set.

I should have said, "if bits 2, 1, and 0 *are* all set."

Thanks,
Richard

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 18/28] posix-timers: Convert timer_delete() to clockid_to_kclock()
  2011-02-02  8:29   ` Richard Cochran
@ 2011-02-02  9:53     ` Thomas Gleixner
  0 siblings, 0 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-02  9:53 UTC (permalink / raw)
  To: Richard Cochran
  Cc: LKML, John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Wed, 2 Feb 2011, Richard Cochran wrote:

> On Tue, Feb 01, 2011 at 01:52:07PM -0000, Thomas Gleixner wrote:
> > 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
> > @@ -254,6 +254,7 @@ static __init int init_posix_timers(void
> >  		.timer_create	= common_timer_create,
> >  		.timer_set	= common_timer_set,
> >  		.timer_get	= common_timer_get,
> > +		.timer_del	= common_timer_del,
> >  	};
> >  	struct k_clock clock_monotonic = {
> >  		.clock_getres	= hrtimer_get_res,
> > @@ -263,6 +264,7 @@ static __init int init_posix_timers(void
> >  		.timer_create	= common_timer_create,
> >  		.timer_set	= common_timer_set,
> >  		.timer_get	= common_timer_get,
> > +		.timer_del	= common_timer_del,
> >  	};
> >  	struct k_clock clock_monotonic_raw = {
> >  		.clock_getres	= hrtimer_get_res,
> 
> The definition of common_timer_del() should not be "inline" since the
> address of the function is in these tables. The declaration is not
> inline, and gcc 4.2.4 gives a warning.
> 
> (But strangly, newer versions do not).

Will fix. Thanks.

     tglx

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 12/28] posix-timers: Convert clock_gettime() to clockid_to_kclock()
  2011-02-02  9:09   ` Richard Cochran
@ 2011-02-02  9:55     ` Thomas Gleixner
  0 siblings, 0 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-02  9:55 UTC (permalink / raw)
  To: Richard Cochran
  Cc: LKML, John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

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

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 27/28] posix-timers: Add support for fd based clocks
  2011-02-02  9:19   ` Richard Cochran
@ 2011-02-02 10:33     ` Thomas Gleixner
  0 siblings, 0 replies; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-02 10:33 UTC (permalink / raw)
  To: Richard Cochran
  Cc: LKML, John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Wed, 2 Feb 2011, Richard Cochran wrote:

> On Tue, Feb 01, 2011 at 01:52:32PM -0000, Thomas Gleixner wrote:
> > --- linux-2.6-tip.orig/include/linux/posix-timers.h
> > +++ linux-2.6-tip/include/linux/posix-timers.h
> 
> > +/*
> > + * Bit fields within a clockid:
> > + *
> > + * The most significant 29 bits hold either a pid or a file descriptor.
> > + *
> > + * Bit 2 indicates whether a cpu clock refers to a thread or a process.
> > + *
> > + * Bits 1 and 0 give the type: PROF=0, VIRT=1, SCHED=2, or FD=3.
> > + *
> > + * A clockid is invalid if bits 2, 1, and 0 all set.
> 
> I should have said, "if bits 2, 1, and 0 *are* all set."

Fixed.

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 28/28] posix clocks: Introduce dynamic clocks
  2011-02-02  7:50     ` Richard Cochran
@ 2011-02-02 10:37       ` Thomas Gleixner
  2011-02-02 11:25         ` Thomas Gleixner
  0 siblings, 1 reply; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-02 10:37 UTC (permalink / raw)
  To: Richard Cochran
  Cc: john stultz, LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Wed, 2 Feb 2011, Richard Cochran wrote:

> On Tue, Feb 01, 2011 at 01:49:47PM -0800, john stultz wrote:
> > I sort of worry about the naming collision with the term posix-clock, as
> > this is just one type of posix clock (I suspect most folks think of a
> > posix clock as the clockid passed to the existing posix api).
> > 
> > Could we maybe use posix-dynclock or posix-fdclock or something? I know
> > its already been changed from clkdev, so sorry for being finicky here
> > and not catching this earlier.
> 
> A rose by any other name...
> 
> I agree that naming (even internal APIs) is important and have no
> objection to changing the name. I did spend a bit of time considering
> various alternatives, and now I'm out of ideas.
> 
> So, please do change the name if you have a better one.

We have a clear distinction between posix-timers and those new
posix-clocks. Adding some artificial "fd", "dyn" or whatever will not
make it much better.

Thanks,

	tglx

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 28/28] posix clocks: Introduce dynamic clocks
  2011-02-02 10:37       ` Thomas Gleixner
@ 2011-02-02 11:25         ` Thomas Gleixner
  2011-02-02 22:06           ` [tip:timers/core] posix-timers: Cleanup namespace tip-bot for Thomas Gleixner
  0 siblings, 1 reply; 111+ messages in thread
From: Thomas Gleixner @ 2011-02-02 11:25 UTC (permalink / raw)
  To: Richard Cochran
  Cc: john stultz, LKML, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Wed, 2 Feb 2011, Thomas Gleixner wrote:

> On Wed, 2 Feb 2011, Richard Cochran wrote:
> 
> > On Tue, Feb 01, 2011 at 01:49:47PM -0800, john stultz wrote:
> > > I sort of worry about the naming collision with the term posix-clock, as
> > > this is just one type of posix clock (I suspect most folks think of a
> > > posix clock as the clockid passed to the existing posix api).
> > > 
> > > Could we maybe use posix-dynclock or posix-fdclock or something? I know
> > > its already been changed from clkdev, so sorry for being finicky here
> > > and not catching this earlier.
> > 
> > A rose by any other name...
> > 
> > I agree that naming (even internal APIs) is important and have no
> > objection to changing the name. I did spend a bit of time considering
> > various alternatives, and now I'm out of ideas.
> > 
> > So, please do change the name if you have a better one.
> 
> We have a clear distinction between posix-timers and those new
> posix-clocks. Adding some artificial "fd", "dyn" or whatever will not
> make it much better.

There is only one function visible outside of posix-timers.c which
uses the posix_clock namespace: register_posix_clock(). That needs to
be cleaned up. See patch below.

Thanks,

	tglx

Subject: posix-timers: Cleanup namespace
From: Thomas Gleixner <tglx@linutronix.de>
Date: Wed, 02 Feb 2011 12:10:09 +0100

Rename register_posix_clock() to posix_timers_register_clock(). That's
what the function really does. As a side effect this cleans up the
posix_clock namespace for the upcoming dynamic posix_clock
infrastructure.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 drivers/char/mmtimer.c       |    2 +-
 include/linux/posix-timers.h |    2 +-
 kernel/posix-cpu-timers.c    |    4 ++--
 kernel/posix-timers.c        |   15 ++++++++-------
 4 files changed, 12 insertions(+), 11 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
@@ -840,7 +840,7 @@ static int __init mmtimer_init(void)
 	}
 
 	sgi_clock_period = NSEC_PER_SEC / sn_rtc_cycles_per_second;
-	register_posix_clock(CLOCK_SGI_CYCLE, &sgi_clock);
+	posix_timers_register_clock(CLOCK_SGI_CYCLE, &sgi_clock);
 
 	printk(KERN_INFO "%s: v%s, %ld MHz\n", MMTIMER_DESC, MMTIMER_VERSION,
 	       sn_rtc_cycles_per_second/(unsigned long)1E6);
Index: linux-2.6-tip/include/linux/posix-timers.h
===================================================================
--- linux-2.6-tip.orig/include/linux/posix-timers.h
+++ linux-2.6-tip/include/linux/posix-timers.h
@@ -101,7 +101,7 @@ struct k_clock {
 
 extern struct k_clock clock_posix_cpu;
 
-void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock);
+void posix_timers_register_clock(const clockid_t clock_id, struct k_clock *new_clock);
 
 /* function to call to trigger timer event */
 int posix_timer_event(struct k_itimer *timr, int si_private);
Index: linux-2.6-tip/kernel/posix-cpu-timers.c
===================================================================
--- linux-2.6-tip.orig/kernel/posix-cpu-timers.c
+++ linux-2.6-tip/kernel/posix-cpu-timers.c
@@ -1618,8 +1618,8 @@ static __init int init_posix_cpu_timers(
 	};
 	struct timespec ts;
 
-	register_posix_clock(CLOCK_PROCESS_CPUTIME_ID, &process);
-	register_posix_clock(CLOCK_THREAD_CPUTIME_ID, &thread);
+	posix_timers_register_clock(CLOCK_PROCESS_CPUTIME_ID, &process);
+	posix_timers_register_clock(CLOCK_THREAD_CPUTIME_ID, &thread);
 
 	cputime_to_timespec(cputime_one_jiffy, &ts);
 	onecputick = ts.tv_nsec;
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
@@ -253,11 +253,11 @@ static __init int init_posix_timers(void
 		.clock_get	= posix_get_monotonic_coarse,
 	};
 
-	register_posix_clock(CLOCK_REALTIME, &clock_realtime);
-	register_posix_clock(CLOCK_MONOTONIC, &clock_monotonic);
-	register_posix_clock(CLOCK_MONOTONIC_RAW, &clock_monotonic_raw);
-	register_posix_clock(CLOCK_REALTIME_COARSE, &clock_realtime_coarse);
-	register_posix_clock(CLOCK_MONOTONIC_COARSE, &clock_monotonic_coarse);
+	posix_timers_register_clock(CLOCK_REALTIME, &clock_realtime);
+	posix_timers_register_clock(CLOCK_MONOTONIC, &clock_monotonic);
+	posix_timers_register_clock(CLOCK_MONOTONIC_RAW, &clock_monotonic_raw);
+	posix_timers_register_clock(CLOCK_REALTIME_COARSE, &clock_realtime_coarse);
+	posix_timers_register_clock(CLOCK_MONOTONIC_COARSE, &clock_monotonic_coarse);
 
 	posix_timers_cache = kmem_cache_create("posix_timers_cache",
 					sizeof (struct k_itimer), 0, SLAB_PANIC,
@@ -433,7 +433,8 @@ static struct pid *good_sigevent(sigeven
 	return task_pid(rtn);
 }
 
-void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock)
+void posix_timers_register_clock(const clockid_t clock_id,
+				 struct k_clock *new_clock)
 {
 	if ((unsigned) clock_id >= MAX_CLOCKS) {
 		printk(KERN_WARNING "POSIX clock register failed for clock_id %d\n",
@@ -454,7 +455,7 @@ void register_posix_clock(const clockid_
 
 	posix_clocks[clock_id] = *new_clock;
 }
-EXPORT_SYMBOL_GPL(register_posix_clock);
+EXPORT_SYMBOL_GPL(posix_timers_register_clock);
 
 static struct k_itimer * alloc_posix_timer(void)
 {



^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 00/28]  Rework of the PTP support series core code
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
                   ` (28 preceding siblings ...)
  2011-02-02  8:17 ` [patch 00/28] Rework of the PTP support series core code Richard Cochran
@ 2011-02-02 13:53 ` Richard Cochran
  2011-02-02 22:04 ` [tip:timers/core] ntp: Add ADJ_SETOFFSET mode bit tip-bot for Richard Cochran
  2011-03-01 15:38 ` [patch 00/28] Rework of the PTP support series core code torbenh
  31 siblings, 0 replies; 111+ messages in thread
From: Richard Cochran @ 2011-02-02 13:53 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: LKML, John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, Feb 01, 2011 at 01:50:55PM -0000, Thomas Gleixner wrote:
> 
> Richard, can you please run that through your testing ? The PTP
> drivers apply on top of that.

My PTP convergence tests ran fine with the gianfar and phyter clocks.

Tested-by: Richard Cochran <richard.cochran@omicron.at>

^ permalink raw reply	[flat|nested] 111+ messages in thread

* [tip:timers/core] time: Correct the *settime* parameters
  2011-02-01 13:50 ` [patch 01/28] time: Correct the *settime* parameters Thomas Gleixner
  2011-02-01 14:22   ` Thomas Gleixner
  2011-02-01 20:32   ` john stultz
@ 2011-02-02 21:54   ` tip-bot for Richard Cochran
  2 siblings, 0 replies; 111+ messages in thread
From: tip-bot for Richard Cochran @ 2011-02-02 21:54 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, johnstul, tglx, richard.cochran

Commit-ID:  1e6d767924c74929c0cfe839ae8f37bcee9e544e
Gitweb:     http://git.kernel.org/tip/1e6d767924c74929c0cfe839ae8f37bcee9e544e
Author:     Richard Cochran <richard.cochran@omicron.at>
AuthorDate: Tue, 1 Feb 2011 13:50:58 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 2 Feb 2011 15:28:11 +0100

time: Correct the *settime* parameters

Both settimeofday() and clock_settime() promise with a 'const'
attribute not to alter the arguments passed in. This patch adds the
missing 'const' attribute into the various kernel functions
implementing these calls.

Signed-off-by: Richard Cochran <richard.cochran@omicron.at>
Acked-by: John Stultz <johnstul@us.ibm.com>
LKML-Reference: <20110201134417.545698637@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 drivers/char/mmtimer.c       |    2 +-
 include/linux/posix-timers.h |    5 +++--
 include/linux/security.h     |    9 +++++----
 include/linux/time.h         |    5 +++--
 kernel/posix-timers.c        |    4 ++--
 kernel/time.c                |    2 +-
 kernel/time/timekeeping.c    |    2 +-
 security/commoncap.c         |    2 +-
 security/security.c          |    2 +-
 9 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index e6d7562..ecd0082 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -487,7 +487,7 @@ static int sgi_clock_get(clockid_t clockid, struct timespec *tp)
 	return 0;
 };
 
-static int sgi_clock_set(clockid_t clockid, struct timespec *tp)
+static int sgi_clock_set(const clockid_t clockid, const struct timespec *tp)
 {
 
 	u64 nsec;
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 3e23844a..b2c14cb 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -69,7 +69,8 @@ struct k_itimer {
 struct k_clock {
 	int res;		/* in nanoseconds */
 	int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
-	int (*clock_set) (const clockid_t which_clock, struct timespec * tp);
+	int (*clock_set) (const clockid_t which_clock,
+			  const struct timespec *tp);
 	int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
 	int (*timer_create) (struct k_itimer *timer);
 	int (*nsleep) (const clockid_t which_clock, int flags,
@@ -89,7 +90,7 @@ void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock);
 /* error handlers for timer_create, nanosleep and settime */
 int do_posix_clock_nonanosleep(const clockid_t, int flags, struct timespec *,
 			       struct timespec __user *);
-int do_posix_clock_nosettime(const clockid_t, struct timespec *tp);
+int do_posix_clock_nosettime(const clockid_t, const struct timespec *tp);
 
 /* function to call to trigger timer event */
 int posix_timer_event(struct k_itimer *timr, int si_private);
diff --git a/include/linux/security.h b/include/linux/security.h
index c642bb8..c096aa6 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -53,7 +53,7 @@ struct audit_krule;
  */
 extern int cap_capable(struct task_struct *tsk, const struct cred *cred,
 		       int cap, int audit);
-extern int cap_settime(struct timespec *ts, struct timezone *tz);
+extern int cap_settime(const struct timespec *ts, const struct timezone *tz);
 extern int cap_ptrace_access_check(struct task_struct *child, unsigned int mode);
 extern int cap_ptrace_traceme(struct task_struct *parent);
 extern int cap_capget(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted);
@@ -1387,7 +1387,7 @@ struct security_operations {
 	int (*quotactl) (int cmds, int type, int id, struct super_block *sb);
 	int (*quota_on) (struct dentry *dentry);
 	int (*syslog) (int type);
-	int (*settime) (struct timespec *ts, struct timezone *tz);
+	int (*settime) (const struct timespec *ts, const struct timezone *tz);
 	int (*vm_enough_memory) (struct mm_struct *mm, long pages);
 
 	int (*bprm_set_creds) (struct linux_binprm *bprm);
@@ -1669,7 +1669,7 @@ int security_sysctl(struct ctl_table *table, int op);
 int security_quotactl(int cmds, int type, int id, struct super_block *sb);
 int security_quota_on(struct dentry *dentry);
 int security_syslog(int type);
-int security_settime(struct timespec *ts, struct timezone *tz);
+int security_settime(const struct timespec *ts, const struct timezone *tz);
 int security_vm_enough_memory(long pages);
 int security_vm_enough_memory_mm(struct mm_struct *mm, long pages);
 int security_vm_enough_memory_kern(long pages);
@@ -1904,7 +1904,8 @@ static inline int security_syslog(int type)
 	return 0;
 }
 
-static inline int security_settime(struct timespec *ts, struct timezone *tz)
+static inline int security_settime(const struct timespec *ts,
+				   const struct timezone *tz)
 {
 	return cap_settime(ts, tz);
 }
diff --git a/include/linux/time.h b/include/linux/time.h
index 38c5206..7c44e77 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -145,8 +145,9 @@ static inline u32 arch_gettimeoffset(void) { return 0; }
 #endif
 
 extern void do_gettimeofday(struct timeval *tv);
-extern int do_settimeofday(struct timespec *tv);
-extern int do_sys_settimeofday(struct timespec *tv, struct timezone *tz);
+extern int do_settimeofday(const struct timespec *tv);
+extern int do_sys_settimeofday(const struct timespec *tv,
+			       const struct timezone *tz);
 #define do_posix_clock_monotonic_gettime(ts) ktime_get_ts(ts)
 extern long do_utimes(int dfd, const char __user *filename, struct timespec *times, int flags);
 struct itimerval;
diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index 93bd2eb..21b7ca2 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -192,7 +192,7 @@ static int common_clock_get(clockid_t which_clock, struct timespec *tp)
 }
 
 static inline int common_clock_set(const clockid_t which_clock,
-				   struct timespec *tp)
+				   const struct timespec *tp)
 {
 	return do_sys_settimeofday(tp, NULL);
 }
@@ -928,7 +928,7 @@ void exit_itimers(struct signal_struct *sig)
 }
 
 /* Not available / possible... functions */
-int do_posix_clock_nosettime(const clockid_t clockid, struct timespec *tp)
+int do_posix_clock_nosettime(const clockid_t clockid, const struct timespec *tp)
 {
 	return -EINVAL;
 }
diff --git a/kernel/time.c b/kernel/time.c
index a31b512..5cb8053 100644
--- a/kernel/time.c
+++ b/kernel/time.c
@@ -150,7 +150,7 @@ static inline void warp_clock(void)
  * various programs will get confused when the clock gets warped.
  */
 
-int do_sys_settimeofday(struct timespec *tv, struct timezone *tz)
+int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
 {
 	static int firsttime = 1;
 	int error = 0;
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 02c13a3..4f9f65b 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -353,7 +353,7 @@ EXPORT_SYMBOL(do_gettimeofday);
  *
  * Sets the time of day to the new time and update NTP and notify hrtimers
  */
-int do_settimeofday(struct timespec *tv)
+int do_settimeofday(const struct timespec *tv)
 {
 	struct timespec ts_delta;
 	unsigned long flags;
diff --git a/security/commoncap.c b/security/commoncap.c
index 64c2ed9..dbfdaed 100644
--- a/security/commoncap.c
+++ b/security/commoncap.c
@@ -93,7 +93,7 @@ int cap_capable(struct task_struct *tsk, const struct cred *cred, int cap,
  * Determine whether the current process may set the system clock and timezone
  * information, returning 0 if permission granted, -ve if denied.
  */
-int cap_settime(struct timespec *ts, struct timezone *tz)
+int cap_settime(const struct timespec *ts, const struct timezone *tz)
 {
 	if (!capable(CAP_SYS_TIME))
 		return -EPERM;
diff --git a/security/security.c b/security/security.c
index 739e403..b995428 100644
--- a/security/security.c
+++ b/security/security.c
@@ -202,7 +202,7 @@ int security_syslog(int type)
 	return security_ops->syslog(type);
 }
 
-int security_settime(struct timespec *ts, struct timezone *tz)
+int security_settime(const struct timespec *ts, const struct timezone *tz)
 {
 	return security_ops->settime(ts, tz);
 }

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [tip:timers/core] posix-timers: Define nanosleep not supported error separate
  2011-02-01 13:51 ` [patch 02/28] posix-timers: Define nanosleep not supported error separate Thomas Gleixner
  2011-02-01 20:32   ` John Stultz
@ 2011-02-02 21:55   ` tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: tip-bot for Thomas Gleixner @ 2011-02-02 21:55 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, johnstul, tglx, richard.cochran

Commit-ID:  65da528d7cc94966cf24d2a1e0837b689159b543
Gitweb:     http://git.kernel.org/tip/65da528d7cc94966cf24d2a1e0837b689159b543
Author:     Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Tue, 1 Feb 2011 13:51:01 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 2 Feb 2011 15:28:11 +0100

posix-timers: Define nanosleep not supported error separate

Define the conditional nanosleep not supported error value outside of
do_posix_clock_nonanosleep(). Preparatory patch for further cleanups. 

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: <20110201134417.643486574@linutronix.de>
---
 kernel/posix-timers.c |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index 21b7ca2..89bff37 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -81,6 +81,14 @@ static DEFINE_SPINLOCK(idr_lock);
 #error "SIGEV_THREAD_ID must not share bit with other SIGEV values!"
 #endif
 
+/*
+ * parisc wants ENOTSUP instead of EOPNOTSUPP
+ */
+#ifndef ENOTSUP
+# define ENANOSLEEP_NOTSUP EOPNOTSUPP
+#else
+# define ENANOSLEEP_NOTSUP ENOTSUP
+#endif
 
 /*
  * The timer ID is turned into a timer address by idr_find().
@@ -937,11 +945,7 @@ EXPORT_SYMBOL_GPL(do_posix_clock_nosettime);
 int do_posix_clock_nonanosleep(const clockid_t clock, int flags,
 			       struct timespec *t, struct timespec __user *r)
 {
-#ifndef ENOTSUP
-	return -EOPNOTSUPP;	/* aka ENOTSUP in userland for POSIX */
-#else  /*  parisc does define it separately.  */
-	return -ENOTSUP;
-#endif
+	return -ENANOSLEEP_NOTSUP;
 }
 EXPORT_SYMBOL_GPL(do_posix_clock_nonanosleep);
 

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [tip:timers/core] posix-timers: Cleanup struct initializers
  2011-02-01 13:51 ` [patch 03/28] posix-timers: Cleanup struct initializers Thomas Gleixner
  2011-02-01 20:33   ` john stultz
@ 2011-02-02 21:55   ` tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: tip-bot for Thomas Gleixner @ 2011-02-02 21:55 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, johnstul, tglx, richard.cochran

Commit-ID:  2fd1f04089cb657c5d6c484b280ec4d3398aa157
Gitweb:     http://git.kernel.org/tip/2fd1f04089cb657c5d6c484b280ec4d3398aa157
Author:     Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Tue, 1 Feb 2011 13:51:03 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 2 Feb 2011 15:28:12 +0100

posix-timers: Cleanup struct initializers

Cosmetic. No functional change

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: <20110201134417.745627057@linutronix.de>
---
 drivers/char/mmtimer.c    |   14 +++++++-------
 kernel/posix-cpu-timers.c |   24 ++++++++++++------------
 kernel/posix-timers.c     |   38 +++++++++++++++++++-------------------
 3 files changed, 38 insertions(+), 38 deletions(-)

diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index ecd0082..fd51cd8 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -765,13 +765,13 @@ static int sgi_timer_set(struct k_itimer *timr, int flags,
 
 static struct k_clock sgi_clock = {
 	.res = 0,
-	.clock_set = sgi_clock_set,
-	.clock_get = sgi_clock_get,
-	.timer_create = sgi_timer_create,
-	.nsleep = do_posix_clock_nonanosleep,
-	.timer_set = sgi_timer_set,
-	.timer_del = sgi_timer_del,
-	.timer_get = sgi_timer_get
+	.clock_set	= sgi_clock_set,
+	.clock_get	= sgi_clock_get,
+	.timer_create	= sgi_timer_create,
+	.nsleep		= do_posix_clock_nonanosleep,
+	.timer_set	= sgi_timer_set,
+	.timer_del	= sgi_timer_del,
+	.timer_get	= sgi_timer_get
 };
 
 /**
diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
index 05bb717..11b91dc 100644
--- a/kernel/posix-cpu-timers.c
+++ b/kernel/posix-cpu-timers.c
@@ -1607,20 +1607,20 @@ static long thread_cpu_nsleep_restart(struct restart_block *restart_block)
 static __init int init_posix_cpu_timers(void)
 {
 	struct k_clock process = {
-		.clock_getres = process_cpu_clock_getres,
-		.clock_get = process_cpu_clock_get,
-		.clock_set = do_posix_clock_nosettime,
-		.timer_create = process_cpu_timer_create,
-		.nsleep = process_cpu_nsleep,
-		.nsleep_restart = process_cpu_nsleep_restart,
+		.clock_getres	= process_cpu_clock_getres,
+		.clock_get	= process_cpu_clock_get,
+		.clock_set	= do_posix_clock_nosettime,
+		.timer_create	= process_cpu_timer_create,
+		.nsleep		= process_cpu_nsleep,
+		.nsleep_restart	= process_cpu_nsleep_restart,
 	};
 	struct k_clock thread = {
-		.clock_getres = thread_cpu_clock_getres,
-		.clock_get = thread_cpu_clock_get,
-		.clock_set = do_posix_clock_nosettime,
-		.timer_create = thread_cpu_timer_create,
-		.nsleep = thread_cpu_nsleep,
-		.nsleep_restart = thread_cpu_nsleep_restart,
+		.clock_getres	= thread_cpu_clock_getres,
+		.clock_get	= thread_cpu_clock_get,
+		.clock_set	= do_posix_clock_nosettime,
+		.timer_create	= thread_cpu_timer_create,
+		.nsleep		= thread_cpu_nsleep,
+		.nsleep_restart	= thread_cpu_nsleep_restart,
 	};
 	struct timespec ts;
 
diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index 89bff37..e7d26af 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -281,33 +281,33 @@ static int posix_get_coarse_res(const clockid_t which_clock, struct timespec *tp
 static __init int init_posix_timers(void)
 {
 	struct k_clock clock_realtime = {
-		.clock_getres = hrtimer_get_res,
+		.clock_getres	= hrtimer_get_res,
 	};
 	struct k_clock clock_monotonic = {
-		.clock_getres = hrtimer_get_res,
-		.clock_get = posix_ktime_get_ts,
-		.clock_set = do_posix_clock_nosettime,
+		.clock_getres	= hrtimer_get_res,
+		.clock_get	= posix_ktime_get_ts,
+		.clock_set	= do_posix_clock_nosettime,
 	};
 	struct k_clock clock_monotonic_raw = {
-		.clock_getres = hrtimer_get_res,
-		.clock_get = posix_get_monotonic_raw,
-		.clock_set = do_posix_clock_nosettime,
-		.timer_create = no_timer_create,
-		.nsleep = no_nsleep,
+		.clock_getres	= hrtimer_get_res,
+		.clock_get	= posix_get_monotonic_raw,
+		.clock_set	= do_posix_clock_nosettime,
+		.timer_create	= no_timer_create,
+		.nsleep		= no_nsleep,
 	};
 	struct k_clock clock_realtime_coarse = {
-		.clock_getres = posix_get_coarse_res,
-		.clock_get = posix_get_realtime_coarse,
-		.clock_set = do_posix_clock_nosettime,
-		.timer_create = no_timer_create,
-		.nsleep = no_nsleep,
+		.clock_getres	= posix_get_coarse_res,
+		.clock_get	= posix_get_realtime_coarse,
+		.clock_set	= do_posix_clock_nosettime,
+		.timer_create	= no_timer_create,
+		.nsleep		= no_nsleep,
 	};
 	struct k_clock clock_monotonic_coarse = {
-		.clock_getres = posix_get_coarse_res,
-		.clock_get = posix_get_monotonic_coarse,
-		.clock_set = do_posix_clock_nosettime,
-		.timer_create = no_timer_create,
-		.nsleep = no_nsleep,
+		.clock_getres	= posix_get_coarse_res,
+		.clock_get	= posix_get_monotonic_coarse,
+		.clock_set	= do_posix_clock_nosettime,
+		.timer_create	= no_timer_create,
+		.nsleep		= no_nsleep,
 	};
 
 	register_posix_clock(CLOCK_REALTIME, &clock_realtime);

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [tip:timers/core] posix-timers: Introduce clock_posix_cpu
  2011-02-01 13:51 ` [patch 04/28] posix-timers: Introduce clock_posix_cpu Thomas Gleixner
  2011-02-01 20:34   ` john stultz
@ 2011-02-02 21:56   ` tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: tip-bot for Thomas Gleixner @ 2011-02-02 21:56 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, johnstul, tglx, richard.cochran

Commit-ID:  1976945eeaab5fa461735a6225a82c3cf1e65d62
Gitweb:     http://git.kernel.org/tip/1976945eeaab5fa461735a6225a82c3cf1e65d62
Author:     Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Tue, 1 Feb 2011 13:51:06 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 2 Feb 2011 15:28:12 +0100

posix-timers: Introduce clock_posix_cpu

The CLOCK_DISPATCH() macro is a horrible magic. We call common
functions if a function pointer is not set. That's just backwards.

To support dynamic file decriptor based clocks we need to cleanup that
dispatch logic.

Create a k_clock struct clock_posix_cpu which has all the
posix-cpu-timer functions filled in. After the cleanup the functions
can be made static.

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: <20110201134417.841974553@linutronix.de>
---
 include/linux/posix-timers.h |    2 ++
 kernel/posix-cpu-timers.c    |   12 ++++++++++++
 2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index b2c14cb..1330ff3 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -85,6 +85,8 @@ struct k_clock {
 			   struct itimerspec * cur_setting);
 };
 
+extern struct k_clock clock_posix_cpu;
+
 void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock);
 
 /* error handlers for timer_create, nanosleep and settime */
diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
index 11b91dc..816cd49 100644
--- a/kernel/posix-cpu-timers.c
+++ b/kernel/posix-cpu-timers.c
@@ -1604,6 +1604,18 @@ static long thread_cpu_nsleep_restart(struct restart_block *restart_block)
 	return -EINVAL;
 }
 
+struct k_clock clock_posix_cpu = {
+	.clock_getres	= posix_cpu_clock_getres,
+	.clock_set	= posix_cpu_clock_set,
+	.clock_get	= posix_cpu_clock_get,
+	.timer_create	= posix_cpu_timer_create,
+	.nsleep		= posix_cpu_nsleep,
+	.nsleep_restart	= posix_cpu_nsleep_restart,
+	.timer_set	= posix_cpu_timer_set,
+	.timer_del	= posix_cpu_timer_del,
+	.timer_get	= posix_cpu_timer_get,
+};
+
 static __init int init_posix_cpu_timers(void)
 {
 	struct k_clock process = {

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [tip:timers/core] posix-timers: Introduce clockid_to_kclock()
  2011-02-01 13:51 ` [patch 05/28] posix-timers: Introduce clockid_to_kclock() Thomas Gleixner
  2011-02-01 20:37   ` john stultz
@ 2011-02-02 21:56   ` tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: tip-bot for Thomas Gleixner @ 2011-02-02 21:56 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, johnstul, tglx, richard.cochran

Commit-ID:  cc785ac22b17ed53e8ff5c1501e422be6d10be3c
Gitweb:     http://git.kernel.org/tip/cc785ac22b17ed53e8ff5c1501e422be6d10be3c
Author:     Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Tue, 1 Feb 2011 13:51:09 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 2 Feb 2011 15:28:12 +0100

posix-timers: Introduce clockid_to_kclock()

New function to find the kclock for a given clockid.

Returns a pointer to clock_posix_cpu if clockid < 0. If clockid >=
MAXCLOCK or if the clock_getres pointer is not set it returns
NULL. For valid clocks it returns a pointer to the matching
posix_clock.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <johnstul@us.ibm.com>
Acked-by: Richard Cochran <richard.cochran@omicron.at>
LKML-Reference: <20110201134417.938447839@linutronix.de>
---
 kernel/posix-timers.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index e7d26af..14b0a70 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -531,6 +531,16 @@ static void release_posix_timer(struct k_itimer *tmr, int it_id_set)
 	kmem_cache_free(posix_timers_cache, tmr);
 }
 
+static struct k_clock *clockid_to_kclock(const clockid_t id)
+{
+	if (id < 0)
+		return &clock_posix_cpu;
+
+	if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
+		return NULL;
+	return &posix_clocks[id];
+}
+
 /* Create a POSIX.1b interval timer. */
 
 SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [tip:timers/core] posix-timers: Convert clock_nanosleep to clockid_to_kclock()
  2011-02-01 13:51 ` [patch 06/28] posix-timers: Convert clock_nanosleep to clockid_to_kclock() Thomas Gleixner
  2011-02-01 20:41   ` john stultz
@ 2011-02-02 21:57   ` tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: tip-bot for Thomas Gleixner @ 2011-02-02 21:57 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, johnstul, tglx, richard.cochran

Commit-ID:  a5cd2880106cb2c79b3fe24f1c53dadba6a542a0
Gitweb:     http://git.kernel.org/tip/a5cd2880106cb2c79b3fe24f1c53dadba6a542a0
Author:     Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Tue, 1 Feb 2011 13:51:11 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 2 Feb 2011 15:28:13 +0100

posix-timers: Convert clock_nanosleep to clockid_to_kclock()

Use the new kclock decoding function in clock_nanosleep and cleanup all
kclocks which use the default functions.

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.034175556@linutronix.de>
---
 drivers/char/mmtimer.c       |    1 -
 include/linux/posix-timers.h |    2 --
 kernel/posix-timers.c        |   26 +++++++-------------------
 3 files changed, 7 insertions(+), 22 deletions(-)

diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index fd51cd8..262d104 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -768,7 +768,6 @@ static struct k_clock sgi_clock = {
 	.clock_set	= sgi_clock_set,
 	.clock_get	= sgi_clock_get,
 	.timer_create	= sgi_timer_create,
-	.nsleep		= do_posix_clock_nonanosleep,
 	.timer_set	= sgi_timer_set,
 	.timer_del	= sgi_timer_del,
 	.timer_get	= sgi_timer_get
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 1330ff3..cd6da06 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -90,8 +90,6 @@ extern struct k_clock clock_posix_cpu;
 void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock);
 
 /* error handlers for timer_create, nanosleep and settime */
-int do_posix_clock_nonanosleep(const clockid_t, int flags, struct timespec *,
-			       struct timespec __user *);
 int do_posix_clock_nosettime(const clockid_t, const struct timespec *tp);
 
 /* function to call to trigger timer event */
diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index 14b0a70..ee69b21 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -216,12 +216,6 @@ static int no_timer_create(struct k_itimer *new_timer)
 	return -EOPNOTSUPP;
 }
 
-static int no_nsleep(const clockid_t which_clock, int flags,
-		     struct timespec *tsave, struct timespec __user *rmtp)
-{
-	return -EOPNOTSUPP;
-}
-
 /*
  * Return nonzero if we know a priori this clockid_t value is bogus.
  */
@@ -282,32 +276,31 @@ static __init int init_posix_timers(void)
 {
 	struct k_clock clock_realtime = {
 		.clock_getres	= hrtimer_get_res,
+		.nsleep		= common_nsleep,
 	};
 	struct k_clock clock_monotonic = {
 		.clock_getres	= hrtimer_get_res,
 		.clock_get	= posix_ktime_get_ts,
 		.clock_set	= do_posix_clock_nosettime,
+		.nsleep		= common_nsleep,
 	};
 	struct k_clock clock_monotonic_raw = {
 		.clock_getres	= hrtimer_get_res,
 		.clock_get	= posix_get_monotonic_raw,
 		.clock_set	= do_posix_clock_nosettime,
 		.timer_create	= no_timer_create,
-		.nsleep		= no_nsleep,
 	};
 	struct k_clock clock_realtime_coarse = {
 		.clock_getres	= posix_get_coarse_res,
 		.clock_get	= posix_get_realtime_coarse,
 		.clock_set	= do_posix_clock_nosettime,
 		.timer_create	= no_timer_create,
-		.nsleep		= no_nsleep,
 	};
 	struct k_clock clock_monotonic_coarse = {
 		.clock_getres	= posix_get_coarse_res,
 		.clock_get	= posix_get_monotonic_coarse,
 		.clock_set	= do_posix_clock_nosettime,
 		.timer_create	= no_timer_create,
-		.nsleep		= no_nsleep,
 	};
 
 	register_posix_clock(CLOCK_REALTIME, &clock_realtime);
@@ -952,13 +945,6 @@ int do_posix_clock_nosettime(const clockid_t clockid, const struct timespec *tp)
 }
 EXPORT_SYMBOL_GPL(do_posix_clock_nosettime);
 
-int do_posix_clock_nonanosleep(const clockid_t clock, int flags,
-			       struct timespec *t, struct timespec __user *r)
-{
-	return -ENANOSLEEP_NOTSUP;
-}
-EXPORT_SYMBOL_GPL(do_posix_clock_nonanosleep);
-
 SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
 		const struct timespec __user *, tp)
 {
@@ -1023,10 +1009,13 @@ SYSCALL_DEFINE4(clock_nanosleep, const clockid_t, which_clock, int, flags,
 		const struct timespec __user *, rqtp,
 		struct timespec __user *, rmtp)
 {
+	struct k_clock *kc = clockid_to_kclock(which_clock);
 	struct timespec t;
 
-	if (invalid_clockid(which_clock))
+	if (!kc)
 		return -EINVAL;
+	if (!kc->nsleep)
+		return -ENANOSLEEP_NOTSUP;
 
 	if (copy_from_user(&t, rqtp, sizeof (struct timespec)))
 		return -EFAULT;
@@ -1034,8 +1023,7 @@ SYSCALL_DEFINE4(clock_nanosleep, const clockid_t, which_clock, int, flags,
 	if (!timespec_valid(&t))
 		return -EINVAL;
 
-	return CLOCK_DISPATCH(which_clock, nsleep,
-			      (which_clock, flags, &t, rmtp));
+	return kc->nsleep(which_clock, flags, &t, rmtp);
 }
 
 /*

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [tip:timers/core] posix-timers: Convert clock_nanosleep_restart to clockid_to_kclock()
  2011-02-01 13:51 ` [patch 07/28] posix-timers: Convert clock_nanosleep_restart " Thomas Gleixner
  2011-02-01 20:42   ` John Stultz
@ 2011-02-02 21:57   ` tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: tip-bot for Thomas Gleixner @ 2011-02-02 21:57 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, johnstul, tglx, richard.cochran

Commit-ID:  59bd5bc24aa69f6c62da1e242c16f09f667def96
Gitweb:     http://git.kernel.org/tip/59bd5bc24aa69f6c62da1e242c16f09f667def96
Author:     Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Tue, 1 Feb 2011 13:51:17 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 2 Feb 2011 15:28:13 +0100

posix-timers: Convert clock_nanosleep_restart to clockid_to_kclock()

Use the new kclock decoding function in clock_nanosleep_restart.

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.131263211@linutronix.de>
---
 kernel/posix-timers.c |   20 ++++++++------------
 1 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index ee69b21..4dd86d1 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -277,12 +277,14 @@ static __init int init_posix_timers(void)
 	struct k_clock clock_realtime = {
 		.clock_getres	= hrtimer_get_res,
 		.nsleep		= common_nsleep,
+		.nsleep_restart	= hrtimer_nanosleep_restart,
 	};
 	struct k_clock clock_monotonic = {
 		.clock_getres	= hrtimer_get_res,
 		.clock_get	= posix_ktime_get_ts,
 		.clock_set	= do_posix_clock_nosettime,
 		.nsleep		= common_nsleep,
+		.nsleep_restart	= hrtimer_nanosleep_restart,
 	};
 	struct k_clock clock_monotonic_raw = {
 		.clock_getres	= hrtimer_get_res,
@@ -1027,22 +1029,16 @@ SYSCALL_DEFINE4(clock_nanosleep, const clockid_t, which_clock, int, flags,
 }
 
 /*
- * nanosleep_restart for monotonic and realtime clocks
- */
-static int common_nsleep_restart(struct restart_block *restart_block)
-{
-	return hrtimer_nanosleep_restart(restart_block);
-}
-
-/*
  * This will restart clock_nanosleep. This is required only by
  * compat_clock_nanosleep_restart for now.
  */
-long
-clock_nanosleep_restart(struct restart_block *restart_block)
+long clock_nanosleep_restart(struct restart_block *restart_block)
 {
 	clockid_t which_clock = restart_block->arg0;
+	struct k_clock *kc = clockid_to_kclock(which_clock);
+
+	if (WARN_ON_ONCE(!kc || !kc->nsleep_restart))
+		return -EINVAL;
 
-	return CLOCK_DISPATCH(which_clock, nsleep_restart,
-			      (restart_block));
+	return kc->nsleep_restart(restart_block);
 }

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [tip:timers/core] posix-timers: Cleanup restart_block usage
  2011-02-01 13:51 ` [patch 08/28] posix-timers: Cleanup restart_block usage Thomas Gleixner
  2011-02-01 21:11   ` john stultz
@ 2011-02-02 21:57   ` tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: tip-bot for Thomas Gleixner @ 2011-02-02 21:57 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, johnstul, tglx, richard.cochran

Commit-ID:  3751f9f29bcbc19bd10e92254a273486f150c245
Gitweb:     http://git.kernel.org/tip/3751f9f29bcbc19bd10e92254a273486f150c245
Author:     Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Tue, 1 Feb 2011 13:51:20 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 2 Feb 2011 15:28:13 +0100

posix-timers: Cleanup restart_block usage

posix timers still use the legacy arg0-arg3 members of
restart_block. Use restart_block.nanosleep instead

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.232288779@linutronix.de>
---
 kernel/posix-cpu-timers.c |   38 +++++++++++++++-----------------------
 kernel/posix-timers.c     |    2 +-
 2 files changed, 16 insertions(+), 24 deletions(-)

diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
index 816cd49..9e617b0 100644
--- a/kernel/posix-cpu-timers.c
+++ b/kernel/posix-cpu-timers.c
@@ -1485,7 +1485,7 @@ int posix_cpu_nsleep(const clockid_t which_clock, int flags,
 		     struct timespec *rqtp, struct timespec __user *rmtp)
 {
 	struct restart_block *restart_block =
-	    &current_thread_info()->restart_block;
+		&current_thread_info()->restart_block;
 	struct itimerspec it;
 	int error;
 
@@ -1501,50 +1501,42 @@ int posix_cpu_nsleep(const clockid_t which_clock, int flags,
 
 	if (error == -ERESTART_RESTARTBLOCK) {
 
-	       	if (flags & TIMER_ABSTIME)
+		if (flags & TIMER_ABSTIME)
 			return -ERESTARTNOHAND;
 		/*
-	 	 * Report back to the user the time still remaining.
-	 	 */
-		if (rmtp != NULL && copy_to_user(rmtp, &it.it_value, sizeof *rmtp))
+		 * Report back to the user the time still remaining.
+		 */
+		if (rmtp && copy_to_user(rmtp, &it.it_value, sizeof *rmtp))
 			return -EFAULT;
 
 		restart_block->fn = posix_cpu_nsleep_restart;
-		restart_block->arg0 = which_clock;
-		restart_block->arg1 = (unsigned long) rmtp;
-		restart_block->arg2 = rqtp->tv_sec;
-		restart_block->arg3 = rqtp->tv_nsec;
+		restart_block->nanosleep.index = which_clock;
+		restart_block->nanosleep.rmtp = rmtp;
+		restart_block->nanosleep.expires = timespec_to_ns(rqtp);
 	}
 	return error;
 }
 
 long posix_cpu_nsleep_restart(struct restart_block *restart_block)
 {
-	clockid_t which_clock = restart_block->arg0;
-	struct timespec __user *rmtp;
+	clockid_t which_clock = restart_block->nanosleep.index;
 	struct timespec t;
 	struct itimerspec it;
 	int error;
 
-	rmtp = (struct timespec __user *) restart_block->arg1;
-	t.tv_sec = restart_block->arg2;
-	t.tv_nsec = restart_block->arg3;
+	t = ns_to_timespec(restart_block->nanosleep.expires);
 
-	restart_block->fn = do_no_restart_syscall;
 	error = do_cpu_nanosleep(which_clock, TIMER_ABSTIME, &t, &it);
 
 	if (error == -ERESTART_RESTARTBLOCK) {
+		struct timespec __user *rmtp = restart_block->nanosleep.rmtp;
 		/*
-	 	 * Report back to the user the time still remaining.
-	 	 */
-		if (rmtp != NULL && copy_to_user(rmtp, &it.it_value, sizeof *rmtp))
+		 * Report back to the user the time still remaining.
+		 */
+		if (rmtp && copy_to_user(rmtp, &it.it_value, sizeof *rmtp))
 			return -EFAULT;
 
-		restart_block->fn = posix_cpu_nsleep_restart;
-		restart_block->arg0 = which_clock;
-		restart_block->arg1 = (unsigned long) rmtp;
-		restart_block->arg2 = t.tv_sec;
-		restart_block->arg3 = t.tv_nsec;
+		restart_block->nanosleep.expires = timespec_to_ns(&t);
 	}
 	return error;
 
diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index 4dd86d1..4762986 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -1034,7 +1034,7 @@ SYSCALL_DEFINE4(clock_nanosleep, const clockid_t, which_clock, int, flags,
  */
 long clock_nanosleep_restart(struct restart_block *restart_block)
 {
-	clockid_t which_clock = restart_block->arg0;
+	clockid_t which_clock = restart_block->nanosleep.index;
 	struct k_clock *kc = clockid_to_kclock(which_clock);
 
 	if (WARN_ON_ONCE(!kc || !kc->nsleep_restart))

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [tip:timers/core] thread_info: Remove legacy arg0-3 from restart_block
  2011-02-01 13:51 ` [patch 09/28] thread_info: Remove legacy arg0-3 from restart_block Thomas Gleixner
  2011-02-01 21:11   ` john stultz
@ 2011-02-02 21:58   ` tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: tip-bot for Thomas Gleixner @ 2011-02-02 21:58 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, johnstul, tglx, richard.cochran

Commit-ID:  d608c18203a969e5d14572a9861c646d0bb66872
Gitweb:     http://git.kernel.org/tip/d608c18203a969e5d14572a9861c646d0bb66872
Author:     Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Tue, 1 Feb 2011 13:51:43 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 2 Feb 2011 15:28:13 +0100

thread_info: Remove legacy arg0-3 from restart_block

posix timers were the last users of the legacy arg0-3 members of
restart_block. Remove the cruft.

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.326209775@linutronix.de>
---
 include/linux/thread_info.h |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)

diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
index c906965..20fc303 100644
--- a/include/linux/thread_info.h
+++ b/include/linux/thread_info.h
@@ -18,9 +18,6 @@ struct compat_timespec;
 struct restart_block {
 	long (*fn)(struct restart_block *);
 	union {
-		struct {
-			unsigned long arg0, arg1, arg2, arg3;
-		};
 		/* For futex_wait and futex_wait_requeue_pi */
 		struct {
 			u32 __user *uaddr;

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [tip:timers/core] posix-cpu-timers: Remove the stub nanosleep functions
  2011-02-01 13:51 ` [patch 10/28] posix-cpu-timers: Remove the stub nanosleep functions Thomas Gleixner
  2011-02-01 21:14   ` John Stultz
@ 2011-02-02 21:58   ` tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: tip-bot for Thomas Gleixner @ 2011-02-02 21:58 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, johnstul, tglx, richard.cochran

Commit-ID:  79c9da0d0539fb341a1b48a2a5a23d974726de90
Gitweb:     http://git.kernel.org/tip/79c9da0d0539fb341a1b48a2a5a23d974726de90
Author:     Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Tue, 1 Feb 2011 13:51:45 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 2 Feb 2011 15:28:14 +0100

posix-cpu-timers: Remove the stub nanosleep functions

CLOCK_THREAD_CPUTIME_ID implements stub functions for nanosleep and
nanosleep_restart, which return -EINVAL. That return value is
wrong. The correct return value is -ENOTSUP.

Remove the stubs and let the new dispatch code return the correct
error code.

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.422446502@linutronix.de>
---
 kernel/posix-cpu-timers.c |   11 -----------
 1 files changed, 0 insertions(+), 11 deletions(-)

diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
index 9e617b0..8dc4cd7 100644
--- a/kernel/posix-cpu-timers.c
+++ b/kernel/posix-cpu-timers.c
@@ -1586,15 +1586,6 @@ static int thread_cpu_timer_create(struct k_itimer *timer)
 	timer->it_clock = THREAD_CLOCK;
 	return posix_cpu_timer_create(timer);
 }
-static int thread_cpu_nsleep(const clockid_t which_clock, int flags,
-			      struct timespec *rqtp, struct timespec __user *rmtp)
-{
-	return -EINVAL;
-}
-static long thread_cpu_nsleep_restart(struct restart_block *restart_block)
-{
-	return -EINVAL;
-}
 
 struct k_clock clock_posix_cpu = {
 	.clock_getres	= posix_cpu_clock_getres,
@@ -1623,8 +1614,6 @@ static __init int init_posix_cpu_timers(void)
 		.clock_get	= thread_cpu_clock_get,
 		.clock_set	= do_posix_clock_nosettime,
 		.timer_create	= thread_cpu_timer_create,
-		.nsleep		= thread_cpu_nsleep,
-		.nsleep_restart	= thread_cpu_nsleep_restart,
 	};
 	struct timespec ts;
 

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [tip:timers/core] posix-timers: Convert clock_settime to clockid_to_kclock()
  2011-02-01 13:51 ` [patch 11/28] posix-timers: Convert clock_settime to clockid_to_kclock() Thomas Gleixner
  2011-02-01 21:15   ` john stultz
@ 2011-02-02 21:59   ` tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: tip-bot for Thomas Gleixner @ 2011-02-02 21:59 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, johnstul, tglx, richard.cochran

Commit-ID:  26f9a4796af330173d790c8d2b5e2efcc489e755
Gitweb:     http://git.kernel.org/tip/26f9a4796af330173d790c8d2b5e2efcc489e755
Author:     Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Tue, 1 Feb 2011 13:51:48 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 2 Feb 2011 15:28:14 +0100

posix-timers: Convert clock_settime to clockid_to_kclock()

Use the new kclock decoding function in clock_settime and cleanup all
kclocks which use the default functions. Rename the misnomed
common_clock_set() to posix_clock_realtime_set().

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.518851246@linutronix.de>
---
 include/linux/posix-timers.h |    3 ---
 kernel/posix-cpu-timers.c    |    2 --
 kernel/posix-timers.c        |   31 ++++++++++++-------------------
 3 files changed, 12 insertions(+), 24 deletions(-)

diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index cd6da06..4aaf0c5 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -89,9 +89,6 @@ extern struct k_clock clock_posix_cpu;
 
 void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock);
 
-/* error handlers for timer_create, nanosleep and settime */
-int do_posix_clock_nosettime(const clockid_t, const struct timespec *tp);
-
 /* function to call to trigger timer event */
 int posix_timer_event(struct k_itimer *timr, int si_private);
 
diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
index 8dc4cd7..504fbab 100644
--- a/kernel/posix-cpu-timers.c
+++ b/kernel/posix-cpu-timers.c
@@ -1604,7 +1604,6 @@ static __init int init_posix_cpu_timers(void)
 	struct k_clock process = {
 		.clock_getres	= process_cpu_clock_getres,
 		.clock_get	= process_cpu_clock_get,
-		.clock_set	= do_posix_clock_nosettime,
 		.timer_create	= process_cpu_timer_create,
 		.nsleep		= process_cpu_nsleep,
 		.nsleep_restart	= process_cpu_nsleep_restart,
@@ -1612,7 +1611,6 @@ static __init int init_posix_cpu_timers(void)
 	struct k_clock thread = {
 		.clock_getres	= thread_cpu_clock_getres,
 		.clock_get	= thread_cpu_clock_get,
-		.clock_set	= do_posix_clock_nosettime,
 		.timer_create	= thread_cpu_timer_create,
 	};
 	struct timespec ts;
diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index 4762986..49f358c 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -199,12 +199,6 @@ static int common_clock_get(clockid_t which_clock, struct timespec *tp)
 	return 0;
 }
 
-static inline int common_clock_set(const clockid_t which_clock,
-				   const struct timespec *tp)
-{
-	return do_sys_settimeofday(tp, NULL);
-}
-
 static int common_timer_create(struct k_itimer *new_timer)
 {
 	hrtimer_init(&new_timer->it.real.timer, new_timer->it_clock, 0);
@@ -232,6 +226,13 @@ static inline int invalid_clockid(const clockid_t which_clock)
 	return 1;
 }
 
+/* Set clock_realtime */
+static int posix_clock_realtime_set(const clockid_t which_clock,
+				    const struct timespec *tp)
+{
+	return do_sys_settimeofday(tp, NULL);
+}
+
 /*
  * Get monotonic time for posix timers
  */
@@ -276,32 +277,29 @@ static __init int init_posix_timers(void)
 {
 	struct k_clock clock_realtime = {
 		.clock_getres	= hrtimer_get_res,
+		.clock_set	= posix_clock_realtime_set,
 		.nsleep		= common_nsleep,
 		.nsleep_restart	= hrtimer_nanosleep_restart,
 	};
 	struct k_clock clock_monotonic = {
 		.clock_getres	= hrtimer_get_res,
 		.clock_get	= posix_ktime_get_ts,
-		.clock_set	= do_posix_clock_nosettime,
 		.nsleep		= common_nsleep,
 		.nsleep_restart	= hrtimer_nanosleep_restart,
 	};
 	struct k_clock clock_monotonic_raw = {
 		.clock_getres	= hrtimer_get_res,
 		.clock_get	= posix_get_monotonic_raw,
-		.clock_set	= do_posix_clock_nosettime,
 		.timer_create	= no_timer_create,
 	};
 	struct k_clock clock_realtime_coarse = {
 		.clock_getres	= posix_get_coarse_res,
 		.clock_get	= posix_get_realtime_coarse,
-		.clock_set	= do_posix_clock_nosettime,
 		.timer_create	= no_timer_create,
 	};
 	struct k_clock clock_monotonic_coarse = {
 		.clock_getres	= posix_get_coarse_res,
 		.clock_get	= posix_get_monotonic_coarse,
-		.clock_set	= do_posix_clock_nosettime,
 		.timer_create	= no_timer_create,
 	};
 
@@ -940,24 +938,19 @@ void exit_itimers(struct signal_struct *sig)
 	}
 }
 
-/* Not available / possible... functions */
-int do_posix_clock_nosettime(const clockid_t clockid, const struct timespec *tp)
-{
-	return -EINVAL;
-}
-EXPORT_SYMBOL_GPL(do_posix_clock_nosettime);
-
 SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
 		const struct timespec __user *, tp)
 {
+	struct k_clock *kc = clockid_to_kclock(which_clock);
 	struct timespec new_tp;
 
-	if (invalid_clockid(which_clock))
+	if (!kc || !kc->clock_set)
 		return -EINVAL;
+
 	if (copy_from_user(&new_tp, tp, sizeof (*tp)))
 		return -EFAULT;
 
-	return CLOCK_DISPATCH(which_clock, clock_set, (which_clock, &new_tp));
+	return kc->clock_set(which_clock, &new_tp);
 }
 
 SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [tip:timers/core] posix-timers: Convert clock_gettime() to clockid_to_kclock()
  2011-02-01 13:51 ` [patch 12/28] posix-timers: Convert clock_gettime() " Thomas Gleixner
  2011-02-01 21:16   ` john stultz
  2011-02-02  9:09   ` Richard Cochran
@ 2011-02-02 21:59   ` tip-bot for Thomas Gleixner
  2 siblings, 0 replies; 111+ messages in thread
From: tip-bot for Thomas Gleixner @ 2011-02-02 21:59 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, johnstul, tglx, richard.cochran

Commit-ID:  42285777631aa0654fbb6442057b3e176445c6c5
Gitweb:     http://git.kernel.org/tip/42285777631aa0654fbb6442057b3e176445c6c5
Author:     Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Tue, 1 Feb 2011 13:51:50 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
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 <tglx@linutronix.de>
Acked-by: John Stultz <johnstul@us.ibm.com>
Tested-by: Richard Cochran <richard.cochran@omicron.at>
LKML-Reference: <20110201134418.611097203@linutronix.de>
---
 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,

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [tip:timers/core] posix-timers: Convert clock_getres() to clockid_to_kclock()
  2011-02-01 13:51 ` [patch 13/28] posix-timers: Convert clock_getres() " Thomas Gleixner
  2011-02-01 21:17   ` john stultz
@ 2011-02-02 22:00   ` tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: tip-bot for Thomas Gleixner @ 2011-02-02 22:00 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, johnstul, tglx, richard.cochran

Commit-ID:  e5e542eea9075dd008993c2ee80b2cc9f31fc494
Gitweb:     http://git.kernel.org/tip/e5e542eea9075dd008993c2ee80b2cc9f31fc494
Author:     Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Tue, 1 Feb 2011 13:51:53 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
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 <tglx@linutronix.de>
Acked-by: John Stultz <johnstul@us.ibm.com>
Tested-by: Richard Cochran <richard.cochran@omicron.at>
LKML-Reference: <20110201134418.709802797@linutronix.de>
---
 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;
 }

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [tip:timers/core] posix-timers: Remove useless res field from k_clock
  2011-02-01 13:51 ` [patch 14/28] posix-timers: Remove useless res field from k_clock Thomas Gleixner
  2011-02-01 21:18   ` john stultz
@ 2011-02-02 22:00   ` tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: tip-bot for Thomas Gleixner @ 2011-02-02 22:00 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, johnstul, tglx, richard.cochran

Commit-ID:  ebaac757acae0431e2c79c00e09f1debdabbddd7
Gitweb:     http://git.kernel.org/tip/ebaac757acae0431e2c79c00e09f1debdabbddd7
Author:     Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Tue, 1 Feb 2011 13:51:56 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 2 Feb 2011 15:28:15 +0100

posix-timers: Remove useless res field from k_clock

The res member of kclock is only used by mmtimer.c, but even there it
contains redundant information. Remove the field and fixup mmtimer.

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.808714587@linutronix.de>
---
 drivers/char/mmtimer.c       |    5 ++---
 include/linux/posix-timers.h |    1 -
 kernel/posix-timers.c        |    2 --
 3 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index 141ffae..ff41eb3 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -768,12 +768,11 @@ static int sgi_timer_set(struct k_itimer *timr, int flags,
 static int sgi_clock_getres(const clockid_t which_clock, struct timespec *tp)
 {
 	tp->tv_sec = 0;
-	tp->tv_nsec = sgi_clock.res;
+	tp->tv_nsec = sgi_clock_period;
 	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,
@@ -840,7 +839,7 @@ static int __init mmtimer_init(void)
 			(unsigned long) node);
 	}
 
-	sgi_clock_period = sgi_clock.res = NSEC_PER_SEC / sn_rtc_cycles_per_second;
+	sgi_clock_period = NSEC_PER_SEC / sn_rtc_cycles_per_second;
 	register_posix_clock(CLOCK_SGI_CYCLE, &sgi_clock);
 
 	printk(KERN_INFO "%s: v%s, %ld MHz\n", MMTIMER_DESC, MMTIMER_VERSION,
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 4aaf0c5..ef574d1 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -67,7 +67,6 @@ struct k_itimer {
 };
 
 struct k_clock {
-	int res;		/* in nanoseconds */
 	int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
 	int (*clock_set) (const clockid_t which_clock,
 			  const struct timespec *tp);
diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index 748497f..f9142a9 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -204,8 +204,6 @@ static inline int invalid_clockid(const clockid_t which_clock)
 		return 1;
 	if (posix_clocks[which_clock].clock_getres != NULL)
 		return 0;
-	if (posix_clocks[which_clock].res != 0)
-		return 0;
 	return 1;
 }
 

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [tip:timers/core] posix-timers: Convert timer_create() to clockid_to_kclock()
  2011-02-01 13:51 ` [patch 15/28] posix-timers: Convert timer_create() to clockid_to_kclock() Thomas Gleixner
  2011-02-01 21:20   ` john stultz
@ 2011-02-02 22:00   ` tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: tip-bot for Thomas Gleixner @ 2011-02-02 22:00 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, johnstul, tglx, richard.cochran

Commit-ID:  838394fbf989973ec7f5a0ad82cb6ff09e5c39aa
Gitweb:     http://git.kernel.org/tip/838394fbf989973ec7f5a0ad82cb6ff09e5c39aa
Author:     Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Tue, 1 Feb 2011 13:51:58 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
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 <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>
---
 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

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [tip:timers/core] posix-timers: Convert timer_settime() to clockid_to_kclock()
  2011-02-01 13:52 ` [patch 16/28] posix-timers: Convert timer_settime() " Thomas Gleixner
  2011-02-01 21:22   ` John Stultz
@ 2011-02-02 22:01   ` tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: tip-bot for Thomas Gleixner @ 2011-02-02 22:01 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, johnstul, tglx, richard.cochran

Commit-ID:  27722df16ef143017db55ac7baac1703a68017ff
Gitweb:     http://git.kernel.org/tip/27722df16ef143017db55ac7baac1703a68017ff
Author:     Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Tue, 1 Feb 2011 13:52:01 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 2 Feb 2011 15:28:16 +0100

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

Set the common function for CLOCK_MONOTONIC and CLOCK_REALTIME kclocks
and use the new decoding function.

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: <20110201134419.001863714@linutronix.de>
---
 kernel/posix-timers.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index 4f71382..a4dbfe7 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -252,6 +252,7 @@ static __init int init_posix_timers(void)
 		.nsleep		= common_nsleep,
 		.nsleep_restart	= hrtimer_nanosleep_restart,
 		.timer_create	= common_timer_create,
+		.timer_set	= common_timer_set,
 	};
 	struct k_clock clock_monotonic = {
 		.clock_getres	= hrtimer_get_res,
@@ -259,6 +260,7 @@ static __init int init_posix_timers(void)
 		.nsleep		= common_nsleep,
 		.nsleep_restart	= hrtimer_nanosleep_restart,
 		.timer_create	= common_timer_create,
+		.timer_set	= common_timer_set,
 	};
 	struct k_clock clock_monotonic_raw = {
 		.clock_getres	= hrtimer_get_res,
@@ -814,6 +816,7 @@ SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
 	int error = 0;
 	unsigned long flag;
 	struct itimerspec *rtn = old_setting ? &old_spec : NULL;
+	struct k_clock *kc;
 
 	if (!new_setting)
 		return -EINVAL;
@@ -829,8 +832,11 @@ retry:
 	if (!timr)
 		return -EINVAL;
 
-	error = CLOCK_DISPATCH(timr->it_clock, timer_set,
-			       (timr, flags, &new_spec, rtn));
+	kc = clockid_to_kclock(timr->it_clock);
+	if (WARN_ON_ONCE(!kc || !kc->timer_set))
+		error = -EINVAL;
+	else
+		error = kc->timer_set(timr, flags, &new_spec, rtn);
 
 	unlock_timer(timr, flag);
 	if (error == TIMER_RETRY) {

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [tip:timers/core] posix-timers: Convert timer_gettime() to clockid_to_kclock()
  2011-02-01 13:52 ` [patch 17/28] posix-timers: Convert timer_gettime() " Thomas Gleixner
  2011-02-01 21:23   ` john stultz
@ 2011-02-02 22:01   ` tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: tip-bot for Thomas Gleixner @ 2011-02-02 22:01 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, johnstul, tglx, richard.cochran

Commit-ID:  a7319fa253a549c4c6528fb550ae6e72a9c83811
Gitweb:     http://git.kernel.org/tip/a7319fa253a549c4c6528fb550ae6e72a9c83811
Author:     Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Tue, 1 Feb 2011 13:52:04 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 2 Feb 2011 15:28:16 +0100

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

Set the common function for CLOCK_MONOTONIC and CLOCK_REALTIME kclocks
and use the new decoding function.

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: <20110201134419.101243181@linutronix.de>
---
 kernel/posix-timers.c |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index a4dbfe7..c1e2636 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -253,6 +253,7 @@ static __init int init_posix_timers(void)
 		.nsleep_restart	= hrtimer_nanosleep_restart,
 		.timer_create	= common_timer_create,
 		.timer_set	= common_timer_set,
+		.timer_get	= common_timer_get,
 	};
 	struct k_clock clock_monotonic = {
 		.clock_getres	= hrtimer_get_res,
@@ -261,6 +262,7 @@ static __init int init_posix_timers(void)
 		.nsleep_restart	= hrtimer_nanosleep_restart,
 		.timer_create	= common_timer_create,
 		.timer_set	= common_timer_set,
+		.timer_get	= common_timer_get,
 	};
 	struct k_clock clock_monotonic_raw = {
 		.clock_getres	= hrtimer_get_res,
@@ -712,22 +714,28 @@ common_timer_get(struct k_itimer *timr, struct itimerspec *cur_setting)
 SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
 		struct itimerspec __user *, setting)
 {
-	struct k_itimer *timr;
 	struct itimerspec cur_setting;
+	struct k_itimer *timr;
+	struct k_clock *kc;
 	unsigned long flags;
+	int ret = 0;
 
 	timr = lock_timer(timer_id, &flags);
 	if (!timr)
 		return -EINVAL;
 
-	CLOCK_DISPATCH(timr->it_clock, timer_get, (timr, &cur_setting));
+	kc = clockid_to_kclock(timr->it_clock);
+	if (WARN_ON_ONCE(!kc || !kc->timer_get))
+		ret = -EINVAL;
+	else
+		kc->timer_get(timr, &cur_setting);
 
 	unlock_timer(timr, flags);
 
-	if (copy_to_user(setting, &cur_setting, sizeof (cur_setting)))
+	if (!ret && copy_to_user(setting, &cur_setting, sizeof (cur_setting)))
 		return -EFAULT;
 
-	return 0;
+	return ret;
 }
 
 /*

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [tip:timers/core] posix-timers: Convert timer_delete() to clockid_to_kclock()
  2011-02-01 13:52 ` [patch 18/28] posix-timers: Convert timer_delete() " Thomas Gleixner
  2011-02-01 21:24   ` john stultz
  2011-02-02  8:29   ` Richard Cochran
@ 2011-02-02 22:02   ` tip-bot for Thomas Gleixner
  2 siblings, 0 replies; 111+ messages in thread
From: tip-bot for Thomas Gleixner @ 2011-02-02 22:02 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, johnstul, tglx, richard.cochran

Commit-ID:  6761c6702e2c647582e1829abe8cf90794f61d9d
Gitweb:     http://git.kernel.org/tip/6761c6702e2c647582e1829abe8cf90794f61d9d
Author:     Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Tue, 1 Feb 2011 13:52:07 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 2 Feb 2011 15:28:17 +0100

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

Set the common function for CLOCK_MONOTONIC and CLOCK_REALTIME kclocks
and use the new decoding function.

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: <20110201134419.198999420@linutronix.de>
---
 kernel/posix-timers.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index c1e2636..ade7dec 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -254,6 +254,7 @@ static __init int init_posix_timers(void)
 		.timer_create	= common_timer_create,
 		.timer_set	= common_timer_set,
 		.timer_get	= common_timer_get,
+		.timer_del	= common_timer_del,
 	};
 	struct k_clock clock_monotonic = {
 		.clock_getres	= hrtimer_get_res,
@@ -263,6 +264,7 @@ static __init int init_posix_timers(void)
 		.timer_create	= common_timer_create,
 		.timer_set	= common_timer_set,
 		.timer_get	= common_timer_get,
+		.timer_del	= common_timer_del,
 	};
 	struct k_clock clock_monotonic_raw = {
 		.clock_getres	= hrtimer_get_res,
@@ -859,7 +861,7 @@ retry:
 	return error;
 }
 
-static inline int common_timer_del(struct k_itimer *timer)
+static int common_timer_del(struct k_itimer *timer)
 {
 	timer->it.real.interval.tv64 = 0;
 
@@ -870,7 +872,11 @@ static inline int common_timer_del(struct k_itimer *timer)
 
 static inline int timer_delete_hook(struct k_itimer *timer)
 {
-	return CLOCK_DISPATCH(timer->it_clock, timer_del, (timer));
+	struct k_clock *kc = clockid_to_kclock(timer->it_clock);
+
+	if (WARN_ON_ONCE(!kc || !kc->timer_del))
+		return -EINVAL;
+	return kc->timer_del(timer);
 }
 
 /* Delete a POSIX.1b interval timer. */

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [tip:timers/core] posix-timers: Remove CLOCK_DISPATCH leftovers
  2011-02-01 13:52 ` [patch 19/28] posix-timers: Remove CLOCK_DISPATCH leftovers Thomas Gleixner
  2011-02-01 21:25   ` john stultz
@ 2011-02-02 22:02   ` tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: tip-bot for Thomas Gleixner @ 2011-02-02 22:02 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, johnstul, tglx, richard.cochran

Commit-ID:  0aa3975f02ce78f27be3076fbfa3d94ae5a659d5
Gitweb:     http://git.kernel.org/tip/0aa3975f02ce78f27be3076fbfa3d94ae5a659d5
Author:     Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Tue, 1 Feb 2011 13:52:09 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 2 Feb 2011 15:28:17 +0100

posix-timers: Remove CLOCK_DISPATCH leftovers

All users gone. Remove the cruft.

Huge thanks to Richard Cochran who tackled that maze first.

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: <20110201134419.294620613@linutronix.de>
---
 kernel/posix-timers.c |   22 ----------------------
 1 files changed, 0 insertions(+), 22 deletions(-)

diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index ade7dec..ad154df 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -167,28 +167,6 @@ static inline void unlock_timer(struct k_itimer *timr, unsigned long flags)
 	spin_unlock_irqrestore(&timr->it_lock, flags);
 }
 
-/*
- * Call the k_clock hook function if non-null, or the default function.
- */
-#define CLOCK_DISPATCH(clock, call, arglist) \
- 	((clock) < 0 ? posix_cpu_##call arglist : \
- 	 (posix_clocks[clock].call != NULL \
- 	  ? (*posix_clocks[clock].call) arglist : common_##call arglist))
-
-/*
- * Return nonzero if we know a priori this clockid_t value is bogus.
- */
-static inline int invalid_clockid(const clockid_t which_clock)
-{
-	if (which_clock < 0)	/* CPU clock, posix_cpu_* will check it */
-		return 0;
-	if ((unsigned) which_clock >= MAX_CLOCKS)
-		return 1;
-	if (posix_clocks[which_clock].clock_getres != NULL)
-		return 0;
-	return 1;
-}
-
 /* Get clock_realtime */
 static int posix_clock_realtime_get(clockid_t which_clock, struct timespec *tp)
 {

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [tip:timers/core] posix-timers: Make posix-cpu-timers functions static
  2011-02-01 13:52 ` [patch 20/28] posix-timers: Make posix-cpu-timers functions static Thomas Gleixner
  2011-02-01 21:28   ` John Stultz
@ 2011-02-02 22:03   ` tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 111+ messages in thread
From: tip-bot for Thomas Gleixner @ 2011-02-02 22:03 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, johnstul, tglx, richard.cochran

Commit-ID:  bc2c8ea483d73e95fc88f1fc9e7755180f89b892
Gitweb:     http://git.kernel.org/tip/bc2c8ea483d73e95fc88f1fc9e7755180f89b892
Author:     Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Tue, 1 Feb 2011 13:52:12 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 2 Feb 2011 15:28:17 +0100

posix-timers: Make posix-cpu-timers functions static

All functions are accessed via clock_posix_cpu now. So make them static.

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: <20110201134419.389755466@linutronix.de>
---
 include/linux/posix-timers.h |   12 ------------
 kernel/posix-cpu-timers.c    |   27 +++++++++++++++------------
 2 files changed, 15 insertions(+), 24 deletions(-)

diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index ef574d1..8206255 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -91,18 +91,6 @@ void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock);
 /* function to call to trigger timer event */
 int posix_timer_event(struct k_itimer *timr, int si_private);
 
-int posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *ts);
-int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *ts);
-int posix_cpu_clock_set(const clockid_t which_clock, const struct timespec *ts);
-int posix_cpu_timer_create(struct k_itimer *timer);
-int posix_cpu_nsleep(const clockid_t which_clock, int flags,
-		     struct timespec *rqtp, struct timespec __user *rmtp);
-long posix_cpu_nsleep_restart(struct restart_block *restart_block);
-int posix_cpu_timer_set(struct k_itimer *timer, int flags,
-			struct itimerspec *new, struct itimerspec *old);
-int posix_cpu_timer_del(struct k_itimer *timer);
-void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp);
-
 void posix_cpu_timer_schedule(struct k_itimer *timer);
 
 void run_posix_cpu_timers(struct task_struct *task);
diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
index 504fbab..609e187 100644
--- a/kernel/posix-cpu-timers.c
+++ b/kernel/posix-cpu-timers.c
@@ -176,7 +176,8 @@ static inline cputime_t virt_ticks(struct task_struct *p)
 	return p->utime;
 }
 
-int posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *tp)
+static int
+posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *tp)
 {
 	int error = check_clock(which_clock);
 	if (!error) {
@@ -194,7 +195,8 @@ int posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *tp)
 	return error;
 }
 
-int posix_cpu_clock_set(const clockid_t which_clock, const struct timespec *tp)
+static int
+posix_cpu_clock_set(const clockid_t which_clock, const struct timespec *tp)
 {
 	/*
 	 * You can never reset a CPU clock, but we check for other errors
@@ -317,7 +319,7 @@ static int cpu_clock_sample_group(const clockid_t which_clock,
 }
 
 
-int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *tp)
+static int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *tp)
 {
 	const pid_t pid = CPUCLOCK_PID(which_clock);
 	int error = -EINVAL;
@@ -379,7 +381,7 @@ int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *tp)
  * This is called from sys_timer_create() and do_cpu_nanosleep() with the
  * new timer already all-zeros initialized.
  */
-int posix_cpu_timer_create(struct k_itimer *new_timer)
+static int posix_cpu_timer_create(struct k_itimer *new_timer)
 {
 	int ret = 0;
 	const pid_t pid = CPUCLOCK_PID(new_timer->it_clock);
@@ -425,7 +427,7 @@ int posix_cpu_timer_create(struct k_itimer *new_timer)
  * If we return TIMER_RETRY, it's necessary to release the timer's lock
  * and try again.  (This happens when the timer is in the middle of firing.)
  */
-int posix_cpu_timer_del(struct k_itimer *timer)
+static int posix_cpu_timer_del(struct k_itimer *timer)
 {
 	struct task_struct *p = timer->it.cpu.task;
 	int ret = 0;
@@ -665,8 +667,8 @@ static int cpu_timer_sample_group(const clockid_t which_clock,
  * If we return TIMER_RETRY, it's necessary to release the timer's lock
  * and try again.  (This happens when the timer is in the middle of firing.)
  */
-int posix_cpu_timer_set(struct k_itimer *timer, int flags,
-			struct itimerspec *new, struct itimerspec *old)
+static int posix_cpu_timer_set(struct k_itimer *timer, int flags,
+			       struct itimerspec *new, struct itimerspec *old)
 {
 	struct task_struct *p = timer->it.cpu.task;
 	union cpu_time_count old_expires, new_expires, old_incr, val;
@@ -820,7 +822,7 @@ int posix_cpu_timer_set(struct k_itimer *timer, int flags,
 	return ret;
 }
 
-void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp)
+static void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp)
 {
 	union cpu_time_count now;
 	struct task_struct *p = timer->it.cpu.task;
@@ -1481,8 +1483,10 @@ static int do_cpu_nanosleep(const clockid_t which_clock, int flags,
 	return error;
 }
 
-int posix_cpu_nsleep(const clockid_t which_clock, int flags,
-		     struct timespec *rqtp, struct timespec __user *rmtp)
+static long posix_cpu_nsleep_restart(struct restart_block *restart_block);
+
+static int posix_cpu_nsleep(const clockid_t which_clock, int flags,
+			    struct timespec *rqtp, struct timespec __user *rmtp)
 {
 	struct restart_block *restart_block =
 		&current_thread_info()->restart_block;
@@ -1517,7 +1521,7 @@ int posix_cpu_nsleep(const clockid_t which_clock, int flags,
 	return error;
 }
 
-long posix_cpu_nsleep_restart(struct restart_block *restart_block)
+static long posix_cpu_nsleep_restart(struct restart_block *restart_block)
 {
 	clockid_t which_clock = restart_block->nanosleep.index;
 	struct timespec t;
@@ -1542,7 +1546,6 @@ long posix_cpu_nsleep_restart(struct restart_block *restart_block)
 
 }
 
-
 #define PROCESS_CLOCK	MAKE_PROCESS_CPUCLOCK(0, CPUCLOCK_SCHED)
 #define THREAD_CLOCK	MAKE_THREAD_CPUCLOCK(0, CPUCLOCK_SCHED)
 

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [tip:timers/core] posix-timer: Update comment
  2011-02-01 13:52 ` [patch 21/28] posix-timer: Update comment Thomas Gleixner
  2011-02-01 21:28   ` john stultz
@ 2011-02-02 22:03   ` tip-bot for Richard Cochran
  1 sibling, 0 replies; 111+ messages in thread
From: tip-bot for Richard Cochran @ 2011-02-02 22:03 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, johnstul, richardcochran, tglx

Commit-ID:  0061748dd2400d0bcd4d49d258db5d7b5d106ca0
Gitweb:     http://git.kernel.org/tip/0061748dd2400d0bcd4d49d258db5d7b5d106ca0
Author:     Richard Cochran <richardcochran@gmail.com>
AuthorDate: Tue, 1 Feb 2011 13:52:15 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 2 Feb 2011 15:28:18 +0100

posix-timer: Update comment

Pick the cleanup to the comment in posix-timers.c from Richards all in
one conversion patch.

Originally-from: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: John Stultz <johnstul@us.ibm.com>
LKML-Reference: <20110201134419.487708516@linutronix.de>
---
 kernel/posix-timers.c |   25 +++++++------------------
 1 files changed, 7 insertions(+), 18 deletions(-)

diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index ad154df..a3fdfd4 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -102,11 +102,7 @@ static DEFINE_SPINLOCK(idr_lock);
 /*
  * CLOCKs: The POSIX standard calls for a couple of clocks and allows us
  *	    to implement others.  This structure defines the various
- *	    clocks and allows the possibility of adding others.	 We
- *	    provide an interface to add clocks to the table and expect
- *	    the "arch" code to add at least one clock that is high
- *	    resolution.	 Here we define the standard CLOCK_REALTIME as a
- *	    1/HZ resolution clock.
+ *	    clocks.
  *
  * RESOLUTION: Clock resolution is used to round up timer and interval
  *	    times, NOT to report clock times, which are reported with as
@@ -116,20 +112,13 @@ static DEFINE_SPINLOCK(idr_lock);
  *	    necessary code is written.	The standard says we should say
  *	    something about this issue in the documentation...
  *
- * FUNCTIONS: The CLOCKs structure defines possible functions to handle
- *	    various clock functions.  For clocks that use the standard
- *	    system timer code these entries should be NULL.  This will
- *	    allow dispatch without the overhead of indirect function
- *	    calls.  CLOCKS that depend on other sources (e.g. WWV or GPS)
- *	    must supply functions here, even if the function just returns
- *	    ENOSYS.  The standard POSIX timer management code assumes the
- *	    following: 1.) The k_itimer struct (sched.h) is used for the
- *	    timer.  2.) The list, it_lock, it_clock, it_id and it_pid
- *	    fields are not modified by timer code.
+ * FUNCTIONS: The CLOCKs structure defines possible functions to
+ *	    handle various clock functions.
  *
- *          At this time all functions EXCEPT clock_nanosleep can be
- *          redirected by the CLOCKS structure.  Clock_nanosleep is in
- *          there, but the code ignores it.
+ *	    The standard POSIX timer management code assumes the
+ *	    following: 1.) The k_itimer struct (sched.h) is used for
+ *	    the timer.  2.) The list, it_lock, it_clock, it_id and
+ *	    it_pid fields are not modified by timer code.
  *
  * Permissions: It is assumed that the clock_settime() function defined
  *	    for each clock will take care of permission checks.	 Some

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [tip:timers/core] time: Introduce timekeeping_inject_offset
  2011-02-01 13:52 ` [patch 22/28] time: Introduce timekeeping_inject_offset Thomas Gleixner
@ 2011-02-02 22:03   ` tip-bot for John Stultz
  0 siblings, 0 replies; 111+ messages in thread
From: tip-bot for John Stultz @ 2011-02-02 22:03 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, john.stultz, hpa, mingo, tglx, richard.cochran

Commit-ID:  c528f7c6c208f1fae6b4025957173dec045e5f21
Gitweb:     http://git.kernel.org/tip/c528f7c6c208f1fae6b4025957173dec045e5f21
Author:     John Stultz <john.stultz@linaro.org>
AuthorDate: Tue, 1 Feb 2011 13:52:17 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 2 Feb 2011 15:28:18 +0100

time: Introduce timekeeping_inject_offset

This adds a kernel-internal timekeeping interface to add or subtract
a fixed amount from CLOCK_REALTIME. This makes it so kernel users or
interfaces trying to do so do not have to read the time, then add an
offset and then call settimeofday(), which adds some extra error in
comparision to just simply adding the offset in the kernel timekeeping
core.

Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Richard Cochran <richard.cochran@omicron.at>
LKML-Reference: <20110201134419.584311693@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 include/linux/time.h      |    1 +
 kernel/time/timekeeping.c |   36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/include/linux/time.h b/include/linux/time.h
index 7c44e77..379b903 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -166,6 +166,7 @@ extern struct timespec timespec_trunc(struct timespec t, unsigned gran);
 extern int timekeeping_valid_for_hres(void);
 extern u64 timekeeping_max_deferment(void);
 extern void timekeeping_leap_insert(int leapsecond);
+extern int timekeeping_inject_offset(struct timespec *ts);
 
 struct tms;
 extern void do_sys_times(struct tms *);
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 4f9f65b..6262c1d 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -387,6 +387,42 @@ int do_settimeofday(const struct timespec *tv)
 
 EXPORT_SYMBOL(do_settimeofday);
 
+
+/**
+ * timekeeping_inject_offset - Adds or subtracts from the current time.
+ * @tv:		pointer to the timespec variable containing the offset
+ *
+ * Adds or subtracts an offset value from the current time.
+ */
+int timekeeping_inject_offset(struct timespec *ts)
+{
+	unsigned long flags;
+
+	if ((unsigned long)ts->tv_nsec >= NSEC_PER_SEC)
+		return -EINVAL;
+
+	write_seqlock_irqsave(&xtime_lock, flags);
+
+	timekeeping_forward_now();
+
+	xtime = timespec_add(xtime, *ts);
+	wall_to_monotonic = timespec_sub(wall_to_monotonic, *ts);
+
+	timekeeper.ntp_error = 0;
+	ntp_clear();
+
+	update_vsyscall(&xtime, &wall_to_monotonic, timekeeper.clock,
+				timekeeper.mult);
+
+	write_sequnlock_irqrestore(&xtime_lock, flags);
+
+	/* signal hrtimers about time change */
+	clock_was_set();
+
+	return 0;
+}
+EXPORT_SYMBOL(timekeeping_inject_offset);
+
 /**
  * change_clocksource - Swaps clocksources if a new one is available
  *

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [tip:timers/core] ntp: Add ADJ_SETOFFSET mode bit
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
                   ` (29 preceding siblings ...)
  2011-02-02 13:53 ` Richard Cochran
@ 2011-02-02 22:04 ` tip-bot for Richard Cochran
  2011-02-18  9:07   ` Richard Cochran
  2011-03-01 15:38 ` [patch 00/28] Rework of the PTP support series core code torbenh
  31 siblings, 1 reply; 111+ messages in thread
From: tip-bot for Richard Cochran @ 2011-02-02 22:04 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, johnstul, richardcochran, tglx,
	richard.cochran

Commit-ID:  094aa1881fdc1b8889b442eb3511b31f3ec2b762
Gitweb:     http://git.kernel.org/tip/094aa1881fdc1b8889b442eb3511b31f3ec2b762
Author:     Richard Cochran <richardcochran@gmail.com>
AuthorDate: Tue, 1 Feb 2011 13:52:20 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 2 Feb 2011 15:28:18 +0100

ntp: Add ADJ_SETOFFSET mode bit

This patch adds a new mode bit into the timex structure. When set, the bit
instructs the kernel to add the given time value to the current time.

Signed-off-by: Richard Cochran <richard.cochran@omicron.at>
Acked-by: John Stultz <johnstul@us.ibm.com>
LKML-Reference: <20110201134320.688829863@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 include/linux/timex.h |    3 ++-
 kernel/time/ntp.c     |   11 +++++++++++
 2 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/include/linux/timex.h b/include/linux/timex.h
index d23999f..aa60fe7 100644
--- a/include/linux/timex.h
+++ b/include/linux/timex.h
@@ -73,7 +73,7 @@ struct timex {
 	long tolerance;		/* clock frequency tolerance (ppm)
 				 * (read only)
 				 */
-	struct timeval time;	/* (read only) */
+	struct timeval time;	/* (read only, except for ADJ_SETOFFSET) */
 	long tick;		/* (modified) usecs between clock ticks */
 
 	long ppsfreq;           /* pps frequency (scaled ppm) (ro) */
@@ -102,6 +102,7 @@ struct timex {
 #define ADJ_STATUS		0x0010	/* clock status */
 #define ADJ_TIMECONST		0x0020	/* pll time constant */
 #define ADJ_TAI			0x0080	/* set TAI offset */
+#define ADJ_SETOFFSET		0x0100  /* add 'time' to current time */
 #define ADJ_MICRO		0x1000	/* select microsecond resolution */
 #define ADJ_NANO		0x2000	/* select nanosecond resolution */
 #define ADJ_TICK		0x4000	/* tick value */
diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index ed8cfdf..5ac5932 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -648,6 +648,17 @@ int do_adjtimex(struct timex *txc)
 			hrtimer_cancel(&leap_timer);
 	}
 
+	if (txc->modes & ADJ_SETOFFSET) {
+		struct timespec delta;
+		if ((unsigned long)txc->time.tv_usec >= NSEC_PER_SEC)
+			return -EINVAL;
+		delta.tv_sec  = txc->time.tv_sec;
+		delta.tv_nsec = txc->time.tv_usec;
+		if (!(txc->modes & ADJ_NANO))
+			delta.tv_nsec *= 1000;
+		timekeeping_inject_offset(&delta);
+	}
+
 	getnstimeofday(&ts);
 
 	write_seqlock_irq(&xtime_lock);

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [tip:timers/core] time: Splitout compat timex accessors
  2011-02-01 13:52 ` [patch 24/28] posix-clocks: Splitout compat timex accessors Thomas Gleixner
  2011-02-01 21:31   ` john stultz
@ 2011-02-02 22:04   ` tip-bot for Richard Cochran
  1 sibling, 0 replies; 111+ messages in thread
From: tip-bot for Richard Cochran @ 2011-02-02 22:04 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, johnstul, richardcochran, tglx

Commit-ID:  65f5d80bdf83ec0d7f3887db10153bf3f36ed73c
Gitweb:     http://git.kernel.org/tip/65f5d80bdf83ec0d7f3887db10153bf3f36ed73c
Author:     Richard Cochran <richardcochran@gmail.com>
AuthorDate: Tue, 1 Feb 2011 13:52:23 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 2 Feb 2011 15:28:18 +0100

time: Splitout compat timex accessors

Split out the compat timex accessors into separate
functions. Preparatory patch for a new syscall.

[ tglx: Split that patch from Richards "posix-timers: Introduce a
  	syscall for clock tuning.". Keeps the changes strictly
  	separate ]

Originally-from: Richard Cochran <richardcochran@gmail.com>
Acked-by: John Stultz <johnstul@us.ibm.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
LKML-Reference: <20110201134419.772343089@linutronix.de>
---
 kernel/compat.c |  113 +++++++++++++++++++++++++++++++-----------------------
 1 files changed, 65 insertions(+), 48 deletions(-)

diff --git a/kernel/compat.c b/kernel/compat.c
index c9e2ec0..449e853 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -52,6 +52,64 @@ static int compat_put_timeval(struct compat_timeval __user *o,
 		put_user(i->tv_usec, &o->tv_usec)) ? -EFAULT : 0;
 }
 
+static int compat_get_timex(struct timex *txc, struct compat_timex __user *utp)
+{
+	memset(txc, 0, sizeof(struct timex));
+
+	if (!access_ok(VERIFY_READ, utp, sizeof(struct compat_timex)) ||
+			__get_user(txc->modes, &utp->modes) ||
+			__get_user(txc->offset, &utp->offset) ||
+			__get_user(txc->freq, &utp->freq) ||
+			__get_user(txc->maxerror, &utp->maxerror) ||
+			__get_user(txc->esterror, &utp->esterror) ||
+			__get_user(txc->status, &utp->status) ||
+			__get_user(txc->constant, &utp->constant) ||
+			__get_user(txc->precision, &utp->precision) ||
+			__get_user(txc->tolerance, &utp->tolerance) ||
+			__get_user(txc->time.tv_sec, &utp->time.tv_sec) ||
+			__get_user(txc->time.tv_usec, &utp->time.tv_usec) ||
+			__get_user(txc->tick, &utp->tick) ||
+			__get_user(txc->ppsfreq, &utp->ppsfreq) ||
+			__get_user(txc->jitter, &utp->jitter) ||
+			__get_user(txc->shift, &utp->shift) ||
+			__get_user(txc->stabil, &utp->stabil) ||
+			__get_user(txc->jitcnt, &utp->jitcnt) ||
+			__get_user(txc->calcnt, &utp->calcnt) ||
+			__get_user(txc->errcnt, &utp->errcnt) ||
+			__get_user(txc->stbcnt, &utp->stbcnt))
+		return -EFAULT;
+
+	return 0;
+}
+
+static int compat_put_timex(struct compat_timex __user *utp, struct timex *txc)
+{
+	if (!access_ok(VERIFY_WRITE, utp, sizeof(struct compat_timex)) ||
+			__put_user(txc->modes, &utp->modes) ||
+			__put_user(txc->offset, &utp->offset) ||
+			__put_user(txc->freq, &utp->freq) ||
+			__put_user(txc->maxerror, &utp->maxerror) ||
+			__put_user(txc->esterror, &utp->esterror) ||
+			__put_user(txc->status, &utp->status) ||
+			__put_user(txc->constant, &utp->constant) ||
+			__put_user(txc->precision, &utp->precision) ||
+			__put_user(txc->tolerance, &utp->tolerance) ||
+			__put_user(txc->time.tv_sec, &utp->time.tv_sec) ||
+			__put_user(txc->time.tv_usec, &utp->time.tv_usec) ||
+			__put_user(txc->tick, &utp->tick) ||
+			__put_user(txc->ppsfreq, &utp->ppsfreq) ||
+			__put_user(txc->jitter, &utp->jitter) ||
+			__put_user(txc->shift, &utp->shift) ||
+			__put_user(txc->stabil, &utp->stabil) ||
+			__put_user(txc->jitcnt, &utp->jitcnt) ||
+			__put_user(txc->calcnt, &utp->calcnt) ||
+			__put_user(txc->errcnt, &utp->errcnt) ||
+			__put_user(txc->stbcnt, &utp->stbcnt) ||
+			__put_user(txc->tai, &utp->tai))
+		return -EFAULT;
+	return 0;
+}
+
 asmlinkage long compat_sys_gettimeofday(struct compat_timeval __user *tv,
 		struct timezone __user *tz)
 {
@@ -951,58 +1009,17 @@ asmlinkage long compat_sys_rt_sigsuspend(compat_sigset_t __user *unewset, compat
 asmlinkage long compat_sys_adjtimex(struct compat_timex __user *utp)
 {
 	struct timex txc;
-	int ret;
+	int err, ret;
 
-	memset(&txc, 0, sizeof(struct timex));
-
-	if (!access_ok(VERIFY_READ, utp, sizeof(struct compat_timex)) ||
-			__get_user(txc.modes, &utp->modes) ||
-			__get_user(txc.offset, &utp->offset) ||
-			__get_user(txc.freq, &utp->freq) ||
-			__get_user(txc.maxerror, &utp->maxerror) ||
-			__get_user(txc.esterror, &utp->esterror) ||
-			__get_user(txc.status, &utp->status) ||
-			__get_user(txc.constant, &utp->constant) ||
-			__get_user(txc.precision, &utp->precision) ||
-			__get_user(txc.tolerance, &utp->tolerance) ||
-			__get_user(txc.time.tv_sec, &utp->time.tv_sec) ||
-			__get_user(txc.time.tv_usec, &utp->time.tv_usec) ||
-			__get_user(txc.tick, &utp->tick) ||
-			__get_user(txc.ppsfreq, &utp->ppsfreq) ||
-			__get_user(txc.jitter, &utp->jitter) ||
-			__get_user(txc.shift, &utp->shift) ||
-			__get_user(txc.stabil, &utp->stabil) ||
-			__get_user(txc.jitcnt, &utp->jitcnt) ||
-			__get_user(txc.calcnt, &utp->calcnt) ||
-			__get_user(txc.errcnt, &utp->errcnt) ||
-			__get_user(txc.stbcnt, &utp->stbcnt))
-		return -EFAULT;
+	err = compat_get_timex(&txc, utp);
+	if (err)
+		return err;
 
 	ret = do_adjtimex(&txc);
 
-	if (!access_ok(VERIFY_WRITE, utp, sizeof(struct compat_timex)) ||
-			__put_user(txc.modes, &utp->modes) ||
-			__put_user(txc.offset, &utp->offset) ||
-			__put_user(txc.freq, &utp->freq) ||
-			__put_user(txc.maxerror, &utp->maxerror) ||
-			__put_user(txc.esterror, &utp->esterror) ||
-			__put_user(txc.status, &utp->status) ||
-			__put_user(txc.constant, &utp->constant) ||
-			__put_user(txc.precision, &utp->precision) ||
-			__put_user(txc.tolerance, &utp->tolerance) ||
-			__put_user(txc.time.tv_sec, &utp->time.tv_sec) ||
-			__put_user(txc.time.tv_usec, &utp->time.tv_usec) ||
-			__put_user(txc.tick, &utp->tick) ||
-			__put_user(txc.ppsfreq, &utp->ppsfreq) ||
-			__put_user(txc.jitter, &utp->jitter) ||
-			__put_user(txc.shift, &utp->shift) ||
-			__put_user(txc.stabil, &utp->stabil) ||
-			__put_user(txc.jitcnt, &utp->jitcnt) ||
-			__put_user(txc.calcnt, &utp->calcnt) ||
-			__put_user(txc.errcnt, &utp->errcnt) ||
-			__put_user(txc.stbcnt, &utp->stbcnt) ||
-			__put_user(txc.tai, &utp->tai))
-		ret = -EFAULT;
+	err = compat_put_timex(utp, &txc);
+	if (err)
+		return err;
 
 	return ret;
 }

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [tip:timers/core] posix-timers: Introduce a syscall for clock tuning.
  2011-02-01 13:52 ` [patch 25/28] posix clocks: Introduce a syscall for clock tuning Thomas Gleixner
  2011-02-01 21:35   ` john stultz
@ 2011-02-02 22:04   ` tip-bot for Richard Cochran
  1 sibling, 0 replies; 111+ messages in thread
From: tip-bot for Richard Cochran @ 2011-02-02 22:04 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, johnstul, richardcochran, tglx,
	richard.cochran

Commit-ID:  f1f1d5ebd10ffa4242bce7a90a56a222d6b7bc77
Gitweb:     http://git.kernel.org/tip/f1f1d5ebd10ffa4242bce7a90a56a222d6b7bc77
Author:     Richard Cochran <richardcochran@gmail.com>
AuthorDate: Tue, 1 Feb 2011 13:52:26 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 2 Feb 2011 15:28:19 +0100

posix-timers: Introduce a syscall for clock tuning.

A new syscall is introduced that allows tuning of a POSIX clock. The
new call, clock_adjtime, takes two parameters, the clock ID and a
pointer to a struct timex. Any ADJTIMEX(2) operation may be requested
via this system call, but various POSIX clocks may or may not support
tuning.

[ tglx: Adapted to the posix-timer cleanup series. Avoid copy_to_user
  	in the error case ]

Signed-off-by: Richard Cochran <richard.cochran@omicron.at>
Acked-by: John Stultz <johnstul@us.ibm.com>
LKML-Reference: <20110201134419.869804645@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 include/linux/posix-timers.h |    2 ++
 include/linux/syscalls.h     |    2 ++
 kernel/compat.c              |   23 +++++++++++++++++++++++
 kernel/posix-timers.c        |   30 ++++++++++++++++++++++++++++++
 4 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 8206255..79a1cea 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -4,6 +4,7 @@
 #include <linux/spinlock.h>
 #include <linux/list.h>
 #include <linux/sched.h>
+#include <linux/timex.h>
 
 union cpu_time_count {
 	cputime_t cpu;
@@ -71,6 +72,7 @@ struct k_clock {
 	int (*clock_set) (const clockid_t which_clock,
 			  const struct timespec *tp);
 	int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
+	int (*clock_adj) (const clockid_t which_clock, struct timex *tx);
 	int (*timer_create) (struct k_itimer *timer);
 	int (*nsleep) (const clockid_t which_clock, int flags,
 		       struct timespec *, struct timespec __user *);
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 18cd068..bfacab9 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -311,6 +311,8 @@ asmlinkage long sys_clock_settime(clockid_t which_clock,
 				const struct timespec __user *tp);
 asmlinkage long sys_clock_gettime(clockid_t which_clock,
 				struct timespec __user *tp);
+asmlinkage long sys_clock_adjtime(clockid_t which_clock,
+				struct timex __user *tx);
 asmlinkage long sys_clock_getres(clockid_t which_clock,
 				struct timespec __user *tp);
 asmlinkage long sys_clock_nanosleep(clockid_t which_clock, int flags,
diff --git a/kernel/compat.c b/kernel/compat.c
index 449e853..38b1d2c 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -675,6 +675,29 @@ long compat_sys_clock_gettime(clockid_t which_clock,
 	return err;
 }
 
+long compat_sys_clock_adjtime(clockid_t which_clock,
+		struct compat_timex __user *utp)
+{
+	struct timex txc;
+	mm_segment_t oldfs;
+	int err, ret;
+
+	err = compat_get_timex(&txc, utp);
+	if (err)
+		return err;
+
+	oldfs = get_fs();
+	set_fs(KERNEL_DS);
+	ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
+	set_fs(oldfs);
+
+	err = compat_put_timex(utp, &txc);
+	if (err)
+		return err;
+
+	return ret;
+}
+
 long compat_sys_clock_getres(clockid_t which_clock,
 		struct compat_timespec __user *tp)
 {
diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index a3fdfd4..5a5a4f1 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -170,6 +170,12 @@ static int posix_clock_realtime_set(const clockid_t which_clock,
 	return do_sys_settimeofday(tp, NULL);
 }
 
+static int posix_clock_realtime_adj(const clockid_t which_clock,
+				    struct timex *t)
+{
+	return do_adjtimex(t);
+}
+
 /*
  * Get monotonic time for posix timers
  */
@@ -216,6 +222,7 @@ static __init int init_posix_timers(void)
 		.clock_getres	= hrtimer_get_res,
 		.clock_get	= posix_clock_realtime_get,
 		.clock_set	= posix_clock_realtime_set,
+		.clock_adj	= posix_clock_realtime_adj,
 		.nsleep		= common_nsleep,
 		.nsleep_restart	= hrtimer_nanosleep_restart,
 		.timer_create	= common_timer_create,
@@ -948,6 +955,29 @@ SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
 	return error;
 }
 
+SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock,
+		struct timex __user *, utx)
+{
+	struct k_clock *kc = clockid_to_kclock(which_clock);
+	struct timex ktx;
+	int err;
+
+	if (!kc)
+		return -EINVAL;
+	if (!kc->clock_adj)
+		return -EOPNOTSUPP;
+
+	if (copy_from_user(&ktx, utx, sizeof(ktx)))
+		return -EFAULT;
+
+	err = kc->clock_adj(which_clock, &ktx);
+
+	if (!err && copy_to_user(utx, &ktx, sizeof(ktx)))
+		return -EFAULT;
+
+	return err;
+}
+
 SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock,
 		struct timespec __user *, tp)
 {

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [tip:timers/core] x86: Add clock_adjtime for x86
  2011-02-01 13:52 ` [patch 26/28] posix_clocks: Add clock_adjtime for x86 Thomas Gleixner
  2011-02-01 21:36   ` john stultz
@ 2011-02-02 22:05   ` tip-bot for Richard Cochran
  1 sibling, 0 replies; 111+ messages in thread
From: tip-bot for Richard Cochran @ 2011-02-02 22:05 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, johnstul, tglx, richard.cochran

Commit-ID:  ce26efdefa5e8f22d933df72d7f7482725091d6d
Gitweb:     http://git.kernel.org/tip/ce26efdefa5e8f22d933df72d7f7482725091d6d
Author:     Richard Cochran <richard.cochran@omicron.at>
AuthorDate: Tue, 1 Feb 2011 13:52:30 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 2 Feb 2011 15:28:19 +0100

x86: Add clock_adjtime for x86

This patch adds the clock_adjtime system call to the x86 architecture.

Signed-off-by: Richard Cochran <richard.cochran@omicron.at>
Acked-by: John Stultz <johnstul@us.ibm.com>
LKML-Reference: <20110201134419.968905083@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 arch/x86/ia32/ia32entry.S          |    1 +
 arch/x86/include/asm/unistd_32.h   |    3 ++-
 arch/x86/include/asm/unistd_64.h   |    2 ++
 arch/x86/kernel/syscall_table_32.S |    1 +
 4 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
index 518bb99..0ed7896 100644
--- a/arch/x86/ia32/ia32entry.S
+++ b/arch/x86/ia32/ia32entry.S
@@ -851,4 +851,5 @@ ia32_sys_call_table:
 	.quad sys_fanotify_init
 	.quad sys32_fanotify_mark
 	.quad sys_prlimit64		/* 340 */
+	.quad compat_sys_clock_adjtime
 ia32_syscall_end:
diff --git a/arch/x86/include/asm/unistd_32.h b/arch/x86/include/asm/unistd_32.h
index b766a5e..b6f73f1 100644
--- a/arch/x86/include/asm/unistd_32.h
+++ b/arch/x86/include/asm/unistd_32.h
@@ -346,10 +346,11 @@
 #define __NR_fanotify_init	338
 #define __NR_fanotify_mark	339
 #define __NR_prlimit64		340
+#define __NR_clock_adjtime	341
 
 #ifdef __KERNEL__
 
-#define NR_syscalls 341
+#define NR_syscalls 342
 
 #define __ARCH_WANT_IPC_PARSE_VERSION
 #define __ARCH_WANT_OLD_READDIR
diff --git a/arch/x86/include/asm/unistd_64.h b/arch/x86/include/asm/unistd_64.h
index 363e9b8..5ee3085 100644
--- a/arch/x86/include/asm/unistd_64.h
+++ b/arch/x86/include/asm/unistd_64.h
@@ -669,6 +669,8 @@ __SYSCALL(__NR_fanotify_init, sys_fanotify_init)
 __SYSCALL(__NR_fanotify_mark, sys_fanotify_mark)
 #define __NR_prlimit64				302
 __SYSCALL(__NR_prlimit64, sys_prlimit64)
+#define __NR_clock_adjtime			303
+__SYSCALL(__NR_clock_adjtime, sys_clock_adjtime)
 
 #ifndef __NO_STUBS
 #define __ARCH_WANT_OLD_READDIR
diff --git a/arch/x86/kernel/syscall_table_32.S b/arch/x86/kernel/syscall_table_32.S
index b35786d..68c7b9a 100644
--- a/arch/x86/kernel/syscall_table_32.S
+++ b/arch/x86/kernel/syscall_table_32.S
@@ -340,3 +340,4 @@ ENTRY(sys_call_table)
 	.long sys_fanotify_init
 	.long sys_fanotify_mark
 	.long sys_prlimit64		/* 340 */
+	.long sys_clock_adjtime

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [tip:timers/core] posix-timers: Add support for fd based clocks
  2011-02-01 13:52 ` [patch 27/28] posix-timers: Add support for fd based clocks Thomas Gleixner
  2011-02-01 21:38   ` john stultz
  2011-02-02  9:19   ` Richard Cochran
@ 2011-02-02 22:05   ` tip-bot for Richard Cochran
  2 siblings, 0 replies; 111+ messages in thread
From: tip-bot for Richard Cochran @ 2011-02-02 22:05 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, johnstul, tglx, richard.cochran

Commit-ID:  81e294cba2596f5f10848bbe19d98b344c2a2d5c
Gitweb:     http://git.kernel.org/tip/81e294cba2596f5f10848bbe19d98b344c2a2d5c
Author:     Richard Cochran <richard.cochran@omicron.at>
AuthorDate: Tue, 1 Feb 2011 13:52:32 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 2 Feb 2011 15:28:19 +0100

posix-timers: Add support for fd based clocks

Extend the negative clockids which are currently used by posix cpu
timers to encode the PID with a file descriptor based type which
encodes the fd in the upper bits.

Originally-from: Richard Cochran <richard.cochran@omicron.at>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: John Stultz <johnstul@us.ibm.com>
LKML-Reference: <20110201134420.062860200@linutronix.de>
---
 include/linux/posix-timers.h |   13 +++++++++++++
 kernel/posix-timers.c        |    2 +-
 2 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 79a1cea..88b9256 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -18,6 +18,17 @@ struct cpu_timer_list {
 	int firing;
 };
 
+/*
+ * Bit fields within a clockid:
+ *
+ * The most significant 29 bits hold either a pid or a file descriptor.
+ *
+ * Bit 2 indicates whether a cpu clock refers to a thread or a process.
+ *
+ * Bits 1 and 0 give the type: PROF=0, VIRT=1, SCHED=2, or FD=3.
+ *
+ * A clockid is invalid if bits 2, 1, and 0 are all set.
+ */
 #define CPUCLOCK_PID(clock)		((pid_t) ~((clock) >> 3))
 #define CPUCLOCK_PERTHREAD(clock) \
 	(((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0)
@@ -29,6 +40,8 @@ struct cpu_timer_list {
 #define CPUCLOCK_VIRT		1
 #define CPUCLOCK_SCHED		2
 #define CPUCLOCK_MAX		3
+#define CLOCKFD			CPUCLOCK_MAX
+#define CLOCKFD_MASK		(CPUCLOCK_PERTHREAD_MASK|CPUCLOCK_CLOCK_MASK)
 
 #define MAKE_PROCESS_CPUCLOCK(pid, clock) \
 	((~(clockid_t) (pid) << 3) | (clockid_t) (clock))
diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index 5a5a4f1..df629d8 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -488,7 +488,7 @@ static void release_posix_timer(struct k_itimer *tmr, int it_id_set)
 static struct k_clock *clockid_to_kclock(const clockid_t id)
 {
 	if (id < 0)
-		return &clock_posix_cpu;
+		return (id & CLOCKFD_MASK) == CLOCKFD ? NULL : &clock_posix_cpu;
 
 	if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
 		return NULL;

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [tip:timers/core] posix-timers: Cleanup namespace
  2011-02-02 11:25         ` Thomas Gleixner
@ 2011-02-02 22:06           ` tip-bot for Thomas Gleixner
  0 siblings, 0 replies; 111+ messages in thread
From: tip-bot for Thomas Gleixner @ 2011-02-02 22:06 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, johnstul, tglx, richard.cochran

Commit-ID:  527087374faa488776a789375a7d6ea74fda6f71
Gitweb:     http://git.kernel.org/tip/527087374faa488776a789375a7d6ea74fda6f71
Author:     Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Wed, 2 Feb 2011 12:10:09 +0100
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 2 Feb 2011 15:28:19 +0100

posix-timers: Cleanup namespace

Rename register_posix_clock() to posix_timers_register_clock(). That's
what the function really does. As a side effect this cleans up the
posix_clock namespace for the upcoming dynamic posix_clock
infrastructure.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Richard Cochran <richard.cochran@omicron.at>
Cc: John Stultz <johnstul@us.ibm.com>
LKML-Reference: <alpine.LFD.2.00.1102021222240.31804@localhost6.localdomain6>
---
 drivers/char/mmtimer.c       |    2 +-
 include/linux/posix-timers.h |    2 +-
 kernel/posix-cpu-timers.c    |    4 ++--
 kernel/posix-timers.c        |   15 ++++++++-------
 4 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index ff41eb3..33dc229 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -840,7 +840,7 @@ static int __init mmtimer_init(void)
 	}
 
 	sgi_clock_period = NSEC_PER_SEC / sn_rtc_cycles_per_second;
-	register_posix_clock(CLOCK_SGI_CYCLE, &sgi_clock);
+	posix_timers_register_clock(CLOCK_SGI_CYCLE, &sgi_clock);
 
 	printk(KERN_INFO "%s: v%s, %ld MHz\n", MMTIMER_DESC, MMTIMER_VERSION,
 	       sn_rtc_cycles_per_second/(unsigned long)1E6);
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 88b9256..9d6ffe2 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -101,7 +101,7 @@ struct k_clock {
 
 extern struct k_clock clock_posix_cpu;
 
-void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock);
+void posix_timers_register_clock(const clockid_t clock_id, struct k_clock *new_clock);
 
 /* function to call to trigger timer event */
 int posix_timer_event(struct k_itimer *timr, int si_private);
diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
index 609e187..67fea9d 100644
--- a/kernel/posix-cpu-timers.c
+++ b/kernel/posix-cpu-timers.c
@@ -1618,8 +1618,8 @@ static __init int init_posix_cpu_timers(void)
 	};
 	struct timespec ts;
 
-	register_posix_clock(CLOCK_PROCESS_CPUTIME_ID, &process);
-	register_posix_clock(CLOCK_THREAD_CPUTIME_ID, &thread);
+	posix_timers_register_clock(CLOCK_PROCESS_CPUTIME_ID, &process);
+	posix_timers_register_clock(CLOCK_THREAD_CPUTIME_ID, &thread);
 
 	cputime_to_timespec(cputime_one_jiffy, &ts);
 	onecputick = ts.tv_nsec;
diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index df629d8..af936fd 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -253,11 +253,11 @@ static __init int init_posix_timers(void)
 		.clock_get	= posix_get_monotonic_coarse,
 	};
 
-	register_posix_clock(CLOCK_REALTIME, &clock_realtime);
-	register_posix_clock(CLOCK_MONOTONIC, &clock_monotonic);
-	register_posix_clock(CLOCK_MONOTONIC_RAW, &clock_monotonic_raw);
-	register_posix_clock(CLOCK_REALTIME_COARSE, &clock_realtime_coarse);
-	register_posix_clock(CLOCK_MONOTONIC_COARSE, &clock_monotonic_coarse);
+	posix_timers_register_clock(CLOCK_REALTIME, &clock_realtime);
+	posix_timers_register_clock(CLOCK_MONOTONIC, &clock_monotonic);
+	posix_timers_register_clock(CLOCK_MONOTONIC_RAW, &clock_monotonic_raw);
+	posix_timers_register_clock(CLOCK_REALTIME_COARSE, &clock_realtime_coarse);
+	posix_timers_register_clock(CLOCK_MONOTONIC_COARSE, &clock_monotonic_coarse);
 
 	posix_timers_cache = kmem_cache_create("posix_timers_cache",
 					sizeof (struct k_itimer), 0, SLAB_PANIC,
@@ -433,7 +433,8 @@ static struct pid *good_sigevent(sigevent_t * event)
 	return task_pid(rtn);
 }
 
-void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock)
+void posix_timers_register_clock(const clockid_t clock_id,
+				 struct k_clock *new_clock)
 {
 	if ((unsigned) clock_id >= MAX_CLOCKS) {
 		printk(KERN_WARNING "POSIX clock register failed for clock_id %d\n",
@@ -454,7 +455,7 @@ void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock)
 
 	posix_clocks[clock_id] = *new_clock;
 }
-EXPORT_SYMBOL_GPL(register_posix_clock);
+EXPORT_SYMBOL_GPL(posix_timers_register_clock);
 
 static struct k_itimer * alloc_posix_timer(void)
 {

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [tip:timers/core] posix clocks: Introduce dynamic clocks
  2011-02-01 13:52 ` [patch 28/28] posix clocks: Introduce dynamic clocks Thomas Gleixner
  2011-02-01 21:49   ` john stultz
@ 2011-02-02 22:06   ` tip-bot for Richard Cochran
  2011-03-03 14:50   ` [patch 28/28] " torbenh
  2 siblings, 0 replies; 111+ messages in thread
From: tip-bot for Richard Cochran @ 2011-02-02 22:06 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, johnstul, richardcochran, tglx,
	richard.cochran

Commit-ID:  0606f422b453f76c31ab2b1bd52943ff06a2dcf2
Gitweb:     http://git.kernel.org/tip/0606f422b453f76c31ab2b1bd52943ff06a2dcf2
Author:     Richard Cochran <richardcochran@gmail.com>
AuthorDate: Tue, 1 Feb 2011 13:52:35 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 2 Feb 2011 15:28:20 +0100

posix clocks: Introduce dynamic clocks

This patch adds support for adding and removing posix clocks. The
clock lifetime cycle is patterned after usb devices. Each clock is
represented by a standard character device. In addition, the driver
may optionally implement custom character device operations.

The posix clock and timer system calls listed below now work with
dynamic posix clocks, as well as the traditional static clocks.
The following system calls are affected:

   - clock_adjtime (brand new syscall)
   - clock_gettime
   - clock_getres
   - clock_settime
   - timer_create
   - timer_delete
   - timer_gettime
   - timer_settime

[ tglx: Adapted to the posix-timer cleanup. Moved clock_posix_dynamic
  	to posix-clock.c and made all referenced functions static ]

Signed-off-by: Richard Cochran <richard.cochran@omicron.at>
Acked-by: John Stultz <johnstul@us.ibm.com>
LKML-Reference: <20110201134420.164172635@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 include/linux/posix-clock.h  |  150 ++++++++++++++
 include/linux/posix-timers.h |    6 +-
 kernel/posix-timers.c        |    4 +-
 kernel/time/Makefile         |    3 +-
 kernel/time/posix-clock.c    |  441 ++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 601 insertions(+), 3 deletions(-)

diff --git a/include/linux/posix-clock.h b/include/linux/posix-clock.h
new file mode 100644
index 0000000..369e19d
--- /dev/null
+++ b/include/linux/posix-clock.h
@@ -0,0 +1,150 @@
+/*
+ * posix-clock.h - support for dynamic clock devices
+ *
+ * Copyright (C) 2010 OMICRON electronics GmbH
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+#ifndef _LINUX_POSIX_CLOCK_H_
+#define _LINUX_POSIX_CLOCK_H_
+
+#include <linux/cdev.h>
+#include <linux/fs.h>
+#include <linux/poll.h>
+#include <linux/posix-timers.h>
+
+struct posix_clock;
+
+/**
+ * struct posix_clock_operations - functional interface to the clock
+ *
+ * Every posix clock is represented by a character device. Drivers may
+ * optionally offer extended capabilities by implementing the
+ * character device methods. The character device file operations are
+ * first handled by the clock device layer, then passed on to the
+ * driver by calling these functions.
+ *
+ * @owner:          The clock driver should set to THIS_MODULE
+ * @clock_adjtime:  Adjust the clock
+ * @clock_gettime:  Read the current time
+ * @clock_getres:   Get the clock resolution
+ * @clock_settime:  Set the current time value
+ * @timer_create:   Create a new timer
+ * @timer_delete:   Remove a previously created timer
+ * @timer_gettime:  Get remaining time and interval of a timer
+ * @timer_setttime: Set a timer's initial expiration and interval
+ * @fasync:         Optional character device fasync method
+ * @mmap:           Optional character device mmap method
+ * @open:           Optional character device open method
+ * @release:        Optional character device release method
+ * @ioctl:          Optional character device ioctl method
+ * @read:           Optional character device read method
+ * @poll:           Optional character device poll method
+ */
+struct posix_clock_operations {
+	struct module *owner;
+
+	int  (*clock_adjtime)(struct posix_clock *pc, struct timex *tx);
+
+	int  (*clock_gettime)(struct posix_clock *pc, struct timespec *ts);
+
+	int  (*clock_getres) (struct posix_clock *pc, struct timespec *ts);
+
+	int  (*clock_settime)(struct posix_clock *pc,
+			      const struct timespec *ts);
+
+	int  (*timer_create) (struct posix_clock *pc, struct k_itimer *kit);
+
+	int  (*timer_delete) (struct posix_clock *pc, struct k_itimer *kit);
+
+	void (*timer_gettime)(struct posix_clock *pc,
+			      struct k_itimer *kit, struct itimerspec *tsp);
+
+	int  (*timer_settime)(struct posix_clock *pc,
+			      struct k_itimer *kit, int flags,
+			      struct itimerspec *tsp, struct itimerspec *old);
+	/*
+	 * Optional character device methods:
+	 */
+	int     (*fasync)  (struct posix_clock *pc,
+			    int fd, struct file *file, int on);
+
+	long    (*ioctl)   (struct posix_clock *pc,
+			    unsigned int cmd, unsigned long arg);
+
+	int     (*mmap)    (struct posix_clock *pc,
+			    struct vm_area_struct *vma);
+
+	int     (*open)    (struct posix_clock *pc, fmode_t f_mode);
+
+	uint    (*poll)    (struct posix_clock *pc,
+			    struct file *file, poll_table *wait);
+
+	int     (*release) (struct posix_clock *pc);
+
+	ssize_t (*read)    (struct posix_clock *pc,
+			    uint flags, char __user *buf, size_t cnt);
+};
+
+/**
+ * struct posix_clock - represents a dynamic posix clock
+ *
+ * @ops:     Functional interface to the clock
+ * @cdev:    Character device instance for this clock
+ * @kref:    Reference count.
+ * @mutex:   Protects the 'zombie' field from concurrent access.
+ * @zombie:  If 'zombie' is true, then the hardware has disappeared.
+ * @release: A function to free the structure when the reference count reaches
+ *           zero. May be NULL if structure is statically allocated.
+ *
+ * Drivers should embed their struct posix_clock within a private
+ * structure, obtaining a reference to it during callbacks using
+ * container_of().
+ */
+struct posix_clock {
+	struct posix_clock_operations ops;
+	struct cdev cdev;
+	struct kref kref;
+	struct mutex mutex;
+	bool zombie;
+	void (*release)(struct posix_clock *clk);
+};
+
+/**
+ * posix_clock_register() - register a new clock
+ * @clk:   Pointer to the clock. Caller must provide 'ops' and 'release'
+ * @devid: Allocated device id
+ *
+ * A clock driver calls this function to register itself with the
+ * clock device subsystem. If 'clk' points to dynamically allocated
+ * memory, then the caller must provide a 'release' function to free
+ * that memory.
+ *
+ * Returns zero on success, non-zero otherwise.
+ */
+int posix_clock_register(struct posix_clock *clk, dev_t devid);
+
+/**
+ * posix_clock_unregister() - unregister a clock
+ * @clk: Clock instance previously registered via posix_clock_register()
+ *
+ * A clock driver calls this function to remove itself from the clock
+ * device subsystem. The posix_clock itself will remain (in an
+ * inactive state) until its reference count drops to zero, at which
+ * point it will be deallocated with its 'release' method.
+ */
+void posix_clock_unregister(struct posix_clock *clk);
+
+#endif
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 9d6ffe2..d51243a 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -32,7 +32,7 @@ struct cpu_timer_list {
 #define CPUCLOCK_PID(clock)		((pid_t) ~((clock) >> 3))
 #define CPUCLOCK_PERTHREAD(clock) \
 	(((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0)
-#define CPUCLOCK_PID_MASK	7
+
 #define CPUCLOCK_PERTHREAD_MASK	4
 #define CPUCLOCK_WHICH(clock)	((clock) & (clockid_t) CPUCLOCK_CLOCK_MASK)
 #define CPUCLOCK_CLOCK_MASK	3
@@ -48,6 +48,9 @@ struct cpu_timer_list {
 #define MAKE_THREAD_CPUCLOCK(tid, clock) \
 	MAKE_PROCESS_CPUCLOCK((tid), (clock) | CPUCLOCK_PERTHREAD_MASK)
 
+#define FD_TO_CLOCKID(fd)	((~(clockid_t) (fd) << 3) | CLOCKFD)
+#define CLOCKID_TO_FD(clk)	((unsigned int) ~((clk) >> 3))
+
 /* POSIX.1b interval timer structure. */
 struct k_itimer {
 	struct list_head list;		/* free/ allocate list */
@@ -100,6 +103,7 @@ struct k_clock {
 };
 
 extern struct k_clock clock_posix_cpu;
+extern struct k_clock clock_posix_dynamic;
 
 void posix_timers_register_clock(const clockid_t clock_id, struct k_clock *new_clock);
 
diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index af936fd..44fcff1 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -41,6 +41,7 @@
 #include <linux/init.h>
 #include <linux/compiler.h>
 #include <linux/idr.h>
+#include <linux/posix-clock.h>
 #include <linux/posix-timers.h>
 #include <linux/syscalls.h>
 #include <linux/wait.h>
@@ -489,7 +490,8 @@ static void release_posix_timer(struct k_itimer *tmr, int it_id_set)
 static struct k_clock *clockid_to_kclock(const clockid_t id)
 {
 	if (id < 0)
-		return (id & CLOCKFD_MASK) == CLOCKFD ? NULL : &clock_posix_cpu;
+		return (id & CLOCKFD_MASK) == CLOCKFD ?
+			&clock_posix_dynamic : &clock_posix_cpu;
 
 	if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
 		return NULL;
diff --git a/kernel/time/Makefile b/kernel/time/Makefile
index ee26662..b042599 100644
--- a/kernel/time/Makefile
+++ b/kernel/time/Makefile
@@ -1,4 +1,5 @@
-obj-y += timekeeping.o ntp.o clocksource.o jiffies.o timer_list.o timecompare.o timeconv.o
+obj-y += timekeeping.o ntp.o clocksource.o jiffies.o timer_list.o timecompare.o
+obj-y += timeconv.o posix-clock.o
 
 obj-$(CONFIG_GENERIC_CLOCKEVENTS_BUILD)		+= clockevents.o
 obj-$(CONFIG_GENERIC_CLOCKEVENTS)		+= tick-common.o
diff --git a/kernel/time/posix-clock.c b/kernel/time/posix-clock.c
new file mode 100644
index 0000000..04498cb
--- /dev/null
+++ b/kernel/time/posix-clock.c
@@ -0,0 +1,441 @@
+/*
+ * posix-clock.c - support for dynamic clock devices
+ *
+ * Copyright (C) 2010 OMICRON electronics GmbH
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+#include <linux/device.h>
+#include <linux/file.h>
+#include <linux/mutex.h>
+#include <linux/posix-clock.h>
+#include <linux/slab.h>
+#include <linux/syscalls.h>
+#include <linux/uaccess.h>
+
+static void delete_clock(struct kref *kref);
+
+/*
+ * Returns NULL if the posix_clock instance attached to 'fp' is old and stale.
+ */
+static struct posix_clock *get_posix_clock(struct file *fp)
+{
+	struct posix_clock *clk = fp->private_data;
+
+	mutex_lock(&clk->mutex);
+
+	if (!clk->zombie)
+		return clk;
+
+	mutex_unlock(&clk->mutex);
+
+	return NULL;
+}
+
+static void put_posix_clock(struct posix_clock *clk)
+{
+	mutex_unlock(&clk->mutex);
+}
+
+static ssize_t posix_clock_read(struct file *fp, char __user *buf,
+				size_t count, loff_t *ppos)
+{
+	struct posix_clock *clk = get_posix_clock(fp);
+	int err = -EINVAL;
+
+	if (!clk)
+		return -ENODEV;
+
+	if (clk->ops.read)
+		err = clk->ops.read(clk, fp->f_flags, buf, count);
+
+	put_posix_clock(clk);
+
+	return err;
+}
+
+static unsigned int posix_clock_poll(struct file *fp, poll_table *wait)
+{
+	struct posix_clock *clk = get_posix_clock(fp);
+	int result = 0;
+
+	if (!clk)
+		return -ENODEV;
+
+	if (clk->ops.poll)
+		result = clk->ops.poll(clk, fp, wait);
+
+	put_posix_clock(clk);
+
+	return result;
+}
+
+static int posix_clock_fasync(int fd, struct file *fp, int on)
+{
+	struct posix_clock *clk = get_posix_clock(fp);
+	int err = 0;
+
+	if (!clk)
+		return -ENODEV;
+
+	if (clk->ops.fasync)
+		err = clk->ops.fasync(clk, fd, fp, on);
+
+	put_posix_clock(clk);
+
+	return err;
+}
+
+static int posix_clock_mmap(struct file *fp, struct vm_area_struct *vma)
+{
+	struct posix_clock *clk = get_posix_clock(fp);
+	int err = -ENODEV;
+
+	if (!clk)
+		return -ENODEV;
+
+	if (clk->ops.mmap)
+		err = clk->ops.mmap(clk, vma);
+
+	put_posix_clock(clk);
+
+	return err;
+}
+
+static long posix_clock_ioctl(struct file *fp,
+			      unsigned int cmd, unsigned long arg)
+{
+	struct posix_clock *clk = get_posix_clock(fp);
+	int err = -ENOTTY;
+
+	if (!clk)
+		return -ENODEV;
+
+	if (clk->ops.ioctl)
+		err = clk->ops.ioctl(clk, cmd, arg);
+
+	put_posix_clock(clk);
+
+	return err;
+}
+
+#ifdef CONFIG_COMPAT
+static long posix_clock_compat_ioctl(struct file *fp,
+				     unsigned int cmd, unsigned long arg)
+{
+	struct posix_clock *clk = get_posix_clock(fp);
+	int err = -ENOTTY;
+
+	if (!clk)
+		return -ENODEV;
+
+	if (clk->ops.ioctl)
+		err = clk->ops.ioctl(clk, cmd, arg);
+
+	put_posix_clock(clk);
+
+	return err;
+}
+#endif
+
+static int posix_clock_open(struct inode *inode, struct file *fp)
+{
+	int err;
+	struct posix_clock *clk =
+		container_of(inode->i_cdev, struct posix_clock, cdev);
+
+	mutex_lock(&clk->mutex);
+
+	if (clk->zombie) {
+		err = -ENODEV;
+		goto out;
+	}
+	if (clk->ops.open)
+		err = clk->ops.open(clk, fp->f_mode);
+	else
+		err = 0;
+
+	if (!err) {
+		kref_get(&clk->kref);
+		fp->private_data = clk;
+	}
+out:
+	mutex_unlock(&clk->mutex);
+	return err;
+}
+
+static int posix_clock_release(struct inode *inode, struct file *fp)
+{
+	struct posix_clock *clk = fp->private_data;
+	int err = 0;
+
+	if (clk->ops.release)
+		err = clk->ops.release(clk);
+
+	kref_put(&clk->kref, delete_clock);
+
+	fp->private_data = NULL;
+
+	return err;
+}
+
+static const struct file_operations posix_clock_file_operations = {
+	.owner		= THIS_MODULE,
+	.llseek		= no_llseek,
+	.read		= posix_clock_read,
+	.poll		= posix_clock_poll,
+	.unlocked_ioctl	= posix_clock_ioctl,
+	.open		= posix_clock_open,
+	.release	= posix_clock_release,
+	.fasync		= posix_clock_fasync,
+	.mmap		= posix_clock_mmap,
+#ifdef CONFIG_COMPAT
+	.compat_ioctl	= posix_clock_compat_ioctl,
+#endif
+};
+
+int posix_clock_register(struct posix_clock *clk, dev_t devid)
+{
+	int err;
+
+	kref_init(&clk->kref);
+	mutex_init(&clk->mutex);
+
+	cdev_init(&clk->cdev, &posix_clock_file_operations);
+	clk->cdev.owner = clk->ops.owner;
+	err = cdev_add(&clk->cdev, devid, 1);
+	if (err)
+		goto no_cdev;
+
+	return err;
+no_cdev:
+	mutex_destroy(&clk->mutex);
+	return err;
+}
+EXPORT_SYMBOL_GPL(posix_clock_register);
+
+static void delete_clock(struct kref *kref)
+{
+	struct posix_clock *clk = container_of(kref, struct posix_clock, kref);
+	mutex_destroy(&clk->mutex);
+	if (clk->release)
+		clk->release(clk);
+}
+
+void posix_clock_unregister(struct posix_clock *clk)
+{
+	cdev_del(&clk->cdev);
+
+	mutex_lock(&clk->mutex);
+	clk->zombie = true;
+	mutex_unlock(&clk->mutex);
+
+	kref_put(&clk->kref, delete_clock);
+}
+EXPORT_SYMBOL_GPL(posix_clock_unregister);
+
+struct posix_clock_desc {
+	struct file *fp;
+	struct posix_clock *clk;
+};
+
+static int get_clock_desc(const clockid_t id, struct posix_clock_desc *cd)
+{
+	struct file *fp = fget(CLOCKID_TO_FD(id));
+	int err = -EINVAL;
+
+	if (!fp)
+		return err;
+
+	if (fp->f_op->open != posix_clock_open || !fp->private_data)
+		goto out;
+
+	cd->fp = fp;
+	cd->clk = get_posix_clock(fp);
+
+	err = cd->clk ? 0 : -ENODEV;
+out:
+	if (err)
+		fput(fp);
+	return err;
+}
+
+static void put_clock_desc(struct posix_clock_desc *cd)
+{
+	put_posix_clock(cd->clk);
+	fput(cd->fp);
+}
+
+static int pc_clock_adjtime(clockid_t id, struct timex *tx)
+{
+	struct posix_clock_desc cd;
+	int err;
+
+	err = get_clock_desc(id, &cd);
+	if (err)
+		return err;
+
+	if (cd.clk->ops.clock_adjtime)
+		err = cd.clk->ops.clock_adjtime(cd.clk, tx);
+	else
+		err = -EOPNOTSUPP;
+
+	put_clock_desc(&cd);
+
+	return err;
+}
+
+static int pc_clock_gettime(clockid_t id, struct timespec *ts)
+{
+	struct posix_clock_desc cd;
+	int err;
+
+	err = get_clock_desc(id, &cd);
+	if (err)
+		return err;
+
+	if (cd.clk->ops.clock_gettime)
+		err = cd.clk->ops.clock_gettime(cd.clk, ts);
+	else
+		err = -EOPNOTSUPP;
+
+	put_clock_desc(&cd);
+
+	return err;
+}
+
+static int pc_clock_getres(clockid_t id, struct timespec *ts)
+{
+	struct posix_clock_desc cd;
+	int err;
+
+	err = get_clock_desc(id, &cd);
+	if (err)
+		return err;
+
+	if (cd.clk->ops.clock_getres)
+		err = cd.clk->ops.clock_getres(cd.clk, ts);
+	else
+		err = -EOPNOTSUPP;
+
+	put_clock_desc(&cd);
+
+	return err;
+}
+
+static int pc_clock_settime(clockid_t id, const struct timespec *ts)
+{
+	struct posix_clock_desc cd;
+	int err;
+
+	err = get_clock_desc(id, &cd);
+	if (err)
+		return err;
+
+	if (cd.clk->ops.clock_settime)
+		err = cd.clk->ops.clock_settime(cd.clk, ts);
+	else
+		err = -EOPNOTSUPP;
+
+	put_clock_desc(&cd);
+
+	return err;
+}
+
+static int pc_timer_create(struct k_itimer *kit)
+{
+	clockid_t id = kit->it_clock;
+	struct posix_clock_desc cd;
+	int err;
+
+	err = get_clock_desc(id, &cd);
+	if (err)
+		return err;
+
+	if (cd.clk->ops.timer_create)
+		err = cd.clk->ops.timer_create(cd.clk, kit);
+	else
+		err = -EOPNOTSUPP;
+
+	put_clock_desc(&cd);
+
+	return err;
+}
+
+static int pc_timer_delete(struct k_itimer *kit)
+{
+	clockid_t id = kit->it_clock;
+	struct posix_clock_desc cd;
+	int err;
+
+	err = get_clock_desc(id, &cd);
+	if (err)
+		return err;
+
+	if (cd.clk->ops.timer_delete)
+		err = cd.clk->ops.timer_delete(cd.clk, kit);
+	else
+		err = -EOPNOTSUPP;
+
+	put_clock_desc(&cd);
+
+	return err;
+}
+
+static void pc_timer_gettime(struct k_itimer *kit, struct itimerspec *ts)
+{
+	clockid_t id = kit->it_clock;
+	struct posix_clock_desc cd;
+
+	if (get_clock_desc(id, &cd))
+		return;
+
+	if (cd.clk->ops.timer_gettime)
+		cd.clk->ops.timer_gettime(cd.clk, kit, ts);
+
+	put_clock_desc(&cd);
+}
+
+static int pc_timer_settime(struct k_itimer *kit, int flags,
+			    struct itimerspec *ts, struct itimerspec *old)
+{
+	clockid_t id = kit->it_clock;
+	struct posix_clock_desc cd;
+	int err;
+
+	err = get_clock_desc(id, &cd);
+	if (err)
+		return err;
+
+	if (cd.clk->ops.timer_settime)
+		err = cd.clk->ops.timer_settime(cd.clk, kit, flags, ts, old);
+	else
+		err = -EOPNOTSUPP;
+
+	put_clock_desc(&cd);
+
+	return err;
+}
+
+struct k_clock clock_posix_dynamic = {
+	.clock_getres	= pc_clock_getres,
+	.clock_set	= pc_clock_settime,
+	.clock_get	= pc_clock_gettime,
+	.clock_adj	= pc_clock_adjtime,
+	.timer_create	= pc_timer_create,
+	.timer_set	= pc_timer_settime,
+	.timer_del	= pc_timer_delete,
+	.timer_get	= pc_timer_gettime,
+};

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* Re: [tip:timers/core] ntp: Add ADJ_SETOFFSET mode bit
  2011-02-02 22:04 ` [tip:timers/core] ntp: Add ADJ_SETOFFSET mode bit tip-bot for Richard Cochran
@ 2011-02-18  9:07   ` Richard Cochran
  2011-02-18 16:07     ` [tip:timers/core] ntp: Remove redundant and incorrect parameter check tip-bot for Richard Cochran
  0 siblings, 1 reply; 111+ messages in thread
From: Richard Cochran @ 2011-02-18  9:07 UTC (permalink / raw)
  To: linux-kernel; +Cc: hpa, mingo, johnstul, tglx, richard.cochran


I just noticed a problem with this code. As is, the code will not
detect if the microseconds field (the non-ADJ_NANO case) is out of
range. However, the call to timekeeping_inject_offset() would silently
fail.

This patch corrects the problem by letting timekeeping_inject_offset()
do the check and catching the return code.

Author: Richard Cochran <richard.cochran@omicron.at>
Date:   Fri Feb 18 09:54:19 2011 +0100

    ntp: remove useless and incorrect parameter check
    
    The ADJ_SETOFFSET code redundantly checks the range of the nanoseconds
    field of the time value. This field is checked again in the subsequent
    call to timekeeping_inject_offset(). Also, as is, the check will not
    detect whether the number of microseconds is out of range.
    
    This patch simply lets timekeeping_inject_offset() do the error checking.
    
    Signed-off-by: Richard Cochran <richard.cochran@omicron.at>

diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index 34d1b64..d62f35a 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -648,13 +648,13 @@ int do_adjtimex(struct timex *txc)
 
 	if (txc->modes & ADJ_SETOFFSET) {
 		struct timespec delta;
-		if ((unsigned long)txc->time.tv_usec >= NSEC_PER_SEC)
-			return -EINVAL;
 		delta.tv_sec  = txc->time.tv_sec;
 		delta.tv_nsec = txc->time.tv_usec;
 		if (!(txc->modes & ADJ_NANO))
 			delta.tv_nsec *= 1000;
-		timekeeping_inject_offset(&delta);
+		result = timekeeping_inject_offset(&delta);
+		if (result)
+			return result;
 	}
 
 	getnstimeofday(&ts);

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [tip:timers/core] ntp: Remove redundant and incorrect parameter check
  2011-02-18  9:07   ` Richard Cochran
@ 2011-02-18 16:07     ` tip-bot for Richard Cochran
  0 siblings, 0 replies; 111+ messages in thread
From: tip-bot for Richard Cochran @ 2011-02-18 16:07 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, richardcochran, tglx, richard.cochran

Commit-ID:  db1c1cce4a653dcbe6949c72ae7b9f42cab1b929
Gitweb:     http://git.kernel.org/tip/db1c1cce4a653dcbe6949c72ae7b9f42cab1b929
Author:     Richard Cochran <richardcochran@gmail.com>
AuthorDate: Fri, 18 Feb 2011 10:07:25 +0100
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Fri, 18 Feb 2011 17:01:12 +0100

ntp: Remove redundant and incorrect parameter check

The ADJ_SETOFFSET code redundantly checks the range of the nanoseconds
field of the time value. This field is checked again in the subsequent
call to timekeeping_inject_offset(). Also, as is, the check will not
detect whether the number of microseconds is out of range.

Let timekeeping_inject_offset() do the error checking.
 
Signed-off-by: Richard Cochran <richard.cochran@omicron.at>
Cc: johnstul@us.ibm.com
LKML-Reference: <20110218090724.GA2924@riccoc20.at.omicron.at>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

---
 kernel/time/ntp.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index 5ac5932..5f1bb8e 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -650,13 +650,13 @@ int do_adjtimex(struct timex *txc)
 
 	if (txc->modes & ADJ_SETOFFSET) {
 		struct timespec delta;
-		if ((unsigned long)txc->time.tv_usec >= NSEC_PER_SEC)
-			return -EINVAL;
 		delta.tv_sec  = txc->time.tv_sec;
 		delta.tv_nsec = txc->time.tv_usec;
 		if (!(txc->modes & ADJ_NANO))
 			delta.tv_nsec *= 1000;
-		timekeeping_inject_offset(&delta);
+		result = timekeeping_inject_offset(&delta);
+		if (result)
+			return result;
 	}
 
 	getnstimeofday(&ts);

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* Re: [patch 00/28]  Rework of the PTP support series core code
  2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
                   ` (30 preceding siblings ...)
  2011-02-02 22:04 ` [tip:timers/core] ntp: Add ADJ_SETOFFSET mode bit tip-bot for Richard Cochran
@ 2011-03-01 15:38 ` torbenh
  2011-03-01 18:50   ` Richard Cochran
  31 siblings, 1 reply; 111+ messages in thread
From: torbenh @ 2011-03-01 15:38 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: LKML, John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, Feb 01, 2011 at 01:50:55PM -0000, Thomas Gleixner wrote:
> This is a rework of Richards PTP support series core code. The PTP
> driver patches are unchanged and not included in this series.
> 
> The reason for this rework is that I got scared when reviewing:
>  [PATCH V10 09/15] posix clocks: cleanup the CLOCK_DISPTACH macro
> 
> The patch is really too large and the risk of wreckage too high. So
> instead of whipping Richard through another round I reworked the
> series in the following way:
> 
> 1) Split the CLOCK_DISPATCH cleanup in fine grained steps.
>    
>    That allowed further cleanups and got rid of 200 lines of code and
>    made a lot of functions static.
>    
>    It also fixes subtle changes to the error return codes which happened
>    in the large all in one overhaul (EINVAL vs. ENOTSUP).
>    
> 2) Move the patches which add new functionality after the cleanup.
> 
>    It does not make sense to add new functionality into the old scheme
>    first and then clean it up.
> 
> Richard, can you please run that through your testing ? The PTP
> drivers apply on top of that.

i am a bit puzzled how a software ptp clock would fit into this
framework. for some avb use-cases we could get away with a ptp clock
thats only accurate to a few 100us.

from a few quick glances it seems, that if userspace is able to create a
ptp clock driven by normal timers and the kernel allows for timestamping 
packets using that clock, a modified ptpd could do the trick.

i am not sure, how much of this should be happening in userspace though.


-- 
torben Hohn

^ permalink raw reply	[flat|nested] 111+ messages in thread

* RE: [patch 00/28]  Rework of the PTP support series core code
  2011-03-01 15:38 ` [patch 00/28] Rework of the PTP support series core code torbenh
@ 2011-03-01 18:50   ` Richard Cochran
  2011-03-02  9:41     ` torbenh
  0 siblings, 1 reply; 111+ messages in thread
From: Richard Cochran @ 2011-03-01 18:50 UTC (permalink / raw)
  To: 'torbenh', 'Thomas Gleixner'
  Cc: 'LKML', 'John Stultz', 'Ingo Molnar',
	'Peter Zijlstra'

>> Richard, can you please run that through your testing ? The PTP
>> drivers apply on top of that.
>
>i am a bit puzzled how a software ptp clock would fit into this
>framework. for some avb use-cases we could get away with a ptp clock
>thats only accurate to a few 100us.
>
>from a few quick glances it seems, that if userspace is able to create a
>ptp clock driven by normal timers and the kernel allows for timestamping
>packets using that clock, a modified ptpd could do the trick.
>
>i am not sure, how much of this should be happening in userspace though.

The point of the PHC patch set is to support special hardware clocks.
After much discussion (see the links in the V12 patch set) we have come
up with an API that will work both with software only (ie normal system
time) as well as with hardware clocks.

The application just uses: clockid_t id = CLOCK_REALTIME
if it wants to use software time stamping with the normal system clock.

I have some patches for the ptpd that show how the API works, and I
will be reposting those to the ptpd.sf.net in the next few days.

HTH,
Richard


^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 00/28]  Rework of the PTP support series core code
  2011-03-01 18:50   ` Richard Cochran
@ 2011-03-02  9:41     ` torbenh
  0 siblings, 0 replies; 111+ messages in thread
From: torbenh @ 2011-03-02  9:41 UTC (permalink / raw)
  To: Richard Cochran
  Cc: 'Thomas Gleixner', 'LKML', 'John Stultz',
	'Ingo Molnar', 'Peter Zijlstra'

On Tue, Mar 01, 2011 at 07:50:55PM +0100, Richard Cochran wrote:
> >> Richard, can you please run that through your testing ? The PTP
> >> drivers apply on top of that.
> >
> >i am a bit puzzled how a software ptp clock would fit into this
> >framework. for some avb use-cases we could get away with a ptp clock
> >thats only accurate to a few 100us.
> >
> >from a few quick glances it seems, that if userspace is able to create a
> >ptp clock driven by normal timers and the kernel allows for timestamping
> >packets using that clock, a modified ptpd could do the trick.
> >
> >i am not sure, how much of this should be happening in userspace though.
> 
> The point of the PHC patch set is to support special hardware clocks.
> After much discussion (see the links in the V12 patch set) we have come
> up with an API that will work both with software only (ie normal system
> time) as well as with hardware clocks.
> 
> The application just uses: clockid_t id = CLOCK_REALTIME
> if it wants to use software time stamping with the normal system clock.

this assumes, that the ptp master clock is actually suitable to be
CLOCK_REALTIME. i am not sure if this assumption holds true, when the
master clock is an audio clock, of some cheap soundcard.

in that case, we need to relate the audio clock to CLOCK_REALTIME.
thats surely possible, but we end up with 2 cascaded clock servos.

additionally userspace must then manage to get the master clocks
relations from the ptpd to the app that plays out the audio.

if i was using a h/w clock, i could just make the audio playing app
query the h/w ptp clock using the right clockid.

so it looks like i would end up with a different api on the audio side.

> 
> I have some patches for the ptpd that show how the API works, and I
> will be reposting those to the ptpd.sf.net in the next few days.
> 
> HTH,
> Richard
> 

-- 
torben Hohn

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 28/28] posix clocks: Introduce dynamic clocks
  2011-02-01 13:52 ` [patch 28/28] posix clocks: Introduce dynamic clocks Thomas Gleixner
  2011-02-01 21:49   ` john stultz
  2011-02-02 22:06   ` [tip:timers/core] posix clocks: Introduce dynamic clocks tip-bot for Richard Cochran
@ 2011-03-03 14:50   ` torbenh
  2011-03-03 16:01     ` Richard Cochran
  2 siblings, 1 reply; 111+ messages in thread
From: torbenh @ 2011-03-03 14:50 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: LKML, John Stultz, Richard Cochran, Ingo Molnar, Peter Zijlstra

On Tue, Feb 01, 2011 at 01:52:35PM -0000, Thomas Gleixner wrote:
> From: Richard Cochran <richardcochran@gmail.com>
> 
> This patch adds support for adding and removing posix clocks. The
> clock lifetime cycle is patterned after usb devices. Each clock is
> represented by a standard character device. In addition, the driver
> may optionally implement custom character device operations.
> 
> The posix clock and timer system calls listed below now work with
> dynamic posix clocks, as well as the traditional static clocks.
> The following system calls are affected:
> 
>    - clock_adjtime (brand new syscall)
>    - clock_gettime
>    - clock_getres
>    - clock_settime
>    - timer_create
>    - timer_delete
>    - timer_gettime
>    - timer_settime
> 
> [ tglx: Adapted to the posix-timer cleanup. Moved clock_posix_dynamic
>   	to posix-clock.c and made all referenced functions static ]
> 
> Signed-off-by: Richard Cochran <richard.cochran@omicron.at>
> Cc: John Stultz <john.stultz@linaro.org>
> LKML-Reference: <21258f45fcc5e08a595f411c7760f3ccc18964bb.1296124770.git.richard.cochran@omicron.at>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> ---
>  include/linux/posix-clock.h  |  150 ++++++++++++++
>  include/linux/posix-timers.h |    6 
>  kernel/posix-timers.c        |    4 
>  kernel/time/Makefile         |    3 
>  kernel/time/posix-clock.c    |  441 +++++++++++++++++++++++++++++++++++++++++++
>  5 files changed, 601 insertions(+), 3 deletions(-)
>  create mode 100644 include/linux/posix-clock.h
>  create mode 100644 kernel/time/posix-clock-syscalls.h
>  create mode 100644 kernel/time/posix-clock.c



> 
> +
> +static int pc_clock_adjtime(clockid_t id, struct timex *tx)
> +{
> +	struct posix_clock_desc cd;
> +	int err;
> +
> +	err = get_clock_desc(id, &cd);
> +	if (err)
> +		return err;

there is no permission check here.
if i get the clock fd in READ mode, i can still adjtime.
same for settime.

> +
> +	if (cd.clk->ops.clock_adjtime)
> +		err = cd.clk->ops.clock_adjtime(cd.clk, tx);
> +	else
> +		err = -EOPNOTSUPP;
> +
> +	put_clock_desc(&cd);
> +
> +	return err;
> +}




-- 
torben Hohn

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 28/28] posix clocks: Introduce dynamic clocks
  2011-03-03 14:50   ` [patch 28/28] " torbenh
@ 2011-03-03 16:01     ` Richard Cochran
  2011-03-03 17:07       ` torbenh
  0 siblings, 1 reply; 111+ messages in thread
From: Richard Cochran @ 2011-03-03 16:01 UTC (permalink / raw)
  To: Thomas Gleixner, LKML, John Stultz, Richard Cochran, Ingo Molnar,
	Peter Zijlstra

On Thu, Mar 03, 2011 at 03:50:08PM +0100, torbenh wrote:
> On Tue, Feb 01, 2011 at 01:52:35PM -0000, Thomas Gleixner wrote:
> > +static int pc_clock_adjtime(clockid_t id, struct timex *tx)
> > +{
> > +	struct posix_clock_desc cd;
> > +	int err;
> > +
> > +	err = get_clock_desc(id, &cd);
> > +	if (err)
> > +		return err;
> 
> there is no permission check here.
> if i get the clock fd in READ mode, i can still adjtime.
> same for settime.

You are right, but I think the check should be for the capability
instead. Checking the file mode for RDWR seems a bit pedantic to me.

For the normal system timer, clock_settime calls security_settime, but
adjtimex calls capable(CAP_SYS_TIME) directly. Perhaps adjtimex should
also use the security call, too.

Thanks,

Richard


^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 28/28] posix clocks: Introduce dynamic clocks
  2011-03-03 16:01     ` Richard Cochran
@ 2011-03-03 17:07       ` torbenh
  2011-03-04  6:05         ` Richard Cochran
  0 siblings, 1 reply; 111+ messages in thread
From: torbenh @ 2011-03-03 17:07 UTC (permalink / raw)
  To: Richard Cochran
  Cc: Thomas Gleixner, LKML, John Stultz, Richard Cochran, Ingo Molnar,
	Peter Zijlstra

On Thu, Mar 03, 2011 at 05:01:14PM +0100, Richard Cochran wrote:
> On Thu, Mar 03, 2011 at 03:50:08PM +0100, torbenh wrote:
> > On Tue, Feb 01, 2011 at 01:52:35PM -0000, Thomas Gleixner wrote:
> > > +static int pc_clock_adjtime(clockid_t id, struct timex *tx)
> > > +{
> > > +	struct posix_clock_desc cd;
> > > +	int err;
> > > +
> > > +	err = get_clock_desc(id, &cd);
> > > +	if (err)
> > > +		return err;
> > 
> > there is no permission check here.
> > if i get the clock fd in READ mode, i can still adjtime.
> > same for settime.
> 
> You are right, but I think the check should be for the capability
> instead. Checking the file mode for RDWR seems a bit pedantic to me.

i dont see, why an fd based clock, which already has associated permissions,
should check against the capability.
why should the ptpd be running as root ?
changing the permissions of /dev/ptp0 to allow ptpd to set the
clock should be enough. 

> 
> For the normal system timer, clock_settime calls security_settime, but
> adjtimex calls capable(CAP_SYS_TIME) directly. Perhaps adjtimex should
> also use the security call, too.

probably yes.

> 
> Thanks,
> 
> Richard
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

-- 
torben Hohn

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [patch 28/28] posix clocks: Introduce dynamic clocks
  2011-03-03 17:07       ` torbenh
@ 2011-03-04  6:05         ` Richard Cochran
  0 siblings, 0 replies; 111+ messages in thread
From: Richard Cochran @ 2011-03-04  6:05 UTC (permalink / raw)
  To: Thomas Gleixner, LKML, John Stultz, Richard Cochran, Ingo Molnar,
	Peter Zijlstra

On Thu, Mar 03, 2011 at 06:07:59PM +0100, torbenh wrote:
> On Thu, Mar 03, 2011 at 05:01:14PM +0100, Richard Cochran wrote:
> > 
> > You are right, but I think the check should be for the capability
> > instead. Checking the file mode for RDWR seems a bit pedantic to me.
> 
> i dont see, why an fd based clock, which already has associated permissions,
> should check against the capability.
> why should the ptpd be running as root ?
> changing the permissions of /dev/ptp0 to allow ptpd to set the
> clock should be enough. 

Thinking a bit more about this, I can see three options:

1. Enfore CAP_SYS_TIME in the posix dynamic clock layer.

2. Defer the CAP_SYS_TIME check to the underlying dynamic clock. That
   puts the decision of whether a clock counts as a "system clock" to
   the author of the driver.

3. As you suggest, just use file read/write as get/set permissions.

The admin can still restrict device node ownership and read access in
any case. You could event combine these methods (1 and 3, or 1 and 2)
but I think that would only lead to user confusion.

I am not opinionated about this, but I would like to gather some
feedback before going forward. The implementation is easy in any case.

Thanks,

Richard

^ permalink raw reply	[flat|nested] 111+ messages in thread

end of thread, other threads:[~2011-03-04  6:05 UTC | newest]

Thread overview: 111+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-01 13:50 [patch 00/28] Rework of the PTP support series core code Thomas Gleixner
2011-02-01 13:50 ` [patch 01/28] time: Correct the *settime* parameters Thomas Gleixner
2011-02-01 14:22   ` Thomas Gleixner
2011-02-01 20:32   ` john stultz
2011-02-02 21:54   ` [tip:timers/core] " tip-bot for Richard Cochran
2011-02-01 13:51 ` [patch 02/28] posix-timers: Define nanosleep not supported error separate Thomas Gleixner
2011-02-01 20:32   ` John Stultz
2011-02-02 21:55   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2011-02-01 13:51 ` [patch 03/28] posix-timers: Cleanup struct initializers Thomas Gleixner
2011-02-01 20:33   ` john stultz
2011-02-02 21:55   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2011-02-01 13:51 ` [patch 04/28] posix-timers: Introduce clock_posix_cpu Thomas Gleixner
2011-02-01 20:34   ` john stultz
2011-02-02 21:56   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2011-02-01 13:51 ` [patch 05/28] posix-timers: Introduce clockid_to_kclock() Thomas Gleixner
2011-02-01 20:37   ` john stultz
2011-02-02 21:56   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2011-02-01 13:51 ` [patch 06/28] posix-timers: Convert clock_nanosleep to clockid_to_kclock() Thomas Gleixner
2011-02-01 20:41   ` john stultz
2011-02-02 21:57   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2011-02-01 13:51 ` [patch 07/28] posix-timers: Convert clock_nanosleep_restart " Thomas Gleixner
2011-02-01 20:42   ` John Stultz
2011-02-01 20:46     ` Thomas Gleixner
2011-02-01 21:08       ` Thomas Gleixner
2011-02-02 21:57   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2011-02-01 13:51 ` [patch 08/28] posix-timers: Cleanup restart_block usage Thomas Gleixner
2011-02-01 21:11   ` john stultz
2011-02-01 21:14     ` Thomas Gleixner
2011-02-02 21:57   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2011-02-01 13:51 ` [patch 09/28] thread_info: Remove legacy arg0-3 from restart_block Thomas Gleixner
2011-02-01 21:11   ` john stultz
2011-02-02 21:58   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2011-02-01 13:51 ` [patch 10/28] posix-cpu-timers: Remove the stub nanosleep functions Thomas Gleixner
2011-02-01 21:14   ` John Stultz
2011-02-02 21:58   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2011-02-01 13:51 ` [patch 11/28] posix-timers: Convert clock_settime to clockid_to_kclock() Thomas Gleixner
2011-02-01 21:15   ` john stultz
2011-02-02 21:59   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2011-02-01 13:51 ` [patch 12/28] posix-timers: Convert clock_gettime() " Thomas Gleixner
2011-02-01 21:16   ` john stultz
2011-02-02  9:09   ` Richard Cochran
2011-02-02  9:55     ` Thomas Gleixner
2011-02-02 21:59   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2011-02-01 13:51 ` [patch 13/28] posix-timers: Convert clock_getres() " Thomas Gleixner
2011-02-01 21:17   ` john stultz
2011-02-02 22:00   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2011-02-01 13:51 ` [patch 14/28] posix-timers: Remove useless res field from k_clock Thomas Gleixner
2011-02-01 21:18   ` john stultz
2011-02-02 22:00   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2011-02-01 13:51 ` [patch 15/28] posix-timers: Convert timer_create() to clockid_to_kclock() Thomas Gleixner
2011-02-01 21:20   ` john stultz
2011-02-02 22:00   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2011-02-01 13:52 ` [patch 16/28] posix-timers: Convert timer_settime() " Thomas Gleixner
2011-02-01 21:22   ` John Stultz
2011-02-02 22:01   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2011-02-01 13:52 ` [patch 17/28] posix-timers: Convert timer_gettime() " Thomas Gleixner
2011-02-01 21:23   ` john stultz
2011-02-02 22:01   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2011-02-01 13:52 ` [patch 18/28] posix-timers: Convert timer_delete() " Thomas Gleixner
2011-02-01 21:24   ` john stultz
2011-02-02  8:29   ` Richard Cochran
2011-02-02  9:53     ` Thomas Gleixner
2011-02-02 22:02   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2011-02-01 13:52 ` [patch 19/28] posix-timers: Remove CLOCK_DISPATCH leftovers Thomas Gleixner
2011-02-01 21:25   ` john stultz
2011-02-02 22:02   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2011-02-01 13:52 ` [patch 20/28] posix-timers: Make posix-cpu-timers functions static Thomas Gleixner
2011-02-01 21:28   ` John Stultz
2011-02-01 21:33     ` Thomas Gleixner
2011-02-02 22:03   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2011-02-01 13:52 ` [patch 21/28] posix-timer: Update comment Thomas Gleixner
2011-02-01 21:28   ` john stultz
2011-02-02 22:03   ` [tip:timers/core] " tip-bot for Richard Cochran
2011-02-01 13:52 ` [patch 22/28] time: Introduce timekeeping_inject_offset Thomas Gleixner
2011-02-02 22:03   ` [tip:timers/core] " tip-bot for John Stultz
2011-02-01 13:52 ` [patch 23/28] ntp: Add ADJ_SETOFFSET mode bit Thomas Gleixner
2011-02-01 21:30   ` john stultz
2011-02-01 13:52 ` [patch 24/28] posix-clocks: Splitout compat timex accessors Thomas Gleixner
2011-02-01 21:31   ` john stultz
2011-02-02 22:04   ` [tip:timers/core] time: " tip-bot for Richard Cochran
2011-02-01 13:52 ` [patch 25/28] posix clocks: Introduce a syscall for clock tuning Thomas Gleixner
2011-02-01 21:35   ` john stultz
2011-02-02 22:04   ` [tip:timers/core] posix-timers: " tip-bot for Richard Cochran
2011-02-01 13:52 ` [patch 26/28] posix_clocks: Add clock_adjtime for x86 Thomas Gleixner
2011-02-01 21:36   ` john stultz
2011-02-02 22:05   ` [tip:timers/core] x86: " tip-bot for Richard Cochran
2011-02-01 13:52 ` [patch 27/28] posix-timers: Add support for fd based clocks Thomas Gleixner
2011-02-01 21:38   ` john stultz
2011-02-02  9:19   ` Richard Cochran
2011-02-02 10:33     ` Thomas Gleixner
2011-02-02 22:05   ` [tip:timers/core] " tip-bot for Richard Cochran
2011-02-01 13:52 ` [patch 28/28] posix clocks: Introduce dynamic clocks Thomas Gleixner
2011-02-01 21:49   ` john stultz
2011-02-01 22:04     ` Thomas Gleixner
2011-02-02  7:50     ` Richard Cochran
2011-02-02 10:37       ` Thomas Gleixner
2011-02-02 11:25         ` Thomas Gleixner
2011-02-02 22:06           ` [tip:timers/core] posix-timers: Cleanup namespace tip-bot for Thomas Gleixner
2011-02-02 22:06   ` [tip:timers/core] posix clocks: Introduce dynamic clocks tip-bot for Richard Cochran
2011-03-03 14:50   ` [patch 28/28] " torbenh
2011-03-03 16:01     ` Richard Cochran
2011-03-03 17:07       ` torbenh
2011-03-04  6:05         ` Richard Cochran
2011-02-02  8:17 ` [patch 00/28] Rework of the PTP support series core code Richard Cochran
2011-02-02 13:53 ` Richard Cochran
2011-02-02 22:04 ` [tip:timers/core] ntp: Add ADJ_SETOFFSET mode bit tip-bot for Richard Cochran
2011-02-18  9:07   ` Richard Cochran
2011-02-18 16:07     ` [tip:timers/core] ntp: Remove redundant and incorrect parameter check tip-bot for Richard Cochran
2011-03-01 15:38 ` [patch 00/28] Rework of the PTP support series core code torbenh
2011-03-01 18:50   ` Richard Cochran
2011-03-02  9:41     ` torbenh

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.