From patchwork Wed Dec 3 19:43:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Pitre X-Patchwork-Id: 41864 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A3C8425E88 for ; Wed, 3 Dec 2014 19:43:17 +0000 (UTC) Received: by mail-wg0-f70.google.com with SMTP id b13sf9999375wgh.9 for ; Wed, 03 Dec 2014 11:43:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:date:from:to:cc:subject:message-id :user-agent:mime-version:content-type:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=mcobnMkc2nXS2P4dlZ4+dBM36Iu3tEuVCvhx7yT+cIE=; b=Dj5vBQ9w+IF7R2GYRI3jxj537mPs9AsJWbhb2n4qEgl2nlZsiiZ1Tbf9tW9z+dbJlP WPpWvG3aV0O0+3yvMuGZdM8OXZo03jp1gR1BhgHf6XfGWVyyyqARqeim/SLcRi4ctlW7 aMuMV31SdvfIBwAjsLhE3kL8dhzJzWzN+aDSLPw0AbWDIz5+WQ1JF2lc+C5icENNvMwR oi2I1qfaBtnGiVwRX4SBqv8qnW06ofXoiWZic+b0fyqpQ2gs9PCOuQ5jtHMGyKOVLm74 SKTJzFxkGfWCXBOn4GGbN9Kknzz66doNo7I/K7ldGda8Fcua9w+zuF67CYhMLeH4zxc/ 0n9Q== X-Gm-Message-State: ALoCoQnGFQTKxXEJjj7hwZagi1yiPoSF3/5SLLwZXDzojiX0kii8tCMz4BIBOmRcb/dhJniv4anw X-Received: by 10.112.142.36 with SMTP id rt4mr1419329lbb.3.1417635796606; Wed, 03 Dec 2014 11:43:16 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.37.6 with SMTP id u6ls187708laj.26.gmail; Wed, 03 Dec 2014 11:43:16 -0800 (PST) X-Received: by 10.112.145.37 with SMTP id sr5mr6083363lbb.76.1417635796102; Wed, 03 Dec 2014 11:43:16 -0800 (PST) Received: from mail-la0-f50.google.com (mail-la0-f50.google.com. [209.85.215.50]) by mx.google.com with ESMTPS id yf4si23852730lbb.124.2014.12.03.11.43.15 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Dec 2014 11:43:15 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) client-ip=209.85.215.50; Received: by mail-la0-f50.google.com with SMTP id pn19so12360721lab.37 for ; Wed, 03 Dec 2014 11:43:15 -0800 (PST) X-Received: by 10.153.7.170 with SMTP id dd10mr5813185lad.44.1417635795646; Wed, 03 Dec 2014 11:43:15 -0800 (PST) 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.184.201 with SMTP id ew9csp726637lbc; Wed, 3 Dec 2014 11:43:14 -0800 (PST) X-Received: by 10.70.128.15 with SMTP id nk15mr11261874pdb.121.1417635794019; Wed, 03 Dec 2014 11:43:14 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ql13si39880210pdb.97.2014.12.03.11.43.13 for ; Wed, 03 Dec 2014 11:43:13 -0800 (PST) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752106AbaLCTnL (ORCPT + 26 others); Wed, 3 Dec 2014 14:43:11 -0500 Received: from mail-qg0-f48.google.com ([209.85.192.48]:36748 "EHLO mail-qg0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751291AbaLCTnJ (ORCPT ); Wed, 3 Dec 2014 14:43:09 -0500 Received: by mail-qg0-f48.google.com with SMTP id q107so11316163qgd.7 for ; Wed, 03 Dec 2014 11:43:08 -0800 (PST) X-Received: by 10.224.69.200 with SMTP id a8mr10529741qaj.40.1417635788806; Wed, 03 Dec 2014 11:43:08 -0800 (PST) Received: from xanadu.home ([2607:fa48:6d48:fb10:21c:c0ff:fe2a:325b]) by mx.google.com with ESMTPSA id t5sm24328412qge.16.2014.12.03.11.43.07 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Dec 2014 11:43:07 -0800 (PST) Date: Wed, 3 Dec 2014 14:43:06 -0500 (EST) From: Nicolas Pitre To: Thomas Gleixner , John Stultz cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] optimize ktime_divns for constant divisors Message-ID: User-Agent: Alpine 2.11 (LFD 23 2013-08-11) MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: nicolas.pitre@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.50 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: , 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. Signed-off-by: Nicolas Pitre --- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/include/linux/ktime.h b/include/linux/ktime.h index c9d645ad98..411dd8bfe5 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 37e50aadd4..890535c41c 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 */ /*