From patchwork Sun May 31 14:42:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Smythies X-Patchwork-Id: 6516071 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 932379F1C1 for ; Sun, 31 May 2015 14:42:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8E3632061C for ; Sun, 31 May 2015 14:42:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7EB9920617 for ; Sun, 31 May 2015 14:42:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758294AbbEaOmp (ORCPT ); Sun, 31 May 2015 10:42:45 -0400 Received: from mail-pa0-f42.google.com ([209.85.220.42]:35639 "EHLO mail-pa0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758252AbbEaOmo (ORCPT ); Sun, 31 May 2015 10:42:44 -0400 Received: by padjw17 with SMTP id jw17so19301812pad.2 for ; Sun, 31 May 2015 07:42:44 -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:mime-version:content-type :content-transfer-encoding; bh=eQDWPKpzl18UcDm05lBpu7uTwLpWk9u0ryv9WkMndzM=; b=EQjp6irORpsvfPu8TztoUeY/dnx946f7nOTXmt9ju46VdErfF1JCZVdzo/7NhL6Hza rqPAG6OZaV76kUQilEdGfodCNIhQBrpOB4xmsIXN4NE0FcSu6KzXkHBPNgU+zq29tWJ+ 9KWiSazmt93xN0g/YdXNs8E+8uKVwh/oqnfelMBjI6NialdkaOKcKUPsYzW5yQ2bvMcO v+zRSqjrNdoofKjVuBHsWUAfGfmJLrlojrdqPXUlGl1ijPaq8gQxM3KWiXl/fiGSyAXG gdN3KcWFDjiBe5ZWAdyohX653AMoiaEPcp0fIa+UlUSSvx//5EprPVw1gtg1zvKUhXiu 2w6Q== X-Received: by 10.70.134.133 with SMTP id pk5mr32282627pdb.133.1433083364389; Sun, 31 May 2015 07:42:44 -0700 (PDT) Received: from s15.smythies.com (s173-180-45-4.bc.hsia.telus.net. [173.180.45.4]) by mx.google.com with ESMTPSA id a10sm11466377pbu.15.2015.05.31.07.42.43 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 31 May 2015 07:42:43 -0700 (PDT) From: Doug Smythies X-Google-Original-From: Doug Smythies To: kristen@linux.intel.com, rjw@rjwysocki.net, linux-pm@vger.kernel.org Cc: dsmythies@telus.net Subject: [PATCH] intel_pstate: Force setting target pstate when required. Date: Sun, 31 May 2015 07:42:29 -0700 Message-Id: <1433083349-4039-1-git-send-email-dsmythies@telus.net> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 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=ham 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 During initialization and exit it is possible that the target pstate might not actually be set. Furthermore, the result can be that the driver and the processor are out of synch and, under some conditions, the driver might never send the processor the proper target pstate. This patch adds a forced or unforced flag to the call to intel_pstate_set_pstate. If forced, then specifically bypass clamp checks and the do not send if it is the same as last time check. If unforced, then, and as before, do the current policy clamp checks, and do not do actual send if the new target is the same as the old. Signed-off-by: Doug Smythies Reported-by: Marien Zwart Reported-by: Alex Lochmann Reported-by: Piotr Ko?aczkowski Reported-by: Clemens Eisserer Tested-by: Marien Zwart Tested-by: Doug Smythies --- drivers/cpufreq/intel_pstate.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index 6414661..77b6edf 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -33,6 +33,9 @@ #include #include +#define FORCED 0 +#define UNFORCED 1 + #define BYT_RATIOS 0x66a #define BYT_VIDS 0x66b #define BYT_TURBO_RATIOS 0x66c @@ -704,19 +707,21 @@ static void intel_pstate_get_min_max(struct cpudata *cpu, int *min, int *max) *min = clamp_t(int, min_perf, cpu->pstate.min_pstate, max_perf); } -static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate) +static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate, int forced) { int max_perf, min_perf; - update_turbo_state(); + if (forced != FORCED) + { + update_turbo_state(); - intel_pstate_get_min_max(cpu, &min_perf, &max_perf); + intel_pstate_get_min_max(cpu, &min_perf, &max_perf); - pstate = clamp_t(int, pstate, min_perf, max_perf); - - if (pstate == cpu->pstate.current_pstate) - return; + pstate = clamp_t(int, pstate, min_perf, max_perf); + if (pstate == cpu->pstate.current_pstate) + return; + } trace_cpu_frequency(pstate * cpu->pstate.scaling, cpu->cpu); cpu->pstate.current_pstate = pstate; @@ -733,7 +738,7 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu) if (pstate_funcs.get_vid) pstate_funcs.get_vid(cpu); - intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate); + intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate, (int) FORCED); } static inline void intel_pstate_calc_busy(struct cpudata *cpu) @@ -844,7 +849,7 @@ static inline void intel_pstate_adjust_busy_pstate(struct cpudata *cpu) ctl = pid_calc(pid, busy_scaled); /* Negative values of ctl increase the pstate and vice versa */ - intel_pstate_set_pstate(cpu, cpu->pstate.current_pstate - ctl); + intel_pstate_set_pstate(cpu, cpu->pstate.current_pstate - ctl, (int) UNFORCED); } static void intel_hwp_timer_func(unsigned long __data) @@ -1007,7 +1012,7 @@ static void intel_pstate_stop_cpu(struct cpufreq_policy *policy) if (hwp_active) return; - intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate); + intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate, (int) FORCED); } static int intel_pstate_cpu_init(struct cpufreq_policy *policy)