Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp695014pxb; Thu, 5 Nov 2020 10:27:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJxnEqArO3He1cLsBbEw7Scgs3b9+8F56PGT0en/UKYm5Qan1eD1q7R0wRqfY3FNif2vxTBm X-Received: by 2002:a17:906:68d8:: with SMTP id y24mr3791765ejr.438.1604600830713; Thu, 05 Nov 2020 10:27:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604600830; cv=none; d=google.com; s=arc-20160816; b=rxPE26ItXLVqwunFabI1NRSSUJsaeY7F6/Lodv/xXmJNnphA1WD1j6e4MrQxU99fsm JU8yYXhAbpv69qx2+Q0Ty19EVobs48d6ieYI20+z3LADxIJ8rssiuxyHFEY19H/ELCCO NMeBUR13IgT4eRPNECxejMNZISaYfkqYbRyea6NpSgW+6HW+xPAViUXToOuXY9pmiuJk TPlHnrcxMeGPG2f9oSgOFODFFikhhLhQmFVPfMSJILqnd/TmIbRdXBj1Gy05wJ6qSyOg XNbJdhQNu1xrq+iOMJCixg5xJkvGvMqVmaOxqy8C5CtnVjaQz8PWK18IxI4KsRKbaJYO PEfQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=eyt89Qrr/BnWJDq6t2QdPbxWwSSamsCQUfJ9WerzNhQ=; b=lkHbu7JX2wk8J73HUBmGB0Oic2fe5S7U14o/X5SZ5szJOZ09FqULjXKlO9XD3ST8df Y16uObm9saFAoSQ1astV40NK14mx/pQOjTrWcTrZOmqKFHNsnWa02PKiQABvWSfpRnU5 PW0czX7fm7T7zpfdDhsO5yAFfU/HzX3tZmtXVoNloYvAfbJT0pEg399dQgncMIet8dR9 wG7Jv22YwnJgOvPZXi0kiJln0KernSandLgu60dLo7mmtNaVi6hnKfWWzh6/vfZv9iLb P37WUJctt96q6cds9NVPqN9xlPJcgvI+nJK+2TqkP2RotoyzQ2BjMoaObAYllyc5i04c TY/w== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n3si1769920ejd.44.2020.11.05.10.26.45; Thu, 05 Nov 2020 10:27:10 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729862AbgKESZU (ORCPT + 99 others); Thu, 5 Nov 2020 13:25:20 -0500 Received: from cloudserver094114.home.pl ([79.96.170.134]:65252 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726214AbgKESZU (ORCPT ); Thu, 5 Nov 2020 13:25:20 -0500 Received: from 89-64-88-191.dynamic.chello.pl (89.64.88.191) (HELO kreacher.localnet) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.514) id 4ff6dc8dccf7dc57; Thu, 5 Nov 2020 19:25:18 +0100 From: "Rafael J. Wysocki" To: Linux PM Cc: "Rafael J. Wysocki" , Viresh Kumar , Srinivas Pandruvada , Zhang Rui , LKML Subject: [PATCH 2/2] cpufreq: intel_pstate: Take target_min and target_max into account Date: Thu, 05 Nov 2020 19:25:10 +0100 Message-ID: <3200924.ySlC381xRO@kreacher> In-Reply-To: <7417968.Ghue05m4RV@kreacher> References: <7417968.Ghue05m4RV@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki Make the intel_pstate driver take the new target_min and target_max cpufreq policy parameters into accout when it operates in the passive mode with HWP enabled, so as to fix the "powersave" governor behavior in that case (currently, HWP is allowed to scale the performance all the way up to the policy max limit when the "powersave" governor is used, but it should be contrained to the policy min limit then). Signed-off-by: Rafael J. Wysocki --- drivers/cpufreq/intel_pstate.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) Index: linux-pm/drivers/cpufreq/intel_pstate.c =================================================================== --- linux-pm.orig/drivers/cpufreq/intel_pstate.c +++ linux-pm/drivers/cpufreq/intel_pstate.c @@ -2527,7 +2527,7 @@ static void intel_cpufreq_trace(struct c } static void intel_cpufreq_adjust_hwp(struct cpudata *cpu, u32 target_pstate, - bool fast_switch) + u32 target_max, bool fast_switch) { u64 prev = READ_ONCE(cpu->hwp_req_cached), value = prev; @@ -2539,7 +2539,7 @@ static void intel_cpufreq_adjust_hwp(str * field in it, so opportunistically update the max too if needed. */ value &= ~HWP_MAX_PERF(~0L); - value |= HWP_MAX_PERF(cpu->max_perf_ratio); + value |= HWP_MAX_PERF(target_max); if (value == prev) return; @@ -2562,19 +2562,31 @@ static void intel_cpufreq_adjust_perf_ct pstate_funcs.get_val(cpu, target_pstate)); } -static int intel_cpufreq_update_pstate(struct cpudata *cpu, int target_pstate, - bool fast_switch) +static int intel_cpufreq_update_pstate(struct cpufreq_policy *policy, + int target_pstate, bool fast_switch) { + struct cpudata *cpu = all_cpu_data[policy->cpu]; int old_pstate = cpu->pstate.current_pstate; - target_pstate = intel_pstate_prepare_request(cpu, target_pstate); if (hwp_active) { - intel_cpufreq_adjust_hwp(cpu, target_pstate, fast_switch); - cpu->pstate.current_pstate = target_pstate; + int min_pstate = max(cpu->pstate.min_pstate, cpu->min_perf_ratio); + int max_pstate = max(min_pstate, cpu->max_perf_ratio); + int target_min = DIV_ROUND_UP(policy->target_min, + cpu->pstate.scaling); + int target_max = policy->target_max / cpu->pstate.scaling; + + target_min = clamp_t(int, target_min, min_pstate, max_pstate); + target_max = clamp_t(int, target_max, min_pstate, max_pstate); + + target_pstate = clamp_t(int, target_pstate, target_min, target_max); + + intel_cpufreq_adjust_hwp(cpu, target_pstate, target_max, fast_switch); } else if (target_pstate != old_pstate) { + target_pstate = intel_pstate_prepare_request(cpu, target_pstate); + intel_cpufreq_adjust_perf_ctl(cpu, target_pstate, fast_switch); - cpu->pstate.current_pstate = target_pstate; } + cpu->pstate.current_pstate = target_pstate; intel_cpufreq_trace(cpu, fast_switch ? INTEL_PSTATE_TRACE_FAST_SWITCH : INTEL_PSTATE_TRACE_TARGET, old_pstate); @@ -2609,7 +2621,7 @@ static int intel_cpufreq_target(struct c break; } - target_pstate = intel_cpufreq_update_pstate(cpu, target_pstate, false); + target_pstate = intel_cpufreq_update_pstate(policy, target_pstate, false); freqs.new = target_pstate * cpu->pstate.scaling; @@ -2628,7 +2640,7 @@ static unsigned int intel_cpufreq_fast_s target_pstate = DIV_ROUND_UP(target_freq, cpu->pstate.scaling); - target_pstate = intel_cpufreq_update_pstate(cpu, target_pstate, true); + target_pstate = intel_cpufreq_update_pstate(policy, target_pstate, true); return target_pstate * cpu->pstate.scaling; }