From patchwork Sat Jan 24 01:43:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 43710 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 AC85E218DB for ; Sat, 24 Jan 2015 01:44:16 +0000 (UTC) Received: by mail-la0-f71.google.com with SMTP id s18sf260623lam.2 for ; Fri, 23 Jan 2015 17:44:15 -0800 (PST) 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:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=swEhwN6cRkoKWvzQQZ1RN+Epyem+tJ6Znbybg4ocATk=; b=A3UhfVZ3A/bgYIWGh1bR8Uf3NdOPQ6SPgwC98yUAR5+PqvwENwQyv4zHIKdZT/kAgS IruvnzOjU5BQJkl5Mu8wK5eaarM4/KpN91iuZ5cdD1izMrkbK2KFKPxC27yymPrdIpWq DD0LiqDPYyJxKMN/5LoYddtTaCR7NZcH6K0/kYWXNTHjaYRvNnFJuCOeh5t7iG3ys87z cYJ2ilUSSCV+sFwGHRPwjzhW/SlJs0iWEA220B+BKdTAB0wt3EzBIS5zt+Ho7AQ8GvSz k6izN7uMKmJaDVd1MA4PXeXW+5d9z3ICz2qKmrxwAeUwwFG/3HMY0k4+DJcV46mmOWXp s8Pg== X-Gm-Message-State: ALoCoQkhf3dfnK4VKRsHELjOMGmTYCzNvK8yb1+hENGF0L7lvZLgYWmgrqWMl5yrZmvb5hnLLghB X-Received: by 10.152.3.234 with SMTP id f10mr1363162laf.1.1422063855413; Fri, 23 Jan 2015 17:44:15 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.207.3 with SMTP id ls3ls333687lac.46.gmail; Fri, 23 Jan 2015 17:44:15 -0800 (PST) X-Received: by 10.112.132.67 with SMTP id os3mr10222001lbb.90.1422063855202; Fri, 23 Jan 2015 17:44:15 -0800 (PST) Received: from mail-lb0-f175.google.com (mail-lb0-f175.google.com. [209.85.217.175]) by mx.google.com with ESMTPS id e1si2805819laa.119.2015.01.23.17.44.15 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 23 Jan 2015 17:44:15 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.175 as permitted sender) client-ip=209.85.217.175; Received: by mail-lb0-f175.google.com with SMTP id 10so474427lbg.6 for ; Fri, 23 Jan 2015 17:44:15 -0800 (PST) X-Received: by 10.152.8.11 with SMTP id n11mr10128847laa.38.1422063855020; Fri, 23 Jan 2015 17:44:15 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.35.133 with SMTP id h5csp90244lbj; Fri, 23 Jan 2015 17:44:14 -0800 (PST) X-Received: by 10.70.131.78 with SMTP id ok14mr15961814pdb.112.1422063853302; Fri, 23 Jan 2015 17:44:13 -0800 (PST) Received: from mail-pd0-f172.google.com (mail-pd0-f172.google.com. [209.85.192.172]) by mx.google.com with ESMTPS id fs12si4013241pdb.56.2015.01.23.17.44.12 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 23 Jan 2015 17:44:13 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.192.172 as permitted sender) client-ip=209.85.192.172; Received: by mail-pd0-f172.google.com with SMTP id v10so1043787pde.3 for ; Fri, 23 Jan 2015 17:44:12 -0800 (PST) X-Received: by 10.68.226.166 with SMTP id rt6mr15747637pbc.120.1422063852390; Fri, 23 Jan 2015 17:44:12 -0800 (PST) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id ci17sm3111170pdb.70.2015.01.23.17.44.11 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 23 Jan 2015 17:44:11 -0800 (PST) From: John Stultz To: lkml Cc: Nicolas Pitre , Arnd Bergmann , Thomas Gleixner , Ingo Molnar , Nicolas Pitre , John Stultz Subject: [PATCH 1/8] ktime: Optimize ktime_divns for constant divisors Date: Fri, 23 Jan 2015 17:43:53 -0800 Message-Id: <1422063840-2837-2-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1422063840-2837-1-git-send-email-john.stultz@linaro.org> References: <1422063840-2837-1-git-send-email-john.stultz@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@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.217.175 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Nicolas Pitre 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 --- 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 37e50aa..890535c 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 */ /*