From patchwork Tue Jun 6 01:01:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: srinivas pandruvada X-Patchwork-Id: 9767873 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D2D346034B for ; Tue, 6 Jun 2017 01:02:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C87CA28445 for ; Tue, 6 Jun 2017 01:02:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BB9E42844E; Tue, 6 Jun 2017 01:02:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6AF7828415 for ; Tue, 6 Jun 2017 01:02:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751636AbdFFBCU (ORCPT ); Mon, 5 Jun 2017 21:02:20 -0400 Received: from mga05.intel.com ([192.55.52.43]:40838 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751701AbdFFBCT (ORCPT ); Mon, 5 Jun 2017 21:02:19 -0400 Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP; 05 Jun 2017 18:02:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,303,1493708400"; d="scan'208";a="110781731" Received: from spandruv-desk.jf.intel.com ([10.54.75.150]) by fmsmga005.fm.intel.com with ESMTP; 05 Jun 2017 18:02:12 -0700 From: Srinivas Pandruvada To: rjw@rjwysocki.net, lenb@kernel.org Cc: linux-pm@vger.kernel.org, Srinivas Pandruvada Subject: [PATCH] cpufreq: intel_pstate: Increase precision Date: Mon, 5 Jun 2017 18:01:04 -0700 Message-Id: <1496710864-117662-1-git-send-email-srinivas.pandruvada@linux.intel.com> X-Mailer: git-send-email 2.7.4 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In some cases the scaling max/min limit set via cpufreq interface doesn't result in correct max/min. For example, with the data below: cpuinfo_max_freq:3700000 scaling_max_freq:2500000 HWP max ratio = 37 With the current fixed point conversion to ratio using 14 bit shift: max_perf = (2500000 << 14) / 3700000 = 11070 Rounding up with 14 = 11070 HWP max ratio corresponding to 2500000 will be = (hwp max ratio * max_perf) >> 14 = 24 So this will result in 100Mhz less frequency than what is requested, with scaling factor of 100000. To fix this if we increase the shift to 15 bits. max_perf = (2500000 << 15) / 3700000 = 22140 rounded up with 15 = 22144 The new max ratio corresponding to 2500000 will be = (hwp max ratio * max_perf) >> 15 = 25 This will result in correct scaling max frequency. This patch changes EXT_BITS to 7 from 6, so this will result in 15 bit shift during fixed point math above. Signed-off-by: Srinivas Pandruvada --- drivers/cpufreq/intel_pstate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index 640eb7e4..6386422 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -52,7 +52,7 @@ #define int_tofp(X) ((int64_t)(X) << FRAC_BITS) #define fp_toint(X) ((X) >> FRAC_BITS) -#define EXT_BITS 6 +#define EXT_BITS 7 #define EXT_FRAC_BITS (EXT_BITS + FRAC_BITS) #define fp_ext_toint(X) ((X) >> EXT_FRAC_BITS) #define int_ext_tofp(X) ((int64_t)(X) << EXT_FRAC_BITS)