From patchwork Thu Jun 4 16:53:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 49541 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 19F802154F for ; Thu, 4 Jun 2015 17:00:27 +0000 (UTC) Received: by labc7 with SMTP id c7sf13280497lab.1 for ; Thu, 04 Jun 2015 10:00:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=3Z8zBtfuckTbJkPAS/XSZDSErxmNBS5KbGimIxP2BWI=; b=i/6c7ZicT4tNaPItkjX7HB5R5Ig9Q1VeUyFTUxCIs3gQveNmenYcUfuoKQkumOatCw aTQQpmT3oKnMlTATjMQb0VHn23s/PgVyYy5Dd1JBlEC67/J5pahz9wEHhcD8dKbSNkS+ t8ALd83flUWE+kcxpGnTegE93qCkq+fjNrhxTyq08EB1vU7+L5CxZFfr/JI342hTfGmS RGD430kV8NA20AyTja0xitBbZPONtx5Q/boHLHrC7j7yZdomQlQ337JRvcFoFq8KjjQA hVeQ+02Y24EoJssQGo57uNfAsfi8tfqHrq9KIFeCRZRRN2tiiYE0oyQ5E7tbVO8746ti RavA== X-Gm-Message-State: ALoCoQn1dWr9wLUwoHK+Id97BnfMbuSkC9PttAP/H8ZAKyF/epoQuBafkeq6PpUOoB4VGFllxYHB X-Received: by 10.112.203.168 with SMTP id kr8mr36460084lbc.10.1433437226087; Thu, 04 Jun 2015 10:00:26 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.246.35 with SMTP id xt3ls221264lac.37.gmail; Thu, 04 Jun 2015 10:00:26 -0700 (PDT) X-Received: by 10.152.181.34 with SMTP id dt2mr38307746lac.84.1433437225970; Thu, 04 Jun 2015 10:00:25 -0700 (PDT) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com. [209.85.215.45]) by mx.google.com with ESMTPS id r3si2326700lah.162.2015.06.04.10.00.25 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Jun 2015 10:00:25 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by laei3 with SMTP id i3so36376192lae.3 for ; Thu, 04 Jun 2015 10:00:25 -0700 (PDT) X-Received: by 10.112.131.98 with SMTP id ol2mr22938619lbb.56.1433437225869; Thu, 04 Jun 2015 10:00:25 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp753822lbb; Thu, 4 Jun 2015 10:00:24 -0700 (PDT) X-Received: by 10.70.95.228 with SMTP id dn4mr70615926pdb.89.1433437195972; Thu, 04 Jun 2015 09:59:55 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ju8si6714853pbb.43.2015.06.04.09.59.55; Thu, 04 Jun 2015 09:59:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753899AbbFDQ7x (ORCPT + 2 others); Thu, 4 Jun 2015 12:59:53 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:45887 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754033AbbFDQzm (ORCPT ); Thu, 4 Jun 2015 12:55:42 -0400 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t54GtVeB031301 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 4 Jun 2015 16:55:31 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.13.8/8.13.8) with ESMTP id t54GtUUZ020412 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Thu, 4 Jun 2015 16:55:31 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userv0122.oracle.com (8.13.8/8.13.8) with ESMTP id t54GtUpi015158; Thu, 4 Jun 2015 16:55:30 GMT Received: from lappy.hsd1.nh.comcast.net (/10.159.130.126) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 04 Jun 2015 09:55:29 -0700 From: Sasha Levin To: stable@vger.kernel.org, stable-commits@vger.kernel.org Cc: Nicolas Pitre , Arnd Bergmann , Thomas Gleixner , Ingo Molnar , Nicolas Pitre , John Stultz , Sasha Levin Subject: [added to the 3.18 stable tree] ktime: Optimize ktime_divns for constant divisors Date: Thu, 4 Jun 2015 12:53:08 -0400 Message-Id: <1433436902-22778-12-git-send-email-sasha.levin@oracle.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1433436902-22778-1-git-send-email-sasha.levin@oracle.com> References: <1433436902-22778-1-git-send-email-sasha.levin@oracle.com> X-Source-IP: aserv0021.oracle.com [141.146.126.233] Sender: stable-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: stable@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: patch@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Nicolas Pitre This patch has been added to the 3.18 stable tree. If you have any objections, please let us know. =============== [ Upstream commit 8b618628b2bf83512fc8df5e8672619d65adfdfb ] At least on ARM, do_div() is optimized to turn constant divisors into an inline multiplication by the reciprocal value at compile time. However this optimization is missed entirely whenever ktime_divns() is used and the slow out-of-line division code is used all the time. Let ktime_divns() use do_div() inline whenever the divisor is constant and small enough. This will make things like ktime_to_us() and ktime_to_ms() much faster. Cc: Arnd Bergmann Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Nicolas Pitre Acked-by: Arnd Bergmann Signed-off-by: Nicolas Pitre Signed-off-by: John Stultz Signed-off-by: Sasha Levin --- include/linux/ktime.h | 12 +++++++++++- kernel/time/hrtimer.c | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/linux/ktime.h b/include/linux/ktime.h index c9d645a..411dd8b 100644 --- a/include/linux/ktime.h +++ b/include/linux/ktime.h @@ -166,7 +166,17 @@ static inline bool ktime_before(const ktime_t cmp1, const ktime_t cmp2) } #if BITS_PER_LONG < 64 -extern u64 ktime_divns(const ktime_t kt, s64 div); +extern u64 __ktime_divns(const ktime_t kt, s64 div); +static inline u64 ktime_divns(const ktime_t kt, s64 div) +{ + if (__builtin_constant_p(div) && !(div >> 32)) { + u64 ns = kt.tv64; + do_div(ns, div); + return ns; + } else { + return __ktime_divns(kt, div); + } +} #else /* BITS_PER_LONG < 64 */ # define ktime_divns(kt, div) (u64)((kt).tv64 / (div)) #endif diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c index d8c724c..5e4d51c 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -266,7 +266,7 @@ lock_hrtimer_base(const struct hrtimer *timer, unsigned long *flags) /* * Divide a ktime value by a nanosecond value */ -u64 ktime_divns(const ktime_t kt, s64 div) +u64 __ktime_divns(const ktime_t kt, s64 div) { u64 dclc; int sft = 0; @@ -282,7 +282,7 @@ u64 ktime_divns(const ktime_t kt, s64 div) return dclc; } -EXPORT_SYMBOL_GPL(ktime_divns); +EXPORT_SYMBOL_GPL(__ktime_divns); #endif /* BITS_PER_LONG >= 64 */ /*