From patchwork Sat Nov 12 00:11:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: srinivas pandruvada X-Patchwork-Id: 9423807 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6F5F060484 for ; Sat, 12 Nov 2016 00:11:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5FB2929BED for ; Sat, 12 Nov 2016 00:11:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5334A29BEF; Sat, 12 Nov 2016 00:11:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9416429BED for ; Sat, 12 Nov 2016 00:11:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934727AbcKLALj (ORCPT ); Fri, 11 Nov 2016 19:11:39 -0500 Received: from mga09.intel.com ([134.134.136.24]:53077 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934500AbcKLALj (ORCPT ); Fri, 11 Nov 2016 19:11:39 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP; 11 Nov 2016 16:11:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,475,1473145200"; d="scan'208";a="30403204" Received: from spandruv-desk.jf.intel.com ([10.54.75.13]) by orsmga005.jf.intel.com with ESMTP; 11 Nov 2016 16:11:37 -0800 From: Srinivas Pandruvada To: lenb@kernel.org, rjw@rjwysocki.net Cc: linux-pm@vger.kernel.org, Srinivas Pandruvada Subject: [PATCH] cpufreq: intel_pstate: Synchronize sysfs limits Date: Fri, 11 Nov 2016 16:11:35 -0800 Message-Id: <1478909495-57026-1-git-send-email-srinivas.pandruvada@linux.intel.com> X-Mailer: git-send-email 2.7.4 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When user sets some limits using Intel P-State sysfs, they are not reflected in the cpufreq policy scaling_max_freq and scaling_min_freq. This change updates the cpufreq policy of each CPU, when user sets limits via Intel P-State sysfs. For example: root@stn1]# cat /sys/devices/system/cpu/intel_pstate/max_perf_pct 100 root@stn1]# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq 2800000 Now limit the max performance root@stn1]# echo 80 > /sys/devices/system/cpu/intel_pstate/max_perf_pct This change now is also changed the scaling_max_freq root@stn1]# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq 2240000 But there is a side effect of this change for the users who use both methods to limit interchangeably. For example if user sets limit via Intel P-State sysfs to a lower maximum value and then sets a higher maximum value via cpufreq sysfs, then the cpufreq display will show a lower maximum value set by the Intel P-State sysfs. But there is no change in the effective P-State used, as the driver will always use the most constrained limit. Signed-off-by: Srinivas Pandruvada --- drivers/cpufreq/intel_pstate.c | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index 8f683e2..d8315e3 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -805,6 +805,18 @@ static ssize_t store_no_turbo(struct kobject *a, struct attribute *b, return count; } +static void update_cpufreq_policies(void) +{ + int cpu; + + get_online_cpus(); + for_each_online_cpu(cpu) { + if (all_cpu_data[cpu]) + cpufreq_update_policy(cpu); + } + put_online_cpus(); +} + static ssize_t store_max_perf_pct(struct kobject *a, struct attribute *b, const char *buf, size_t count) { @@ -830,6 +842,9 @@ static ssize_t store_max_perf_pct(struct kobject *a, struct attribute *b, if (hwp_active) intel_pstate_hwp_set_online_cpus(); + + update_cpufreq_policies(); + return count; } @@ -858,6 +873,9 @@ static ssize_t store_min_perf_pct(struct kobject *a, struct attribute *b, if (hwp_active) intel_pstate_hwp_set_online_cpus(); + + update_cpufreq_policies(); + return count; } @@ -1802,6 +1820,28 @@ static struct cpufreq_driver intel_pstate_driver = { .name = "intel_pstate", }; +static int cpufreq_intel_pstate_notifier(struct notifier_block *nb, + unsigned long event, void *data) +{ + struct cpufreq_policy *policy = data; + int max_freq, min_freq; + + /* When per-CPU limits are used, sysfs limits can't be set */ + if (per_cpu_limits) + return NOTIFY_OK; + + max_freq = policy->cpuinfo.max_freq * limits->max_sysfs_pct / 100; + min_freq = policy->cpuinfo.max_freq * limits->min_sysfs_pct / 100; + + cpufreq_verify_within_limits(policy, min_freq, max_freq); + + return NOTIFY_OK; +} + +static struct notifier_block intel_pstate_cpufreq_notifier_block = { + .notifier_call = cpufreq_intel_pstate_notifier, +}; + static int no_load __initdata; static int no_hwp __initdata; static int hwp_only __initdata; @@ -2032,6 +2072,9 @@ static int __init intel_pstate_init(void) if (hwp_active) pr_info("HWP enabled\n"); + cpufreq_register_notifier(&intel_pstate_cpufreq_notifier_block, + CPUFREQ_POLICY_NOTIFIER); + return rc; out: get_online_cpus();