Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2321096pxa; Mon, 24 Aug 2020 10:50:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkFSEiXTAJsuSJwTdKGdtZe4Z53Au/zXziGxazBD1iD8BYt+J7UpKFbLgLS7Gu6q2H+Nsa X-Received: by 2002:a05:6402:3070:: with SMTP id bs16mr6426721edb.269.1598291440216; Mon, 24 Aug 2020 10:50:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598291440; cv=none; d=google.com; s=arc-20160816; b=oFsnoreS688/CkD53dPQhAcJ+LxnBRhbtgDyfHpm10Y+yPLT+yZjj2NKM04r4NzMJc 0JH9dUA89ERmyvlQRJJdEwWbMW2CSbdPIfDg3I/SFveLRF3Y5xcTSA3P103LqknAENwW 0HAmmcY7dUXwO7K+1yIRhXT3jIP4PXY82tGQFQKLJRcX7dMdd4HaZ9XKFQgEAVAIGcAV W7ph/wBgiVvFlmBy6se/CKIl69HFNvZPxEVzp40qJn+TpiVET1p2ytGh0ycPArBJRoOs DJtB0Xx5PUzjgxnquzMRc+1dN0IO9V8y8gpxTqIYutbFVjxymU9750Ja8xZqyuyXkr9k gxUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=DGuGGgc3F/PzqQNRQptAnjo31p7qLgGa99VwfdoqiWM=; b=zJ8pVHJcAqgAib3pNoIqoAiEBHroEoIXLmFrbOGWVU9LkDHUT00HjlP+J+c0g3lw22 ijpJ8LLLj7cqLI78PxU5jF6aof6ti1NNeSFFLG4zuTCa2jzPiyAm6+cBBgPyzTWU9QLW QYovlsI2IW1TlNXyO5E5tdsMPOrjbXS5gY9ozpcsy4Tv7v23FO0owXSmxkR4zTHmjIsd 9UsX6EnEQYr9NhfCzCGt8fMYwerlB4SdgWKlo1w+Edorsw1j69hlJmNSmkgnqU6ntvs6 LiJ2upRb9PEWk9QzQ7h4ybx/mOJuGlDVoIh1DMCP9FENEqNDFUsjf6YOVbFAB1rEfowj x9eA== 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 s15si7033864ejc.7.2020.08.24.10.50.17; Mon, 24 Aug 2020 10:50:40 -0700 (PDT) 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 S1727124AbgHXRsY (ORCPT + 99 others); Mon, 24 Aug 2020 13:48:24 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:62272 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726413AbgHXRsP (ORCPT ); Mon, 24 Aug 2020 13:48:15 -0400 Received: from 89-64-88-199.dynamic.chello.pl (89.64.88.199) (HELO kreacher.localnet) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.459) id aa5e0bdb7cd08725; Mon, 24 Aug 2020 19:48:13 +0200 From: "Rafael J. Wysocki" To: Linux PM Cc: Srinivas Pandruvada , LKML , Doug Smythies Subject: [PATCH v2 2/5] cpufreq: intel_pstate: Always return last EPP value from sysfs Date: Mon, 24 Aug 2020 19:42:20 +0200 Message-ID: <2064342.aRc67yb0pC@kreacher> In-Reply-To: <4169555.5IIHXK4Dsd@kreacher> References: <4169555.5IIHXK4Dsd@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Rafael J. Wysocki" Make the energy_performance_preference policy attribute in sysfs always return the last EPP value written to it instead of the one currently in the HWP Request MSR to avoid possible confusion when the performance scaling algorithm is used in the active mode with HWP enabled (in which case the EPP is forced to 0 regardless of what value it has been set to via sysfs). Signed-off-by: Rafael J. Wysocki --- -> v2: No changes. --- drivers/cpufreq/intel_pstate.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index bcda1e700a73..3d18934fa975 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -606,13 +606,10 @@ static const unsigned int epp_values[] = { static int intel_pstate_get_energy_pref_index(struct cpudata *cpu_data, int *raw_epp) { - s16 epp; + s16 epp = cpu_data->epp_cached; int index = -EINVAL; *raw_epp = 0; - epp = intel_pstate_get_epp(cpu_data, 0); - if (epp < 0) - return epp; if (boot_cpu_has(X86_FEATURE_HWP_EPP)) { if (epp == HWP_EPP_PERFORMANCE) @@ -644,6 +641,8 @@ static int intel_pstate_get_energy_pref_index(struct cpudata *cpu_data, int *raw static int intel_pstate_set_epp(struct cpudata *cpu, u32 epp) { + int ret; + /* * Use the cached HWP Request MSR value, because in the active mode the * register itself may be updated by intel_pstate_hwp_boost_up() or @@ -659,7 +658,11 @@ static int intel_pstate_set_epp(struct cpudata *cpu, u32 epp) * function, so it cannot run in parallel with the update below. */ WRITE_ONCE(cpu->hwp_req_cached, value); - return wrmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, value); + ret = wrmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, value); + if (!ret) + cpu->epp_cached = epp; + + return ret; } static int intel_pstate_set_energy_pref_index(struct cpudata *cpu_data, @@ -762,10 +765,8 @@ static ssize_t store_energy_performance_preference( cpufreq_stop_governor(policy); ret = intel_pstate_set_epp(cpu, epp); err = cpufreq_start_governor(policy); - if (!ret) { - cpu->epp_cached = epp; + if (!ret) ret = err; - } } } @@ -2378,6 +2379,13 @@ static int intel_pstate_cpu_init(struct cpufreq_policy *policy) */ policy->policy = CPUFREQ_POLICY_POWERSAVE; + + if (hwp_active) { + struct cpudata *cpu = all_cpu_data[policy->cpu]; + + cpu->epp_cached = intel_pstate_get_epp(cpu, 0); + } + return 0; } @@ -2585,7 +2593,7 @@ static int intel_cpufreq_cpu_init(struct cpufreq_policy *policy) policy->transition_delay_us = INTEL_CPUFREQ_TRANSITION_DELAY_HWP; rdmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, &value); WRITE_ONCE(cpu->hwp_req_cached, value); - cpu->epp_cached = (value & GENMASK_ULL(31, 24)) >> 24; + cpu->epp_cached = intel_pstate_get_epp(cpu, value); } else { turbo_max = cpu->pstate.turbo_pstate; policy->transition_delay_us = INTEL_CPUFREQ_TRANSITION_DELAY; -- 2.26.2