From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9097EC433DF for ; Tue, 25 Aug 2020 16:18:01 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 516EE2076C for ; Tue, 25 Aug 2020 16:18:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="VG8z+Jiq"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=mg.codeaurora.org header.i=@mg.codeaurora.org header.b="NCyCHb2q" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 516EE2076C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+L9B9buCzcXnLRmgAiQgrBbx4qOnN63+otQirLfDPpY=; b=VG8z+JiqZUkZoLscuGBUCGaT7 3+nT7/sHx4IgI9ywSnbUkjferY8/6Jt+ARZimd9OLUHdscBoGRHFNvZs7BTXSncBlqy+zCSk6n8S7 DLF06B8uXiCP0VLyFxUxXtYm1HjbSlPm0SMJtkpSaLa366o9R88IbTvihNPqqZv/wDX8q8waBVAN9 uYoDoz0TPZAHxdq1mICVar62SgbFHzFEEKdmg2vwWKx5lJBxJASSSWuy9t9fVuuxsTcPh77M2mEmT pw6bnXovy5G49agxxuOVoYqQ/ars2CT1Xf49a/ooecN5TBhhMh//qW4r5U9ZueehSealtU6gdlX5u SCCreAVdA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAbcJ-00058R-EU; Tue, 25 Aug 2020 16:16:11 +0000 Received: from mail29.static.mailgun.info ([104.130.122.29]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAbcF-00057z-Rk for linux-arm-kernel@lists.infradead.org; Tue, 25 Aug 2020 16:16:09 +0000 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1598372166; h=In-Reply-To: Content-Type: MIME-Version: References: Message-ID: Subject: Cc: To: From: Date: Sender; bh=+pAZ+GZwg+dyHEK9ty9PV7fNDRVaLYxMaLMuViXVx20=; b=NCyCHb2qanSLfzaFGF8p07OjdY54iX2IziEmaPxmmnEFc+iXQvNQkPjI+jELBCLjaCOjbnNC NR5o5uM5siTEY01F/Xp3ydAD4b+Ik3Y0UeT5HA3Ym+eEUPqrXMZV4VyecCeGB3lEm5akEH36 QreBBELbbIlW6B9dHz6JGNuCsSE= X-Mailgun-Sending-Ip: 104.130.122.29 X-Mailgun-Sid: WyJiYzAxZiIsICJsaW51eC1hcm0ta2VybmVsQGxpc3RzLmluZnJhZGVhZC5vcmciLCAiYmU5ZTRhIl0= Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n04.prod.us-east-1.postgun.com with SMTP id 5f4539452ec932ecb71a9049 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Tue, 25 Aug 2020 16:16:05 GMT Received: by smtp.codeaurora.org (Postfix, from userid 1001) id D7A81C4339C; Tue, 25 Aug 2020 16:16:04 +0000 (UTC) Received: from localhost (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: ilina) by smtp.codeaurora.org (Postfix) with ESMTPSA id 4E236C433CA; Tue, 25 Aug 2020 16:16:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 4E236C433CA Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=ilina@codeaurora.org Date: Tue, 25 Aug 2020 10:16:02 -0600 From: Lina Iyer To: Ulf Hansson Subject: Re: [PATCH 3/3] PM / Domains: Add support for PM domain on/off notifiers for genpd Message-ID: <20200825161602.GE12523@codeaurora.org> References: <20200819104057.318230-1-ulf.hansson@linaro.org> <20200819104057.318230-4-ulf.hansson@linaro.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200819104057.318230-4-ulf.hansson@linaro.org> User-Agent: Mutt/1.5.24 (2015-08-30) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200825_121608_045667_E323066D X-CRM114-Status: GOOD ( 31.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lorenzo Pieralisi , Vincent Guittot , Benjamin Gaignard , linux-pm@vger.kernel.org, Stephen Boyd , Daniel Lezcano , "Rafael J . Wysocki" , linux-kernel@vger.kernel.org, Bjorn Andersson , Kevin Hilman , linux-arm-kernel@lists.infradead.org, Sudeep Holla , Lukasz Luba Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Aug 19 2020 at 04:41 -0600, Ulf Hansson wrote: >A device may have specific HW constraints that must be obeyed to, before >its corresponding PM domain (genpd) can be powered off - and vice verse at >power on. These constraints can't be managed through the regular runtime PM >based deployment for a device, because the access pattern for it, isn't >always request based. In other words, using the runtime PM callbacks to >deal with the constraints doesn't work for these cases. > >For these reasons, let's instead add a PM domain power on/off notification >mechanism to genpd. To add/remove a notifier for a device, the device must >already have been attached to the genpd, which also means that it needs to >be a part of the PM domain topology. > >To add/remove a notifier, let's introduce two genpd specific functions: > - dev_pm_genpd_add|remove_notifier() > >Note that, to further clarify when genpd power on/off notifiers may be >used, one can compare with the existing CPU_CLUSTER_PM_ENTER|EXIT >notifiers. In the long run, the genpd power on/off notifiers should be able >to replace them, but that requires additional genpd based platform support >for the current users. > >Signed-off-by: Ulf Hansson >--- > drivers/base/power/domain.c | 130 ++++++++++++++++++++++++++++++++++-- > include/linux/pm_domain.h | 15 +++++ > 2 files changed, 141 insertions(+), 4 deletions(-) > >diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c >index 4b787e1ff188..9cb85a5e8342 100644 >--- a/drivers/base/power/domain.c >+++ b/drivers/base/power/domain.c >@@ -545,13 +545,21 @@ static int genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on, > if (!genpd->gov) > genpd->state_idx = 0; > >+ /* Notify consumers that we are about to power off. */ >+ ret = raw_notifier_call_chain(&genpd->power_notifiers, GENPD_STATE_OFF, >+ NULL); >+ if (ret) >+ return ret; >+ > /* Don't power off, if a child domain is waiting to power on. */ >- if (atomic_read(&genpd->sd_count) > 0) >- return -EBUSY; >+ if (atomic_read(&genpd->sd_count) > 0) { >+ ret = -EBUSY; >+ goto busy; >+ } > > ret = _genpd_power_off(genpd, true); > if (ret) >- return ret; >+ goto busy; > > genpd->status = GENPD_STATE_OFF; > genpd_update_accounting(genpd); >@@ -564,6 +572,9 @@ static int genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on, > } > > return 0; >+busy: >+ raw_notifier_call_chain(&genpd->power_notifiers, GENPD_STATE_ON, NULL); It would be helpful to abstract these notification related calls into functions of their own. So, for CPU PM domains, it would help to add RCU_NONIDLE() around the notifiers, allowing the callbacks to add trace functions. --Lina >+ return ret; > } > > /** >@@ -606,6 +617,9 @@ static int genpd_power_on(struct generic_pm_domain *genpd, unsigned int depth) > if (ret) > goto err; > >+ /* Inform consumers that we have powered on. */ >+ raw_notifier_call_chain(&genpd->power_notifiers, GENPD_STATE_ON, NULL); >+ > genpd->status = GENPD_STATE_ON; > genpd_update_accounting(genpd); > >@@ -948,9 +962,18 @@ static void genpd_sync_power_off(struct generic_pm_domain *genpd, bool use_lock, > > /* Choose the deepest state when suspending */ > genpd->state_idx = genpd->state_count - 1; >- if (_genpd_power_off(genpd, false)) >+ >+ /* Notify consumers that we are about to power off. */ >+ if (raw_notifier_call_chain(&genpd->power_notifiers, >+ GENPD_STATE_OFF, NULL)) > return; > >+ if (_genpd_power_off(genpd, false)) { >+ raw_notifier_call_chain(&genpd->power_notifiers, >+ GENPD_STATE_ON, NULL); >+ return; >+ } >+ > genpd->status = GENPD_STATE_OFF; > > list_for_each_entry(link, &genpd->child_links, child_node) { >@@ -998,6 +1021,9 @@ static void genpd_sync_power_on(struct generic_pm_domain *genpd, bool use_lock, > > _genpd_power_on(genpd, false); > >+ /* Inform consumers that we have powered on. */ >+ raw_notifier_call_chain(&genpd->power_notifiers, GENPD_STATE_ON, NULL); >+ > genpd->status = GENPD_STATE_ON; > } > >@@ -1593,6 +1619,101 @@ int pm_genpd_remove_device(struct device *dev) > } > EXPORT_SYMBOL_GPL(pm_genpd_remove_device); > >+/** >+ * dev_pm_genpd_add_notifier - Add a genpd power on/off notifier for @dev >+ * >+ * @dev: Device that should be associated with the notifier >+ * @nb: The notifier block to register >+ * >+ * Users may call this function to add a genpd power on/off notifier for an >+ * attached @dev. Only one notifier per device is allowed. The notifier is >+ * sent when genpd is powering on/off the PM domain. >+ * >+ * It is assumed that the user guarantee that the genpd wouldn't be detached >+ * while this routine is getting called. >+ * >+ * Returns 0 on success and negative error values on failures. >+ */ >+int dev_pm_genpd_add_notifier(struct device *dev, struct notifier_block *nb) >+{ >+ struct generic_pm_domain *genpd; >+ struct generic_pm_domain_data *gpd_data; >+ int ret; >+ >+ genpd = dev_to_genpd_safe(dev); >+ if (!genpd) >+ return -ENODEV; >+ >+ if (WARN_ON(!dev->power.subsys_data || >+ !dev->power.subsys_data->domain_data)) >+ return -EINVAL; >+ >+ gpd_data = to_gpd_data(dev->power.subsys_data->domain_data); >+ if (gpd_data->power_nb) >+ return -EEXIST; >+ >+ genpd_lock(genpd); >+ ret = raw_notifier_chain_register(&genpd->power_notifiers, nb); >+ genpd_unlock(genpd); >+ >+ if (ret) { >+ dev_warn(dev, "failed to add notifier for PM domain %s\n", >+ genpd->name); >+ return ret; >+ } >+ >+ gpd_data->power_nb = nb; >+ return 0; >+} >+EXPORT_SYMBOL_GPL(dev_pm_genpd_add_notifier); >+ >+/** >+ * dev_pm_genpd_remove_notifier - Remove a genpd power on/off notifier for @dev >+ * >+ * @dev: Device that is associated with the notifier >+ * >+ * Users may call this function to remove a genpd power on/off notifier for an >+ * attached @dev. >+ * >+ * It is assumed that the user guarantee that the genpd wouldn't be detached >+ * while this routine is getting called. >+ * >+ * Returns 0 on success and negative error values on failures. >+ */ >+int dev_pm_genpd_remove_notifier(struct device *dev) >+{ >+ struct generic_pm_domain *genpd; >+ struct generic_pm_domain_data *gpd_data; >+ int ret; >+ >+ genpd = dev_to_genpd_safe(dev); >+ if (!genpd) >+ return -ENODEV; >+ >+ if (WARN_ON(!dev->power.subsys_data || >+ !dev->power.subsys_data->domain_data)) >+ return -EINVAL; >+ >+ gpd_data = to_gpd_data(dev->power.subsys_data->domain_data); >+ if (!gpd_data->power_nb) >+ return -ENODEV; >+ >+ genpd_lock(genpd); >+ ret = raw_notifier_chain_unregister(&genpd->power_notifiers, >+ gpd_data->power_nb); >+ genpd_unlock(genpd); >+ >+ if (ret) { >+ dev_warn(dev, "failed to remove notifier for PM domain %s\n", >+ genpd->name); >+ return ret; >+ } >+ >+ gpd_data->power_nb = NULL; >+ return 0; >+} >+EXPORT_SYMBOL_GPL(dev_pm_genpd_remove_notifier); >+ > static int genpd_add_subdomain(struct generic_pm_domain *genpd, > struct generic_pm_domain *subdomain) > { >@@ -1763,6 +1884,7 @@ int pm_genpd_init(struct generic_pm_domain *genpd, > INIT_LIST_HEAD(&genpd->parent_links); > INIT_LIST_HEAD(&genpd->child_links); > INIT_LIST_HEAD(&genpd->dev_list); >+ RAW_INIT_NOTIFIER_HEAD(&genpd->power_notifiers); > genpd_lock_init(genpd); > genpd->gov = gov; > INIT_WORK(&genpd->power_off_work, genpd_power_off_work_fn); >diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h >index 66f3c5d64d81..3b2b561ce846 100644 >--- a/include/linux/pm_domain.h >+++ b/include/linux/pm_domain.h >@@ -112,6 +112,7 @@ struct generic_pm_domain { > cpumask_var_t cpus; /* A cpumask of the attached CPUs */ > int (*power_off)(struct generic_pm_domain *domain); > int (*power_on)(struct generic_pm_domain *domain); >+ struct raw_notifier_head power_notifiers; /* Power on/off notifiers */ > struct opp_table *opp_table; /* OPP table of the genpd */ > unsigned int (*opp_to_performance_state)(struct generic_pm_domain *genpd, > struct dev_pm_opp *opp); >@@ -178,6 +179,7 @@ struct generic_pm_domain_data { > struct pm_domain_data base; > struct gpd_timing_data td; > struct notifier_block nb; >+ struct notifier_block *power_nb; > int cpu; > unsigned int performance_state; > void *data; >@@ -204,6 +206,8 @@ int pm_genpd_init(struct generic_pm_domain *genpd, > struct dev_power_governor *gov, bool is_off); > int pm_genpd_remove(struct generic_pm_domain *genpd); > int dev_pm_genpd_set_performance_state(struct device *dev, unsigned int state); >+int dev_pm_genpd_add_notifier(struct device *dev, struct notifier_block *nb); >+int dev_pm_genpd_remove_notifier(struct device *dev); > > extern struct dev_power_governor simple_qos_governor; > extern struct dev_power_governor pm_domain_always_on_gov; >@@ -251,6 +255,17 @@ static inline int dev_pm_genpd_set_performance_state(struct device *dev, > return -ENOTSUPP; > } > >+static inline int dev_pm_genpd_add_notifier(struct device *dev, >+ struct notifier_block *nb) >+{ >+ return -ENOTSUPP; >+} >+ >+static inline int dev_pm_genpd_remove_notifier(struct device *dev) >+{ >+ return -ENOTSUPP; >+} >+ > #define simple_qos_governor (*(struct dev_power_governor *)(NULL)) > #define pm_domain_always_on_gov (*(struct dev_power_governor *)(NULL)) > #endif >-- >2.25.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel