Skip to content

Commit

Permalink
Merge branches 'pm-sleep' and 'pm-domains'
Browse files Browse the repository at this point in the history
* pm-sleep:
  PM / watchdog: iTCO: stop watchdog during system suspend
  PM / sleep: add pm-trace support for suspending phase
  PM / sleep: add configurable delay for pm_test

* pm-domains:
  PM / domains: avoid potential oops in pm_genpd_remove_device()
  PM / domains: factor out code to get the generic PM domain from a struct device
  PM / domains: quieten down generic pm domains
  PM / Domains: Sync runtime PM status with genpd after probe
  driver core / PM: Add PM domain callbacks for device setup/cleanup
  MAINTAINERS: add entry for Generic PM domains (genpd)
  • Loading branch information
Rafael J. Wysocki committed Apr 12, 2015
3 parents 419a48c + be77002 + df6a0d6 commit 0fe0952
Show file tree
Hide file tree
Showing 14 changed files with 189 additions and 46 deletions.
7 changes: 7 additions & 0 deletions Documentation/kernel-parameters.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3462,6 +3462,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
improve throughput, but will also increase the
amount of memory reserved for use by the client.

suspend.pm_test_delay=
[SUSPEND]
Sets the number of seconds to remain in a suspend test
mode before resuming the system (see
/sys/power/pm_test). Only available when CONFIG_PM_DEBUG
is set. Default value is 5.

swapaccount=[0|1]
[KNL] Enable accounting of swap in memory resource
controller if no parameter or 1 is given or disable
Expand Down
10 changes: 6 additions & 4 deletions Documentation/power/basic-pm-debugging.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ you should do the following:
# echo platform > /sys/power/disk
# echo disk > /sys/power/state

Then, the kernel will try to freeze processes, suspend devices, wait 5 seconds,
resume devices and thaw processes. If "platform" is written to
Then, the kernel will try to freeze processes, suspend devices, wait a few
seconds (5 by default, but configurable by the suspend.pm_test_delay module
parameter), resume devices and thaw processes. If "platform" is written to
/sys/power/pm_test , then after suspending devices the kernel will additionally
invoke the global control methods (eg. ACPI global control methods) used to
prepare the platform firmware for hibernation. Next, it will wait 5 seconds and
invoke the platform (eg. ACPI) global methods used to cancel hibernation etc.
prepare the platform firmware for hibernation. Next, it will wait a
configurable number of seconds and invoke the platform (eg. ACPI) global
methods used to cancel hibernation etc.

Writing "none" to /sys/power/pm_test causes the kernel to switch to the normal
hibernation/suspend operations. Also, when open for reading, /sys/power/pm_test
Expand Down
9 changes: 9 additions & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -4312,6 +4312,15 @@ S: Supported
F: drivers/phy/
F: include/linux/phy/

GENERIC PM DOMAINS
M: "Rafael J. Wysocki" <rjw@rjwysocki.net>
M: Kevin Hilman <khilman@kernel.org>
M: Ulf Hansson <ulf.hansson@linaro.org>
L: linux-pm@vger.kernel.org
S: Supported
F: drivers/base/power/domain*.c
F: include/linux/pm_domain.h

GENERIC UIO DRIVER FOR PCI DEVICES
M: "Michael S. Tsirkin" <mst@redhat.com>
L: kvm@vger.kernel.org
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _ASM_X86_RESUME_TRACE_H
#define _ASM_X86_RESUME_TRACE_H
#ifndef _ASM_X86_PM_TRACE_H
#define _ASM_X86_PM_TRACE_H

#include <asm/asm.h>

Expand All @@ -14,8 +14,10 @@ do { \
".previous" \
:"=r" (tracedata) \
: "i" (__LINE__), "i" (__FILE__)); \
generate_resume_trace(tracedata, user); \
generate_pm_trace(tracedata, user); \
} \
} while (0)

#endif /* _ASM_X86_RESUME_TRACE_H */
#define TRACE_SUSPEND(user) TRACE_RESUME(user)

#endif /* _ASM_X86_PM_TRACE_H */
14 changes: 14 additions & 0 deletions drivers/base/dd.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,12 @@ static int really_probe(struct device *dev, struct device_driver *drv)
goto probe_failed;
}

if (dev->pm_domain && dev->pm_domain->activate) {
ret = dev->pm_domain->activate(dev);
if (ret)
goto probe_failed;
}

if (dev->bus->probe) {
ret = dev->bus->probe(dev);
if (ret)
Expand All @@ -308,6 +314,9 @@ static int really_probe(struct device *dev, struct device_driver *drv)
goto probe_failed;
}

if (dev->pm_domain && dev->pm_domain->sync)
dev->pm_domain->sync(dev);

driver_bound(dev);
ret = 1;
pr_debug("bus: '%s': %s: bound device %s to driver %s\n",
Expand All @@ -319,6 +328,8 @@ static int really_probe(struct device *dev, struct device_driver *drv)
driver_sysfs_remove(dev);
dev->driver = NULL;
dev_set_drvdata(dev, NULL);
if (dev->pm_domain && dev->pm_domain->dismiss)
dev->pm_domain->dismiss(dev);

if (ret == -EPROBE_DEFER) {
/* Driver requested deferred probing */
Expand Down Expand Up @@ -525,6 +536,9 @@ static void __device_release_driver(struct device *dev)
devres_release_all(dev);
dev->driver = NULL;
dev_set_drvdata(dev, NULL);
if (dev->pm_domain && dev->pm_domain->dismiss)
dev->pm_domain->dismiss(dev);

klist_remove(&dev->p->knode_driver);
if (dev->bus)
blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
Expand Down
70 changes: 49 additions & 21 deletions drivers/base/power/domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,36 @@ static struct generic_pm_domain *pm_genpd_lookup_name(const char *domain_name)
return genpd;
}

struct generic_pm_domain *dev_to_genpd(struct device *dev)
/*
* Get the generic PM domain for a particular struct device.
* This validates the struct device pointer, the PM domain pointer,
* and checks that the PM domain pointer is a real generic PM domain.
* Any failure results in NULL being returned.
*/
struct generic_pm_domain *pm_genpd_lookup_dev(struct device *dev)
{
struct generic_pm_domain *genpd = NULL, *gpd;

if (IS_ERR_OR_NULL(dev) || IS_ERR_OR_NULL(dev->pm_domain))
return NULL;

mutex_lock(&gpd_list_lock);
list_for_each_entry(gpd, &gpd_list, gpd_list_node) {
if (&gpd->domain == dev->pm_domain) {
genpd = gpd;
break;
}
}
mutex_unlock(&gpd_list_lock);

return genpd;
}

/*
* This should only be used where we are certain that the pm_domain
* attached to the device is a genpd domain.
*/
static struct generic_pm_domain *dev_to_genpd(struct device *dev)
{
if (IS_ERR_OR_NULL(dev->pm_domain))
return ERR_PTR(-EINVAL);
Expand Down Expand Up @@ -173,8 +202,8 @@ static int genpd_power_on(struct generic_pm_domain *genpd)
genpd->power_on_latency_ns = elapsed_ns;
genpd->max_off_time_changed = true;
genpd_recalc_cpu_exit_latency(genpd);
pr_warn("%s: Power-%s latency exceeded, new value %lld ns\n",
genpd->name, "on", elapsed_ns);
pr_debug("%s: Power-%s latency exceeded, new value %lld ns\n",
genpd->name, "on", elapsed_ns);

return ret;
}
Expand All @@ -199,8 +228,8 @@ static int genpd_power_off(struct generic_pm_domain *genpd)

genpd->power_off_latency_ns = elapsed_ns;
genpd->max_off_time_changed = true;
pr_warn("%s: Power-%s latency exceeded, new value %lld ns\n",
genpd->name, "off", elapsed_ns);
pr_debug("%s: Power-%s latency exceeded, new value %lld ns\n",
genpd->name, "off", elapsed_ns);

return ret;
}
Expand Down Expand Up @@ -1513,9 +1542,7 @@ int pm_genpd_remove_device(struct generic_pm_domain *genpd,

dev_dbg(dev, "%s()\n", __func__);

if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(dev)
|| IS_ERR_OR_NULL(dev->pm_domain)
|| pd_to_genpd(dev->pm_domain) != genpd)
if (!genpd || genpd != pm_genpd_lookup_dev(dev))
return -EINVAL;

/* The above validation also means we have existing domain_data. */
Expand Down Expand Up @@ -2093,21 +2120,10 @@ EXPORT_SYMBOL_GPL(of_genpd_get_from_provider);
*/
static void genpd_dev_pm_detach(struct device *dev, bool power_off)
{
struct generic_pm_domain *pd = NULL, *gpd;
struct generic_pm_domain *pd;
int ret = 0;

if (!dev->pm_domain)
return;

mutex_lock(&gpd_list_lock);
list_for_each_entry(gpd, &gpd_list, gpd_list_node) {
if (&gpd->domain == dev->pm_domain) {
pd = gpd;
break;
}
}
mutex_unlock(&gpd_list_lock);

pd = pm_genpd_lookup_dev(dev);
if (!pd)
return;

Expand All @@ -2130,6 +2146,17 @@ static void genpd_dev_pm_detach(struct device *dev, bool power_off)
genpd_queue_power_off_work(pd);
}

static void genpd_dev_pm_sync(struct device *dev)
{
struct generic_pm_domain *pd;

pd = dev_to_genpd(dev);
if (IS_ERR(pd))
return;

genpd_queue_power_off_work(pd);
}

/**
* genpd_dev_pm_attach - Attach a device to its PM domain using DT.
* @dev: Device to attach.
Expand Down Expand Up @@ -2196,6 +2223,7 @@ int genpd_dev_pm_attach(struct device *dev)
}

dev->pm_domain->detach = genpd_dev_pm_detach;
dev->pm_domain->sync = genpd_dev_pm_sync;
pm_genpd_poweron(pd);

return 0;
Expand Down
20 changes: 16 additions & 4 deletions drivers/base/power/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <linux/mutex.h>
#include <linux/pm.h>
#include <linux/pm_runtime.h>
#include <linux/resume-trace.h>
#include <linux/pm-trace.h>
#include <linux/interrupt.h>
#include <linux/sched.h>
#include <linux/async.h>
Expand Down Expand Up @@ -1017,6 +1017,9 @@ static int __device_suspend_noirq(struct device *dev, pm_message_t state, bool a
char *info = NULL;
int error = 0;

TRACE_DEVICE(dev);
TRACE_SUSPEND(0);

if (async_error)
goto Complete;

Expand Down Expand Up @@ -1057,6 +1060,7 @@ static int __device_suspend_noirq(struct device *dev, pm_message_t state, bool a

Complete:
complete_all(&dev->power.completion);
TRACE_SUSPEND(error);
return error;
}

Expand All @@ -1078,7 +1082,7 @@ static int device_suspend_noirq(struct device *dev)
{
reinit_completion(&dev->power.completion);

if (pm_async_enabled && dev->power.async_suspend) {
if (is_async(dev)) {
get_device(dev);
async_schedule(async_suspend_noirq, dev);
return 0;
Expand Down Expand Up @@ -1157,6 +1161,9 @@ static int __device_suspend_late(struct device *dev, pm_message_t state, bool as
char *info = NULL;
int error = 0;

TRACE_DEVICE(dev);
TRACE_SUSPEND(0);

__pm_runtime_disable(dev, false);

if (async_error)
Expand Down Expand Up @@ -1198,6 +1205,7 @@ static int __device_suspend_late(struct device *dev, pm_message_t state, bool as
async_error = error;

Complete:
TRACE_SUSPEND(error);
complete_all(&dev->power.completion);
return error;
}
Expand All @@ -1219,7 +1227,7 @@ static int device_suspend_late(struct device *dev)
{
reinit_completion(&dev->power.completion);

if (pm_async_enabled && dev->power.async_suspend) {
if (is_async(dev)) {
get_device(dev);
async_schedule(async_suspend_late, dev);
return 0;
Expand Down Expand Up @@ -1338,6 +1346,9 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
int error = 0;
DECLARE_DPM_WATCHDOG_ON_STACK(wd);

TRACE_DEVICE(dev);
TRACE_SUSPEND(0);

dpm_wait_for_children(dev, async);

if (async_error)
Expand Down Expand Up @@ -1444,6 +1455,7 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
if (error)
async_error = error;

TRACE_SUSPEND(error);
return error;
}

Expand All @@ -1465,7 +1477,7 @@ static int device_suspend(struct device *dev)
{
reinit_completion(&dev->power.completion);

if (pm_async_enabled && dev->power.async_suspend) {
if (is_async(dev)) {
get_device(dev);
async_schedule(async_suspend, dev);
return 0;
Expand Down
6 changes: 3 additions & 3 deletions drivers/base/power/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* devices may be working.
*/

#include <linux/resume-trace.h>
#include <linux/pm-trace.h>
#include <linux/export.h>
#include <linux/rtc.h>

Expand Down Expand Up @@ -154,7 +154,7 @@ EXPORT_SYMBOL(set_trace_device);
* it's not any guarantee, but it's a high _likelihood_ that
* the match is valid).
*/
void generate_resume_trace(const void *tracedata, unsigned int user)
void generate_pm_trace(const void *tracedata, unsigned int user)
{
unsigned short lineno = *(unsigned short *)tracedata;
const char *file = *(const char **)(tracedata + 2);
Expand All @@ -164,7 +164,7 @@ void generate_resume_trace(const void *tracedata, unsigned int user)
file_hash_value = hash_string(lineno, file, FILEHASH);
set_magic_time(user_hash_value, file_hash_value, dev_hash_value);
}
EXPORT_SYMBOL(generate_resume_trace);
EXPORT_SYMBOL(generate_pm_trace);

extern char __tracedata_start, __tracedata_end;
static int show_file_hash(unsigned int value)
Expand Down
Loading

0 comments on commit 0fe0952

Please sign in to comment.