From patchwork Thu May 29 16:32:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: dirk.brandewie@gmail.com X-Patchwork-Id: 4266341 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E6312BEEA7 for ; Thu, 29 May 2014 16:32:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 103E920379 for ; Thu, 29 May 2014 16:32:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 36BAE20351 for ; Thu, 29 May 2014 16:32:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757564AbaE2Qcj (ORCPT ); Thu, 29 May 2014 12:32:39 -0400 Received: from mail-pb0-f54.google.com ([209.85.160.54]:59896 "EHLO mail-pb0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757052AbaE2Qcj (ORCPT ); Thu, 29 May 2014 12:32:39 -0400 Received: by mail-pb0-f54.google.com with SMTP id jt11so645225pbb.13 for ; Thu, 29 May 2014 09:32:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=J/oRCIv8zMiCj4B5J3bClAdiIXw3MZ8tPhjqWHRQsMY=; b=FzmdMAAdTJWqsCopQ7EUubw7H7kVRmJdhpiO+huWtQRbqEHRNZpu4SQx0h35wcmp7/ rDYpgX6YhI9n/wPqGIF/iQvc8TOjr5r3HU9KFPpB/BNpTq6J9DumqhanRVKn22KuAEi0 dsKQ9CpwYh2NCNUg3UKDIt0YDiPqTCCkr3QO4Iqj7tEiDYKSk9viYz70stPM2bsaGtYK yOY7CZClxLQIcgdiYyw5fUeSgnUDQL0lgeDdView+Rxo/7aBqL+zuneqbY3uLSr2qhko Zqp88dWJHS5FNCEzUEXErr+NH0wbcvVjuS3j9TDdWdGZAPRce8jDx39DT2WENpzWQbta SjXA== X-Received: by 10.68.200.10 with SMTP id jo10mr10014695pbc.143.1401381158644; Thu, 29 May 2014 09:32:38 -0700 (PDT) Received: from echolake.localdomain (static-50-43-42-35.bvtn.or.frontiernet.net. [50.43.42.35]) by mx.google.com with ESMTPSA id lr3sm5411991pab.4.2014.05.29.09.32.36 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 May 2014 09:32:37 -0700 (PDT) From: dirk.brandewie@gmail.com X-Google-Original-From: dirk.j.brandewie@intel.com To: linux-pm@vger.kernel.org Cc: dirk.brandewie@gmail.com, rjw@rjwysocki.net, dsmythies@telus.net, Dirk Brandewie , Subject: [PATCH 2/4] intel_pstate: Correct rounding in busy calculation Date: Thu, 29 May 2014 09:32:23 -0700 Message-Id: <1401381145-17745-3-git-send-email-dirk.j.brandewie@intel.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1401381145-17745-1-git-send-email-dirk.j.brandewie@intel.com> References: <1401381145-17745-1-git-send-email-dirk.j.brandewie@intel.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Dirk Brandewie Changing to fixed point math throughout the busy calculation in commit e66c1768 Change busy calculation to use fixed point math. Introduced some inaccuracies by rounding the busy value at two points in the calculation. This change removes roundings and moves the rounding to the output of the PID where the calculations are complete and the value returned as an integer. Reported-by: Doug Smythies Cc: # 3.14.x Signed-off-by: Dirk Brandewie --- drivers/cpufreq/intel_pstate.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index ffef765..db8a992 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -38,10 +38,10 @@ #define BYT_TURBO_VIDS 0x66d -#define FRAC_BITS 6 +#define FRAC_BITS 8 #define int_tofp(X) ((int64_t)(X) << FRAC_BITS) #define fp_toint(X) ((X) >> FRAC_BITS) -#define FP_ROUNDUP(X) ((X) += 1 << FRAC_BITS) + static inline int32_t mul_fp(int32_t x, int32_t y) { @@ -194,7 +194,10 @@ static signed int pid_calc(struct _pid *pid, int32_t busy) pid->last_err = fp_error; result = pterm + mul_fp(pid->integral, pid->i_gain) + dterm; - + if (result >= 0) + result = result + (1 << (FRAC_BITS-1)); + else + result = result - (1 << (FRAC_BITS-1)); return (signed int)fp_toint(result); } @@ -556,7 +559,6 @@ static inline void intel_pstate_calc_busy(struct cpudata *cpu) core_pct = div_fp(int_tofp(sample->aperf), int_tofp(sample->mperf)); core_pct = mul_fp(core_pct, int_tofp(100)); - FP_ROUNDUP(core_pct); sample->freq = fp_toint( mul_fp(int_tofp(cpu->pstate.max_pstate * 1000), core_pct)); @@ -602,7 +604,7 @@ static inline int32_t intel_pstate_get_scaled_busy(struct cpudata *cpu) max_pstate = int_tofp(cpu->pstate.max_pstate); current_pstate = int_tofp(cpu->pstate.current_pstate); core_busy = mul_fp(core_busy, div_fp(max_pstate, current_pstate)); - return FP_ROUNDUP(core_busy); + return core_busy; } static inline void intel_pstate_adjust_busy_pstate(struct cpudata *cpu)