Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1275163pxu; Thu, 17 Dec 2020 06:27:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJy6HihFj9nqIDuUxVP06zchku8E5v4EQ9C52E4j7vPe10NklzOR/NWUi8jqsSorwGxfx8wW X-Received: by 2002:a17:906:31cb:: with SMTP id f11mr35875317ejf.142.1608215224631; Thu, 17 Dec 2020 06:27:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608215224; cv=none; d=google.com; s=arc-20160816; b=OoPtSNe6pDBqyIMqOuV+w+Je4fqJpqCYAqded7PRTEsFWI3FDM4Ea5YBoO1PD2ISBM 6uTUaEnvNmzDiI+nAC5SYtC4cmtxjLkTKotqS0FoXRilg1WQ+ZuIWPzXjg9nNdNU6NqL uEANLabI7UJf2ZhAMb8xzE6Jc6NTmSD2/4+zGHc1rizih2avprIQjltwiJbvvzngAbDK kX2+8LepDCvoUTx7U0Fw1pDakOpBh9Fh1Q+uKS4LTrhtY3tDL1gE8U7ppvPMHJGcj3Ek c9Ek3HTDl1YZ5iMVnjQFei8ZEqrK4KzFsoBkXAuPl923BD4/l+Gbvmp6FFqQfVRKcFqy baXw== 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:date:cc:to:from:subject :message-id:ironport-sdr:ironport-sdr; bh=+H4eGkrKidVri0946c1HnEa129yDerMae6yUZPVxiSI=; b=vEqc8KGZS979mkZlLnqrn8066H7IV8V0ycftsX5r2uz90j3Wbahuaxz+h6OhJAm98/ dbZLsxQeN/BXm8ux7rCPa+b2H1A9SHiJyCFY9ljjxTWg0uWKoESp/O4h83k04jkwDrIb 1w3PzLltplWaeYJEhNITupeXYz2okBThmI3oQ+IUDQRbPdQAkGdajsvGgSiCT9U2eXDI HgOlH3S2x6d8NF06XuiTMKQra+ogkCSUdF3zvFvFNUXFZkZCmK0NRM1KaMYwbwFNI0MO lNfjGffcIWSQK1xm2rgUi0NZD74AHeFqJ/PC01Xs0uUTSCNEOzXt4SwjCe//hqCDEAd7 dNWw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id do13si2767773ejc.286.2020.12.17.06.26.40; Thu, 17 Dec 2020 06:27:04 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728655AbgLQOZh (ORCPT + 99 others); Thu, 17 Dec 2020 09:25:37 -0500 Received: from mga17.intel.com ([192.55.52.151]:31353 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728110AbgLQOZg (ORCPT ); Thu, 17 Dec 2020 09:25:36 -0500 IronPort-SDR: pLgXWNU8sob6Bu9I40OSV+D5Y2opwtfItvnA08aAWDD8VCZtAzqlDE0BruvjaOkituHtEyhEkg uwts9Y+JSS4A== X-IronPort-AV: E=McAfee;i="6000,8403,9837"; a="155063944" X-IronPort-AV: E=Sophos;i="5.78,428,1599548400"; d="scan'208";a="155063944" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Dec 2020 06:23:50 -0800 IronPort-SDR: 32pP68rHrkQgPMzKAIbwI45wjRbWMFwWiyx40hUZFifmb1rDeszsIKfGD2Ia5IJqKyndid8nJ9 bpih4KWj6o6Q== X-IronPort-AV: E=Sophos;i="5.78,428,1599548400"; d="scan'208";a="385517924" Received: from apstasen-mobl.amr.corp.intel.com ([10.212.63.173]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Dec 2020 06:23:47 -0800 Message-ID: <93d4eebb5121ad0497af555c55a6ad74b8a06e64.camel@linux.intel.com> Subject: Re: [PATCH] cpufreq: intel_pstate: Use the latest guaranteed freq during verify From: Srinivas Pandruvada To: "Rafael J. Wysocki" Cc: Len Brown , "Rafael J. Wysocki" , Viresh Kumar , Linux PM , Linux Kernel Mailing List Date: Thu, 17 Dec 2020 06:23:44 -0800 In-Reply-To: References: <20201217104215.2544837-1-srinivas.pandruvada@linux.intel.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.38.2 (3.38.2-1.fc33) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2020-12-17 at 06:19 -0800, Srinivas Pandruvada wrote: > On Thu, 2020-12-17 at 14:58 +0100, Rafael J. Wysocki wrote: > > On Thu, Dec 17, 2020 at 11:44 AM Srinivas Pandruvada > > wrote: > > > > > > This change tries to address an issue, when BIOS disabled turbo > > > but HWP_CAP guaranteed is changed later and user space wants to > > > take > > > advantage of this increased guaranteed performance. > > > > > > The HWP_CAP.GUARANTEED value is not a static value. It can be > > > changed > > > by some out of band agent or during Intel Speed Select > > > performance > > > level change. The HWP_CAP.MAX still shows max possible > > > performance > > > when > > > BIOS disabled turbo. So guaranteed can still change as long as > > > this > > > is > > > same or below HWP_CAP.MAX. > > > > > > When guaranteed is changed, the sysfs base_frequency attributes > > > shows > > > the latest guaranteed frequency. This attribute can be used by > > > user > > > space software to update scaling min/max frequency. > > > > > > Currently the setpolicy callback already uses the latest HWP_CAP > > > values when setting HWP_REQ. But the verify callback will still > > > restrict > > > the user settings to the to old guaranteed value. So if the > > > guaranteed > > > is increased, user space can't take advantage of it. > > > > > > To solve this similar to setpolicy callback, read the latest > > > HWP_CAP > > > values and use it to restrict the maximum setting. This is done > > > by > > > calling intel_pstate_get_hwp_max(), which already accounts for > > > user > > > and BIOS turbo disable to get the current max performance. > > > > > > This issue is side effect of fixing the issue of scaling > > > frequency > > > limits by the > > >  'commit eacc9c5a927e ("cpufreq: intel_pstate: > > >  Fix intel_pstate_get_hwp_max() for turbo disabled")' > > > The fix resulted in correct setting of reduced scaling > > > frequencies, > > > but this resulted in capping HWP.REQ to HWP_CAP.GUARANTEED in > > > this > > > case. > > > > > > Cc: 5.8+ # 5.8+ > > > Signed-off-by: Srinivas Pandruvada < > > > srinivas.pandruvada@linux.intel.com> > > > --- > > >  drivers/cpufreq/intel_pstate.c | 6 ++++++ > > >  1 file changed, 6 insertions(+) > > > > > > diff --git a/drivers/cpufreq/intel_pstate.c > > > b/drivers/cpufreq/intel_pstate.c > > > index 2a4db856222f..7081d1edb22b 100644 > > > --- a/drivers/cpufreq/intel_pstate.c > > > +++ b/drivers/cpufreq/intel_pstate.c > > > @@ -2199,6 +2199,12 @@ static void > > > intel_pstate_clear_update_util_hook(unsigned int cpu) > > > > > >  static int intel_pstate_get_max_freq(struct cpudata *cpu) > > >  { > > > +       if (hwp_active) { > > > +               int turbo_max, max_state; > > > + > > > +               intel_pstate_get_hwp_max(cpu->cpu, &turbo_max, > > > &max_state); > > > > This would cause intel_pstate_get_hwp_max() to be called twice in > > intel_pstate_update_perf_limits() which is not perfect. > > We can optimize by using cached value. > > > diff --git a/drivers/cpufreq/intel_pstate.c > b/drivers/cpufreq/intel_pstate.c > index 7081d1edb22b..d345c9ef240c 100644 > --- a/drivers/cpufreq/intel_pstate.c > +++ b/drivers/cpufreq/intel_pstate.c > @@ -2223,7 +2223,11 @@ static void > intel_pstate_update_perf_limits(struct cpudata *cpu, >          * rather than pure ratios. >          */ >         if (hwp_active) { > -               intel_pstate_get_hwp_max(cpu->cpu, &turbo_max, > &max_state); > +               if (global.no_turbo || global.turbo_disabled) > +                       max_state = HWP_GUARANTEED_PERF(cpu- > > hwp_cap_cached); > +               else > +                       max_state = HWP_HIGHEST_PERF(cpu- > > hwp_cap_cached); Can use ternary operator instead of if..else. to further simplify. > +               turbo_max = HWP_HIGHEST_PERF(cpu->hwp_cached); >         } else { >                 max_state = global.no_turbo || global.turbo_disabled > ? >                         cpu->pstate.max_pstate : cpu- > > pstate.turbo_pstate; > > > Thanks, > Srinivas > > > > > > > +               return max_state * cpu->pstate.scaling; > > > +       } > > >         return global.turbo_disabled || global.no_turbo ? > > >                         cpu->pstate.max_freq : cpu- > > > > pstate.turbo_freq; > > >  } > > > -- >