From patchwork Fri Jan 23 00:09:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 43544 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id AF4C1218DB for ; Fri, 23 Jan 2015 00:09:37 +0000 (UTC) Received: by mail-lb0-f200.google.com with SMTP id u10sf2597575lbd.3 for ; Thu, 22 Jan 2015 16:09:36 -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=YWdiIfrpxZMtm7nHrtHhO5mKr2xiyvptiVlbqfif2WzAs8NiM9iT/0yx0L/4F3MHk4 H4UNI3b3WJoSZq7FOVRkPvf1V1LbMlG6q8XJCtPa61dv/78RK2THARKiQWIR1R6J9HBh IOgW14POVfL9IwbOVsrpWpADc2gcnXVsmOYhDYE/1np5B1odRWrgyHvDTXiN4z2AQUMI zDxDdhHK4r+F15IA/cKleFb/cg1pQHf9PdA+OIGmF77Bapi3of2wVaCqIVC1WSDlJI5c 9j4Tg6L6iJtzZ4nOLr7WpTNRUROZiSUbqIzgxVpeGF2ADpBUZIuvBkYKAjVtfjfn9MQR tvOQ== X-Gm-Message-State: ALoCoQkJEvwpZXqTN8Cll3iTWvHgldtynA2T6GkncmRj6EDjjFcXZKfQW0JjxlrfYAryTIFQEMRA X-Received: by 10.112.114.162 with SMTP id jh2mr589439lbb.9.1421971776677; Thu, 22 Jan 2015 16:09:36 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.97 with SMTP id v1ls242461lal.29.gmail; Thu, 22 Jan 2015 16:09:36 -0800 (PST) X-Received: by 10.152.42.164 with SMTP id p4mr4487570lal.45.1421971776538; Thu, 22 Jan 2015 16:09:36 -0800 (PST) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id ku8si352933lac.24.2015.01.22.16.09.36 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Jan 2015 16:09:36 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by mail-lb0-f171.google.com with SMTP id u14so4452956lbd.2 for ; Thu, 22 Jan 2015 16:09:36 -0800 (PST) X-Received: by 10.152.6.132 with SMTP id b4mr4531578laa.59.1421971776024; Thu, 22 Jan 2015 16:09:36 -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 c8csp63844lbb; Thu, 22 Jan 2015 16:09:35 -0800 (PST) X-Received: by 10.70.103.37 with SMTP id ft5mr6342029pdb.159.1421971774135; Thu, 22 Jan 2015 16:09:34 -0800 (PST) Received: from mail-pd0-f173.google.com (mail-pd0-f173.google.com. [209.85.192.173]) by mx.google.com with ESMTPS id qh1si11399042pbb.226.2015.01.22.16.09.33 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Jan 2015 16:09:34 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.192.173 as permitted sender) client-ip=209.85.192.173; Received: by mail-pd0-f173.google.com with SMTP id fp1so4797254pdb.4 for ; Thu, 22 Jan 2015 16:09:33 -0800 (PST) X-Received: by 10.70.127.205 with SMTP id ni13mr6490289pdb.43.1421971773179; Thu, 22 Jan 2015 16:09:33 -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 am14sm10405657pac.35.2015.01.22.16.09.31 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 22 Jan 2015 16:09:32 -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/12] clocksource: Simplify clocks_calc_max_nsecs logic Date: Thu, 22 Jan 2015 16:09:16 -0800 Message-Id: <1421971767-17707-2-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1421971767-17707-1-git-send-email-john.stultz@linaro.org> References: <1421971767-17707-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.171 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