From patchwork Wed Jun 19 08:53:07 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 17980 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f72.google.com (mail-qa0-f72.google.com [209.85.216.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 951242397B for ; Wed, 19 Jun 2013 08:56:31 +0000 (UTC) Received: by mail-qa0-f72.google.com with SMTP id f14sf688661qak.3 for ; Wed, 19 Jun 2013 01:56:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-beenthere:x-forwarded-to:x-forwarded-for :delivered-to:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:in-reply-to:references:x-gm-message-state :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:x-google-group-id:list-post:list-help :list-archive:list-unsubscribe; bh=GGRWG8v6cEnZwv0Bk83+qNXVXn157y38BSxikAPca9I=; b=OOtJN4/GE6/KelzG4ibErGmwvCUgtqNubqUNlFs/ls0rAiabgCadHVmzTQ+Gasc4aZ yeL+xeF/cim3HiAuFssKea1qmpjhNbc8eh5/WX/sYJj94AY3btHi5umrBgjKxgaLwUOn WYdItc0cPV4Mh/GSKuZCxBggpe6XJx0J+CmJ5UUrMi7P19jPrgZ5r3JboROYq03OgZnC ITUQoXch8UcogbheMHuyyO9qVCr92WW+g8WbBIX/OGwAKY1K6Vis2N7BZfrdqBpuRxAO Zpk9k6qkdffESCtUasEr/s9jau+SePl3dnPtXRtmJ1QSKZuR3Ls95DwHOk2YGW7u6rAB A7+Q== X-Received: by 10.236.189.241 with SMTP id c77mr1142662yhn.17.1371632191428; Wed, 19 Jun 2013 01:56:31 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.24.162 with SMTP id v2ls65712qef.8.gmail; Wed, 19 Jun 2013 01:56:31 -0700 (PDT) X-Received: by 10.58.243.2 with SMTP id wu2mr616847vec.74.1371632191288; Wed, 19 Jun 2013 01:56:31 -0700 (PDT) Received: from mail-ve0-x22e.google.com (mail-ve0-x22e.google.com [2607:f8b0:400c:c01::22e]) by mx.google.com with ESMTPS id n3si5261456vcr.68.2013.06.19.01.56.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 19 Jun 2013 01:56:31 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c01::22e is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c01::22e; Received: by mail-ve0-f174.google.com with SMTP id oz10so3886270veb.33 for ; Wed, 19 Jun 2013 01:56:31 -0700 (PDT) X-Received: by 10.220.53.7 with SMTP id k7mr316146vcg.52.1371632191177; Wed, 19 Jun 2013 01:56:31 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.58.165.8 with SMTP id yu8csp100312veb; Wed, 19 Jun 2013 01:56:30 -0700 (PDT) X-Received: by 10.66.232.65 with SMTP id tm1mr5642646pac.145.1371632190161; Wed, 19 Jun 2013 01:56:30 -0700 (PDT) Received: from mail-pa0-x230.google.com (mail-pa0-x230.google.com [2607:f8b0:400e:c03::230]) by mx.google.com with ESMTPS id zg2si10009115pbb.75.2013.06.19.01.56.29 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 19 Jun 2013 01:56:30 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400e:c03::230 is neither permitted nor denied by best guess record for domain of viresh.kumar@linaro.org) client-ip=2607:f8b0:400e:c03::230; Received: by mail-pa0-f48.google.com with SMTP id kp12so4910655pab.21 for ; Wed, 19 Jun 2013 01:56:29 -0700 (PDT) X-Received: by 10.68.196.37 with SMTP id ij5mr1728924pbc.214.1371632189748; Wed, 19 Jun 2013 01:56:29 -0700 (PDT) Received: from localhost ([106.198.29.238]) by mx.google.com with ESMTPSA id u6sm22237303pbb.46.2013.06.19.01.56.20 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 19 Jun 2013 01:56:29 -0700 (PDT) From: Viresh Kumar To: rjw@sisk.pl Cc: linaro-kernel@lists.linaro.org, patches@linaro.org, cpufreq@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, robin.randhawa@arm.com, Steve.Bannister@arm.com, Liviu.Dudau@arm.com, charles.garcia-tobin@arm.com, arvind.chauhan@arm.com, dave.martin@arm.com, Viresh Kumar Subject: [PATCH 13/13] cpufreq: make sure frequency transitions are serialized Date: Wed, 19 Jun 2013 14:23:07 +0530 Message-Id: <0bebf56a27f799a282cc00d0c17c187f9941f122.1371630975.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 1.7.12.rc2.18.g61b472e In-Reply-To: References: In-Reply-To: References: X-Gm-Message-State: ALoCoQlFLfqAV7b1I1+sO14Y+DjZpKhx54zWKkEaKRvx9A9ylED3w3pTyCfwoVHDtsfwQA/M4tB5 X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c01::22e is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Whenever we are changing frequency of a cpu, we are calling PRECHANGE and POSTCHANGE notifiers. They must be serialized. i.e. PRECHANGE or POSTCHANGE shouldn't be called twice contiguously. This can happen due to bugs in users of __cpufreq_driver_target() or actual cpufreq drivers who are sending these notifiers. This patch adds some protection against this. Now, we keep track of the last transaction and see if something went wrong. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 2d53f47..92cb8b3 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -107,6 +107,9 @@ static void handle_update(struct work_struct *work); static BLOCKING_NOTIFIER_HEAD(cpufreq_policy_notifier_list); static struct srcu_notifier_head cpufreq_transition_notifier_list; +/* Tracks status of transition */ +static int transition_ongoing; + static bool init_cpufreq_transition_notifier_list_called; static int __init init_cpufreq_transition_notifier_list(void) { @@ -264,6 +267,8 @@ void __cpufreq_notify_transition(struct cpufreq_policy *policy, switch (state) { case CPUFREQ_PRECHANGE: + WARN_ON(transition_ongoing++); + /* detect if the driver reported a value as "old frequency" * which is not equal to what the cpufreq core thinks is * "old frequency". @@ -283,6 +288,8 @@ void __cpufreq_notify_transition(struct cpufreq_policy *policy, break; case CPUFREQ_POSTCHANGE: + WARN_ON(!transition_ongoing--); + adjust_jiffies(CPUFREQ_POSTCHANGE, freqs); pr_debug("FREQ: %lu - CPU: %lu", (unsigned long)freqs->new, (unsigned long)freqs->cpu); @@ -1458,6 +1465,8 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy, if (cpufreq_disabled()) return -ENODEV; + if (transition_ongoing) + return -EBUSY; /* Make sure that target_freq is within supported range */ if (target_freq > policy->max)