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: 19658 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vb0-f69.google.com (mail-vb0-f69.google.com [209.85.212.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DF1BE246B8 for ; Sun, 1 Sep 2013 05:26:20 +0000 (UTC) Received: by mail-vb0-f69.google.com with SMTP id e13sf3884071vbg.8 for ; Sat, 31 Aug 2013 22:26:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=mime-version:x-gm-message-state:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=aS1S1AfTTo8xlmi+Ix0FzRaeSGd5nPabitm+NGcCdjQ=; b=moXY7gPOn+hC5AqrR9AAKIxqt5R6Jz05D0wNihxm3UYyVy5D59nB782K4NMUetsmBg yzfa/Kofv49NteZKwd5oZUZkBe4dVk5RfCHIZTfwF57edxxhLH3i+Ua7MLBu+XcgMZld gjOyT+8Q9I+wM4Yg1rCCfGNcY7RAgFCigQFX0xFY1izWMOycd1BQyJplh5PuUiztpkeh /YKBY0q/YNMYj67hRIvN0VsMmlqKJTDGazy2n3MBva5uMTX6wbdTflIQmLovQI/YY++9 NyiKBbJzXTneRBUVnpIX4sl4p7OkdOxbwW0adYJ7GO7uKui9VbUu90fQTm7h3d9nv86l /z8A== X-Received: by 10.236.19.225 with SMTP id n61mr5916099yhn.8.1378013180432; Sat, 31 Aug 2013 22:26:20 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.73.138 with SMTP id l10ls1853384qev.24.gmail; Sat, 31 Aug 2013 22:26:20 -0700 (PDT) X-Received: by 10.220.164.70 with SMTP id d6mr426298vcy.19.1378013180325; Sat, 31 Aug 2013 22:26:20 -0700 (PDT) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id o5si557180vdw.89.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 31 Aug 2013 22:26:20 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id gd11so2280651vcb.33 for ; Sat, 31 Aug 2013 22:26:20 -0700 (PDT) X-Gm-Message-State: ALoCoQlkTZTo+EyTqsYlNMqAG+1rt7suUU4c/PcyzgTR5Px8w2h/hQb52UL7MipSI1CyHq7r7pAO X-Received: by 10.52.249.102 with SMTP id yt6mr13252517vdc.21.1378013180243; Sat, 31 Aug 2013 22:26:20 -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.220.174.196 with SMTP id u4csp49997vcz; Sat, 31 Aug 2013 22:26:19 -0700 (PDT) X-Received: by 10.68.254.138 with SMTP id ai10mr76849pbd.151.1378013179160; Sat, 31 Aug 2013 22:26:19 -0700 (PDT) Received: from mail-pb0-f53.google.com (mail-pb0-f53.google.com [209.85.160.53]) by mx.google.com with ESMTPS id yk3si5558343pac.128.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 31 Aug 2013 22:26:18 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.160.53 is neither permitted nor denied by best guess record for domain of viresh.kumar@linaro.org) client-ip=209.85.160.53; Received: by mail-pb0-f53.google.com with SMTP id up15so3425628pbc.40 for ; Sat, 31 Aug 2013 22:26:18 -0700 (PDT) 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> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.174 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: , 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 */