Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp2985926imm; Sun, 1 Jul 2018 09:44:20 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJ1r8sl6fQ0gqySwJ+NCxITOcSAGfMaduqt/lhDtGE9pTtwmBeJa195wpBo220rCL4mv9fP X-Received: by 2002:a17:902:4424:: with SMTP id k33-v6mr22676639pld.242.1530463460563; Sun, 01 Jul 2018 09:44:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530463460; cv=none; d=google.com; s=arc-20160816; b=1ICeXoMfQPtZLisLGumz9rUfmF/+ZLkhrB3r68ZszdSMZha/LP6iSdtSbuDH4mXt/g A9tbPJRgbPwJw0b/m1opOEaLXBpHMVrwyTK0McYv8rPNmEwPEiAenSXA0SsBCEslC8I7 GchTC+ZEpjPUAU9qQNXRn/+W1IWJoBGtUK6KwZAkTK/rms2dNE3Ms53aGeaxveHCpndT nf4qbN9Ki3oYfMb/NtNEY7LvnG4dnKgVCPeNtY/STt4jRfGoAVfBlI4UHHP5jgesI7fd hFa+26AoplsAhxogoVFDXjjvwFZp4tFC0injzmaooQfcSEOgsZmgQH0gs/WejTKZ6kjw iHjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=wGG9p1UVK044NLNdnrZD0SY6jmgYjY4vxe11va2Txe8=; b=EtuHvelcCBoydpQNQWVxgbwsWbe5kSlmUzUwv6UFQ5/n4b7EpxnKZTbqZrdcnDoSBz 5Vcx0w+cMS8PdhUC2S/zdd9eD/NAz6x0JCbA83VgHuf5smQnTC7WO0S9v6nMnbg1nBvl qXBMyOkhkRZNP7gmS47W/iCQdm6lbjTaAfykwDyy06PG9R7Kb/paYCqfp5RdTGKskRoS ysvTIr7wOLb3om3KogNyGk3SKIw9T0YZjJT207Nl0ZYd7TJgME/WX3HPQmCP28+WcOW1 ItYLKE0N2VdzjMv76wRkJfsHtEaPZ10CDb+ltA506AgqToX19HTz4U5zkqvq+5Uwjhnt A5eg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k1-v6si14591479pld.40.2018.07.01.09.44.06; Sun, 01 Jul 2018 09:44:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1032148AbeGAQmK (ORCPT + 99 others); Sun, 1 Jul 2018 12:42:10 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:37516 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031893AbeGAQmE (ORCPT ); Sun, 1 Jul 2018 12:42:04 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id E9907AE0; Sun, 1 Jul 2018 16:42:03 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Srinivas Pandruvada , "Rafael J. Wysocki" Subject: [PATCH 4.17 121/220] cpufreq: intel_pstate: Fix scaling max/min limits with Turbo 3.0 Date: Sun, 1 Jul 2018 18:22:25 +0200 Message-Id: <20180701160913.407434862@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701160908.272447118@linuxfoundation.org> References: <20180701160908.272447118@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.17-stable review patch. If anyone has any objections, please let me know. ------------------ From: Srinivas Pandruvada commit ff7c9917143b3a6cf2fa61212a32d67cf259bf9c upstream. When scaling max/min settings are changed, internally they are converted to a ratio using the max turbo 1 core turbo frequency. This works fine when 1 core max is same irrespective of the core. But under Turbo 3.0, this will not be the case. For example: Core 0: max turbo pstate: 43 (4.3GHz) Core 1: max turbo pstate: 45 (4.5GHz) In this case 1 core turbo ratio will be maximum of all, so it will be 45 (4.5GHz). Suppose scaling max is set to 4GHz (ratio 40) for all cores ,then on core one it will be = max_state * policy->max / max_freq; = 43 * (4000000/4500000) = 38 (3.8GHz) = 38 which is 200MHz less than the desired. On core2, it will be correctly set to ratio 40 (4GHz). Same holds true for scaling min frequency limit. So this requires usage of correct turbo max frequency for core one, which in this case is 4.3GHz. So we need to adjust per CPU cpu->pstate.turbo_freq using the maximum HWP ratio of that core. This change uses the HWP capability of a core to adjust max turbo frequency. But since Broadwell HWP doesn't use ratios in the HWP capabilities, we have to use legacy max 1 core turbo ratio. This is not a problem as the HWP capabilities don't differ among cores in Broadwell. We need to check for non Broadwell CPU model for applying this change, though. Signed-off-by: Srinivas Pandruvada Cc: 4.6+ # 4.6+ Signed-off-by: Rafael J. Wysocki Signed-off-by: Greg Kroah-Hartman --- drivers/cpufreq/intel_pstate.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -284,6 +284,7 @@ struct pstate_funcs { static struct pstate_funcs pstate_funcs __read_mostly; static int hwp_active __read_mostly; +static int hwp_mode_bdw __read_mostly; static bool per_cpu_limits __read_mostly; static struct cpufreq_driver *intel_pstate_driver __read_mostly; @@ -1370,7 +1371,15 @@ static void intel_pstate_get_cpu_pstates cpu->pstate.turbo_pstate = pstate_funcs.get_turbo(); cpu->pstate.scaling = pstate_funcs.get_scaling(); cpu->pstate.max_freq = cpu->pstate.max_pstate * cpu->pstate.scaling; - cpu->pstate.turbo_freq = cpu->pstate.turbo_pstate * cpu->pstate.scaling; + + if (hwp_active && !hwp_mode_bdw) { + unsigned int phy_max, current_max; + + intel_pstate_get_hwp_max(cpu->cpu, &phy_max, ¤t_max); + cpu->pstate.turbo_freq = phy_max * cpu->pstate.scaling; + } else { + cpu->pstate.turbo_freq = cpu->pstate.turbo_pstate * cpu->pstate.scaling; + } if (pstate_funcs.get_aperf_mperf_shift) cpu->aperf_mperf_shift = pstate_funcs.get_aperf_mperf_shift(); @@ -2252,28 +2261,36 @@ static inline bool intel_pstate_has_acpi static inline void intel_pstate_request_control_from_smm(void) {} #endif /* CONFIG_ACPI */ +#define INTEL_PSTATE_HWP_BROADWELL 0x01 + +#define ICPU_HWP(model, hwp_mode) \ + { X86_VENDOR_INTEL, 6, model, X86_FEATURE_HWP, hwp_mode } + static const struct x86_cpu_id hwp_support_ids[] __initconst = { - { X86_VENDOR_INTEL, 6, X86_MODEL_ANY, X86_FEATURE_HWP }, + ICPU_HWP(INTEL_FAM6_BROADWELL_X, INTEL_PSTATE_HWP_BROADWELL), + ICPU_HWP(INTEL_FAM6_BROADWELL_XEON_D, INTEL_PSTATE_HWP_BROADWELL), + ICPU_HWP(X86_MODEL_ANY, 0), {} }; static int __init intel_pstate_init(void) { + const struct x86_cpu_id *id; int rc; if (no_load) return -ENODEV; - if (x86_match_cpu(hwp_support_ids)) { + id = x86_match_cpu(hwp_support_ids); + if (id) { copy_cpu_funcs(&core_funcs); if (!no_hwp) { hwp_active++; + hwp_mode_bdw = id->driver_data; intel_pstate.attr = hwp_cpufreq_attrs; goto hwp_cpu_matched; } } else { - const struct x86_cpu_id *id; - id = x86_match_cpu(intel_pstate_cpu_ids); if (!id) return -ENODEV;