From patchwork Tue Jul 15 22:47:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 4561321 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id DAFF3C0514 for ; Tue, 15 Jul 2014 22:48:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E906A2017E for ; Tue, 15 Jul 2014 22:48:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1260C2018A for ; Tue, 15 Jul 2014 22:48:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758964AbaGOWsF (ORCPT ); Tue, 15 Jul 2014 18:48:05 -0400 Received: from smtp.codeaurora.org ([198.145.11.231]:43294 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752536AbaGOWsD (ORCPT ); Tue, 15 Jul 2014 18:48:03 -0400 Received: from smtp.codeaurora.org (localhost [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id 67463140240; Tue, 15 Jul 2014 22:48:02 +0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 486) id 597E3140242; Tue, 15 Jul 2014 22:48:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from skannan1-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: skannan@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id B5C3B140240; Tue, 15 Jul 2014 22:48:01 +0000 (UTC) From: Saravana Kannan To: "Rafael J . Wysocki" , Viresh Kumar , Todd Poynor , "Srivatsa S . Bhat" Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, "Saravana Kannan" , Stephen Boyd Subject: [PATCH v3 2/2] cpufreq: Simplify and fix mutual exclusion with hotplug Date: Tue, 15 Jul 2014 15:47:53 -0700 Message-Id: <1405464473-3916-3-git-send-email-skannan@codeaurora.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1405464473-3916-1-git-send-email-skannan@codeaurora.org> References: <1405464473-3916-1-git-send-email-skannan@codeaurora.org> X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since we no longer alloc and destroy/freeze policy and sysfs nodes during hotplug and suspend, we don't need to lock sysfs with hotplug. We can achieve the same effect by checking if policy->cpus is empty. Hotplug mutual exclusion was only done for sysfs writes. But reads need the same protection too. So, this patch adds that too. Also, cpufreq driver (un)register can race with hotplug since CPU online state can change between adding/removing the currently online devices and registering/unregistering for hotplug notifiers. So, fix that by registering for hotplug notifiers first before adding devices and unregistering from hotplug notifiers first before removing devices. Signed-off-by: Saravana Kannan --- drivers/cpufreq/cpufreq.c | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index a0a2ec2..f72b2b7 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -748,17 +748,18 @@ static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf) { struct cpufreq_policy *policy = to_policy(kobj); struct freq_attr *fattr = to_attr(attr); - ssize_t ret; + ssize_t ret = -EINVAL; if (!down_read_trylock(&cpufreq_rwsem)) - return -EINVAL; - + return ret; down_read(&policy->rwsem); - if (fattr->show) - ret = fattr->show(policy, buf); - else - ret = -EIO; + if (!cpumask_empty(policy->cpus)) { + if (fattr->show) + ret = fattr->show(policy, buf); + else + ret = -EIO; + } up_read(&policy->rwsem); up_read(&cpufreq_rwsem); @@ -773,26 +774,19 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr, struct freq_attr *fattr = to_attr(attr); ssize_t ret = -EINVAL; - get_online_cpus(); - - if (!cpu_online(policy->cpu)) - goto unlock; - if (!down_read_trylock(&cpufreq_rwsem)) - goto unlock; - + return ret; down_write(&policy->rwsem); - if (fattr->store) - ret = fattr->store(policy, buf, count); - else - ret = -EIO; + if (!cpumask_empty(policy->cpus)) { + if (fattr->store) + ret = fattr->store(policy, buf, count); + else + ret = -EIO; + } up_write(&policy->rwsem); - up_read(&cpufreq_rwsem); -unlock: - put_online_cpus(); return ret; } @@ -2270,6 +2264,8 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data) } } + register_hotcpu_notifier(&cpufreq_cpu_notifier); + ret = subsys_interface_register(&cpufreq_interface); if (ret) goto err_boost_unreg; @@ -2293,13 +2289,13 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data) } } - register_hotcpu_notifier(&cpufreq_cpu_notifier); pr_debug("driver %s up and running\n", driver_data->name); return 0; err_if_unreg: subsys_interface_unregister(&cpufreq_interface); err_boost_unreg: + unregister_hotcpu_notifier(&cpufreq_cpu_notifier); if (cpufreq_boost_supported()) cpufreq_sysfs_remove_file(&boost.attr); err_null_driver: @@ -2327,12 +2323,12 @@ int cpufreq_unregister_driver(struct cpufreq_driver *driver) pr_debug("unregistering driver %s\n", driver->name); + unregister_hotcpu_notifier(&cpufreq_cpu_notifier); + subsys_interface_unregister(&cpufreq_interface); if (cpufreq_boost_supported()) cpufreq_sysfs_remove_file(&boost.attr); - unregister_hotcpu_notifier(&cpufreq_cpu_notifier); - down_write(&cpufreq_rwsem); write_lock_irqsave(&cpufreq_driver_lock, flags);