Skip to contentSkip to conversation

Rework of the PTP support series core code

PATCH In review Thomas Gleixner 7 participants 111 messages Feb 1, 2011 – Mar 4, 2011

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

cover Rework of the PTP support series core code

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

#1 lore raw

PATCH 1/28 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.

LKML-Reference: <681d9f8ba43fea01bae9f6a17a4674194a90353b.1296124770.git.richard.cochran@omicron.at>

---
 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(-)
drivers/char/mmtimer.c +1 -1
Index: 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;
include/linux/posix-timers.h +3 -2
Index: 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);
include/linux/security.h +5 -4
Index: 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);
 }
include/linux/time.h +3 -2
Index: 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;
kernel/posix-timers.c +2 -2
Index: 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;
 }
kernel/time.c +1 -1
Index: 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;
kernel/time/timekeeping.c +1 -1
Index: 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;
security/commoncap.c +1 -1
Index: 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;
security/security.c +1 -1
Index: 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);
 }
#2 lore raw

Re: [patch 01/28] time: Correct the *settime* parameters

On Tue, 1 Feb 2011, Thomas Gleixner wrote:

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

Thanks,

tglx

Acked-by on v1 1/28
#3 lore raw

Re: [patch 01/28] time: Correct the *settime* parameters

In reply to Thomas Gleixner
Quoted 11 lines · Thomas Gleixner

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.

LKML-Reference: <681d9f8ba43fea01bae9f6a17a4674194a90353b.1296124770.git.richard.cochran@omicron.at>

#4 lore raw

[tip:timers/core] time: Correct the *settime* parameters

In reply to Thomas Gleixner
Commit-ID:  1e6d767924c74929c0cfe839ae8f37bcee9e544e
Gitweb:     http://git.kernel.org/tip/1e6d767924c74929c0cfe839ae8f37bcee9e544e
Author:     Richard Cochran <[email protected]>
AuthorDate: Tue, 1 Feb 2011 13:50:58 +0000
Committer:  Thomas Gleixner <[email protected]>
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.

LKML-Reference: <[email protected]>

---
 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(-)
drivers/char/mmtimer.c +1 -1
index e6d7562..ecd0082 100644
@@ -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;
include/linux/posix-timers.h +3 -2
index 3e23844a..b2c14cb 100644
@@ -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);
include/linux/security.h +5 -4
index c642bb8..c096aa6 100644
@@ -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);
 }
include/linux/time.h +3 -2
index 38c5206..7c44e77 100644
@@ -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;
kernel/posix-timers.c +2 -2
index 93bd2eb..21b7ca2 100644
@@ -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;
 }
kernel/time.c +1 -1
index a31b512..5cb8053 100644
@@ -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;
kernel/time/timekeeping.c +1 -1
index 02c13a3..4f9f65b 100644
@@ -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;
security/commoncap.c +1 -1
index 64c2ed9..dbfdaed 100644
@@ -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;
security/security.c +1 -1
index 739e403..b995428 100644
@@ -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);
 }
#5 lore raw

PATCH 2/28 posix-timers: Define nanosleep not supported error separate

In reply to Thomas Gleixner

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

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>
---
 kernel/posix-timers.c |   14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
kernel/posix-timers.c +9 -5
Index: 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);
 
Acked-by on v1 2/28
#6 lore raw

Re: [patch 02/28] posix-timers: Define nanosleep not supported error separate

Quoted 8 lines · Thomas Gleixner

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.

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>
#7 lore raw

[tip:timers/core] posix-timers: Define nanosleep not supported error separate

In reply to Thomas Gleixner
Commit-ID:  65da528d7cc94966cf24d2a1e0837b689159b543
Gitweb:     http://git.kernel.org/tip/65da528d7cc94966cf24d2a1e0837b689159b543
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Tue, 1 Feb 2011 13:51:01 +0000
Committer:  Thomas Gleixner <[email protected]>
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.

LKML-Reference: <[email protected]>

---
 kernel/posix-timers.c |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)
kernel/posix-timers.c +9 -5
index 21b7ca2..89bff37 100644
@@ -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);
 
#8 lore raw

PATCH 3/28 posix-timers: Cleanup struct initializers

In reply to Thomas Gleixner

Cosmetic. No functional change

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>
---
 drivers/char/mmtimer.c    |   14 +++++++-------
 kernel/posix-cpu-timers.c |   24 ++++++++++++------------
 kernel/posix-timers.c     |   38 +++++++++++++++++++-------------------
 3 files changed, 38 insertions(+), 38 deletions(-)
drivers/char/mmtimer.c +7 -7
Index: 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
 };
 
 /**
kernel/posix-cpu-timers.c +12 -12
Index: 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;
 
kernel/posix-timers.c +19 -19
Index: 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);
Acked-by on v1 3/28
#9 lore raw

Re: [patch 03/28] posix-timers: Cleanup struct initializers

Quoted 7 lines · Thomas Gleixner

plain text document attachment (posix-timers-cleanup-struct-initializers-codingstyle.patch) Cosmetic. No functional change

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>
Quoted 127 lines
---
 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
===================================================================

drivers/char/mmtimer.c +7 -7
@@ -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
===================================================================

kernel/posix-cpu-timers.c +12 -12
@@ -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
===================================================================

kernel/posix-timers.c +19 -19
@@ -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);
#10 lore raw

[tip:timers/core] posix-timers: Cleanup struct initializers

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

posix-timers: Cleanup struct initializers

Cosmetic. No functional change

LKML-Reference: <[email protected]>

---
 drivers/char/mmtimer.c    |   14 +++++++-------
 kernel/posix-cpu-timers.c |   24 ++++++++++++------------
 kernel/posix-timers.c     |   38 +++++++++++++++++++-------------------
 3 files changed, 38 insertions(+), 38 deletions(-)
drivers/char/mmtimer.c +7 -7
index ecd0082..fd51cd8 100644
@@ -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
 };
 
 /**
kernel/posix-cpu-timers.c +12 -12
index 05bb717..11b91dc 100644
@@ -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;
 
kernel/posix-timers.c +19 -19
index 89bff37..e7d26af 100644
@@ -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);
#11 lore raw

PATCH 4/28 posix-timers: Introduce clock_posix_cpu

In reply to Thomas Gleixner

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.

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>
---
 include/linux/posix-timers.h |    2 ++
 kernel/posix-cpu-timers.c    |   12 ++++++++++++
 2 files changed, 14 insertions(+)
include/linux/posix-timers.h +2 -0
Index: 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 */
kernel/posix-cpu-timers.c +12 -0
Index: 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 = {
Acked-by on v1 4/28
#12 lore raw

Re: [patch 04/28] posix-timers: Introduce clock_posix_cpu

Quoted 8 lines · Thomas Gleixner

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.

Quoted 7 lines

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.

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>
Quoted 43 lines
---
 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
===================================================================

include/linux/posix-timers.h +2 -0
@@ -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
===================================================================

kernel/posix-cpu-timers.c +12 -0
@@ -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 = {
#13 lore raw

[tip:timers/core] posix-timers: Introduce clock_posix_cpu

In reply to Thomas Gleixner
Commit-ID:  1976945eeaab5fa461735a6225a82c3cf1e65d62
Gitweb:     http://git.kernel.org/tip/1976945eeaab5fa461735a6225a82c3cf1e65d62
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Tue, 1 Feb 2011 13:51:06 +0000
Committer:  Thomas Gleixner <[email protected]>
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.

LKML-Reference: <[email protected]>

---
 include/linux/posix-timers.h |    2 ++
 kernel/posix-cpu-timers.c    |   12 ++++++++++++
 2 files changed, 14 insertions(+), 0 deletions(-)
include/linux/posix-timers.h +2 -0
index b2c14cb..1330ff3 100644
@@ -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 */
kernel/posix-cpu-timers.c +12 -0
index 11b91dc..816cd49 100644
@@ -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 = {
#14 lore raw

PATCH 5/28 posix-timers: Introduce clockid_to_kclock()

In reply to Thomas Gleixner

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.

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>
---
 kernel/posix-timers.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
kernel/posix-timers.c +10 -0
Index: 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,
Acked-by on v1 5/28
#15 lore raw

Re: [patch 05/28] posix-timers: Introduce clockid_to_kclock()

Quoted 4 lines · Thomas Gleixner

plain text document attachment (posix-timers-introduce-clockid-to-kclock.patch) New function to find the kclock for a given clockid.

Quoted 8 lines

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.

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>
#16 lore raw

[tip:timers/core] posix-timers: Introduce clockid_to_kclock()

In reply to Thomas Gleixner
Commit-ID:  cc785ac22b17ed53e8ff5c1501e422be6d10be3c
Gitweb:     http://git.kernel.org/tip/cc785ac22b17ed53e8ff5c1501e422be6d10be3c
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Tue, 1 Feb 2011 13:51:09 +0000
Committer:  Thomas Gleixner <[email protected]>
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.

LKML-Reference: <[email protected]>

---
 kernel/posix-timers.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
kernel/posix-timers.c +10 -0
index e7d26af..14b0a70 100644
@@ -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,
#17 lore raw

PATCH 6/28 posix-timers: Convert clock_nanosleep to clockid_to_kclock()

In reply to Thomas Gleixner

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

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>
---
 drivers/char/mmtimer.c       |    1 -
 include/linux/posix-timers.h |    2 --
 kernel/posix-timers.c        |   26 +++++++-------------------
 3 files changed, 7 insertions(+), 22 deletions(-)
drivers/char/mmtimer.c +0 -1
Index: 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
include/linux/posix-timers.h +0 -2
Index: 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 */
kernel/posix-timers.c +7 -19
Index: 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);
 }
 
 /*
Acked-by on v1 6/28
#18 lore raw

Re: [patch 06/28] posix-timers: Convert clock_nanosleep to clockid_to_kclock()

Quoted 7 lines · Thomas Gleixner

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.

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>
#19 lore raw

[tip:timers/core] posix-timers: Convert clock_nanosleep to clockid_to_kclock()

In reply to Thomas Gleixner
Commit-ID:  a5cd2880106cb2c79b3fe24f1c53dadba6a542a0
Gitweb:     http://git.kernel.org/tip/a5cd2880106cb2c79b3fe24f1c53dadba6a542a0
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Tue, 1 Feb 2011 13:51:11 +0000
Committer:  Thomas Gleixner <[email protected]>
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.

LKML-Reference: <[email protected]>

---
 drivers/char/mmtimer.c       |    1 -
 include/linux/posix-timers.h |    2 --
 kernel/posix-timers.c        |   26 +++++++-------------------
 3 files changed, 7 insertions(+), 22 deletions(-)
drivers/char/mmtimer.c +0 -1
index fd51cd8..262d104 100644
@@ -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
include/linux/posix-timers.h +0 -2
index 1330ff3..cd6da06 100644
@@ -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 */
kernel/posix-timers.c +7 -19
index 14b0a70..ee69b21 100644
@@ -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);
 }
 
 /*
#20 lore raw

PATCH 7/28 posix-timers: Convert clock_nanosleep_restart to clockid_to_kclock()

In reply to Thomas Gleixner

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.

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>
---
 kernel/posix-timers.c |   17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)
kernel/posix-timers.c +5 -12
Index: 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);
 }
#21 lore raw

Re: [patch 07/28] posix-timers: Convert clock_nanosleep_restart to clockid_to_kclock()

Quoted 9 lines · Thomas Gleixner

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.

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>

One nit.

kernel/posix-timers.c SYSCALL_DEFINE4(clock_nanosleep, const c · line 1041

Quoted 11 lines
kernel/posix-timers.c +3 -4
-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

#22 lore raw

Re: [patch 07/28] posix-timers: Convert clock_nanosleep_restart to clockid_to_kclock()

Quoted 20 lines · John Stultz
Quoted 9 lines · Thomas Gleixner

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.

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>

One nit.

Quoted 7 lines
kernel/posix-timers.c +2 -2
-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);
Quoted 8 lines

kernel/posix-timers.c SYSCALL_DEFINE4(clock_nanosleep, const c · line 1041

Quoted 4 lines
kernel/posix-timers.c +1 -2
-	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

#23 lore raw

Re: [patch 07/28] posix-timers: Convert clock_nanosleep_restart to clockid_to_kclock()

Quoted 31 lines · Thomas Gleixner
Quoted 20 lines · John Stultz
Quoted 9 lines · Thomas Gleixner

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.

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>

One nit.

Quoted 7 lines
kernel/posix-timers.c +2 -2
-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);
Quoted 8 lines

kernel/posix-timers.c SYSCALL_DEFINE4(clock_nanosleep, const c · line 1041

Quoted 4 lines
kernel/posix-timers.c +1 -2
-	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?

Quoted 2 lines

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

#24 lore raw

[tip:timers/core] posix-timers: Convert clock_nanosleep_restart to clockid_to_kclock()

In reply to Thomas Gleixner
Commit-ID:  59bd5bc24aa69f6c62da1e242c16f09f667def96
Gitweb:     http://git.kernel.org/tip/59bd5bc24aa69f6c62da1e242c16f09f667def96
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Tue, 1 Feb 2011 13:51:17 +0000
Committer:  Thomas Gleixner <[email protected]>
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.

LKML-Reference: <[email protected]>

---
 kernel/posix-timers.c |   20 ++++++++------------
 1 files changed, 8 insertions(+), 12 deletions(-)
kernel/posix-timers.c +8 -12
index ee69b21..4dd86d1 100644
@@ -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);
 }
#25 lore raw

PATCH 8/28 posix-timers: Cleanup restart_block usage

In reply to Thomas Gleixner

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

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>
---
 kernel/posix-cpu-timers.c |   38 +++++++++++++++-----------------------
 kernel/posix-timers.c     |    2 +-
 2 files changed, 16 insertions(+), 24 deletions(-)
kernel/posix-cpu-timers.c +15 -23
Index: 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;
 
kernel/posix-timers.c +1 -1
Index: 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);
Acked-by on v1 8/28
#26 lore raw

Re: [patch 08/28] posix-timers: Cleanup restart_block usage

Quoted 8 lines · Thomas Gleixner

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

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>

[snip]

Quoted 24 lines

long posix_cpu_nsleep_restart(struct restart_block *restart_block) {

kernel/posix-cpu-timers.c +4 -9
-	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.

kernel/posix-cpu-timers.c int posix_cpu_nsleep(const clockid_t whi · line 1539

Quoted 10 lines
kernel/posix-cpu-timers.c +3 -5
+		 */
+		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).

thanks
-john

#27 lore raw

Re: [patch 08/28] posix-timers: Cleanup restart_block usage

Quoted 12 lines · john stultz

kernel/posix-cpu-timers.c int posix_cpu_nsleep(const clockid_t whi · line 1539

Quoted 6 lines · Thomas Gleixner
kernel/posix-cpu-timers.c +1 -5
-		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

#28 lore raw

[tip:timers/core] posix-timers: Cleanup restart_block usage

In reply to Thomas Gleixner
Commit-ID:  3751f9f29bcbc19bd10e92254a273486f150c245
Gitweb:     http://git.kernel.org/tip/3751f9f29bcbc19bd10e92254a273486f150c245
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Tue, 1 Feb 2011 13:51:20 +0000
Committer:  Thomas Gleixner <[email protected]>
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

LKML-Reference: <[email protected]>

---
 kernel/posix-cpu-timers.c |   38 +++++++++++++++-----------------------
 kernel/posix-timers.c     |    2 +-
 2 files changed, 16 insertions(+), 24 deletions(-)
kernel/posix-cpu-timers.c +15 -23
index 816cd49..9e617b0 100644
@@ -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;
 
kernel/posix-timers.c +1 -1
index 4dd86d1..4762986 100644
@@ -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))
#29 lore raw

PATCH 9/28 thread_info: Remove legacy arg0-3 from restart_block

In reply to Thomas Gleixner

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

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>
---
 include/linux/thread_info.h |    3 ---
 1 file changed, 3 deletions(-)
include/linux/thread_info.h +0 -3
Index: 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;
Acked-by on v1 9/28
#30 lore raw

Re: [patch 09/28] thread_info: Remove legacy arg0-3 from restart_block

Quoted 8 lines · Thomas Gleixner

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.

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>

---

#31 lore raw

[tip:timers/core] thread_info: Remove legacy arg0-3 from restart_block

In reply to Thomas Gleixner
Commit-ID:  d608c18203a969e5d14572a9861c646d0bb66872
Gitweb:     http://git.kernel.org/tip/d608c18203a969e5d14572a9861c646d0bb66872
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Tue, 1 Feb 2011 13:51:43 +0000
Committer:  Thomas Gleixner <[email protected]>
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.

LKML-Reference: <[email protected]>

---
 include/linux/thread_info.h |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)
include/linux/thread_info.h +0 -3
index c906965..20fc303 100644
@@ -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;
#32 lore raw

PATCH 10/28 posix-cpu-timers: Remove the stub nanosleep functions

In reply to Thomas Gleixner

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.

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>
---
 kernel/posix-cpu-timers.c |   11 -----------
 1 file changed, 11 deletions(-)
kernel/posix-cpu-timers.c +0 -11
Index: 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;
 
Acked-by on v1 10/28
#33 lore raw

Re: [patch 10/28] posix-cpu-timers: Remove the stub nanosleep functions

Quoted 6 lines · Thomas Gleixner

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.

Quoted 7 lines

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

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>

---

#34 lore raw

[tip:timers/core] posix-cpu-timers: Remove the stub nanosleep functions

In reply to Thomas Gleixner
Commit-ID:  79c9da0d0539fb341a1b48a2a5a23d974726de90
Gitweb:     http://git.kernel.org/tip/79c9da0d0539fb341a1b48a2a5a23d974726de90
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Tue, 1 Feb 2011 13:51:45 +0000
Committer:  Thomas Gleixner <[email protected]>
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.

LKML-Reference: <[email protected]>

---
 kernel/posix-cpu-timers.c |   11 -----------
 1 files changed, 0 insertions(+), 11 deletions(-)
kernel/posix-cpu-timers.c +0 -11
index 9e617b0..8dc4cd7 100644
@@ -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;
 
#35 lore raw

PATCH 11/28 posix-timers: Convert clock_settime to clockid_to_kclock()

In reply to Thomas Gleixner

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().

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>
---
 include/linux/posix-timers.h |    3 ---
 kernel/posix-cpu-timers.c    |    2 --
 kernel/posix-timers.c        |   31 ++++++++++++-------------------
 3 files changed, 12 insertions(+), 24 deletions(-)
include/linux/posix-timers.h +0 -3
Index: 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);
 
kernel/posix-cpu-timers.c +0 -2
Index: 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;
kernel/posix-timers.c +12 -19
Index: 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,
Acked-by on v1 11/28
#36 lore raw

Re: [patch 11/28] posix-timers: Convert clock_settime to clockid_to_kclock()

Quoted 8 lines · Thomas Gleixner

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().

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>
#37 lore raw

[tip:timers/core] posix-timers: Convert clock_settime to clockid_to_kclock()

In reply to Thomas Gleixner
Commit-ID:  26f9a4796af330173d790c8d2b5e2efcc489e755
Gitweb:     http://git.kernel.org/tip/26f9a4796af330173d790c8d2b5e2efcc489e755
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Tue, 1 Feb 2011 13:51:48 +0000
Committer:  Thomas Gleixner <[email protected]>
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().

LKML-Reference: <[email protected]>

---
 include/linux/posix-timers.h |    3 ---
 kernel/posix-cpu-timers.c    |    2 --
 kernel/posix-timers.c        |   31 ++++++++++++-------------------
 3 files changed, 12 insertions(+), 24 deletions(-)
include/linux/posix-timers.h +0 -3
index cd6da06..4aaf0c5 100644
@@ -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);
 
kernel/posix-cpu-timers.c +0 -2
index 8dc4cd7..504fbab 100644
@@ -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;
kernel/posix-timers.c +12 -19
index 4762986..49f358c 100644
@@ -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,
#38 lore raw

PATCH 12/28 posix-timers: Convert clock_gettime() to clockid_to_kclock()

In reply to Thomas Gleixner

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

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>
---
 kernel/posix-timers.c |   28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)
kernel/posix-timers.c +15 -13
Index: 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,
Acked-by on v1 12/28
#39 lore raw

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

Quoted 7 lines · Thomas Gleixner

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().

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>
#40 lore raw

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

In reply to Thomas Gleixner
Quoted 8 lines · Thomas Gleixner
kernel/posix-timers.c +1 -0
@@ -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);

kernel/posix-timers.c SYSCALL_DEFINE2(clock_settime, const clo · line 965

Quoted 10 lines
kernel/posix-timers.c +3 -3
 	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().

kernel/posix-timers.c SYSCALL_DEFINE2(clock_settime, const clo · line 973

Quoted 9 lines
kernel/posix-timers.c +3 -1
+
+	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

#41 lore raw

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

Quoted 22 lines · Richard Cochran
Quoted 8 lines · Thomas Gleixner
kernel/posix-timers.c +1 -0
@@ -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);

kernel/posix-timers.c SYSCALL_DEFINE2(clock_settime, const clo · line 965

Quoted 10 lines
kernel/posix-timers.c +3 -3
 	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?

Quoted 2 lines

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

#42 lore raw

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

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

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

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

LKML-Reference: <[email protected]>

---
 kernel/posix-timers.c |   28 +++++++++++++++-------------
 1 files changed, 15 insertions(+), 13 deletions(-)
kernel/posix-timers.c +15 -13
index 49f358c..d9e5edf 100644
@@ -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,
#43 lore raw

PATCH 13/28 posix-timers: Convert clock_getres() to clockid_to_kclock()

In reply to Thomas Gleixner

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

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>
---
 drivers/char/mmtimer.c |   10 ++++++++++
 kernel/posix-timers.c  |   17 ++++-------------
 2 files changed, 14 insertions(+), 13 deletions(-)
drivers/char/mmtimer.c +10 -0
Index: 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,
kernel/posix-timers.c +4 -13
Index: 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;
 }
#45 lore raw

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

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

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

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

LKML-Reference: <[email protected]>

---
 drivers/char/mmtimer.c |   10 ++++++++++
 kernel/posix-timers.c  |   17 ++++-------------
 2 files changed, 14 insertions(+), 13 deletions(-)
drivers/char/mmtimer.c +10 -0
index 262d104..141ffae 100644
@@ -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,
kernel/posix-timers.c +4 -13
index 7f66143..748497f 100644
@@ -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;
 }
#46 lore raw

PATCH 14/28 posix-timers: Remove useless res field from k_clock

In reply to Thomas Gleixner

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

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>
---
 drivers/char/mmtimer.c       |    5 ++---
 include/linux/posix-timers.h |    1 -
 kernel/posix-timers.c        |    2 --
 3 files changed, 2 insertions(+), 6 deletions(-)
drivers/char/mmtimer.c +2 -3
Index: 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,
include/linux/posix-timers.h +0 -1
Index: 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);
kernel/posix-timers.c +0 -2
Index: 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;
 }
 
Acked-by on v1 14/28
#47 lore raw

Re: [patch 14/28] posix-timers: Remove useless res field from k_clock

Quoted 8 lines · Thomas Gleixner

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.

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>
#48 lore raw

[tip:timers/core] posix-timers: Remove useless res field from k_clock

In reply to Thomas Gleixner
Commit-ID:  ebaac757acae0431e2c79c00e09f1debdabbddd7
Gitweb:     http://git.kernel.org/tip/ebaac757acae0431e2c79c00e09f1debdabbddd7
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Tue, 1 Feb 2011 13:51:56 +0000
Committer:  Thomas Gleixner <[email protected]>
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.

LKML-Reference: <[email protected]>

---
 drivers/char/mmtimer.c       |    5 ++---
 include/linux/posix-timers.h |    1 -
 kernel/posix-timers.c        |    2 --
 3 files changed, 2 insertions(+), 6 deletions(-)
drivers/char/mmtimer.c +2 -3
index 141ffae..ff41eb3 100644
@@ -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,
include/linux/posix-timers.h +0 -1
index 4aaf0c5..ef574d1 100644
@@ -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);
kernel/posix-timers.c +0 -2
index 748497f..f9142a9 100644
@@ -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;
 }
 
#49 lore raw

PATCH 15/28 posix-timers: Convert timer_create() to clockid_to_kclock()

In reply to Thomas Gleixner

Setup timer_create for CLOCK_MONOTONIC and CLOCK_REALTIME kclocks and remove the no_timer_create() implementation.

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>
---
 kernel/posix-timers.c |   40 +++++++++++++++-------------------------
 1 file changed, 15 insertions(+), 25 deletions(-)
kernel/posix-timers.c +15 -25
Index: 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
Acked-by on v1 15/28
#50 lore raw

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

Quoted 8 lines · Thomas Gleixner

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.

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>
#51 lore raw

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

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

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

Setup timer_create for CLOCK_MONOTONIC and CLOCK_REALTIME kclocks and remove the no_timer_create() implementation.

LKML-Reference: <[email protected]>

---
 kernel/posix-timers.c |   40 +++++++++++++++-------------------------
 1 files changed, 15 insertions(+), 25 deletions(-)
kernel/posix-timers.c +15 -25
index f9142a9..4f71382 100644
@@ -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
#52 lore raw

PATCH 16/28 posix-timers: Convert timer_settime() to clockid_to_kclock()

In reply to Thomas Gleixner

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.

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>
---
 kernel/posix-timers.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
kernel/posix-timers.c +5 -2
Index: 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) {
#53 lore raw

Re: [patch 16/28] posix-timers: Convert timer_settime() to clockid_to_kclock()

Quoted 10 lines · Thomas Gleixner

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.

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>

[snip]

kernel/posix-timers.c retry: · line 825

Quoted 8 lines
kernel/posix-timers.c +2 -2
@@ -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

#54 lore raw

[tip:timers/core] posix-timers: Convert timer_settime() to clockid_to_kclock()

In reply to Thomas Gleixner
Commit-ID:  27722df16ef143017db55ac7baac1703a68017ff
Gitweb:     http://git.kernel.org/tip/27722df16ef143017db55ac7baac1703a68017ff
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Tue, 1 Feb 2011 13:52:01 +0000
Committer:  Thomas Gleixner <[email protected]>
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.

LKML-Reference: <[email protected]>

---
 kernel/posix-timers.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
kernel/posix-timers.c +8 -2
index 4f71382..a4dbfe7 100644
@@ -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) {
#55 lore raw

PATCH 17/28 posix-timers: Convert timer_gettime() to clockid_to_kclock()

In reply to Thomas Gleixner

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.

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>
---
 kernel/posix-timers.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
kernel/posix-timers.c +6 -2
Index: 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);
 
#56 lore raw

Re: [patch 17/28] posix-timers: Convert timer_gettime() to clockid_to_kclock()

Quoted 10 lines · Thomas Gleixner

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.

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>

[snip]

kernel/posix-timers.c common_timer_get(struct k_itimer *timr, · line 716

Quoted 3 lines
kernel/posix-timers.c +2 -1
-	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

#57 lore raw

[tip:timers/core] posix-timers: Convert timer_gettime() to clockid_to_kclock()

In reply to Thomas Gleixner
Commit-ID:  a7319fa253a549c4c6528fb550ae6e72a9c83811
Gitweb:     http://git.kernel.org/tip/a7319fa253a549c4c6528fb550ae6e72a9c83811
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Tue, 1 Feb 2011 13:52:04 +0000
Committer:  Thomas Gleixner <[email protected]>
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.

LKML-Reference: <[email protected]>

---
 kernel/posix-timers.c |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)
kernel/posix-timers.c +12 -4
index a4dbfe7..c1e2636 100644
@@ -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;
 }
 
 /*
#58 lore raw

PATCH 18/28 posix-timers: Convert timer_delete() to clockid_to_kclock()

In reply to Thomas Gleixner

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.

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>
---
 kernel/posix-timers.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
kernel/posix-timers.c +5 -1
Index: 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. */
#59 lore raw

Re: [patch 18/28] posix-timers: Convert timer_delete() to clockid_to_kclock()

Quoted 11 lines · Thomas Gleixner

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.

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>

---

[snip]

kernel/posix-timers.c static inline int common_timer_del(struc · line 860

Quoted 9 lines
kernel/posix-timers.c +3 -1
@@ -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

#60 lore raw

Re: [patch 18/28] posix-timers: Convert timer_delete() to clockid_to_kclock()

In reply to Thomas Gleixner
Quoted 13 lines · Thomas Gleixner

Index: linux-2.6-tip/kernel/posix-timers.c
===================================================================

kernel/posix-timers.c +1 -0
@@ -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,

kernel/posix-timers.c static __init int init_posix_timers(void · line 270

Quoted 7 lines
kernel/posix-timers.c +1 -0
@@ -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

#61 lore raw

Re: [patch 18/28] posix-timers: Convert timer_delete() to clockid_to_kclock()

Quoted 26 lines · Richard Cochran
Quoted 13 lines · Thomas Gleixner

Index: linux-2.6-tip/kernel/posix-timers.c
===================================================================

kernel/posix-timers.c +1 -0
@@ -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,

kernel/posix-timers.c static __init int init_posix_timers(void · line 270

Quoted 7 lines
kernel/posix-timers.c +1 -0
@@ -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.

Quoted 1 line

(But strangly, newer versions do not).

Will fix. Thanks.

tglx

#62 lore raw

[tip:timers/core] posix-timers: Convert timer_delete() to clockid_to_kclock()

In reply to Thomas Gleixner
Commit-ID:  6761c6702e2c647582e1829abe8cf90794f61d9d
Gitweb:     http://git.kernel.org/tip/6761c6702e2c647582e1829abe8cf90794f61d9d
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Tue, 1 Feb 2011 13:52:07 +0000
Committer:  Thomas Gleixner <[email protected]>
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.

LKML-Reference: <[email protected]>

---
 kernel/posix-timers.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
kernel/posix-timers.c +8 -2
index c1e2636..ade7dec 100644
@@ -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. */
#63 lore raw

PATCH 19/28 posix-timers: Remove CLOCK_DISPATCH leftovers

In reply to Thomas Gleixner

All users gone. Remove the cruft.

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>
---
 kernel/posix-timers.c |   22 ----------------------
 1 file changed, 22 deletions(-)
kernel/posix-timers.c +0 -22
Index: 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)
 {
Acked-by on v1 19/28
#64 lore raw

Re: [patch 19/28] posix-timers: Remove CLOCK_DISPATCH leftovers

Quoted 17 lines · Thomas Gleixner

plain text document attachment (posix-timers-remove-clock-dispatch-leftovers.patch) All users gone. Remove the cruft.

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>
---
 kernel/posix-timers.c |   22 ----------------------
 1 file changed, 22 deletions(-)

Index: linux-2.6-tip/kernel/posix-timers.c
===================================================================

kernel/posix-timers.c +0 -0
@@ -167,28 +167,6 @@ static inline void unlock_timer(struct k
 	spin_unlock_irqrestore(&timr->it_lock, flags);

kernel/posix-timers.c static inline void unlock_timer(struct k · line 177

Quoted 10 lines
kernel/posix-timers.c +0 -8
 }
 
-/*
- * 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!

#65 lore raw

[tip:timers/core] posix-timers: Remove CLOCK_DISPATCH leftovers

In reply to Thomas Gleixner
Commit-ID:  0aa3975f02ce78f27be3076fbfa3d94ae5a659d5
Gitweb:     http://git.kernel.org/tip/0aa3975f02ce78f27be3076fbfa3d94ae5a659d5
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Tue, 1 Feb 2011 13:52:09 +0000
Committer:  Thomas Gleixner <[email protected]>
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.

LKML-Reference: <[email protected]>

---
 kernel/posix-timers.c |   22 ----------------------
 1 files changed, 0 insertions(+), 22 deletions(-)
kernel/posix-timers.c +0 -22
index ade7dec..ad154df 100644
@@ -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)
 {
#66 lore raw

PATCH 20/28 posix-timers: Make posix-cpu-timers functions static

In reply to Thomas Gleixner

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

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>
---
 include/linux/posix-timers.h |   12 -------
 kernel/posix-cpu-timers.c    |   73 +++++++++++++++++++++----------------------
 2 files changed, 37 insertions(+), 48 deletions(-)
include/linux/posix-timers.h +0 -12
Index: 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);
kernel/posix-cpu-timers.c +37 -36

155 lines not on this page · raw message

#67 lore raw

Re: [patch 20/28] posix-timers: Make posix-cpu-timers functions static

Quoted 7 lines · Thomas Gleixner

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.

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>

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

Quoted 81 lines
kernel/posix-cpu-timers.c +23 -25
@@ -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;

kernel/posix-cpu-timers.c static int do_cpu_nanosleep(const clocki · line 1545

Quoted 10 lines
kernel/posix-cpu-timers.c +4 -2
 
-		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

#68 lore raw

Re: [patch 20/28] posix-timers: Make posix-cpu-timers functions static

Quoted 93 lines · John Stultz
Quoted 7 lines · Thomas Gleixner

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.

Cc John Stultz <[email protected]>
Cc Richard Cochran <[email protected]>

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

Quoted 82 lines
kernel/posix-cpu-timers.c +23 -25
@@ -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;
 
Quoted 11 lines

kernel/posix-cpu-timers.c static int do_cpu_nanosleep(const clocki · line 1545

Quoted 9 lines
kernel/posix-cpu-timers.c +4 -2
-		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

#69 lore raw

[tip:timers/core] posix-timers: Make posix-cpu-timers functions static

In reply to Thomas Gleixner
Commit-ID:  bc2c8ea483d73e95fc88f1fc9e7755180f89b892
Gitweb:     http://git.kernel.org/tip/bc2c8ea483d73e95fc88f1fc9e7755180f89b892
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Tue, 1 Feb 2011 13:52:12 +0000
Committer:  Thomas Gleixner <[email protected]>
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.

LKML-Reference: <[email protected]>

---
 include/linux/posix-timers.h |   12 ------------
 kernel/posix-cpu-timers.c    |   27 +++++++++++++++------------
 2 files changed, 15 insertions(+), 24 deletions(-)
include/linux/posix-timers.h +0 -12
index ef574d1..8206255 100644
@@ -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);
kernel/posix-cpu-timers.c +15 -12
index 504fbab..609e187 100644
@@ -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)
 
#70 lore raw

PATCH 21/28 posix-timer: Update comment

In reply to Thomas Gleixner

From: Richard Cochran <[email protected]>

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

Originally-from: Richard Cochran <[email protected]>

---
 kernel/posix-timers.c |   25 +++++++------------------
 1 file changed, 7 insertions(+), 18 deletions(-)
kernel/posix-timers.c +7 -18
Index: 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
Acked-by on v1 21/28
#71 lore raw

Re: [patch 21/28] posix-timer: Update comment

Quoted 9 lines · Thomas Gleixner

plain text document attachment (posix-timer-update-comment.patch)
From: Richard Cochran <[email protected]>

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

Originally-from: Richard Cochran <[email protected]>

#72 lore raw

[tip:timers/core] posix-timer: Update comment

In reply to Thomas Gleixner
Commit-ID:  0061748dd2400d0bcd4d49d258db5d7b5d106ca0
Gitweb:     http://git.kernel.org/tip/0061748dd2400d0bcd4d49d258db5d7b5d106ca0
Author:     Richard Cochran <[email protected]>
AuthorDate: Tue, 1 Feb 2011 13:52:15 +0000
Committer:  Thomas Gleixner <[email protected]>
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 <[email protected]>

LKML-Reference: <[email protected]>

---
 kernel/posix-timers.c |   25 +++++++------------------
 1 files changed, 7 insertions(+), 18 deletions(-)
kernel/posix-timers.c +7 -18
index ad154df..a3fdfd4 100644
@@ -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
#73 lore raw

PATCH 22/28 time: Introduce timekeeping_inject_offset

In reply to Thomas Gleixner

From: John Stultz <[email protected]>

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.

LKML-Reference: <6aec014551fc1d34924d6a7bcf97769867c15ba9.1296124770.git.richard.cochran@omicron.at>

---
 include/linux/time.h      |    1 +
 kernel/time/timekeeping.c |   36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)
include/linux/time.h +1 -0
Index: 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 *);
kernel/time/timekeeping.c +36 -0
Index: 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
  *
#74 lore raw

[tip:timers/core] time: Introduce timekeeping_inject_offset

Commit-ID:  c528f7c6c208f1fae6b4025957173dec045e5f21
Gitweb:     http://git.kernel.org/tip/c528f7c6c208f1fae6b4025957173dec045e5f21
Author:     John Stultz <[email protected]>
AuthorDate: Tue, 1 Feb 2011 13:52:17 +0000
Committer:  Thomas Gleixner <[email protected]>
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.

LKML-Reference: <[email protected]>

---
 include/linux/time.h      |    1 +
 kernel/time/timekeeping.c |   36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 0 deletions(-)
include/linux/time.h +1 -0
index 7c44e77..379b903 100644
@@ -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 *);
kernel/time/timekeeping.c +36 -0
index 4f9f65b..6262c1d 100644
@@ -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
  *
#75 lore raw

PATCH 23/28 ntp: Add ADJ_SETOFFSET mode bit

In reply to Thomas Gleixner

From: Richard Cochran <[email protected]>

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.

LKML-Reference: <2f7ed6bce83c23e4b7e4530794f0aa175df31a39.1296124770.git.richard.cochran@omicron.at>

---
 include/linux/timex.h |    3 ++-
 kernel/time/ntp.c     |   11 +++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
include/linux/timex.h +2 -1
Index: 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 */
kernel/time/ntp.c +11 -0
Index: 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);
Acked-by on v1 23/28
#76 lore raw

Re: [patch 23/28] ntp: Add ADJ_SETOFFSET mode bit

Quoted 10 lines · Thomas Gleixner

plain text document attachment (ntp-add-adj_setoffset-mode-bit.patch)
From: Richard Cochran <[email protected]>

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.

LKML-Reference: <2f7ed6bce83c23e4b7e4530794f0aa175df31a39.1296124770.git.richard.cochran@omicron.at>

#77 lore raw

PATCH 24/28 posix-clocks: Splitout compat timex accessors

In reply to Thomas Gleixner

From: Richard Cochran <[email protected]>

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 <[email protected]>
Cc: John Stultz <[email protected]>
LKML-Reference: <2d5e2f3e6f388aa1848d40406646aab2e26a906f.1296124770.git.richard.cochran@omicron.at>

---
 kernel/compat.c |  113 ++++++++++++++++++++++++++++++++------------------------
 1 file changed, 65 insertions(+), 48 deletions(-)
kernel/compat.c +65 -48
Index: 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;
 }
Acked-by on v1 24/28
#78 lore raw

Re: [patch 24/28] posix-clocks: Splitout compat timex accessors

Quoted 7 lines · Thomas Gleixner

plain text document attachment (posix-clocks-splitout-compat-timex-accessors.patch)
From: Richard Cochran <[email protected]>

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

Quoted 8 lines

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

Originally-from: Richard Cochran <[email protected]>
Cc: John Stultz <[email protected]>
LKML-Reference: <2d5e2f3e6f388aa1848d40406646aab2e26a906f.1296124770.git.richard.cochran@omicron.at>

#79 lore raw

[tip:timers/core] time: Splitout compat timex accessors

In reply to Thomas Gleixner
Commit-ID:  65f5d80bdf83ec0d7f3887db10153bf3f36ed73c
Gitweb:     http://git.kernel.org/tip/65f5d80bdf83ec0d7f3887db10153bf3f36ed73c
Author:     Richard Cochran <[email protected]>
AuthorDate: Tue, 1 Feb 2011 13:52:23 +0000
Committer:  Thomas Gleixner <[email protected]>
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 <[email protected]>

LKML-Reference: <[email protected]>

---
 kernel/compat.c |  113 +++++++++++++++++++++++++++++++-----------------------
 1 files changed, 65 insertions(+), 48 deletions(-)
kernel/compat.c +65 -48
index c9e2ec0..449e853 100644
@@ -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;
 }
#80 lore raw

PATCH 25/28 posix clocks: Introduce a syscall for clock tuning.

In reply to Thomas Gleixner

From: Richard Cochran <[email protected]>

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 ]

Cc Alan Cox <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Christoph Lameter <[email protected]>
Cc David Miller <[email protected]>
Cc John Stultz <[email protected]>
Cc Krzysztof Halasa <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Rodolfo Giometti <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Mike Frysinger <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Russell King <[email protected]>

LKML-Reference: <2d5e2f3e6f388aa1848d40406646aab2e26a906f.1296124770.git.richard.cochran@omicron.at>

---
 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(+)
include/linux/posix-timers.h +2 -0
Index: 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 *);
include/linux/syscalls.h +2 -0
Index: 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,
kernel/compat.c +23 -0
Index: 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)
 {
kernel/posix-timers.c +30 -0
Index: 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)
 {
Acked-by on v1 25/28
#81 lore raw

Re: [patch 25/28] posix clocks: Introduce a syscall for clock tuning.

Quoted 4 lines · Thomas Gleixner

plain text document attachment (posix-clocks-introduce-a-syscall-for-clock-tuning.patch)
From: Richard Cochran <[email protected]>

Quoted 8 lines

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 ]

#82 lore raw

[tip:timers/core] posix-timers: Introduce a syscall for clock tuning.

In reply to Thomas Gleixner
Commit-ID:  f1f1d5ebd10ffa4242bce7a90a56a222d6b7bc77
Gitweb:     http://git.kernel.org/tip/f1f1d5ebd10ffa4242bce7a90a56a222d6b7bc77
Author:     Richard Cochran <[email protected]>
AuthorDate: Tue, 1 Feb 2011 13:52:26 +0000
Committer:  Thomas Gleixner <[email protected]>
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 ]

LKML-Reference: <[email protected]>

---
 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(-)
include/linux/posix-timers.h +2 -0
index 8206255..79a1cea 100644
@@ -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 *);
include/linux/syscalls.h +2 -0
index 18cd068..bfacab9 100644
@@ -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,
kernel/compat.c +23 -0
index 449e853..38b1d2c 100644
@@ -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)
 {
kernel/posix-timers.c +30 -0
index a3fdfd4..5a5a4f1 100644
@@ -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)
 {
#83 lore raw

PATCH 26/28 posix_clocks: Add clock_adjtime for x86

In reply to Thomas Gleixner

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

LKML-Reference: <4501cddb99d555624baade4609030ca458dfa3a0.1296124770.git.richard.cochran@omicron.at>

---
 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(-)
arch/x86/ia32/ia32entry.S +1 -0
Index: 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:
arch/x86/include/asm/unistd_32.h +2 -1
Index: 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
arch/x86/include/asm/unistd_64.h +2 -0
Index: 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
arch/x86/kernel/syscall_table_32.S +1 -0
Index: 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
Acked-by on v1 26/28
#84 lore raw

Re: [patch 26/28] posix_clocks: Add clock_adjtime for x86

Quoted 8 lines · Thomas Gleixner

plain text document attachment (posix_clocks-add-clock_adjtime-for-x86.patch)
This patch adds the clock_adjtime system call to the x86 architecture.

LKML-Reference: <4501cddb99d555624baade4609030ca458dfa3a0.1296124770.git.richard.cochran@omicron.at>

#85 lore raw

[tip:timers/core] x86: Add clock_adjtime for x86

In reply to Thomas Gleixner
Commit-ID:  ce26efdefa5e8f22d933df72d7f7482725091d6d
Gitweb:     http://git.kernel.org/tip/ce26efdefa5e8f22d933df72d7f7482725091d6d
Author:     Richard Cochran <[email protected]>
AuthorDate: Tue, 1 Feb 2011 13:52:30 +0000
Committer:  Thomas Gleixner <[email protected]>
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.

LKML-Reference: <[email protected]>

---
 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(-)
arch/x86/ia32/ia32entry.S +1 -0
index 518bb99..0ed7896 100644
@@ -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:
arch/x86/include/asm/unistd_32.h +2 -1
index b766a5e..b6f73f1 100644
@@ -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
arch/x86/include/asm/unistd_64.h +2 -0
index 363e9b8..5ee3085 100644
@@ -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
arch/x86/kernel/syscall_table_32.S +1 -0
index b35786d..68c7b9a 100644
@@ -340,3 +340,4 @@ ENTRY(sys_call_table)
 	.long sys_fanotify_init
 	.long sys_fanotify_mark
 	.long sys_prlimit64		/* 340 */
+	.long sys_clock_adjtime
#86 lore raw

PATCH 27/28 posix-timers: Add support for fd based clocks

In reply to Thomas Gleixner

From: Richard Cochran <[email protected]>

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 <[email protected]>

---
 include/linux/posix-timers.h |   13 +++++++++++++
 kernel/posix-timers.c        |    2 +-
 2 files changed, 14 insertions(+), 1 deletion(-)
include/linux/posix-timers.h +13 -0
Index: 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))
kernel/posix-timers.c +1 -1
Index: 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;
Acked-by on v1 27/28
#87 lore raw

Re: [patch 27/28] posix-timers: Add support for fd based clocks

Quoted 11 lines · Thomas Gleixner

plain text document attachment (posix-timers-add-support-for-fd-based-clocks.patch)
From: Richard Cochran <[email protected]>

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 <[email protected]>

#88 lore raw

Re: [patch 27/28] posix-timers: Add support for fd based clocks

In reply to Thomas Gleixner

include/linux/posix-timers.h struct cpu_timer_list { · line 30

Quoted 13 lines · Thomas Gleixner
include/linux/posix-timers.h +10 -0
 
+/*
+ * 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

#89 lore raw

Re: [patch 27/28] posix-timers: Add support for fd based clocks

Quoted 15 lines · Richard Cochran

include/linux/posix-timers.h struct cpu_timer_list { · line 30

Quoted 13 lines · Thomas Gleixner
include/linux/posix-timers.h +10 -0
 
+/*
+ * 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.
Quoted 1 line

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

Fixed.

#90 lore raw

[tip:timers/core] posix-timers: Add support for fd based clocks

In reply to Thomas Gleixner
Commit-ID:  81e294cba2596f5f10848bbe19d98b344c2a2d5c
Gitweb:     http://git.kernel.org/tip/81e294cba2596f5f10848bbe19d98b344c2a2d5c
Author:     Richard Cochran <[email protected]>
AuthorDate: Tue, 1 Feb 2011 13:52:32 +0000
Committer:  Thomas Gleixner <[email protected]>
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 <[email protected]>

LKML-Reference: <[email protected]>

---
 include/linux/posix-timers.h |   13 +++++++++++++
 kernel/posix-timers.c        |    2 +-
 2 files changed, 14 insertions(+), 1 deletions(-)
include/linux/posix-timers.h +13 -0
index 79a1cea..88b9256 100644
@@ -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))
kernel/posix-timers.c +1 -1
index 5a5a4f1..df629d8 100644
@@ -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;
#91 lore raw

PATCH 28/28 posix clocks: Introduce dynamic clocks

In reply to Thomas Gleixner

From: Richard Cochran <[email protected]>

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 ]

LKML-Reference: <21258f45fcc5e08a595f411c7760f3ccc18964bb.1296124770.git.richard.cochran@omicron.at>

---
 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
include/linux/posix-clock.h new file +150 -0
Index: 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
include/linux/posix-timers.h +5 -1
Index: 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);
 
kernel/posix-timers.c +3 -1
Index: 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;
kernel/time/Makefile +2 -1
Index: 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
kernel/time/posix-clock.c new file +441 -0

441 lines not on this page · raw message

#92 lore raw

Re: [patch 28/28] posix clocks: Introduce dynamic clocks

Quoted 22 lines · Thomas Gleixner

plain text document attachment
(posix-clocks-introduce-dynamic-clocks.patch)
From: Richard Cochran <[email protected]>

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

Quoted 2 lines

[ 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

#93 lore raw

Re: [patch 28/28] posix clocks: Introduce dynamic clocks

Quoted 23 lines · john stultz
Quoted 22 lines · Thomas Gleixner

plain text document attachment
(posix-clocks-introduce-dynamic-clocks.patch)
From: Richard Cochran <[email protected]>

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

Quoted 6 lines
Quoted 2 lines

[ 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.

Quoted 3 lines

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

#94 lore raw

Re: [patch 28/28] posix clocks: Introduce dynamic clocks

In reply to john stultz
Quoted 7 lines · john stultz

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

#95 lore raw

Re: [patch 28/28] posix clocks: Introduce dynamic clocks

Quoted 9 lines · Richard Cochran
Quoted 7 lines · john stultz

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.

Quoted 7 lines

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

#96 lore raw

Re: [patch 28/28] posix clocks: Introduce dynamic clocks

Quoted 17 lines · Thomas Gleixner
Quoted 15 lines · Richard Cochran
Quoted 7 lines · john stultz

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.

Quoted 5 lines
Quoted 1 line

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 <[email protected]>
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.

---
 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(-)
drivers/char/mmtimer.c +1 -1
Index: 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);
include/linux/posix-timers.h +1 -1
Index: 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);
kernel/posix-cpu-timers.c +2 -2
Index: 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;
kernel/posix-timers.c +8 -7
Index: 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)
 {
#97 lore raw

[tip:timers/core] posix-timers: Cleanup namespace

Commit-ID:  527087374faa488776a789375a7d6ea74fda6f71
Gitweb:     http://git.kernel.org/tip/527087374faa488776a789375a7d6ea74fda6f71
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Wed, 2 Feb 2011 12:10:09 +0100
Committer:  Thomas Gleixner <[email protected]>
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.

LKML-Reference: <[email protected]>

---
 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(-)
drivers/char/mmtimer.c +1 -1
index ff41eb3..33dc229 100644
@@ -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);
include/linux/posix-timers.h +1 -1
index 88b9256..9d6ffe2 100644
@@ -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);
kernel/posix-cpu-timers.c +2 -2
index 609e187..67fea9d 100644
@@ -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;
kernel/posix-timers.c +8 -7
index df629d8..af936fd 100644
@@ -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)
 {
#98 lore raw

[tip:timers/core] posix clocks: Introduce dynamic clocks

In reply to Thomas Gleixner
Commit-ID:  0606f422b453f76c31ab2b1bd52943ff06a2dcf2
Gitweb:     http://git.kernel.org/tip/0606f422b453f76c31ab2b1bd52943ff06a2dcf2
Author:     Richard Cochran <[email protected]>
AuthorDate: Tue, 1 Feb 2011 13:52:35 +0000
Committer:  Thomas Gleixner <[email protected]>
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 ]

LKML-Reference: <[email protected]>

---
 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(-)
include/linux/posix-clock.h new file +150 -0
new file mode 100644
index 0000000..369e19d
@@ -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
include/linux/posix-timers.h +5 -1
index 9d6ffe2..d51243a 100644
@@ -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);
 
kernel/posix-timers.c +3 -1
index af936fd..44fcff1 100644
@@ -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;
kernel/time/Makefile +2 -1
index ee26662..b042599 100644
@@ -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
kernel/time/posix-clock.c new file +441 -0

441 lines not on this page · raw message

#99 lore raw

Re: [patch 28/28] posix clocks: Introduce dynamic clocks

In reply to Thomas Gleixner
Quoted 41 lines · Thomas Gleixner

From: Richard Cochran <[email protected]>

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 ]

LKML-Reference: <21258f45fcc5e08a595f411c7760f3ccc18964bb.1296124770.git.richard.cochran@omicron.at>

---
 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

kernel/time/posix-clock.c line 288

Quoted 9 lines
kernel/time/posix-clock.c new file +9 -0
+
+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.

Quoted 10 lines
kernel/time/posix-clock.c new file +10 -0
+
+	if (cd.clk->ops.clock_adjtime)
+		err = cd.clk->ops.clock_adjtime(cd.clk, tx);
+	else
+		err = -EOPNOTSUPP;
+
+	put_clock_desc(&cd);
+
+	return err;
+}
Signature · 1 line
torben Hohn
#100 lore raw

Re: [patch 28/28] posix clocks: Introduce dynamic clocks

Quoted 13 lines · torbenh

kernel/time/posix-clock.c line 288

Quoted 8 lines · Thomas Gleixner
kernel/time/posix-clock.c new file +8 -0
+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

#101 lore raw

Re: [patch 28/28] posix clocks: Introduce dynamic clocks

Quoted 15 lines · Richard Cochran
Quoted 13 lines · torbenh

kernel/time/posix-clock.c line 288

Quoted 8 lines · Thomas Gleixner
kernel/time/posix-clock.c new file +8 -0
+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.

Quoted 2 lines

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.

Quoted 4 lines

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.

Quoted 10 lines

Thanks,

Richard

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 1 line
torben Hohn
#102 lore raw

Re: [patch 28/28] posix clocks: Introduce dynamic clocks

Quoted 10 lines · torbenh
Quoted 3 lines · Richard Cochran

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

#103 lore raw
In reply to Thomas Gleixner
Quoted 2 lines · Thomas Gleixner

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 ;)

Quoted 5 lines

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.

Quoted 2 lines

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.

Quoted 2 lines

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

#105 lore raw

[tip:timers/core] ntp: Add ADJ_SETOFFSET mode bit

In reply to Thomas Gleixner
Commit-ID:  094aa1881fdc1b8889b442eb3511b31f3ec2b762
Gitweb:     http://git.kernel.org/tip/094aa1881fdc1b8889b442eb3511b31f3ec2b762
Author:     Richard Cochran <[email protected]>
AuthorDate: Tue, 1 Feb 2011 13:52:20 +0000
Committer:  Thomas Gleixner <[email protected]>
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.

LKML-Reference: <[email protected]>

---
 include/linux/timex.h |    3 ++-
 kernel/time/ntp.c     |   11 +++++++++++
 2 files changed, 13 insertions(+), 1 deletions(-)
include/linux/timex.h +2 -1
index d23999f..aa60fe7 100644
@@ -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 */
kernel/time/ntp.c +11 -0
index ed8cfdf..5ac5932 100644
@@ -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);
#106 lore raw

Re: [tip:timers/core] ntp: Add ADJ_SETOFFSET mode bit

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 <[email protected]>
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.

kernel/time/ntp.c +3 -3
index 34d1b64..d62f35a 100644
@@ -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);
#107 lore raw

[tip:timers/core] ntp: Remove redundant and incorrect parameter check

Commit-ID:  db1c1cce4a653dcbe6949c72ae7b9f42cab1b929
Gitweb:     http://git.kernel.org/tip/db1c1cce4a653dcbe6949c72ae7b9f42cab1b929
Author:     Richard Cochran <[email protected]>
AuthorDate: Fri, 18 Feb 2011 10:07:25 +0100
Committer:  Thomas Gleixner <[email protected]>
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.

LKML-Reference: <[email protected]>

---
 kernel/time/ntp.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
kernel/time/ntp.c +3 -3
index 5ac5932..5f1bb8e 100644
@@ -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);
#108 lore raw
In reply to Thomas Gleixner
Quoted 18 lines · Thomas Gleixner

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).

Quoted 7 lines

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.

Signature · 1 line
torben Hohn
#109 lore raw
Quoted 7 lines
Quoted 2 lines

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.

Quoted 5 lines

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

#110 lore raw
Quoted 13 lines · Richard Cochran
Quoted 7 lines
Quoted 2 lines

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.

Quoted 5 lines

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.

Quoted 7 lines

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.

Quoted 7 lines

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

Signature · 1 line
torben Hohn