Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1500056pxa; Thu, 20 Aug 2020 12:57:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzfEu8c66i8FZSWQ7HJnfLaJLM92xtkxCF1TalR6c4A2jBjGwADvJY4kA8tObcLqwpJLQk X-Received: by 2002:aa7:d304:: with SMTP id p4mr159483edq.267.1597953440346; Thu, 20 Aug 2020 12:57:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597953440; cv=none; d=google.com; s=arc-20160816; b=I4mO61bi6COBtuBAC6HJW7Krw7Lu85ihnwIKNgvc3fEh48Adz+Zs6H+9fhACB7LADi YAs7nR9l4JR80T2HDZ+TMTSyJmIgB8jKzwrtopnENyeObn6SsQKMBaEV9NmO7cjhKYcL 7oRTEJDLNadrvlbib6swmLiT63PdfdzFxYtzkkUSiL1tUTH6kenjI8JXYM5UVrdR9N4f VHtdSY0yMSg+OM4nLIzHCfr+Kosc88C8j3Nkc8Lhzaq+z/MO/yTVOczhPDJXDgOlBFOq Tcz+MV+5uUJvZMlGB8gH7ckz1rEWxyGDHRzUwD51Gwn7zhDpLpZh+xUWUjZ9GxwquDVT xz8g== 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=JVCnDBncj7kKIuL6a1qp8A5nFmb9AROypK/8gbwdzNU=; b=Q951Q/L7yIKsHDJsmvzxFglDGOBiG7io8/L/BrwVzE/Vvm0FjTnPTQM6FVpY5AFD72 D+i2YPNc8ezFSU8jzQ37hCpJqgmUo7CYODFvLu+rHWwvs0EiqXOWR21wVYtmGrJq9h+n jcmlr+GQ+tsRhMqJ1us6OjYydETOvLwG1qnEctFmmlkEQJtC/MAqVWtE5LflHX6fARZ/ /Hxr0M6DUmw5LxVg51xVeCxPb3WoYEwhmlOqUyOEs4cr1bL7vF4L+oEg9YhlQlZywy0y 4HYpzoLcCO8GVzVQpIqTezYn7hV2hJmauyqXKaugmtZJDg/3ikssDcMnROeJ3PjIFHRD VJbw== 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 t22si1926232ejy.466.2020.08.20.12.56.57; Thu, 20 Aug 2020 12:57:20 -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 S1730030AbgHTQjY (ORCPT + 99 others); Thu, 20 Aug 2020 12:39:24 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:47954 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728979AbgHTQjL (ORCPT ); Thu, 20 Aug 2020 12:39:11 -0400 Received: from 89-64-87-57.dynamic.chello.pl (89.64.87.57) (HELO kreacher.localnet) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.459) id 7dcc2d20ba34ff81; Thu, 20 Aug 2020 18:39:08 +0200 From: "Rafael J. Wysocki" To: Linux PM Cc: Srinivas Pandruvada , LKML , Doug Smythies Subject: [PATCH 2/4] cpufreq: intel_pstate: Always return last EPP value from sysfs Date: Thu, 20 Aug 2020 18:37:11 +0200 Message-ID: <2549178.0mQMFifXHc@kreacher> In-Reply-To: <2283366.Lr8yYYnyev@kreacher> References: <2283366.Lr8yYYnyev@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 --- 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