From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753419AbcADTwk (ORCPT ); Mon, 4 Jan 2016 14:52:40 -0500 Received: from mga11.intel.com ([192.55.52.93]:24813 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752890AbcADTuo (ORCPT ); Mon, 4 Jan 2016 14:50:44 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,521,1444719600"; d="scan'208";a="627914330" From: "Christopher S. Hall" To: tglx@linutronix.de, richardcochran@gmail.com, mingo@redhat.com, john.stultz@linaro.org, hpa@zytor.com, jeffrey.t.kirsher@intel.com Cc: "Christopher S. Hall" , x86@kernel.org, linux-kernel@vger.kernel.org, intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, kevin.b.stanton@intel.com Subject: [RFC v5 4/6] Remove duplicate code from ktime_get_raw_and_real code Date: Mon, 4 Jan 2016 04:45:21 -0800 Message-Id: <1451911523-8534-5-git-send-email-christopher.s.hall@intel.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1451911523-8534-1-git-send-email-christopher.s.hall@intel.com> References: <1451911523-8534-1-git-send-email-christopher.s.hall@intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The code in ktime_get_snapshot() is a superset of the code in ktime_get_raw_and_real() code. Changes the latter to call the former. A side effect of this is that ktime_get_raw_and_real() returns two clock times corresponding to the *exact* same clock tick. Previously, this code read the underlying counter twice. Signed-off-by: Christopher S. Hall --- kernel/time/timekeeping.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 5a7f784..a0f096c 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -910,26 +910,14 @@ EXPORT_SYMBOL_GPL(ktime_get_snapshot); */ void ktime_get_raw_and_real_ts64(struct timespec64 *ts_raw, struct timespec64 *ts_real) { - struct timekeeper *tk = &tk_core.timekeeper; - unsigned long seq; - s64 nsecs_raw, nsecs_real; + struct system_time_snapshot snap; WARN_ON_ONCE(timekeeping_suspended); - do { - seq = read_seqcount_begin(&tk_core.seq); - - *ts_raw = tk->raw_time; - ts_real->tv_sec = tk->xtime_sec; - ts_real->tv_nsec = 0; - - nsecs_raw = timekeeping_get_ns(&tk->tkr_raw); - nsecs_real = timekeeping_get_ns(&tk->tkr_mono); - - } while (read_seqcount_retry(&tk_core.seq, seq)); + ktime_get_snapshot(&snap); - timespec64_add_ns(ts_raw, nsecs_raw); - timespec64_add_ns(ts_real, nsecs_real); + *ts_raw = ktime_to_timespec64(snap.raw); + *ts_real = ktime_to_timespec64(snap.real); } EXPORT_SYMBOL(ktime_get_raw_and_real_ts64); -- 2.1.4 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christopher S. Hall Date: Mon, 4 Jan 2016 04:45:21 -0800 Subject: [Intel-wired-lan] [RFC v5 4/6] Remove duplicate code from ktime_get_raw_and_real code In-Reply-To: <1451911523-8534-1-git-send-email-christopher.s.hall@intel.com> References: <1451911523-8534-1-git-send-email-christopher.s.hall@intel.com> Message-ID: <1451911523-8534-5-git-send-email-christopher.s.hall@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: intel-wired-lan@osuosl.org List-ID: The code in ktime_get_snapshot() is a superset of the code in ktime_get_raw_and_real() code. Changes the latter to call the former. A side effect of this is that ktime_get_raw_and_real() returns two clock times corresponding to the *exact* same clock tick. Previously, this code read the underlying counter twice. Signed-off-by: Christopher S. Hall --- kernel/time/timekeeping.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 5a7f784..a0f096c 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -910,26 +910,14 @@ EXPORT_SYMBOL_GPL(ktime_get_snapshot); */ void ktime_get_raw_and_real_ts64(struct timespec64 *ts_raw, struct timespec64 *ts_real) { - struct timekeeper *tk = &tk_core.timekeeper; - unsigned long seq; - s64 nsecs_raw, nsecs_real; + struct system_time_snapshot snap; WARN_ON_ONCE(timekeeping_suspended); - do { - seq = read_seqcount_begin(&tk_core.seq); - - *ts_raw = tk->raw_time; - ts_real->tv_sec = tk->xtime_sec; - ts_real->tv_nsec = 0; - - nsecs_raw = timekeeping_get_ns(&tk->tkr_raw); - nsecs_real = timekeeping_get_ns(&tk->tkr_mono); - - } while (read_seqcount_retry(&tk_core.seq, seq)); + ktime_get_snapshot(&snap); - timespec64_add_ns(ts_raw, nsecs_raw); - timespec64_add_ns(ts_real, nsecs_real); + *ts_raw = ktime_to_timespec64(snap.raw); + *ts_real = ktime_to_timespec64(snap.real); } EXPORT_SYMBOL(ktime_get_raw_and_real_ts64); -- 2.1.4