From patchwork Sat Mar 7 02:49:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 45505 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id F30D0214A0 for ; Sat, 7 Mar 2015 02:50:24 +0000 (UTC) Received: by lbdu14 with SMTP id u14sf16232195lbd.3 for ; Fri, 06 Mar 2015 18:50:24 -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=lY0ejMeUVymw/PlunRF4ba7Wo1MsaTkQs+A3ViUtWFA=; b=E1Xi7Io7bJPSKoBeE533AdbNaY1C7bj+J7TqCKWlv18Y9o/y3vfkfP7QADGjAmzj6r RjB7FX0b2cCNcLVhQzM088cSciihf79q5u5nJIPH9OysaFTty4VmYaI83T5eU/8XYgm0 w2CJTCpkZy8aP59RBVZugNBtMycxA/zJTwiWUeuxKxrEQ/4uBHhU4zYqtZkQlyLH64z6 SnlYnTO4TH5cGaM6wJ/jJfeRJnEK1skxJgz8h1kBYJ6iM8w3bO+vIRYyCxo77Bnbpssz iaLXYjJUfQex4E42Kux7/9j5oWi4nbI+kf+HrKozZOCE2pFKDpown197Qoe9+z+DMQdY /jgw== X-Gm-Message-State: ALoCoQkP7292asca6PCyJ9cgIRECWEar77DGILKHbaWgLi6FbziWhDY6oUNM8FqmM1f1ikVboi9N X-Received: by 10.194.95.67 with SMTP id di3mr2736631wjb.0.1425696623986; Fri, 06 Mar 2015 18:50:23 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.207.101 with SMTP id lv5ls140529lac.22.gmail; Fri, 06 Mar 2015 18:50:23 -0800 (PST) X-Received: by 10.152.87.178 with SMTP id az18mr15835842lab.122.1425696623778; Fri, 06 Mar 2015 18:50:23 -0800 (PST) Received: from mail-la0-f53.google.com (mail-la0-f53.google.com. [209.85.215.53]) by mx.google.com with ESMTPS id d9si8493143laf.139.2015.03.06.18.50.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Mar 2015 18:50:23 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by labge10 with SMTP id ge10so61171859lab.12 for ; Fri, 06 Mar 2015 18:50:23 -0800 (PST) X-Received: by 10.112.204.197 with SMTP id la5mr15411270lbc.29.1425696623178; Fri, 06 Mar 2015 18:50:23 -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 h5csp256403lbj; Fri, 6 Mar 2015 18:50:22 -0800 (PST) X-Received: by 10.70.44.100 with SMTP id d4mr31166665pdm.36.1425696621501; Fri, 06 Mar 2015 18:50:21 -0800 (PST) Received: from mail-pa0-f51.google.com (mail-pa0-f51.google.com. [209.85.220.51]) by mx.google.com with ESMTPS id kx7si17450787pbc.158.2015.03.06.18.50.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Mar 2015 18:50:21 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.51 as permitted sender) client-ip=209.85.220.51; Received: by pabli10 with SMTP id li10so56251752pab.13 for ; Fri, 06 Mar 2015 18:50:20 -0800 (PST) X-Received: by 10.68.132.103 with SMTP id ot7mr31506822pbb.0.1425696615604; Fri, 06 Mar 2015 18:50:15 -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 a2sm8381456pbu.27.2015.03.06.18.50.14 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 06 Mar 2015 18:50:14 -0800 (PST) From: John Stultz To: lkml Cc: John Stultz , Dave Jones , Linus Torvalds , Thomas Gleixner , Richard Cochran , Prarit Bhargava , Stephen Boyd , Ingo Molnar , Peter Zijlstra Subject: [PATCH 01/12] clocksource: Simplify clocks_calc_max_nsecs logic Date: Fri, 6 Mar 2015 18:49:52 -0800 Message-Id: <1425696603-16878-2-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1425696603-16878-1-git-send-email-john.stultz@linaro.org> References: <1425696603-16878-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.215.53 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: , The previous clocks_calc_max_nsecs had some unecessarily complex bit logic to find the max interval that could cause multiplication overflows. Since this is not in the hot path, just do the divide to make it easier to read. The previous implementation also had a subtle issue that it avoided overflows into signed 64bit values, where as the intervals are always unsigned. This resulted in overly conservative intervals, which other saftey margins were then added to, reducing the intended interval length. Cc: Dave Jones Cc: Linus Torvalds Cc: Thomas Gleixner Cc: Richard Cochran Cc: Prarit Bhargava Cc: Stephen Boyd Cc: Ingo Molnar Cc: Peter Zijlstra Signed-off-by: John Stultz --- kernel/time/clocksource.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c index 4892352..11323f4 100644 --- a/kernel/time/clocksource.c +++ b/kernel/time/clocksource.c @@ -476,19 +476,10 @@ u64 clocks_calc_max_nsecs(u32 mult, u32 shift, u32 maxadj, u64 mask) /* * Calculate the maximum number of cycles that we can pass to the - * cyc2ns function without overflowing a 64-bit signed result. The - * maximum number of cycles is equal to ULLONG_MAX/(mult+maxadj) - * which is equivalent to the below. - * max_cycles < (2^63)/(mult + maxadj) - * max_cycles < 2^(log2((2^63)/(mult + maxadj))) - * max_cycles < 2^(log2(2^63) - log2(mult + maxadj)) - * max_cycles < 2^(63 - log2(mult + maxadj)) - * max_cycles < 1 << (63 - log2(mult + maxadj)) - * Please note that we add 1 to the result of the log2 to account for - * any rounding errors, ensure the above inequality is satisfied and - * no overflow will occur. + * cyc2ns function without overflowing a 64-bit result. */ - max_cycles = 1ULL << (63 - (ilog2(mult + maxadj) + 1)); + max_cycles = ULLONG_MAX; + do_div(max_cycles, mult+maxadj); /* * The actual maximum number of cycles we can defer the clocksource is