From patchwork Sun Sep 1 05:26:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 2852464 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 079759F3DC for ; Sun, 1 Sep 2013 05:26:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1D1EF20397 for ; Sun, 1 Sep 2013 05:26:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3EFDC20396 for ; Sun, 1 Sep 2013 05:26:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754859Ab3IAF0c (ORCPT ); Sun, 1 Sep 2013 01:26:32 -0400 Received: from mail-pa0-f47.google.com ([209.85.220.47]:62789 "EHLO mail-pa0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755291Ab3IAF0S (ORCPT ); Sun, 1 Sep 2013 01:26:18 -0400 Received: by mail-pa0-f47.google.com with SMTP id kl13so3875098pab.20 for ; Sat, 31 Aug 2013 22:26:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=aS1S1AfTTo8xlmi+Ix0FzRaeSGd5nPabitm+NGcCdjQ=; b=UBD4wR4hWbxs+/NYMS3v6EHDSMtaKs/EQquf0VJoNfM7AJj8aqkod54kZBnCrHTkgq 2Kyj0zZGgE91qPOLBtTNgs4SChApdqdtdrIgOH6JaCPBQqK/QRlSL3zPMtWfdX8lRk0J GLWFzxTnKTzEWnVk1Ldo4BOkcLnIxITQf794vQKsqI1VPxsja6jjXnNoQzMN0/URgsMC zrhMSGRTdBQ+0YoF5GoW1IslHSRIN639nzme9Vdc3H49+D1BnJZuN9BWpK+TMX1E4uyt N0QnyZHSpZsHK7Jb60PLyBGD2trB3gQuki531SjJKDxmRXbOkJGCIutLorXNda8vN1Xb V/BA== X-Gm-Message-State: ALoCoQm7xhBXri/uWgTRuwFoct2yiYjWLgqdYJOWlSiibqmHMLOTiMRYflyAZhbXZJWT0j2moP+l X-Received: by 10.66.149.198 with SMTP id uc6mr19555898pab.61.1378013178421; Sat, 31 Aug 2013 22:26:18 -0700 (PDT) Received: from localhost ([122.167.78.148]) by mx.google.com with ESMTPSA id qa9sm7745808pbc.7.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 31 Aug 2013 22:26:17 -0700 (PDT) From: Viresh Kumar To: rjw@sisk.pl, sboyd@codeaurora.org Cc: linaro-kernel@lists.linaro.org, patches@linaro.org, cpufreq@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Viresh Kumar Subject: [PATCH 2/2] cpufreq: serialize calls to __cpufreq_governor() Date: Sun, 1 Sep 2013 10:56:02 +0530 Message-Id: <80c4bd8c577e5da0aa63342671773be5cdc26a9a.1378012620.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 1.7.12.rc2.18.g61b472e In-Reply-To: <085013f4e584e3fef97187bcb349c3fa76942e19.1378012620.git.viresh.kumar@linaro.org> References: <085013f4e584e3fef97187bcb349c3fa76942e19.1378012620.git.viresh.kumar@linaro.org> In-Reply-To: <085013f4e584e3fef97187bcb349c3fa76942e19.1378012620.git.viresh.kumar@linaro.org> References: <085013f4e584e3fef97187bcb349c3fa76942e19.1378012620.git.viresh.kumar@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 We can't take a big lock around __cpufreq_governor() as this causes recursive locking for some cases. But calls to this routine must be serialized for every policy. Lets introduce another variable which would guarantee serialization here. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 7 ++++++- include/linux/cpufreq.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index f320a20..4d5723db 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1692,13 +1692,15 @@ static int __cpufreq_governor(struct cpufreq_policy *policy, policy->cpu, event); mutex_lock(&cpufreq_governor_lock); - if ((policy->governor_enabled && (event == CPUFREQ_GOV_START)) || + if (policy->governor_busy || + (policy->governor_enabled && (event == CPUFREQ_GOV_START)) || (!policy->governor_enabled && ((event == CPUFREQ_GOV_LIMITS) || (event == CPUFREQ_GOV_STOP)))) { mutex_unlock(&cpufreq_governor_lock); return -EBUSY; } + policy->governor_busy = true; if (event == CPUFREQ_GOV_STOP) policy->governor_enabled = false; else if (event == CPUFREQ_GOV_START) @@ -1727,6 +1729,9 @@ static int __cpufreq_governor(struct cpufreq_policy *policy, ((event == CPUFREQ_GOV_POLICY_EXIT) && !ret)) module_put(policy->governor->owner); + mutex_lock(&cpufreq_governor_lock); + policy->governor_busy = false; + mutex_unlock(&cpufreq_governor_lock); return ret; } diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index d568f39..cca885d 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -76,6 +76,7 @@ struct cpufreq_policy { struct cpufreq_governor *governor; /* see below */ void *governor_data; bool governor_enabled; /* governor start/stop flag */ + bool governor_busy; struct work_struct update; /* if update_policy() needs to be * called, but you're in IRQ context */