瀏覽代碼

timekeeping: Provide internal ktime_t based data

The ktime_t based interfaces are used a lot in performance critical
code pathes. Add ktime_t based data so the interfaces don't have to
convert from the xtime/timespec based data.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Thomas Gleixner 11 年之前
父節點
當前提交
7c032df557
共有 2 個文件被更改,包括 25 次插入0 次删除
  1. 3 0
      include/linux/timekeeper_internal.h
  2. 22 0
      kernel/time/timekeeping.c

+ 3 - 0
include/linux/timekeeper_internal.h

@@ -36,6 +36,9 @@ struct timekeeper {
 	/* Clock shifted nano seconds */
 	/* Clock shifted nano seconds */
 	u64			xtime_nsec;
 	u64			xtime_nsec;
 
 
+	/* Monotonic base time */
+	ktime_t			base_mono;
+
 	/* Current CLOCK_REALTIME time in seconds */
 	/* Current CLOCK_REALTIME time in seconds */
 	u64			xtime_sec;
 	u64			xtime_sec;
 	/* CLOCK_REALTIME to CLOCK_MONOTONIC offset */
 	/* CLOCK_REALTIME to CLOCK_MONOTONIC offset */

+ 22 - 0
kernel/time/timekeeping.c

@@ -291,6 +291,26 @@ int pvclock_gtod_unregister_notifier(struct notifier_block *nb)
 }
 }
 EXPORT_SYMBOL_GPL(pvclock_gtod_unregister_notifier);
 EXPORT_SYMBOL_GPL(pvclock_gtod_unregister_notifier);
 
 
+/*
+ * Update the ktime_t based scalar nsec members of the timekeeper
+ */
+static inline void tk_update_ktime_data(struct timekeeper *tk)
+{
+	s64 nsec;
+
+	/*
+	 * The xtime based monotonic readout is:
+	 *	nsec = (xtime_sec + wtm_sec) * 1e9 + wtm_nsec + now();
+	 * The ktime based monotonic readout is:
+	 *	nsec = base_mono + now();
+	 * ==> base_mono = (xtime_sec + wtm_sec) * 1e9 + wtm_nsec
+	 */
+	nsec = (s64)(tk->xtime_sec + tk->wall_to_monotonic.tv_sec);
+	nsec *= NSEC_PER_SEC;
+	nsec += tk->wall_to_monotonic.tv_nsec;
+	tk->base_mono = ns_to_ktime(nsec);
+}
+
 /* must hold timekeeper_lock */
 /* must hold timekeeper_lock */
 static void timekeeping_update(struct timekeeper *tk, unsigned int action)
 static void timekeeping_update(struct timekeeper *tk, unsigned int action)
 {
 {
@@ -301,6 +321,8 @@ static void timekeeping_update(struct timekeeper *tk, unsigned int action)
 	update_vsyscall(tk);
 	update_vsyscall(tk);
 	update_pvclock_gtod(tk, action & TK_CLOCK_WAS_SET);
 	update_pvclock_gtod(tk, action & TK_CLOCK_WAS_SET);
 
 
+	tk_update_ktime_data(tk);
+
 	if (action & TK_MIRROR)
 	if (action & TK_MIRROR)
 		memcpy(&shadow_timekeeper, &tk_core.timekeeper,
 		memcpy(&shadow_timekeeper, &tk_core.timekeeper,
 		       sizeof(tk_core.timekeeper));
 		       sizeof(tk_core.timekeeper));