Skip to contentSkip to conversation

posix-timers:Convert to the 64bit methods for the clock_gettime syscall function

PATCH Superseded Baolin Wang 2 participants 2 messages May 11, 2015 – May 12, 2015 Posix clocks and timers

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 11/22 posix-timers:Convert to the 64bit methods for the clock_gettime syscall function

This patch introduces the clock_get64 methods with timespec64 type for k_clock structure.

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

---
 include/linux/posix-timers.h |    1 +
 kernel/time/posix-timers.c   |   32 ++++++++++++++++++++++++++------
 2 files changed, 27 insertions(+), 6 deletions(-)
include/linux/posix-timers.h +1 -0
index 9b6469c..c08a536 100644
@@ -103,6 +103,7 @@ struct k_clock {
 	int (*clock_set64) (const clockid_t which_clock,
 			    const struct timespec64 *tp);
 	int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
+	int (*clock_get64) (const clockid_t which_clock, struct timespec64 *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,
kernel/time/posix-timers.c +26 -6
index 8aac06d..ccc84d3 100644
@@ -545,6 +545,16 @@ static int default_clock_set64(const clockid_t which_clock,
 	return 0;
 }
 
+static int default_clock_get64(const clockid_t which_clock,
+			       struct timespec64 *tp64)
+{
+	struct k_clock *kc = clockid_to_kclock(which_clock);
+	struct timespec tp;
+
+	kc->clock_get(which_clock, &tp);
+	return 0;
+}
+
 void posix_timers_register_clock(const clockid_t clock_id,
 				 struct k_clock *new_clock)
 {
@@ -554,8 +564,8 @@ void posix_timers_register_clock(const clockid_t clock_id,
 		return;
 	}
 
-	if (!new_clock->clock_get) {
-		printk(KERN_WARNING "POSIX clock id %d lacks clock_get()\n",
+	if (!new_clock->clock_get && !new_clock->clock_get64) {
+		printk(KERN_WARNING "POSIX clock id %d lacks clock_get() and clock_get64()\n",
 		       clock_id);
 		return;
 	}
@@ -571,6 +581,8 @@ void posix_timers_register_clock(const clockid_t clock_id,
 		new_clock->timer_set64 = default_timer_set64;
 	if (new_clock->clock_set && !new_clock->clock_set64)
 		new_clock->clock_set64 = default_clock_set64;
+	if (new_clock->clock_get && !new_clock->clock_get64)
+		new_clock->clock_get64 = default_clock_get64;
 
 	posix_clocks[clock_id] = *new_clock;
 }
@@ -1115,23 +1127,31 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
 #endif
 }
 
-static int __clock_gettime(clockid_t which_clock, struct timespec *ts)
+static int __clock_gettime(clockid_t which_clock, struct timespec64 *ts)
 {
 	struct k_clock *kc = clockid_to_kclock(which_clock);
 
 	if (!kc)
 		return -EINVAL;
 
-	return kc->clock_get(which_clock, ts);
+	return kc->clock_get64(which_clock, ts);
 }
 
 SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
 		struct timespec __user *,tp)
 {
-	struct timespec kernel_tp;
 	int error;
-
+#ifdef CONFIG_64BIT
+	struct timespec64 kernel_tp;
 	error = __clock_gettime(which_clock, &kernel_tp);
+#else
+	struct timespec64 kernel_tp64;
+	struct timespec kernel_tp;
+
+	error = __clock_gettime(which_clock, &kernel_tp64);
+	if (!error)
+		kernel_tp = timespec64_to_timespec(kernel_tp64);
+#endif
 
 	if (!error && copy_to_user(tp, &kernel_tp, sizeof (kernel_tp)))
 		error = -EFAULT;
Signature · 1 line
1.7.9.5
#1 lore raw

kernel/time/posix-timers.c static int default_clock_set64(const clockid_t which_clock, · line 555

Quoted 8 lines · Baolin Wang
kernel/time/posix-timers.c +8 -0
+static int default_clock_get64(const clockid_t which_clock,
+			       struct timespec64 *tp64)
+{
+	struct k_clock *kc = clockid_to_kclock(which_clock);
+	struct timespec tp;
+
+	kc->clock_get(which_clock, &tp);
+	return 0;

Sigh.