Skip to content

Commit d09fcec

Browse files
committed
Merge tag 'pm-4.18-rc1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull more power management updates from Rafael Wysocki: "These revert a recent PM core change that introduced a regression, fix the build when the recently added Kryo cpufreq driver is selected, add support for devices attached to multiple power domains to the generic power domains (genpd) framework, add support for iowait boosting on systens with hardware-managed P-states (HWP) enabled to the intel_pstate driver, modify the behavior of the wakeup_count device attribute in sysfs, fix a few issues and clean up some ugliness, mostly in cpufreq (core and drivers) and in the cpupower utility. Specifics: - Revert a recent PM core change that attempted to fix an issue related to device links, but introduced a regression (Rafael Wysocki) - Fix build when the recently added cpufreq driver for Kryo processors is selected by making it possible to build that driver as a module (Arnd Bergmann) - Fix the long idle detection mechanism in the out-of-band (ondemand and conservative) cpufreq governors (Chen Yu) - Add support for devices in multiple power domains to the generic power domains (genpd) framework (Ulf Hansson) - Add support for iowait boosting on systems with hardware-managed P-states (HWP) enabled to the intel_pstate driver and make it use that feature on systems with Skylake Xeon processors as it is reported to improve performance significantly on those systems (Srinivas Pandruvada) - Fix and update the acpi_cpufreq, ti-cpufreq and imx6q cpufreq drivers (Colin Ian King, Suman Anna, Sébastien Szymanski) - Change the behavior of the wakeup_count device attribute in sysfs to expose the number of events when the device might have aborted system suspend in progress (Ravi Chandra Sadineni) - Fix two minor issues in the cpupower utility (Abhishek Goel, Colin Ian King)" * tag 'pm-4.18-rc1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: Revert "PM / runtime: Fixup reference counting of device link suppliers at probe" cpufreq: imx6q: check speed grades for i.MX6ULL cpufreq: governors: Fix long idle detection logic in load calculation cpufreq: intel_pstate: enable boost for Skylake Xeon PM / wakeup: Export wakeup_count instead of event_count via sysfs PM / Domains: Add dev_pm_domain_attach_by_id() to manage multi PM domains PM / Domains: Add support for multi PM domains per device to genpd PM / Domains: Split genpd_dev_pm_attach() PM / Domains: Don't attach devices in genpd with multi PM domains PM / Domains: dt: Allow power-domain property to be a list of specifiers cpufreq: intel_pstate: New sysfs entry to control HWP boost cpufreq: intel_pstate: HWP boost performance on IO wakeup cpufreq: intel_pstate: Add HWP boost utility and sched util hooks cpufreq: ti-cpufreq: Use devres managed API in probe() cpufreq: ti-cpufreq: Fix an incorrect error return value cpufreq: ACPI: make function acpi_cpufreq_fast_switch() static cpufreq: kryo: allow building as a loadable module cpupower : Fix header name to read idle state name cpupower: fix spelling mistake: "logilename" -> "logfilename"
2 parents f5b7769 + 6a900f8 commit d09fcec

File tree

18 files changed

+468
-75
lines changed

18 files changed

+468
-75
lines changed

Documentation/devicetree/bindings/power/power_domain.txt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ Example 3:
111111
==PM domain consumers==
112112

113113
Required properties:
114-
- power-domains : A phandle and PM domain specifier as defined by bindings of
115-
the power controller specified by phandle.
114+
- power-domains : A list of PM domain specifiers, as defined by bindings of
115+
the power controller that is the PM domain provider.
116116

117117
Example:
118118

@@ -122,9 +122,18 @@ Example:
122122
power-domains = <&power 0>;
123123
};
124124

125-
The node above defines a typical PM domain consumer device, which is located
126-
inside a PM domain with index 0 of a power controller represented by a node
127-
with the label "power".
125+
leaky-device@12351000 {
126+
compatible = "foo,i-leak-current";
127+
reg = <0x12351000 0x1000>;
128+
power-domains = <&power 0>, <&power 1> ;
129+
};
130+
131+
The first example above defines a typical PM domain consumer device, which is
132+
located inside a PM domain with index 0 of a power controller represented by a
133+
node with the label "power".
134+
In the second example the consumer device are partitioned across two PM domains,
135+
the first with index 0 and the second with index 1, of a power controller that
136+
is represented by a node with the label "power.
128137

129138
Optional properties:
130139
- required-opps: This contains phandle to an OPP node in another device's OPP

drivers/base/dd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ int driver_probe_device(struct device_driver *drv, struct device *dev)
580580
pr_debug("bus: '%s': %s: matched device %s with driver %s\n",
581581
drv->bus->name, __func__, dev_name(dev), drv->name);
582582

583-
pm_runtime_resume_suppliers(dev);
583+
pm_runtime_get_suppliers(dev);
584584
if (dev->parent)
585585
pm_runtime_get_sync(dev->parent);
586586

@@ -591,6 +591,7 @@ int driver_probe_device(struct device_driver *drv, struct device *dev)
591591
if (dev->parent)
592592
pm_runtime_put(dev->parent);
593593

594+
pm_runtime_put_suppliers(dev);
594595
return ret;
595596
}
596597

drivers/base/power/common.c

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,51 @@ int dev_pm_domain_attach(struct device *dev, bool power_on)
116116
}
117117
EXPORT_SYMBOL_GPL(dev_pm_domain_attach);
118118

119+
/**
120+
* dev_pm_domain_attach_by_id - Associate a device with one of its PM domains.
121+
* @dev: The device used to lookup the PM domain.
122+
* @index: The index of the PM domain.
123+
*
124+
* As @dev may only be attached to a single PM domain, the backend PM domain
125+
* provider creates a virtual device to attach instead. If attachment succeeds,
126+
* the ->detach() callback in the struct dev_pm_domain are assigned by the
127+
* corresponding backend attach function, as to deal with detaching of the
128+
* created virtual device.
129+
*
130+
* This function should typically be invoked by a driver during the probe phase,
131+
* in case its device requires power management through multiple PM domains. The
132+
* driver may benefit from using the received device, to configure device-links
133+
* towards its original device. Depending on the use-case and if needed, the
134+
* links may be dynamically changed by the driver, which allows it to control
135+
* the power to the PM domains independently from each other.
136+
*
137+
* Callers must ensure proper synchronization of this function with power
138+
* management callbacks.
139+
*
140+
* Returns the virtual created device when successfully attached to its PM
141+
* domain, NULL in case @dev don't need a PM domain, else an ERR_PTR().
142+
* Note that, to detach the returned virtual device, the driver shall call
143+
* dev_pm_domain_detach() on it, typically during the remove phase.
144+
*/
145+
struct device *dev_pm_domain_attach_by_id(struct device *dev,
146+
unsigned int index)
147+
{
148+
if (dev->pm_domain)
149+
return ERR_PTR(-EEXIST);
150+
151+
return genpd_dev_pm_attach_by_id(dev, index);
152+
}
153+
EXPORT_SYMBOL_GPL(dev_pm_domain_attach_by_id);
154+
119155
/**
120156
* dev_pm_domain_detach - Detach a device from its PM domain.
121157
* @dev: Device to detach.
122158
* @power_off: Used to indicate whether we should power off the device.
123159
*
124-
* This functions will reverse the actions from dev_pm_domain_attach() and thus
125-
* try to detach the @dev from its PM domain. Typically it should be invoked
126-
* from subsystem level code during the remove phase.
160+
* This functions will reverse the actions from dev_pm_domain_attach() and
161+
* dev_pm_domain_attach_by_id(), thus it detaches @dev from its PM domain.
162+
* Typically it should be invoked during the remove phase, either from
163+
* subsystem level code or from drivers.
127164
*
128165
* Callers must ensure proper synchronization of this function with power
129166
* management callbacks.

drivers/base/power/domain.c

Lines changed: 114 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2171,6 +2171,15 @@ struct generic_pm_domain *of_genpd_remove_last(struct device_node *np)
21712171
}
21722172
EXPORT_SYMBOL_GPL(of_genpd_remove_last);
21732173

2174+
static void genpd_release_dev(struct device *dev)
2175+
{
2176+
kfree(dev);
2177+
}
2178+
2179+
static struct bus_type genpd_bus_type = {
2180+
.name = "genpd",
2181+
};
2182+
21742183
/**
21752184
* genpd_dev_pm_detach - Detach a device from its PM domain.
21762185
* @dev: Device to detach.
@@ -2208,6 +2217,10 @@ static void genpd_dev_pm_detach(struct device *dev, bool power_off)
22082217

22092218
/* Check if PM domain can be powered off after removing this device. */
22102219
genpd_queue_power_off_work(pd);
2220+
2221+
/* Unregister the device if it was created by genpd. */
2222+
if (dev->bus == &genpd_bus_type)
2223+
device_unregister(dev);
22112224
}
22122225

22132226
static void genpd_dev_pm_sync(struct device *dev)
@@ -2221,32 +2234,17 @@ static void genpd_dev_pm_sync(struct device *dev)
22212234
genpd_queue_power_off_work(pd);
22222235
}
22232236

2224-
/**
2225-
* genpd_dev_pm_attach - Attach a device to its PM domain using DT.
2226-
* @dev: Device to attach.
2227-
*
2228-
* Parse device's OF node to find a PM domain specifier. If such is found,
2229-
* attaches the device to retrieved pm_domain ops.
2230-
*
2231-
* Returns 1 on successfully attached PM domain, 0 when the device don't need a
2232-
* PM domain or a negative error code in case of failures. Note that if a
2233-
* power-domain exists for the device, but it cannot be found or turned on,
2234-
* then return -EPROBE_DEFER to ensure that the device is not probed and to
2235-
* re-try again later.
2236-
*/
2237-
int genpd_dev_pm_attach(struct device *dev)
2237+
static int __genpd_dev_pm_attach(struct device *dev, struct device_node *np,
2238+
unsigned int index)
22382239
{
22392240
struct of_phandle_args pd_args;
22402241
struct generic_pm_domain *pd;
22412242
int ret;
22422243

2243-
if (!dev->of_node)
2244-
return 0;
2245-
2246-
ret = of_parse_phandle_with_args(dev->of_node, "power-domains",
2247-
"#power-domain-cells", 0, &pd_args);
2244+
ret = of_parse_phandle_with_args(np, "power-domains",
2245+
"#power-domain-cells", index, &pd_args);
22482246
if (ret < 0)
2249-
return 0;
2247+
return ret;
22502248

22512249
mutex_lock(&gpd_list_lock);
22522250
pd = genpd_get_from_provider(&pd_args);
@@ -2282,8 +2280,98 @@ int genpd_dev_pm_attach(struct device *dev)
22822280

22832281
return ret ? -EPROBE_DEFER : 1;
22842282
}
2283+
2284+
/**
2285+
* genpd_dev_pm_attach - Attach a device to its PM domain using DT.
2286+
* @dev: Device to attach.
2287+
*
2288+
* Parse device's OF node to find a PM domain specifier. If such is found,
2289+
* attaches the device to retrieved pm_domain ops.
2290+
*
2291+
* Returns 1 on successfully attached PM domain, 0 when the device don't need a
2292+
* PM domain or when multiple power-domains exists for it, else a negative error
2293+
* code. Note that if a power-domain exists for the device, but it cannot be
2294+
* found or turned on, then return -EPROBE_DEFER to ensure that the device is
2295+
* not probed and to re-try again later.
2296+
*/
2297+
int genpd_dev_pm_attach(struct device *dev)
2298+
{
2299+
if (!dev->of_node)
2300+
return 0;
2301+
2302+
/*
2303+
* Devices with multiple PM domains must be attached separately, as we
2304+
* can only attach one PM domain per device.
2305+
*/
2306+
if (of_count_phandle_with_args(dev->of_node, "power-domains",
2307+
"#power-domain-cells") != 1)
2308+
return 0;
2309+
2310+
return __genpd_dev_pm_attach(dev, dev->of_node, 0);
2311+
}
22852312
EXPORT_SYMBOL_GPL(genpd_dev_pm_attach);
22862313

2314+
/**
2315+
* genpd_dev_pm_attach_by_id - Associate a device with one of its PM domains.
2316+
* @dev: The device used to lookup the PM domain.
2317+
* @index: The index of the PM domain.
2318+
*
2319+
* Parse device's OF node to find a PM domain specifier at the provided @index.
2320+
* If such is found, creates a virtual device and attaches it to the retrieved
2321+
* pm_domain ops. To deal with detaching of the virtual device, the ->detach()
2322+
* callback in the struct dev_pm_domain are assigned to genpd_dev_pm_detach().
2323+
*
2324+
* Returns the created virtual device if successfully attached PM domain, NULL
2325+
* when the device don't need a PM domain, else an ERR_PTR() in case of
2326+
* failures. If a power-domain exists for the device, but cannot be found or
2327+
* turned on, then ERR_PTR(-EPROBE_DEFER) is returned to ensure that the device
2328+
* is not probed and to re-try again later.
2329+
*/
2330+
struct device *genpd_dev_pm_attach_by_id(struct device *dev,
2331+
unsigned int index)
2332+
{
2333+
struct device *genpd_dev;
2334+
int num_domains;
2335+
int ret;
2336+
2337+
if (!dev->of_node)
2338+
return NULL;
2339+
2340+
/* Deal only with devices using multiple PM domains. */
2341+
num_domains = of_count_phandle_with_args(dev->of_node, "power-domains",
2342+
"#power-domain-cells");
2343+
if (num_domains < 2 || index >= num_domains)
2344+
return NULL;
2345+
2346+
/* Allocate and register device on the genpd bus. */
2347+
genpd_dev = kzalloc(sizeof(*genpd_dev), GFP_KERNEL);
2348+
if (!genpd_dev)
2349+
return ERR_PTR(-ENOMEM);
2350+
2351+
dev_set_name(genpd_dev, "genpd:%u:%s", index, dev_name(dev));
2352+
genpd_dev->bus = &genpd_bus_type;
2353+
genpd_dev->release = genpd_release_dev;
2354+
2355+
ret = device_register(genpd_dev);
2356+
if (ret) {
2357+
kfree(genpd_dev);
2358+
return ERR_PTR(ret);
2359+
}
2360+
2361+
/* Try to attach the device to the PM domain at the specified index. */
2362+
ret = __genpd_dev_pm_attach(genpd_dev, dev->of_node, index);
2363+
if (ret < 1) {
2364+
device_unregister(genpd_dev);
2365+
return ret ? ERR_PTR(ret) : NULL;
2366+
}
2367+
2368+
pm_runtime_set_active(genpd_dev);
2369+
pm_runtime_enable(genpd_dev);
2370+
2371+
return genpd_dev;
2372+
}
2373+
EXPORT_SYMBOL_GPL(genpd_dev_pm_attach_by_id);
2374+
22872375
static const struct of_device_id idle_state_match[] = {
22882376
{ .compatible = "domain-idle-state", },
22892377
{ }
@@ -2443,6 +2531,12 @@ unsigned int of_genpd_opp_to_performance_state(struct device *dev,
24432531
}
24442532
EXPORT_SYMBOL_GPL(of_genpd_opp_to_performance_state);
24452533

2534+
static int __init genpd_bus_init(void)
2535+
{
2536+
return bus_register(&genpd_bus_type);
2537+
}
2538+
core_initcall(genpd_bus_init);
2539+
24462540
#endif /* CONFIG_PM_GENERIC_DOMAINS_OF */
24472541

24482542

drivers/base/power/runtime.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,16 +1563,37 @@ void pm_runtime_clean_up_links(struct device *dev)
15631563
}
15641564

15651565
/**
1566-
* pm_runtime_resume_suppliers - Resume supplier devices.
1566+
* pm_runtime_get_suppliers - Resume and reference-count supplier devices.
15671567
* @dev: Consumer device.
15681568
*/
1569-
void pm_runtime_resume_suppliers(struct device *dev)
1569+
void pm_runtime_get_suppliers(struct device *dev)
15701570
{
1571+
struct device_link *link;
15711572
int idx;
15721573

15731574
idx = device_links_read_lock();
15741575

1575-
rpm_get_suppliers(dev);
1576+
list_for_each_entry_rcu(link, &dev->links.suppliers, c_node)
1577+
if (link->flags & DL_FLAG_PM_RUNTIME)
1578+
pm_runtime_get_sync(link->supplier);
1579+
1580+
device_links_read_unlock(idx);
1581+
}
1582+
1583+
/**
1584+
* pm_runtime_put_suppliers - Drop references to supplier devices.
1585+
* @dev: Consumer device.
1586+
*/
1587+
void pm_runtime_put_suppliers(struct device *dev)
1588+
{
1589+
struct device_link *link;
1590+
int idx;
1591+
1592+
idx = device_links_read_lock();
1593+
1594+
list_for_each_entry_rcu(link, &dev->links.suppliers, c_node)
1595+
if (link->flags & DL_FLAG_PM_RUNTIME)
1596+
pm_runtime_put(link->supplier);
15761597

15771598
device_links_read_unlock(idx);
15781599
}

drivers/base/power/sysfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ static ssize_t wakeup_count_show(struct device *dev,
353353

354354
spin_lock_irq(&dev->power.lock);
355355
if (dev->power.wakeup) {
356-
count = dev->power.wakeup->event_count;
356+
count = dev->power.wakeup->wakeup_count;
357357
enabled = true;
358358
}
359359
spin_unlock_irq(&dev->power.lock);

drivers/cpufreq/Kconfig.arm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ config ARM_OMAP2PLUS_CPUFREQ
125125
default ARCH_OMAP2PLUS
126126

127127
config ARM_QCOM_CPUFREQ_KRYO
128-
bool "Qualcomm Kryo based CPUFreq"
128+
tristate "Qualcomm Kryo based CPUFreq"
129129
depends on ARM64
130130
depends on QCOM_QFPROM
131131
depends on QCOM_SMEM

drivers/cpufreq/acpi-cpufreq.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,8 @@ static int acpi_cpufreq_target(struct cpufreq_policy *policy,
465465
return result;
466466
}
467467

468-
unsigned int acpi_cpufreq_fast_switch(struct cpufreq_policy *policy,
469-
unsigned int target_freq)
468+
static unsigned int acpi_cpufreq_fast_switch(struct cpufreq_policy *policy,
469+
unsigned int target_freq)
470470
{
471471
struct acpi_cpufreq_data *data = policy->driver_data;
472472
struct acpi_processor_performance *perf;

drivers/cpufreq/cpufreq_governor.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ unsigned int dbs_update(struct cpufreq_policy *policy)
165165
* calls, so the previous load value can be used then.
166166
*/
167167
load = j_cdbs->prev_load;
168-
} else if (unlikely(time_elapsed > 2 * sampling_rate &&
168+
} else if (unlikely((int)idle_time > 2 * sampling_rate &&
169169
j_cdbs->prev_load)) {
170170
/*
171171
* If the CPU had gone completely idle and a task has
@@ -185,10 +185,8 @@ unsigned int dbs_update(struct cpufreq_policy *policy)
185185
* clear prev_load to guarantee that the load will be
186186
* computed again next time.
187187
*
188-
* Detecting this situation is easy: the governor's
189-
* utilization update handler would not have run during
190-
* CPU-idle periods. Hence, an unusually large
191-
* 'time_elapsed' (as compared to the sampling rate)
188+
* Detecting this situation is easy: an unusually large
189+
* 'idle_time' (as compared to the sampling rate)
192190
* indicates this scenario.
193191
*/
194192
load = j_cdbs->prev_load;
@@ -217,8 +215,8 @@ unsigned int dbs_update(struct cpufreq_policy *policy)
217215
j_cdbs->prev_load = load;
218216
}
219217

220-
if (time_elapsed > 2 * sampling_rate) {
221-
unsigned int periods = time_elapsed / sampling_rate;
218+
if (unlikely((int)idle_time > 2 * sampling_rate)) {
219+
unsigned int periods = idle_time / sampling_rate;
222220

223221
if (periods < idle_periods)
224222
idle_periods = periods;

0 commit comments

Comments
 (0)