From patchwork Thu Mar 12 04:16:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 45714 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D786B21534 for ; Thu, 12 Mar 2015 04:16:49 +0000 (UTC) Received: by wggy19 with SMTP id y19sf9602792wgg.2 for ; Wed, 11 Mar 2015 21:16:49 -0700 (PDT) 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=U0ONpxGKSwNQy/hDyX1xmi9hH+zzBF1T5Bql8QvwiDk=; b=h6iDimH1W5H9q0hhvT6CKE7BwNj8/zCWdRJhl08xKH7ZRIDDlvKYqSet3MsyDBZVpM 73VKxrPRAhk/wYCWQbfq+DNu520VR/j7upb5Yy4xFVh1/8z9egq0KmqDQar9PAfbTOMe qW+viBQL4AUbemiCXweGc1HjBShUbeJjxRKBOFNrCJweSHVIsT5W9tr+k0YLcNfh4dkT gOIYtbOzE/+LOwO9RU1pfWZrsWKKAHPVwdq4rXSMi33yOTe0QhLbNJ4mtYY4xxDyHXNr KLSiHX+zOi/VN7PVrEGDxRM0N7sL3HtsLh7/fFrs/jKS9WUz6zHmgw0d3zG/wMQhymie nxUg== X-Gm-Message-State: ALoCoQnnIE/e3APpS42dnIT94GsmCY5NJ198SfCfHV/oksKnwTYrHntr0ic1oX0MxuMzswzy29B+ X-Received: by 10.112.125.67 with SMTP id mo3mr4284699lbb.6.1426133809100; Wed, 11 Mar 2015 21:16:49 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.206.104 with SMTP id ln8ls220204lac.94.gmail; Wed, 11 Mar 2015 21:16:48 -0700 (PDT) X-Received: by 10.112.147.66 with SMTP id ti2mr37881036lbb.124.1426133808952; Wed, 11 Mar 2015 21:16:48 -0700 (PDT) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com. [209.85.217.169]) by mx.google.com with ESMTPS id o10si3552541lbw.132.2015.03.11.21.16.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Mar 2015 21:16:48 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by lbiz12 with SMTP id z12so13284592lbi.12 for ; Wed, 11 Mar 2015 21:16:48 -0700 (PDT) X-Received: by 10.112.212.106 with SMTP id nj10mr18600099lbc.36.1426133808655; Wed, 11 Mar 2015 21:16:48 -0700 (PDT) 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 h5csp3173178lbj; Wed, 11 Mar 2015 21:16:47 -0700 (PDT) X-Received: by 10.66.218.129 with SMTP id pg1mr85357841pac.65.1426133805783; Wed, 11 Mar 2015 21:16:45 -0700 (PDT) Received: from mail-pd0-f182.google.com (mail-pd0-f182.google.com. [209.85.192.182]) by mx.google.com with ESMTPS id d8si10607551pas.166.2015.03.11.21.16.44 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Mar 2015 21:16:45 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.192.182 as permitted sender) client-ip=209.85.192.182; Received: by pdjp10 with SMTP id p10so16730134pdj.10 for ; Wed, 11 Mar 2015 21:16:44 -0700 (PDT) X-Received: by 10.70.30.162 with SMTP id t2mr81230634pdh.142.1426133804838; Wed, 11 Mar 2015 21:16:44 -0700 (PDT) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id x1sm3070268pdp.1.2015.03.11.21.16.43 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Mar 2015 21:16:44 -0700 (PDT) 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: Wed, 11 Mar 2015 21:16:29 -0700 Message-Id: <1426133800-29329-2-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1426133800-29329-1-git-send-email-john.stultz@linaro.org> References: <1426133800-29329-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.169 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 64-bit values, where as the intervals are always unsigned. This resulted in overly conservative intervals, which other safety 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