From patchwork Mon Jun 8 13:40:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 49630 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 502ED214B2 for ; Mon, 8 Jun 2015 13:52:06 +0000 (UTC) Received: by wgme6 with SMTP id e6sf32884219wgm.3 for ; Mon, 08 Jun 2015 06:52:05 -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=rE7YHx4A75plFs+UO0PS7HlSXxleVw0PjCi1plvEPng=; b=avrk8bOkFPImXoOXdXmuVQPqtSvz3v5PqvX9jX7zdMk2FC9hcl9wj+tVN3fUokXZOI AyEhcgYIaQI8ExDEuflz8wU3ybFg9GCunB8hdvMB2SWrU53hPssNJPs6QMK9rgOR0X8Y 1Du4BGHPYkucIy5PufsVGM+7efQa2OoFO4WOy7xf8SYiwsowLtp59B4Tgg/9at46Bgj/ MOCVbFJJ4z32iOXpxQSNZfsbhLGyvIJpNT6k46sBwSrDpuMJEkxl2cPnFGTmZYalCE+L XnZoOFsOBs3VEyBza1cer6HB+OyNnUqYwxT/euRKwc4+kZTfussIfll9aO/m/+kNOgVN kPOg== X-Gm-Message-State: ALoCoQmO2KYvpG9tVpmUHnJb1LfVw1YmfQ9kTpXOnFnKE1Cv6xLHK1vPRiPfh0ZInFd8LzL8ZXDx X-Received: by 10.112.166.137 with SMTP id zg9mr17192004lbb.11.1433771525620; Mon, 08 Jun 2015 06:52:05 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.34 with SMTP id p2ls746920lap.32.gmail; Mon, 08 Jun 2015 06:52:05 -0700 (PDT) X-Received: by 10.112.122.9 with SMTP id lo9mr17107441lbb.104.1433771525506; Mon, 08 Jun 2015 06:52:05 -0700 (PDT) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id da3si2756139lac.178.2015.06.08.06.52.05 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Jun 2015 06:52:05 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by labpy14 with SMTP id py14so97655816lab.0 for ; Mon, 08 Jun 2015 06:52:05 -0700 (PDT) X-Received: by 10.152.27.1 with SMTP id p1mr16566627lag.112.1433771525411; Mon, 08 Jun 2015 06:52:05 -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 hn6csp1880417lbb; Mon, 8 Jun 2015 06:52:04 -0700 (PDT) X-Received: by 10.66.216.161 with SMTP id or1mr29805327pac.34.1433771085952; Mon, 08 Jun 2015 06:44:45 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ig4si4189681pbb.82.2015.06.08.06.44.45; Mon, 08 Jun 2015 06:44:45 -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 S932651AbbFHNoj (ORCPT + 2 others); Mon, 8 Jun 2015 09:44:39 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:46101 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753248AbbFHNoG (ORCPT ); Mon, 8 Jun 2015 09:44:06 -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 t58Di5lP030590 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 8 Jun 2015 13:44:05 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.13.8/8.13.8) with ESMTP id t58Di5gt004892 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Mon, 8 Jun 2015 13:44:05 GMT Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0122.oracle.com (8.13.8/8.13.8) with ESMTP id t58Di5Yp004606; Mon, 8 Jun 2015 13:44:05 GMT Received: from lappy.hsd1.nh.comcast.net (/10.159.178.227) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 08 Jun 2015 06:44:05 -0700 From: Sasha Levin To: stable@vger.kernel.org, stable-commits@vger.kernel.org Cc: sasha.levin@oracle.com Subject: [PATCH 3.18 063/178] ktime: Optimize ktime_divns for constant divisors Date: Mon, 8 Jun 2015 09:40:54 -0400 Message-Id: <1433770969-2003-64-git-send-email-sasha.levin@oracle.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1433770969-2003-1-git-send-email-sasha.levin@oracle.com> References: <1433770969-2003-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.42 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 [ 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 */ /*