From patchwork Thu May 15 05:56:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 30220 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f197.google.com (mail-ve0-f197.google.com [209.85.128.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 164912055D for ; Thu, 15 May 2014 05:57:06 +0000 (UTC) Received: by mail-ve0-f197.google.com with SMTP id db11sf2482515veb.4 for ; Wed, 14 May 2014 22:57:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=77zMbrWEq1HCa5SXa4enAtj5xgYubLENAX9+hAqCRh0=; b=PgXIEgr6wuDbK3KuIT3n3bBRisFTaNfHEwl/ARSx7HuIpl0lxLWszOSZwN/L2cM0Qm dJ5RitLRpQ/mlP2umSCpaE1kiG9yIvYtGpbNNuZ4foPEchWgwsawJWz1dX+FvMZiPdnC bMAlIKh7OJhum0K8qoUjFtkgSBaLZf5Wif61kBdhm0cbP1e0BEc22uyIToN398YCYnLL 1RIxtOcm1TLvvRH9eRtQWKfyTJ6o9gLgWh/pAaw0taZn+DdTgoLJ2UpM3Ry8Cr94Bqfd IH7VX9l/gx3I1ArEinFCSI1UMqW/MSgEkZiBzJ8TpXPPM4sjABGpFb5r5kafuGnoltlh WTgQ== X-Gm-Message-State: ALoCoQkM7hLAvYhLWRqv97e3n7RrtzfJMN7QNuCXO2uuz2QJ0WdU+WD4edK5KQigr46ZmhI2U9aM X-Received: by 10.58.127.66 with SMTP id ne2mr3911121veb.27.1400133425827; Wed, 14 May 2014 22:57:05 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.44.36 with SMTP id f33ls99828qga.19.gmail; Wed, 14 May 2014 22:57:05 -0700 (PDT) X-Received: by 10.220.103.141 with SMTP id k13mr6737189vco.25.1400133425703; Wed, 14 May 2014 22:57:05 -0700 (PDT) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id fh9si739990vec.160.2014.05.14.22.57.05 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 14 May 2014 22:57:05 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.178 as permitted sender) client-ip=209.85.220.178; Received: by mail-vc0-f178.google.com with SMTP id hq16so3730633vcb.23 for ; Wed, 14 May 2014 22:57:05 -0700 (PDT) X-Received: by 10.221.4.66 with SMTP id ob2mr310543vcb.28.1400133425577; Wed, 14 May 2014 22:57:05 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp295825vcb; Wed, 14 May 2014 22:57:04 -0700 (PDT) X-Received: by 10.68.194.229 with SMTP id hz5mr9752427pbc.91.1400133424410; Wed, 14 May 2014 22:57:04 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id is5si2111690pbb.431.2014.05.14.22.57.03; Wed, 14 May 2014 22:57:03 -0700 (PDT) Received-SPF: none (google.com: linux-pm-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753476AbaEOF5B (ORCPT + 12 others); Thu, 15 May 2014 01:57:01 -0400 Received: from mail-we0-f174.google.com ([74.125.82.174]:63031 "EHLO mail-we0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753467AbaEOF5B (ORCPT ); Thu, 15 May 2014 01:57:01 -0400 Received: by mail-we0-f174.google.com with SMTP id k48so532817wev.5 for ; Wed, 14 May 2014 22:56:59 -0700 (PDT) X-Received: by 10.180.36.35 with SMTP id n3mr17164266wij.23.1400133419541; Wed, 14 May 2014 22:56:59 -0700 (PDT) Received: from localhost ([213.122.173.131]) by mx.google.com with ESMTPSA id lo18sm7927711wic.1.2014.05.14.22.56.54 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 14 May 2014 22:56:58 -0700 (PDT) From: Viresh Kumar To: rjw@rjwysocki.net Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, arvind.chauhan@arm.com, swarren@nvidia.com, nicolas.pitre@linaro.org, swarren@wwwdotorg.org, dianders@chromium.org, linux@arm.linux.org.uk, Viresh Kumar Subject: [RFC] cpufreq: send notifications for intermediate (stable) frequencies Date: Thu, 15 May 2014 11:26:51 +0530 Message-Id: <25738681139c04272b6d2ebeff244c6d36c893f7.1400133090.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.0.0.rc2 Sender: linux-pm-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.178 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Douglas Anderson, recently pointed out an interesting problem due to which his udelay() was expiring earlier than it should: https://lkml.org/lkml/2014/5/13/766 While transitioning between frequencies few platforms may temporarily switch to a stable frequency, waiting for the main PLL to stabilize. For example: When we transition between very low frequencies on exynos, like between 200MHz and 300MHz, we may temporarily switch to a PLL running at 800MHz. No CPUFREQ notification is sent for that. That means there's a period of time when we're running at 800MHz but loops_per_jiffy is calibrated at between 200MHz and 300MHz. And so udelay behaves badly. To get this fixed in a generic way, lets introduce another callback safe_freq() for the cpufreq drivers. safe_freq() should return a stable intermediate frequency a platform might want to switch to, before jumping to the frequency corresponding to 'index'. Core will send the 'PRE' notification for this 'stable' frequency and 'POST' for the 'target' frequency. Though if ->target_index() fails, it will handle POST for 'stable' frequency only. Drivers must send 'POST' notification for 'stable' freq and 'PRE' for 'target' freq. If they can't switch to target frequency, they don't need to send any notification. Signed-off-by: Viresh Kumar --- Doug/Stephen, If this doesn't look too ugly, then I would need patches from you to fix your platforms as I am not well aware of clk hierarchy of your platforms. drivers/cpufreq/cpufreq.c | 13 +++++++++++-- include/linux/cpufreq.h | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index a05c921..8d1cb4f 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1874,11 +1874,17 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy, if (notify) { freqs.old = policy->cur; - freqs.new = freq_table[index].frequency; + /* Switch to some safe intermediate freq */ + if (cpufreq_driver->safe_freq) + freqs.new = cpufreq_driver->safe_freq(policy, + index); + else + freqs.new = freq_table[index].frequency; freqs.flags = 0; pr_debug("%s: cpu: %d, oldfreq: %u, new freq: %u\n", - __func__, policy->cpu, freqs.old, freqs.new); + __func__, policy->cpu, freqs.old, + freq_table[index].frequency); cpufreq_freq_transition_begin(policy, &freqs); } @@ -1887,6 +1893,9 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy, if (retval) pr_err("%s: Failed to change cpu frequency: %d\n", __func__, retval); + else + /* Send POST notification for the target frequency */ + freqs.new = freq_table[index].frequency; if (notify) cpufreq_freq_transition_end(policy, &freqs, retval); diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 3f45889..b5ba275 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -226,6 +226,24 @@ struct cpufreq_driver { unsigned int relation); int (*target_index) (struct cpufreq_policy *policy, unsigned int index); + /* + * Only for drivers with target_index() and CPUFREQ_ASYNC_NOTIFICATION + * unset. + * + * safe_freq() should return a stable intermediate frequency a platform + * might want to switch to, before jumping to the frequency + * corresponding to 'index'. Core will send the 'PRE' notification for + * this 'stable' frequency and 'POST' for the 'target' frequency. Though + * if ->target_index() fails, it will handle POST for 'stable' frequency + * only. + * + * Drivers must send 'POST' notification for 'stable' freq and 'PRE' for + * 'target' freq. If they can't switch to target frequency, they don't + * need to send any notification. + * + */ + unsigned int (*safe_freq)(struct cpufreq_policy *policy, + unsigned int index); /* should be defined, if possible */ unsigned int (*get) (unsigned int cpu);