From patchwork Fri Jul 13 05:21:54 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 9966 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 506FA23F4C for ; Fri, 13 Jul 2012 05:22:35 +0000 (UTC) Received: from mail-yw0-f52.google.com (mail-yw0-f52.google.com [209.85.213.52]) by fiordland.canonical.com (Postfix) with ESMTP id DE1D6A1814F for ; Fri, 13 Jul 2012 05:22:34 +0000 (UTC) Received: by yhpp61 with SMTP id p61so3631052yhp.11 for ; Thu, 12 Jul 2012 22:22:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-content-scanned:x-cbid:x-gm-message-state; bh=SQTWqd/h5catCH75R/0vYaJyCnSvmP9NJ0ARSB9QKkQ=; b=TUB+df2nOOtCny70A2YCksdTiE70hWBQ8Mflao5KuSnTP4dlcaBscQmvdK4FWkipqH V+GK7mbN2gqKnTCo/9ATrCmziFtRoVnUsZSvRma5He3Kt+e2GpjSdbgcxajGGGeG9nlc s/PbxZ3Wcw+Bh5ModvcK61w/2IujEUH5Djtie/ct19+2ZRWzEJ2F9HVwpK8emt+ViUN2 oOA9IsTBaewJNEqgjhW22NF0stQ07OCMaYeNtRZ3vecQ0D15em9ooIDia3gHBRMw3pJx L7XzMECC8Lcwd5CcFRizRy6lHVlcoMtVXfYofUJixmd1x9yifucPS9EGb/NuSH10BxIf rCPA== Received: by 10.42.68.65 with SMTP id w1mr403426ici.57.1342156954173; Thu, 12 Jul 2012 22:22:34 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.241.2 with SMTP id lc2csp11715ibb; Thu, 12 Jul 2012 22:22:33 -0700 (PDT) Received: by 10.50.189.134 with SMTP id gi6mr212247igc.55.1342156953255; Thu, 12 Jul 2012 22:22:33 -0700 (PDT) Received: from e4.ny.us.ibm.com (e4.ny.us.ibm.com. [32.97.182.144]) by mx.google.com with ESMTPS id dk7si798068igb.70.2012.07.12.22.22.33 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 12 Jul 2012 22:22:33 -0700 (PDT) Received-SPF: neutral (google.com: 32.97.182.144 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=32.97.182.144; Authentication-Results: mx.google.com; spf=neutral (google.com: 32.97.182.144 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) smtp.mail=john.stultz@linaro.org Received: from /spool/local by e4.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 13 Jul 2012 01:22:32 -0400 Received: from d01dlp02.pok.ibm.com (9.56.224.85) by e4.ny.us.ibm.com (192.168.1.104) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 13 Jul 2012 01:22:25 -0400 Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com [9.56.227.236]) by d01dlp02.pok.ibm.com (Postfix) with ESMTP id B30D46E8059; Fri, 13 Jul 2012 01:22:24 -0400 (EDT) Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d01relay04.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q6D5MOHm440134; Fri, 13 Jul 2012 01:22:24 -0400 Received: from d03av02.boulder.ibm.com (loopback [127.0.0.1]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q6D5MNvT017902; Thu, 12 Jul 2012 23:22:23 -0600 Received: from kernel.stglabs.ibm.com (kernel.stglabs.ibm.com [9.114.214.19]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q6D5MIiQ017604; Thu, 12 Jul 2012 23:22:22 -0600 From: John Stultz To: Linux Kernel Cc: John Stultz , Ingo Molnar , Peter Zijlstra , Richard Cochran , Prarit Bhargava , Thomas Gleixner Subject: [PATCH 5/8] time: Refactor accumulation of nsecs to secs Date: Fri, 13 Jul 2012 01:21:54 -0400 Message-Id: <1342156917-25092-6-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1342156917-25092-1-git-send-email-john.stultz@linaro.org> References: <1342156917-25092-1-git-send-email-john.stultz@linaro.org> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12071305-3534-0000-0000-00000A6723E8 X-Gm-Message-State: ALoCoQnvlmqPtNIyU6+rvhaLzHbzvJX02wmXjUr8J/S5vAe+1awWQDQRfnCQKWnyFSdTxTtfLs3z We do the exact same logic moving nsecs to secs in the timekeeper in multiple places, so condense this into a single function. CC: Ingo Molnar CC: Peter Zijlstra CC: Richard Cochran CC: Prarit Bhargava CC: Thomas Gleixner Signed-off-by: John Stultz --- kernel/time/timekeeping.c | 54 +++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 80d0c78..5ffb2b6 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -995,6 +995,35 @@ static void timekeeping_adjust(s64 offset) /** + * accumulate_nsecs_to_secs - Accumulates nsecs into secs + * + * Helper function that accumulates a the nsecs greater then a second + * from the xtime_nsec field to the xtime_secs field. + * It also calls into the NTP code to handle leapsecond processing. + * + */ +static inline void accumulate_nsecs_to_secs(struct timekeeper *tk) +{ + u64 nsecps = (u64)NSEC_PER_SEC << tk->shift; + + while (tk->xtime_nsec >= nsecps) { + int leap; + + tk->xtime_nsec -= nsecps; + tk->xtime_sec++; + + /* Figure out if its a leap sec and apply if needed */ + leap = second_overflow(tk->xtime_sec); + tk->xtime_sec += leap; + tk->wall_to_monotonic.tv_sec -= leap; + if (leap) + clock_was_set_delayed(); + + } +} + + +/** * logarithmic_accumulation - shifted accumulation of cycles * * This functions accumulates a shifted interval of cycles into @@ -1005,7 +1034,6 @@ static void timekeeping_adjust(s64 offset) */ static cycle_t logarithmic_accumulation(cycle_t offset, u32 shift) { - u64 nsecps = (u64)NSEC_PER_SEC << timekeeper.shift; u64 raw_nsecs; /* If the offset is smaller than a shifted interval, do nothing */ @@ -1017,16 +1045,8 @@ static cycle_t logarithmic_accumulation(cycle_t offset, u32 shift) timekeeper.clock->cycle_last += timekeeper.cycle_interval << shift; timekeeper.xtime_nsec += timekeeper.xtime_interval << shift; - while (timekeeper.xtime_nsec >= nsecps) { - int leap; - timekeeper.xtime_nsec -= nsecps; - timekeeper.xtime_sec++; - leap = second_overflow(timekeeper.xtime_sec); - timekeeper.xtime_sec += leap; - timekeeper.wall_to_monotonic.tv_sec -= leap; - if (leap) - clock_was_set_delayed(); - } + + accumulate_nsecs_to_secs(&timekeeper); /* Accumulate raw time */ raw_nsecs = timekeeper.raw_interval << shift; @@ -1136,17 +1156,7 @@ static void update_wall_time(void) * Finally, make sure that after the rounding * xtime_nsec isn't larger than NSEC_PER_SEC */ - if (unlikely(timekeeper.xtime_nsec >= - ((u64)NSEC_PER_SEC << timekeeper.shift))) { - int leap; - timekeeper.xtime_nsec -= (u64)NSEC_PER_SEC << timekeeper.shift; - timekeeper.xtime_sec++; - leap = second_overflow(timekeeper.xtime_sec); - timekeeper.xtime_sec += leap; - timekeeper.wall_to_monotonic.tv_sec -= leap; - if (leap) - clock_was_set_delayed(); - } + accumulate_nsecs_to_secs(&timekeeper); timekeeping_update(false);