From patchwork Tue Jan 27 20:13:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 43846 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A338623FFF for ; Tue, 27 Jan 2015 20:14:33 +0000 (UTC) Received: by mail-wi0-f199.google.com with SMTP id r20sf3691282wiv.2 for ; Tue, 27 Jan 2015 12:14:33 -0800 (PST) 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: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=WztgYTFIR+59Po877gc2DsVWPb5qHA4Pet6v5nS61WY=; b=dhFCm2r49wVQDVGLZ7dsVbho5+mdH2FMk5nVvaY/jAlPiJZD/ZuNN98gNSlhF7g+sn nve6GHR2gKumcrsJAOLQgOmzK/EK66/avq9iJKvy0KnDbo8oNvRBL6/CXtY+7OZaXzD9 7W4RBEuPjy8sP8THsaYEwc4fZEYrU9aQnI5kbIiSQKCCScwnenxbqyHEgQ+4wP8BDVsX nPm0hsshcCx+bChim/bHA1N52Nwjr0hr6RCChIOOa82Z3bbM4RTEf1h6R82zHvp64aMh Lwpuhi5LisDCckabaJ6LpvAFdxhjvE4c1qhijvRaD9TPDVGwzfAWVwKNg93q9g86f8FN XgKg== X-Gm-Message-State: ALoCoQkjCHKR26hooPWpX4ouxFpAMZG3bmwJazG9wntetlEGoa9OjTg2TzeNJm3RqZT66rmYkuUJ X-Received: by 10.112.42.104 with SMTP id n8mr513407lbl.19.1422389672943; Tue, 27 Jan 2015 12:14:32 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.185.69 with SMTP id fa5ls76396lac.84.gmail; Tue, 27 Jan 2015 12:14:32 -0800 (PST) X-Received: by 10.112.235.67 with SMTP id uk3mr3987078lbc.48.1422389672809; Tue, 27 Jan 2015 12:14:32 -0800 (PST) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com. [209.85.217.172]) by mx.google.com with ESMTPS id ei2si2294621lad.39.2015.01.27.12.14.32 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 27 Jan 2015 12:14:32 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) client-ip=209.85.217.172; Received: by mail-lb0-f172.google.com with SMTP id l4so15126307lbv.3 for ; Tue, 27 Jan 2015 12:14:32 -0800 (PST) X-Received: by 10.152.6.132 with SMTP id b4mr3932104laa.59.1422389672726; Tue, 27 Jan 2015 12:14:32 -0800 (PST) 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.112.35.133 with SMTP id h5csp1213865lbj; Tue, 27 Jan 2015 12:14:32 -0800 (PST) X-Received: by 10.112.164.101 with SMTP id yp5mr3913744lbb.82.1422389655596; Tue, 27 Jan 2015 12:14:15 -0800 (PST) Received: from mail-la0-f53.google.com (mail-la0-f53.google.com. [209.85.215.53]) by mx.google.com with ESMTPS id ql3si2214990lbb.133.2015.01.27.12.14.15 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 27 Jan 2015 12:14:15 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by mail-la0-f53.google.com with SMTP id gq15so15325795lab.12 for ; Tue, 27 Jan 2015 12:14:15 -0800 (PST) X-Received: by 10.112.148.34 with SMTP id tp2mr3897290lbb.94.1422389655493; Tue, 27 Jan 2015 12:14:15 -0800 (PST) Received: from uffe-Latitude-E6430s.lan (90-231-160-185-no158.tbcn.telia.com. [90.231.160.185]) by mx.google.com with ESMTPSA id ya4sm713470lbb.32.2015.01.27.12.14.13 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Jan 2015 12:14:14 -0800 (PST) From: Ulf Hansson To: "Rafael J. Wysocki" , Len Brown , Pavel Machek , Kevin Hilman , linux-pm@vger.kernel.org Cc: Geert Uytterhoeven , Dmitry Torokhov , linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, Ulf Hansson Subject: [PATCH 5/8] PM / Domains: Eliminate the mutex for the generic_pm_domain_data Date: Tue, 27 Jan 2015 21:13:42 +0100 Message-Id: <1422389625-11730-6-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1422389625-11730-1-git-send-email-ulf.hansson@linaro.org> References: <1422389625-11730-1-git-send-email-ulf.hansson@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ulf.hansson@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.217.172 as permitted sender) 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: , While adding devices to their PM domains, dev_pm_qos_add_notifier() was invoked while allocating the generic_pm_domain_data for the device. Since the generic_pm_domain_data's device pointer will be assigned after allocation, the ->genpd_dev_pm_qos_notifier() callback could be called prior having a valid pointer to the device. Similar scenario existed while removing a device from a genpd. To cope with these scenarios a mutex was used to protect the pointer to the device. By re-order the sequence for when dev_pm_qos_add|remove_notifier() are invoked, we make sure the ->genpd_dev_pm_qos_notifier() callback are always called with a valid device pointer available. In this way, we eliminate the need for protecting the pointer and thus we can remove the mutex from the struct generic_pm_domain_data. Signed-off-by: Ulf Hansson --- drivers/base/power/domain.c | 37 ++++++++++++++----------------------- include/linux/pm_domain.h | 1 - 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 88198ba..1f026c1 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -344,14 +344,7 @@ static int genpd_dev_pm_qos_notifier(struct notifier_block *nb, struct device *dev; gpd_data = container_of(nb, struct generic_pm_domain_data, nb); - - mutex_lock(&gpd_data->lock); dev = gpd_data->base.dev; - if (!dev) { - mutex_unlock(&gpd_data->lock); - return NOTIFY_DONE; - } - mutex_unlock(&gpd_data->lock); for (;;) { struct generic_pm_domain *genpd; @@ -1392,16 +1385,12 @@ static struct generic_pm_domain_data *genpd_alloc_dev_data(struct device *dev) if (!gpd_data) return NULL; - mutex_init(&gpd_data->lock); - gpd_data->nb.notifier_call = genpd_dev_pm_qos_notifier; - dev_pm_qos_add_notifier(dev, &gpd_data->nb); return gpd_data; } static void genpd_free_dev_data(struct device *dev, struct generic_pm_domain_data *gpd_data) { - dev_pm_qos_remove_notifier(dev, &gpd_data->nb); kfree(gpd_data); } @@ -1414,7 +1403,7 @@ static void genpd_free_dev_data(struct device *dev, int __pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev, struct gpd_timing_data *td) { - struct generic_pm_domain_data *gpd_data_new, *gpd_data = NULL; + struct generic_pm_domain_data *gpd_data; int ret = 0; dev_dbg(dev, "%s()\n", __func__); @@ -1422,8 +1411,8 @@ int __pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev, if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(dev)) return -EINVAL; - gpd_data_new = genpd_alloc_dev_data(dev); - if (!gpd_data_new) + gpd_data = genpd_alloc_dev_data(dev); + if (!gpd_data) return -ENOMEM; genpd_acquire_lock(genpd); @@ -1445,7 +1434,6 @@ int __pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev, goto out; } - gpd_data = gpd_data_new; dev->power.subsys_data->domain_data = &gpd_data->base; if (td) @@ -1461,19 +1449,20 @@ int __pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev, genpd->device_count++; genpd->max_off_time_changed = true; - mutex_lock(&gpd_data->lock); gpd_data->base.dev = dev; list_add_tail(&gpd_data->base.list_node, &genpd->dev_list); gpd_data->need_restore = -1; gpd_data->td.constraint_changed = true; gpd_data->td.effective_constraint_ns = -1; - mutex_unlock(&gpd_data->lock); + gpd_data->nb.notifier_call = genpd_dev_pm_qos_notifier; out: genpd_release_lock(genpd); - if (gpd_data != gpd_data_new) - genpd_free_dev_data(dev, gpd_data_new); + if (ret) + genpd_free_dev_data(dev, gpd_data); + else + dev_pm_qos_add_notifier(dev, &gpd_data->nb); return ret; } @@ -1509,6 +1498,11 @@ int pm_genpd_remove_device(struct generic_pm_domain *genpd, || pd_to_genpd(dev->pm_domain) != genpd) return -EINVAL; + /* The above validation also means we have existing domain_data. */ + pdd = dev->power.subsys_data->domain_data; + gpd_data = to_gpd_data(pdd); + dev_pm_qos_remove_notifier(dev, &gpd_data->nb); + genpd_acquire_lock(genpd); if (genpd->prepared_count > 0) { @@ -1525,16 +1519,12 @@ int pm_genpd_remove_device(struct generic_pm_domain *genpd, spin_lock_irq(&dev->power.lock); dev->pm_domain = NULL; - pdd = dev->power.subsys_data->domain_data; list_del_init(&pdd->list_node); - gpd_data = to_gpd_data(pdd); dev->power.subsys_data->domain_data = NULL; spin_unlock_irq(&dev->power.lock); - mutex_lock(&gpd_data->lock); pdd->dev = NULL; - mutex_unlock(&gpd_data->lock); genpd_release_lock(genpd); @@ -1545,6 +1535,7 @@ int pm_genpd_remove_device(struct generic_pm_domain *genpd, out: genpd_release_lock(genpd); + dev_pm_qos_add_notifier(dev, &gpd_data->nb); return ret; } diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index e160a0b..080e778 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -113,7 +113,6 @@ struct generic_pm_domain_data { struct pm_domain_data base; struct gpd_timing_data td; struct notifier_block nb; - struct mutex lock; int need_restore; };