From patchwork Tue Oct 6 21:49:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prarit Bhargava X-Patchwork-Id: 7340191 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 451B49F1B9 for ; Tue, 6 Oct 2015 21:49:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4A0CF20630 for ; Tue, 6 Oct 2015 21:49:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BEA66202A1 for ; Tue, 6 Oct 2015 21:49:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752577AbbJFVtL (ORCPT ); Tue, 6 Oct 2015 17:49:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38606 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752663AbbJFVtL (ORCPT ); Tue, 6 Oct 2015 17:49:11 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 8DB9BC0B7700; Tue, 6 Oct 2015 21:49:10 +0000 (UTC) Received: from praritdesktop.bos.redhat.com (prarit-guest.khw.lab.eng.bos.redhat.com [10.16.186.145]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t96Ln9HP004926; Tue, 6 Oct 2015 17:49:09 -0400 From: Prarit Bhargava To: linux-kernel@vger.kernel.org Cc: Prarit Bhargava , Kristen Carlson Accardi , "Rafael J. Wysocki" , Viresh Kumar , linux-pm@vger.kernel.org Subject: [PATCH] cpufreq, intel_pstate, set max_sysfs_pct and min_sysfs_pct on governor switch Date: Tue, 6 Oct 2015 17:49:07 -0400 Message-Id: <1444168147-17812-1-git-send-email-prarit@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Intel CPUs will not enter higher p-states when after switching from the performance governor to the powersave governor, until /sys/devices/system/cpu/intel_pstate/min_perf_pct is set to a low value. This differs from previous behaviour in which a switch to the powersave governor would result in a low default value for min_perf_pct. The behavior of the powersave governor changed after commit a04759924e25 ("[cpufreq] intel_pstate: honor user space min_perf_pct override on resume"). The commit introduced tracking of performance percentage changes via sysfs in order to restore userspace changes during suspend/resume. The problem occurs because the global values of the newly introduced max_sysfs_pct and min_sysfs_pct are not reset on a governor change and this causes the new governor to inherit the previous governor's settings. This patch sets max_sysfs_pct to 100 and min_sysfs_pct to 0 on a governor change which fixes the problem with governor switching. These changes also make the initial calculations for max_perf_pct and min_perf_pct slightly simpler. Before patch: [root@intel-skylake-y-01 power]# cpupower frequency-set -g performance [root@intel-skylake-y-01 power]# cat /sys/devices/system/cpu/intel_pstate/min_perf_pct 100 [root@intel-skylake-y-01 power]# cat /sys/devices/system/cpu/intel_pstate/max_perf_pct 100 [root@intel-skylake-y-01 power]# cpupower frequency-set -g powersave [root@intel-skylake-y-01 power]# cat /sys/devices/system/cpu/intel_pstate/min_perf_pct 100 [root@intel-skylake-y-01 power]# cat /sys/devices/system/cpu/intel_pstate/max_perf_pct 100 After patch: [root@intel-skylake-y-01 power]# cpupower frequency-set -g performance [root@intel-skylake-y-01 power]# cat /sys/devices/system/cpu/intel_pstate/min_perf_pct 100 [root@intel-skylake-y-01 power]# cat /sys/devices/system/cpu/intel_pstate/max_perf_pct 100 [root@intel-skylake-y-01 power]# cpupower frequency-set -g powersave [root@intel-skylake-y-01 power]# cat /sys/devices/system/cpu/intel_pstate/min_perf_pct 14 [root@intel-skylake-y-01 power]# cat /sys/devices/system/cpu/intel_pstate/max_perf_pct 100 Also note that I have tested suspend/resume (using CONFIG_PM_DEBUG): [root@intel-skylake-y-01 power]# echo 50 > /sys/devices/system/cpu/intel_pstate/min_perf_pct [root@intel-skylake-y-01 power]# cat /sys/devices/system/cpu/intel_pstate/*_perf_pct 100 50 [root@intel-skylake-y-01 power]# echo devices > /sys/power/pm_test [root@intel-skylake-y-01 power]# echo platform > /sys/power/disk [root@intel-skylake-y-01 power]# echo disk > /sys/power/state [root@intel-skylake-y-01 power]# cat /sys/devices/system/cpu/intel_pstate/*_perf_pct 100 50 Fixes: a04759924e25 ("[cpufreq] intel_pstate: honor user space min_perf_pct override on resume") Cc: Kristen Carlson Accardi Cc: "Rafael J. Wysocki" Cc: Viresh Kumar Cc: linux-pm@vger.kernel.org Signed-off-by: Prarit Bhargava --- drivers/cpufreq/intel_pstate.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index 3af9dd7..bb24458 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -986,6 +986,9 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy) if (!policy->cpuinfo.max_freq) return -ENODEV; + limits.min_sysfs_pct = 0; + limits.max_sysfs_pct = 100; + if (policy->policy == CPUFREQ_POLICY_PERFORMANCE && policy->max >= policy->cpuinfo.max_freq) { limits.min_policy_pct = 100; @@ -1004,9 +1007,9 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy) limits.max_policy_pct = clamp_t(int, limits.max_policy_pct, 0 , 100); /* Normalize user input to [min_policy_pct, max_policy_pct] */ - limits.min_perf_pct = max(limits.min_policy_pct, limits.min_sysfs_pct); + limits.min_perf_pct = limits.min_policy_pct; limits.min_perf_pct = min(limits.max_policy_pct, limits.min_perf_pct); - limits.max_perf_pct = min(limits.max_policy_pct, limits.max_sysfs_pct); + limits.max_perf_pct = limits.max_sysfs_pct; limits.max_perf_pct = max(limits.min_policy_pct, limits.max_perf_pct); /* Make sure min_perf_pct <= max_perf_pct */