diff mbox

[v3,14/23] posix-timers:Convert to the 64bit methods for the clock_getres syscall function

Message ID 1431439935-6090-1-git-send-email-baolin.wang@linaro.org
State New
Headers show

Commit Message

(Exiting) Baolin Wang May 12, 2015, 2:12 p.m. UTC
This patch introduces the clock_getres64 method with timespec64 type for k_clock
structure, that makes it ready for the 2038 year.

Convert to the 64bit method with timespec64 type for the clock_getres
syscall function, and change the clock_getres syscall implementation according to
the CONFIG_64BIT macro.

Also add a default 64bit method for the clock_getres64 pointer of k_clock structure,
and it will be removed after all the drivers are converted to 64bit methods.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 include/linux/posix-timers.h |    1 +
 kernel/time/posix-timers.c   |   38 ++++++++++++++++++++++++++++++++------
 2 files changed, 33 insertions(+), 6 deletions(-)
diff mbox

Patch

diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index be2123d..35786c5 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -98,6 +98,7 @@  struct k_itimer {
 
 struct k_clock {
 	int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
+	int (*clock_getres64) (const clockid_t which_clock, struct timespec64 *tp);
 	int (*clock_set) (const clockid_t which_clock,
 			  const struct timespec *tp);
 	int (*clock_set64) (const clockid_t which_clock,
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index a9e14cf..e0a6a09 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -567,6 +567,20 @@  static int default_clock_get64(const clockid_t which_clock,
 	return ret;
 }
 
+static int default_clock_getres64(const clockid_t which_clock,
+				  struct timespec64 *tp64)
+{
+	struct k_clock *kc = clockid_to_kclock(which_clock);
+	struct timespec tp;
+	int ret;
+
+	ret = kc->clock_getres(which_clock, &tp);
+	if (!ret)
+		*tp64 = timespec_to_timespec64(tp);
+
+	return 0;
+}
+
 void posix_timers_register_clock(const clockid_t clock_id,
 				 struct k_clock *new_clock)
 {
@@ -581,8 +595,8 @@  void posix_timers_register_clock(const clockid_t clock_id,
 		       clock_id);
 		return;
 	}
-	if (!new_clock->clock_getres) {
-		printk(KERN_WARNING "POSIX clock id %d lacks clock_getres()\n",
+	if (!new_clock->clock_getres && !new_clock->clock_getres64) {
+		printk(KERN_WARNING "POSIX clock id %d lacks clock_getres() and clock_getres64()\n",
 		       clock_id);
 		return;
 	}
@@ -595,6 +609,8 @@  void posix_timers_register_clock(const clockid_t clock_id,
 		new_clock->clock_set64 = default_clock_set64;
 	if (new_clock->clock_get && !new_clock->clock_get64)
 		new_clock->clock_get64 = default_clock_get64;
+	if (new_clock->clock_getres && !new_clock->clock_getres64)
+		new_clock->clock_getres64 = default_clock_getres64;
 
 	posix_clocks[clock_id] = *new_clock;
 }
@@ -642,7 +658,8 @@  static struct k_clock *clockid_to_kclock(const clockid_t id)
 		return (id & CLOCKFD_MASK) == CLOCKFD ?
 			&clock_posix_dynamic : &clock_posix_cpu;
 
-	if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
+	if (id >= MAX_CLOCKS || (!posix_clocks[id].clock_getres
+	    && !posix_clocks[id].clock_getres64))
 		return NULL;
 	return &posix_clocks[id];
 }
@@ -1195,23 +1212,32 @@  SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock,
 	return err;
 }
 
-static int __clock_getres(clockid_t which_clock, struct timespec *ts)
+static int __clock_getres(clockid_t which_clock, struct timespec64 *ts)
 {
 	struct k_clock *kc = clockid_to_kclock(which_clock);
 
 	if (!kc)
 		return -EINVAL;
 
-	return kc->clock_getres(which_clock, ts);
+	return kc->clock_getres64(which_clock, ts);
 }
 
 SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock,
 		struct timespec __user *, tp)
 {
-	struct timespec rtn_tp;
 	int error;
+#ifdef CONFIG_64BIT
+	struct timespec64 rtn_tp;
 
 	error = __clock_getres(which_clock, &rtn_tp);
+#else
+	struct timespec64 rtn_tp64;
+	struct timespec rtn_tp;
+
+	error = __clock_getres(which_clock, &rtn_tp64);
+	if (!error)
+		rtn_tp = timespec64_to_timespec(rtn_tp64);
+#endif
 
 	if (!error && tp && copy_to_user(tp, &rtn_tp, sizeof (rtn_tp)))
 		error = -EFAULT;