Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9093346pxu; Mon, 28 Dec 2020 06:28:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJzti+1TAaaxMsf6lEdBFyZbRteewc8rFKprbxPm1hrCYG/Ig5/JcZMeECOvoBphtph5VycR X-Received: by 2002:a50:d5d5:: with SMTP id g21mr43756220edj.41.1609165733431; Mon, 28 Dec 2020 06:28:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609165733; cv=none; d=google.com; s=arc-20160816; b=F5LHXqi974rP8+dryirHdgN6DJmGHtYhHcId02tqo8Kkz12qSiwQbkome2LoQpdsRH uU1ZjAE9F0N4xo5IworpKL7cGbLlkW4pwQs7mYW05vY93aZQTDH/Grf8xpBJ+WY+RXgl MYLV2D2d8jRp9aATes1igYrPmUl7Ya1L08NzfgE9q7FLvlDYc9hhsyu7Nnf9XDEndlGO GozFh3/Q3ffe2X+BcbXABjFfjkKuV6Flx3R/FYsYu34VINsxF7fIHynzEjyYDThXw5JV 1bCLjxga/QTI9ruCaMTmCkZkdGwb3whTd0M4NRQQ4m3SEQYWeOi7nfBDMaVRd1LxKTSr 7Cgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=y1BywqjF17SAXW0pbs1DhxW+Hv0D+einPdud36kNo+g=; b=OzvSpQtKtqiGqzwclrlTuqZPQsKl6FiQvcKivyB2Y4ME3w+sjX8hdzH6Yh7bNB1adb dceP0NbunM+yWs8Ce+kVjLkMg2U4LAscx9lz8qno5qqh6Tf/2TqiyOXIYSGPFp0AwHy1 x/jqMBkO9rJWsA5erGfks4YlvWyZe6eIFQ+EcPHXYLKyHMT3wN6aG7580rFm5J7QpAHT Lin27ygF9ID75EadA5uhZ5OgOWovGcz5DFbFT9UVBcF1Lx5z7Ecdj4uiMyRUDfnppT6l Sz+pzi7z44D4SUHGU9UpGGxrEy+lzsBDgi6dcA2iWO7zUTyI8lxeT6W7cKIgEZ4kz23D 8tXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Z7FxhCZY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o2si18417575ejn.501.2020.12.28.06.28.31; Mon, 28 Dec 2020 06:28:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Z7FxhCZY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2503816AbgL1O0a (ORCPT + 99 others); Mon, 28 Dec 2020 09:26:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:34350 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2503736AbgL1O02 (ORCPT ); Mon, 28 Dec 2020 09:26:28 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id AD20220791; Mon, 28 Dec 2020 14:25:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609165548; bh=x1C+sd9U7BcgZbl7VcaA0VS0rV5JSsThmUO33qAU6JU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z7FxhCZY2T5upVGKxy5iiafIpIy7cLitEv0haGK+NhaB0wK0nrpE7ANauWhQx1Xqe ck6dUT33BJAXPBHmhcScJEOGbntFXRfdz5fAVuoCH1G2issngS0uQmezN0jpHyvTym 1mKsMurk9Ei7ZARBLR9MylH26vqnjgSXIiM34RUk= 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 5.10 570/717] cpufreq: intel_pstate: Use most recent guaranteed performance values Date: Mon, 28 Dec 2020 13:49:28 +0100 Message-Id: <20201228125048.223015610@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki commit e40ad84c26b4deeee46666492ec66b9a534b8e59 upstream. When turbo has been disabled by the BIOS, but HWP_CAP.GUARANTEED is changed later, user space may want to take advantage of this increased guaranteed performance. HWP_CAP.GUARANTEED is not a static value. It can be adjusted by an out-of-band agent or during an Intel Speed Select performance level change. The HWP_CAP.MAX is still the maximum achievable performance with turbo disabled by the BIOS, so HWP_CAP.GUARANTEED can still change as long as it remains less than or equal to HWP_CAP.MAX. When HWP_CAP.GUARANTEED is changed, the sysfs base_frequency attribute shows the most recent guaranteed frequency value. This attribute can be used by user space software to update the scaling min/max limits of the CPU. Currently, the ->setpolicy() callback already uses the latest HWP_CAP values when setting HWP_REQ, but the ->verify() callback will restrict the user settings to the to old guaranteed performance value which prevents user space from making use of the extra CPU capacity theoretically available to it after increasing HWP_CAP.GUARANTEED. To address this, read HWP_CAP in intel_pstate_verify_cpu_policy() to obtain the maximum P-state that can be used and use that to confine the policy max limit instead of using the cached and possibly stale pstate.max_freq value for this purpose. For consistency, update intel_pstate_update_perf_limits() to use the maximum available P-state returned by intel_pstate_get_hwp_max() to compute the maximum frequency instead of using the return value of intel_pstate_get_max_freq() which, again, may be stale. This issue is a side-effect of fixing the scaling frequency limits in commit eacc9c5a927e ("cpufreq: intel_pstate: Fix intel_pstate_get_hwp_max() for turbo disabled") which corrected the setting of the reduced scaling frequency values, but caused stale HWP_CAP.GUARANTEED to be used in the case at hand. Fixes: eacc9c5a927e ("cpufreq: intel_pstate: Fix intel_pstate_get_hwp_max() for turbo disabled") Reported-by: Srinivas Pandruvada Tested-by: Srinivas Pandruvada Cc: 5.8+ # 5.8+ Signed-off-by: Rafael J. Wysocki Signed-off-by: Greg Kroah-Hartman --- drivers/cpufreq/intel_pstate.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -2207,9 +2207,9 @@ static void intel_pstate_update_perf_lim unsigned int policy_min, unsigned int policy_max) { - int max_freq = intel_pstate_get_max_freq(cpu); int32_t max_policy_perf, min_policy_perf; int max_state, turbo_max; + int max_freq; /* * HWP needs some special consideration, because on BDX the @@ -2223,6 +2223,7 @@ static void intel_pstate_update_perf_lim cpu->pstate.max_pstate : cpu->pstate.turbo_pstate; turbo_max = cpu->pstate.turbo_pstate; } + max_freq = max_state * cpu->pstate.scaling; max_policy_perf = max_state * policy_max / max_freq; if (policy_max == policy_min) { @@ -2325,9 +2326,18 @@ static void intel_pstate_adjust_policy_m static void intel_pstate_verify_cpu_policy(struct cpudata *cpu, struct cpufreq_policy_data *policy) { + int max_freq; + update_turbo_state(); - cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq, - intel_pstate_get_max_freq(cpu)); + if (hwp_active) { + int max_state, turbo_max; + + intel_pstate_get_hwp_max(cpu->cpu, &turbo_max, &max_state); + max_freq = max_state * cpu->pstate.scaling; + } else { + max_freq = intel_pstate_get_max_freq(cpu); + } + cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq, max_freq); intel_pstate_adjust_policy_max(cpu, policy); }