Skip to content

Commit 67732cd

Browse files
Ulf Hanssonrafaeljw
authored andcommitted
PM / Domains: Fix initial default state of the need_restore flag
The initial state of the device's need_restore flag should'nt depend on the current state of the PM domain. For example it should be perfectly valid to attach an inactive device to a powered PM domain. The pm_genpd_dev_need_restore() API allow us to update the need_restore flag to somewhat cope with such scenarios. Typically that should have been done from drivers/buses ->probe() since it's those that put the requirements on the value of the need_restore flag. Until recently, the Exynos SOCs were the only user of the pm_genpd_dev_need_restore() API, though invoking it from a centralized location while adding devices to their PM domains. Due to that Exynos now have swithed to the generic OF-based PM domain look-up, it's no longer possible to invoke the API from a centralized location. The reason is because devices are now added to their PM domains during the probe sequence. Commit "ARM: exynos: Move to generic PM domain DT bindings" did the switch for Exynos to the generic OF-based PM domain look-up, but it also removed the call to pm_genpd_dev_need_restore(). This caused a regression for some of the Exynos drivers. To handle things more properly in the generic PM domain, let's change the default initial value of the need_restore flag to reflect that the state is unknown. As soon as some of the runtime PM callbacks gets invoked, update the initial value accordingly. Moreover, since the generic PM domain is verifying that all devices are both runtime PM enabled and suspended, using pm_runtime_suspended() while pm_genpd_poweroff() is invoked from the scheduled work, we can be sure of that the PM domain won't be powering off while having active devices. Do note that, the generic PM domain can still only know about active devices which has been activated through invoking its runtime PM resume callback. In other words, buses/drivers using pm_runtime_set_active() during ->probe() will still suffer from a race condition, potentially probing a device without having its PM domain being powered. That issue will have to be solved using a different approach. This a log from the boot regression for Exynos5, which is being fixed in this patch. ------------[ cut here ]------------ WARNING: CPU: 0 PID: 308 at ../drivers/clk/clk.c:851 clk_disable+0x24/0x30() Modules linked in: CPU: 0 PID: 308 Comm: kworker/0:1 Not tainted 3.18.0-rc3-00569-gbd9449f-dirty raspberrypi#10 Workqueue: pm pm_runtime_work [<c0013c64>] (unwind_backtrace) from [<c0010dec>] (show_stack+0x10/0x14) [<c0010dec>] (show_stack) from [<c03ee4cc>] (dump_stack+0x70/0xbc) [<c03ee4cc>] (dump_stack) from [<c0020d34>] (warn_slowpath_common+0x64/0x88) [<c0020d34>] (warn_slowpath_common) from [<c0020d74>] (warn_slowpath_null+0x1c/0x24) [<c0020d74>] (warn_slowpath_null) from [<c03107b0>] (clk_disable+0x24/0x30) [<c03107b0>] (clk_disable) from [<c02cc834>] (gsc_runtime_suspend+0x128/0x160) [<c02cc834>] (gsc_runtime_suspend) from [<c0249024>] (pm_generic_runtime_suspend+0x2c/0x38) [<c0249024>] (pm_generic_runtime_suspend) from [<c024f44c>] (pm_genpd_default_save_state+0x2c/0x8c) [<c024f44c>] (pm_genpd_default_save_state) from [<c024ff2c>] (pm_genpd_poweroff+0x224/0x3ec) [<c024ff2c>] (pm_genpd_poweroff) from [<c02501b4>] (pm_genpd_runtime_suspend+0x9c/0xcc) [<c02501b4>] (pm_genpd_runtime_suspend) from [<c024a4f8>] (__rpm_callback+0x2c/0x60) [<c024a4f8>] (__rpm_callback) from [<c024a54c>] (rpm_callback+0x20/0x74) [<c024a54c>] (rpm_callback) from [<c024a930>] (rpm_suspend+0xd4/0x43c) [<c024a930>] (rpm_suspend) from [<c024bbcc>] (pm_runtime_work+0x80/0x90) [<c024bbcc>] (pm_runtime_work) from [<c0032a9c>] (process_one_work+0x12c/0x314) [<c0032a9c>] (process_one_work) from [<c0032cf4>] (worker_thread+0x3c/0x4b0) [<c0032cf4>] (worker_thread) from [<c003747c>] (kthread+0xcc/0xe8) [<c003747c>] (kthread) from [<c000e738>] (ret_from_fork+0x14/0x3c) ---[ end trace 40cd58bcd6988f12 ]--- Fixes: a4a8c2c (ARM: exynos: Move to generic PM domain DT bindings) Reported-and-tested0by: Sylwester Nawrocki <s.nawrocki@samsung.com> Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com> Reviewed-by: Kevin Hilman <khilman@linaro.org> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent c16561e commit 67732cd

2 files changed

Lines changed: 33 additions & 7 deletions

File tree

‎drivers/base/power/domain.c‎

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,19 @@ static int __pm_genpd_save_device(struct pm_domain_data *pdd,
361361
struct device *dev = pdd->dev;
362362
int ret = 0;
363363

364-
if (gpd_data->need_restore)
364+
if (gpd_data->need_restore > 0)
365365
return 0;
366366

367+
/*
368+
* If the value of the need_restore flag is still unknown at this point,
369+
* we trust that pm_genpd_poweroff() has verified that the device is
370+
* already runtime PM suspended.
371+
*/
372+
if (gpd_data->need_restore < 0) {
373+
gpd_data->need_restore = 1;
374+
return 0;
375+
}
376+
367377
mutex_unlock(&genpd->lock);
368378

369379
genpd_start_dev(genpd, dev);
@@ -373,7 +383,7 @@ static int __pm_genpd_save_device(struct pm_domain_data *pdd,
373383
mutex_lock(&genpd->lock);
374384

375385
if (!ret)
376-
gpd_data->need_restore = true;
386+
gpd_data->need_restore = 1;
377387

378388
return ret;
379389
}
@@ -389,12 +399,17 @@ static void __pm_genpd_restore_device(struct pm_domain_data *pdd,
389399
{
390400
struct generic_pm_domain_data *gpd_data = to_gpd_data(pdd);
391401
struct device *dev = pdd->dev;
392-
bool need_restore = gpd_data->need_restore;
402+
int need_restore = gpd_data->need_restore;
393403

394-
gpd_data->need_restore = false;
404+
gpd_data->need_restore = 0;
395405
mutex_unlock(&genpd->lock);
396406

397407
genpd_start_dev(genpd, dev);
408+
409+
/*
410+
* Call genpd_restore_dev() for recently added devices too (need_restore
411+
* is negative then).
412+
*/
398413
if (need_restore)
399414
genpd_restore_dev(genpd, dev);
400415

@@ -603,6 +618,7 @@ static void genpd_power_off_work_fn(struct work_struct *work)
603618
static int pm_genpd_runtime_suspend(struct device *dev)
604619
{
605620
struct generic_pm_domain *genpd;
621+
struct generic_pm_domain_data *gpd_data;
606622
bool (*stop_ok)(struct device *__dev);
607623
int ret;
608624

@@ -628,6 +644,16 @@ static int pm_genpd_runtime_suspend(struct device *dev)
628644
return 0;
629645

630646
mutex_lock(&genpd->lock);
647+
648+
/*
649+
* If we have an unknown state of the need_restore flag, it means none
650+
* of the runtime PM callbacks has been invoked yet. Let's update the
651+
* flag to reflect that the current state is active.
652+
*/
653+
gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
654+
if (gpd_data->need_restore < 0)
655+
gpd_data->need_restore = 0;
656+
631657
genpd->in_progress++;
632658
pm_genpd_poweroff(genpd);
633659
genpd->in_progress--;
@@ -1442,7 +1468,7 @@ int __pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev,
14421468
mutex_lock(&gpd_data->lock);
14431469
gpd_data->base.dev = dev;
14441470
list_add_tail(&gpd_data->base.list_node, &genpd->dev_list);
1445-
gpd_data->need_restore = genpd->status == GPD_STATE_POWER_OFF;
1471+
gpd_data->need_restore = -1;
14461472
gpd_data->td.constraint_changed = true;
14471473
gpd_data->td.effective_constraint_ns = -1;
14481474
mutex_unlock(&gpd_data->lock);
@@ -1546,7 +1572,7 @@ void pm_genpd_dev_need_restore(struct device *dev, bool val)
15461572

15471573
psd = dev_to_psd(dev);
15481574
if (psd && psd->domain_data)
1549-
to_gpd_data(psd->domain_data)->need_restore = val;
1575+
to_gpd_data(psd->domain_data)->need_restore = val ? 1 : 0;
15501576

15511577
spin_unlock_irqrestore(&dev->power.lock, flags);
15521578
}

‎include/linux/pm_domain.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ struct generic_pm_domain_data {
106106
struct notifier_block nb;
107107
struct mutex lock;
108108
unsigned int refcount;
109-
bool need_restore;
109+
int need_restore;
110110
};
111111

112112
#ifdef CONFIG_PM_GENERIC_DOMAINS

0 commit comments

Comments
 (0)