From patchwork Mon Oct 13 15:37:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: dirk.brandewie@gmail.com X-Patchwork-Id: 5076911 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 319C09F387 for ; Mon, 13 Oct 2014 15:38:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 35ECB201BC for ; Mon, 13 Oct 2014 15:38:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BAB68201F5 for ; Mon, 13 Oct 2014 15:38:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754140AbaJMPh5 (ORCPT ); Mon, 13 Oct 2014 11:37:57 -0400 Received: from mail-pa0-f45.google.com ([209.85.220.45]:62869 "EHLO mail-pa0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753103AbaJMPhz (ORCPT ); Mon, 13 Oct 2014 11:37:55 -0400 Received: by mail-pa0-f45.google.com with SMTP id rd3so6069655pab.32 for ; Mon, 13 Oct 2014 08:37:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0g+mM3OJONZmDLfflI/hfFftKVWAYMom/pr4AHY0Mo8=; b=xPVs6iVaUx/1ojI7C7wAZPBzdAbg4vDG/flGbAeBI7PDQpbSsVUX0U5QqVwr0j9MxF W5SyqFLunZ2S8btEW5Ww7DecA2UpNzXMJI79IFWV1nayB8Sdzk8u3EfBsFT5t9XvMZdu 2pv/3EH0QsTRo+NQKeXYaOkuaf2RWcuUFZvoljA+0fnzRiKWfptFqCUR4SnN3bCQodLc F39euw1eN98OsS+xGZ2Ar6xVho9ugmaY0j1WC3sSJE/5LpXFZp7nLSOds9gUtoIgiaOC sqLYcgZYA8K3p4iYpAJBWO5ZJ8K2wrA7Q4Jh+SRqoHB51VXd+D5/CSdJAhPxd7VfcycY 3OhQ== X-Received: by 10.66.187.175 with SMTP id ft15mr8577041pac.31.1413214674837; Mon, 13 Oct 2014 08:37:54 -0700 (PDT) Received: from echolake.localdomain (static-50-43-32-60.bvtn.or.frontiernet.net. [50.43.32.60]) by mx.google.com with ESMTPSA id dg5sm10340216pdb.54.2014.10.13.08.37.53 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Oct 2014 08:37:53 -0700 (PDT) From: dirk.brandewie@gmail.com X-Google-Original-From: dirk.j.brandewie@intel.com To: linux-pm@vger.kernel.org Cc: rjw@rjwysocki.net, dirk.brandewie@gmail.com, Gabriele Mazzotta , stable@vger.kernel.org, Dirk Brandewie Subject: [PATCH 2/5] cpufreq: intel_pstate: Reflect current no_turbo state correctly Date: Mon, 13 Oct 2014 08:37:41 -0700 Message-Id: <1413214664-17687-2-git-send-email-dirk.j.brandewie@intel.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1413214664-17687-1-git-send-email-dirk.j.brandewie@intel.com> References: <1413214664-17687-1-git-send-email-dirk.j.brandewie@intel.com> 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.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, 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 From: Gabriele Mazzotta Some BIOSes modify the state of MSR_IA32_MISC_ENABLE_TURBO_DISABLE based on the current power source for the system battery AC vs battery. Reflect the correct current state and ability to modify the no_turbo sysfs file based on current state of MSR_IA32_MISC_ENABLE_TURBO_DISABLE. References: https://bugzilla.kernel.org/show_bug.cgi?id=83151 Cc: stable@vger.kernel.org Signed-off-by: Gabriele Mazzotta Signed-off-by: Dirk Brandewie --- drivers/cpufreq/intel_pstate.c | 48 +++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index 0668b38..a85b262 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -138,6 +138,7 @@ struct perf_limits { static struct perf_limits limits = { .no_turbo = 0, + .turbo_disabled = 0, .max_perf_pct = 100, .max_perf = int_tofp(1), .min_perf_pct = 0, @@ -218,6 +219,18 @@ static inline void intel_pstate_reset_all_pid(void) } } +static inline void update_turbo_state(void) +{ + u64 misc_en; + struct cpudata *cpu; + + cpu = all_cpu_data[0]; + rdmsrl(MSR_IA32_MISC_ENABLE, misc_en); + limits.turbo_disabled = + (misc_en & MSR_IA32_MISC_ENABLE_TURBO_DISABLE || + cpu->pstate.max_pstate == cpu->pstate.turbo_pstate); +} + /************************** debugfs begin ************************/ static int pid_param_set(void *data, u64 val) { @@ -274,6 +287,20 @@ static void __init intel_pstate_debug_expose_params(void) return sprintf(buf, "%u\n", limits.object); \ } +static ssize_t show_no_turbo(struct kobject *kobj, + struct attribute *attr, char *buf) +{ + ssize_t ret; + + update_turbo_state(); + if (limits.turbo_disabled) + ret = sprintf(buf, "%u\n", limits.turbo_disabled); + else + ret = sprintf(buf, "%u\n", limits.no_turbo); + + return ret; +} + static ssize_t store_no_turbo(struct kobject *a, struct attribute *b, const char *buf, size_t count) { @@ -283,11 +310,14 @@ static ssize_t store_no_turbo(struct kobject *a, struct attribute *b, ret = sscanf(buf, "%u", &input); if (ret != 1) return -EINVAL; - limits.no_turbo = clamp_t(int, input, 0 , 1); + + update_turbo_state(); if (limits.turbo_disabled) { pr_warn("Turbo disabled by BIOS or unavailable on processor\n"); - limits.no_turbo = limits.turbo_disabled; + return -EPERM; } + limits.no_turbo = clamp_t(int, input, 0, 1); + return count; } @@ -323,7 +353,6 @@ static ssize_t store_min_perf_pct(struct kobject *a, struct attribute *b, return count; } -show_one(no_turbo, no_turbo); show_one(max_perf_pct, max_perf_pct); show_one(min_perf_pct, min_perf_pct); @@ -501,7 +530,7 @@ static void intel_pstate_get_min_max(struct cpudata *cpu, int *min, int *max) int max_perf_adj; int min_perf; - if (limits.no_turbo) + if (limits.no_turbo || limits.turbo_disabled) max_perf = cpu->pstate.max_pstate; max_perf_adj = fp_toint(mul_fp(int_tofp(max_perf), limits.max_perf)); @@ -516,6 +545,8 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate) { int max_perf, min_perf; + update_turbo_state(); + intel_pstate_get_min_max(cpu, &min_perf, &max_perf); pstate = clamp_t(int, pstate, min_perf, max_perf); @@ -716,7 +747,7 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy) limits.min_perf = int_tofp(1); limits.max_perf_pct = 100; limits.max_perf = int_tofp(1); - limits.no_turbo = limits.turbo_disabled; + limits.no_turbo = 0; return 0; } limits.min_perf_pct = (policy->min * 100) / policy->cpuinfo.max_freq; @@ -759,7 +790,6 @@ static int intel_pstate_cpu_init(struct cpufreq_policy *policy) { struct cpudata *cpu; int rc; - u64 misc_en; rc = intel_pstate_init_cpu(policy->cpu); if (rc) @@ -767,12 +797,6 @@ static int intel_pstate_cpu_init(struct cpufreq_policy *policy) cpu = all_cpu_data[policy->cpu]; - rdmsrl(MSR_IA32_MISC_ENABLE, misc_en); - if (misc_en & MSR_IA32_MISC_ENABLE_TURBO_DISABLE || - cpu->pstate.max_pstate == cpu->pstate.turbo_pstate) { - limits.turbo_disabled = 1; - limits.no_turbo = 1; - } if (limits.min_perf_pct == 100 && limits.max_perf_pct == 100) policy->policy = CPUFREQ_POLICY_PERFORMANCE; else