Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp1117981ybg; Mon, 27 Jul 2020 08:21:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz42rvfT+HiP3AVd9s9hlxZeYgYmaNtxBZ6fgXYBck0UsQVFC+iKIgIlvMnC5EKu0iLnX+n X-Received: by 2002:a17:906:dd5:: with SMTP id p21mr11720743eji.416.1595863264239; Mon, 27 Jul 2020 08:21:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595863264; cv=none; d=google.com; s=arc-20160816; b=XEiQda+2gP6YCyWcXznnO2/6PSfkpDfHqNe3bSI7cN7TJ/IK5fC0o4XgCGu8QE1H/Y XVG+kV9MiDlbWNgKZ9K+G8tolbX/x7wLKDIndePtYaxfbN8n3JgBhnRX6U6M0vaL169F KgnNZljISALj1RSqlbq22RWNzS6gPqTlt5FDVeNkqFFQWUfQ2zWte2Cl10yk6EOc5GQ3 iBw29/DhhyANg/GVUZyJMrXGGrw6CsAUwRM+GOlWavLpWBIYU0Cz2Wx1hNXgc52ubnTo KVIvIPFCslnI+/aVvWWEmrKKtltBdC3/9Z7V3ae5U6eeDBlgi7VF4nNTwUX/8tUR4KcB XTfQ== 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=niHK3PM3LBBc1sin3+JZweQ1uxyMcRQvkp2Lgeb6e7I=; b=ccTlw865f9Ghxe+WQGLl9QapA3w7RfGVGOhSGDQOJ0twXi7ySys4SaQsKgJjEDmXwo gM6k6w7M3Iqofgg24rP8H/VXt8wrKdZbhGP984Efw+ybShRrCHz06imUvr4A7GylhiIr o/NURZdYPUDtm1YZb7zOncxtiGDuSHZrWvRwj9VJJYLxr3uK4K0e5ISQTm/EeU/IePPz 9XLoCb6iODqdS6S004dXaJ4hMuC8ClOsBQ3Zy1o8k3SewVVkpHd5/Q6y/Hr0XvDLR7HM u9lqU4Npr0YvuLqfaNsrw0mZBhvR0KNiCxSefDFHoo/mXnw2no8rgxH1LbcORjSTMWs5 M5yQ== 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 m23si5626014eji.400.2020.07.27.08.20.42; Mon, 27 Jul 2020 08:21:04 -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 S1728872AbgG0PRp (ORCPT + 99 others); Mon, 27 Jul 2020 11:17:45 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:61416 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728824AbgG0PRo (ORCPT ); Mon, 27 Jul 2020 11:17:44 -0400 Received: from 89-64-87-33.dynamic.chello.pl (89.64.87.33) (HELO kreacher.localnet) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.415) id 2e44a79a69b3ba76; Mon, 27 Jul 2020 17:17:42 +0200 From: "Rafael J. Wysocki" To: Linux PM Cc: Linux Documentation , LKML , Peter Zijlstra , Srinivas Pandruvada , Giovanni Gherdovich , Doug Smythies , Francisco Jerez Subject: [PATCH v3 1/2] cpufreq: intel_pstate: Rearrange the storing of new EPP values Date: Mon, 27 Jul 2020 17:15:43 +0200 Message-ID: <1874278.Dp5iLYrgV3@kreacher> In-Reply-To: <1709487.Bxjb1zNRZM@kreacher> References: <4981405.3kqTVLv5tO@kreacher> <1709487.Bxjb1zNRZM@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 Move the locking away from intel_pstate_set_energy_pref_index() into its only caller and drop the (now redundant) return_pref label from it. Also move the "raw" EPP value check into the caller of that function, so as to do it before acquiring the mutex, and reduce code duplication related to the "raw" EPP values processing somewhat. No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- v2 -> v3: * Fix error handling in intel_pstate_set_energy_pref_index() and rebase. --- drivers/cpufreq/intel_pstate.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) Index: linux-pm/drivers/cpufreq/intel_pstate.c =================================================================== --- linux-pm.orig/drivers/cpufreq/intel_pstate.c +++ linux-pm/drivers/cpufreq/intel_pstate.c @@ -649,28 +649,18 @@ static int intel_pstate_set_energy_pref_ if (!pref_index) epp = cpu_data->epp_default; - mutex_lock(&intel_pstate_limits_lock); - if (boot_cpu_has(X86_FEATURE_HWP_EPP)) { u64 value; ret = rdmsrl_on_cpu(cpu_data->cpu, MSR_HWP_REQUEST, &value); if (ret) - goto return_pref; + return ret; value &= ~GENMASK_ULL(31, 24); - if (use_raw) { - if (raw_epp > 255) { - ret = -EINVAL; - goto return_pref; - } - value |= (u64)raw_epp << 24; - ret = wrmsrl_on_cpu(cpu_data->cpu, MSR_HWP_REQUEST, value); - goto return_pref; - } - - if (epp == -EINVAL) + if (use_raw) + epp = raw_epp; + else if (epp == -EINVAL) epp = epp_values[pref_index - 1]; value |= (u64)epp << 24; @@ -680,8 +670,6 @@ static int intel_pstate_set_energy_pref_ epp = (pref_index - 1) << 2; ret = intel_pstate_set_epb(cpu_data->cpu, epp); } -return_pref: - mutex_unlock(&intel_pstate_limits_lock); return ret; } @@ -708,8 +696,8 @@ static ssize_t store_energy_performance_ struct cpudata *cpu_data = all_cpu_data[policy->cpu]; char str_preference[21]; bool raw = false; + ssize_t ret; u32 epp = 0; - int ret; ret = sscanf(buf, "%20s", str_preference); if (ret != 1) @@ -724,14 +712,21 @@ static ssize_t store_energy_performance_ if (ret) return ret; + if (epp > 255) + return -EINVAL; + raw = true; } + mutex_lock(&intel_pstate_limits_lock); + ret = intel_pstate_set_energy_pref_index(cpu_data, ret, raw, epp); - if (ret) - return ret; + if (!ret) + ret = count; - return count; + mutex_unlock(&intel_pstate_limits_lock); + + return ret; } static ssize_t show_energy_performance_preference(