From patchwork Sat Jan 10 00:34:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 42928 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DB16C26CF1 for ; Sat, 10 Jan 2015 00:34:39 +0000 (UTC) Received: by mail-lb0-f198.google.com with SMTP id p9sf5981182lbv.1 for ; Fri, 09 Jan 2015 16:34:38 -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=ekF9TqEo6kevHrxUmywtGeIeoZQW9FwNuN8bkbGxC08=; b=RHTHnPq7L4Uf28x+cOpIT9xKGKf3JdE+KGnlJR+95XgF8fDQazWHEarpic5gNNh5f8 B+3cQRF8cymISlN8nZ16tpGsTM2cDFRKyhEYcotf6CbyqAGZY7bH5eN7uBx2P+wXcbq0 OhevnKv2MVJm8VJzjljHK1gqlgUNqhrJ3Rjmh4RLqrWEYtOQz+uV7oBa7xsA4t9TZSS9 xZSDoWGXuyqDpR98T82yFaadASFabjjqRUNHQSMcpIqnLQ7qLRcPeR86dA8uwQYITqJy 5WV0VPotrkHt58hAnQ9SIXEpm2fftBcT2dd1RJ8YCkN7Sf32YkYCs4T91x5TFCokaxmO qeCg== X-Gm-Message-State: ALoCoQliSVKPluzN/MyJ5NRgAB02gVyEcYZLiy2Igg/JPHgcl6GiouiZhsqU+WZcb9zgy8Z8yzP9 X-Received: by 10.152.170.201 with SMTP id ao9mr1149lac.5.1420850078793; Fri, 09 Jan 2015 16:34:38 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.242.129 with SMTP id wq1ls436203lac.56.gmail; Fri, 09 Jan 2015 16:34:38 -0800 (PST) X-Received: by 10.112.13.103 with SMTP id g7mr24689141lbc.29.1420850078518; Fri, 09 Jan 2015 16:34:38 -0800 (PST) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id q2si14574451lbb.130.2015.01.09.16.34.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 09 Jan 2015 16:34:38 -0800 (PST) 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 mail-la0-f42.google.com with SMTP id gd6so17183055lab.1 for ; Fri, 09 Jan 2015 16:34:38 -0800 (PST) X-Received: by 10.152.234.35 with SMTP id ub3mr24576581lac.70.1420850078243; Fri, 09 Jan 2015 16:34:38 -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.9.200 with SMTP id c8csp484789lbb; Fri, 9 Jan 2015 16:34:37 -0800 (PST) X-Received: by 10.66.249.99 with SMTP id yt3mr27288877pac.59.1420850076515; Fri, 09 Jan 2015 16:34:36 -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 ew2si15266665pdb.190.2015.01.09.16.34.35 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 09 Jan 2015 16:34:36 -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 y13so20238209pdi.3 for ; Fri, 09 Jan 2015 16:34:35 -0800 (PST) X-Received: by 10.70.48.235 with SMTP id p11mr27817924pdn.134.1420850075635; Fri, 09 Jan 2015 16:34:35 -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 hc10sm8046439pbd.78.2015.01.09.16.34.34 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Jan 2015 16:34:34 -0800 (PST) From: John Stultz To: Linux Kernel Mailing List Cc: John Stultz , Dave Jones , Linus Torvalds , Thomas Gleixner , Richard Cochran , Prarit Bhargava , Stephen Boyd , Ingo Molnar , Peter Zijlstra Subject: [PATCH 01/10] clocksource: Simplify clocks_calc_max_nsecs logic Date: Fri, 9 Jan 2015 16:34:19 -0800 Message-Id: <1420850068-27828-2-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1420850068-27828-1-git-send-email-john.stultz@linaro.org> References: <1420850068-27828-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.42 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 b79f39b..c14cd03 100644 --- a/kernel/time/clocksource.c +++ b/kernel/time/clocksource.c @@ -552,19 +552,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