Commit 0759e80b authored by Rafael J. Wysocki's avatar Rafael J. Wysocki

PM / QoS: Fix device resume latency framework

The special value of 0 for device resume latency PM QoS means
"no restriction", but there are two problems with that.

First, device resume latency PM QoS requests with 0 as the
value are always put in front of requests with positive
values in the priority lists used internally by the PM QoS
framework, causing 0 to be chosen as an effective constraint
value.  However, that 0 is then interpreted as "no restriction"
effectively overriding the other requests with specific
restrictions which is incorrect.

Second, the users of device resume latency PM QoS have no
way to specify that *any* resume latency at all should be
avoided, which is an artificial limitation in general.

To address these issues, modify device resume latency PM QoS to
use S32_MAX as the "no constraint" value and 0 as the "no
latency at all" one and rework its users (the cpuidle menu
governor, the genpd QoS governor and the runtime PM framework)
to follow these changes.

Also add a special "n/a" value to the corresponding user space I/F
to allow user space to indicate that it cannot accept any resume
latencies at all for the given device.

Fixes: 85dc0b8a (PM / QoS: Make it possible to expose PM QoS latency constraints)
Link: https://bugzilla.kernel.org/show_bug.cgi?id=197323Reported-by: default avatarReinette Chatre <reinette.chatre@intel.com>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: default avatarReinette Chatre <reinette.chatre@intel.com>
Tested-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
Tested-by: default avatarTero Kristo <t-kristo@ti.com>
Reviewed-by: default avatarRamesh Thomas <ramesh.thomas@intel.com>
parent 31f18230
...@@ -211,7 +211,9 @@ Description: ...@@ -211,7 +211,9 @@ Description:
device, after it has been suspended at run time, from a resume device, after it has been suspended at run time, from a resume
request to the moment the device will be ready to process I/O, request to the moment the device will be ready to process I/O,
in microseconds. If it is equal to 0, however, this means that in microseconds. If it is equal to 0, however, this means that
the PM QoS resume latency may be arbitrary. the PM QoS resume latency may be arbitrary and the special value
"n/a" means that user space cannot accept any resume latency at
all for the given device.
Not all drivers support this attribute. If it isn't supported, Not all drivers support this attribute. If it isn't supported,
it is not present. it is not present.
......
...@@ -377,7 +377,8 @@ int register_cpu(struct cpu *cpu, int num) ...@@ -377,7 +377,8 @@ int register_cpu(struct cpu *cpu, int num)
per_cpu(cpu_sys_devices, num) = &cpu->dev; per_cpu(cpu_sys_devices, num) = &cpu->dev;
register_cpu_under_node(num, cpu_to_node(num)); register_cpu_under_node(num, cpu_to_node(num));
dev_pm_qos_expose_latency_limit(&cpu->dev, 0); dev_pm_qos_expose_latency_limit(&cpu->dev,
PM_QOS_RESUME_LATENCY_NO_CONSTRAINT);
return 0; return 0;
} }
......
...@@ -1326,7 +1326,7 @@ static struct generic_pm_domain_data *genpd_alloc_dev_data(struct device *dev, ...@@ -1326,7 +1326,7 @@ static struct generic_pm_domain_data *genpd_alloc_dev_data(struct device *dev,
gpd_data->base.dev = dev; gpd_data->base.dev = dev;
gpd_data->td.constraint_changed = true; gpd_data->td.constraint_changed = true;
gpd_data->td.effective_constraint_ns = 0; gpd_data->td.effective_constraint_ns = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT_NS;
gpd_data->nb.notifier_call = genpd_dev_pm_qos_notifier; gpd_data->nb.notifier_call = genpd_dev_pm_qos_notifier;
spin_lock_irq(&dev->power.lock); spin_lock_irq(&dev->power.lock);
......
...@@ -33,15 +33,10 @@ static int dev_update_qos_constraint(struct device *dev, void *data) ...@@ -33,15 +33,10 @@ static int dev_update_qos_constraint(struct device *dev, void *data)
* known at this point anyway). * known at this point anyway).
*/ */
constraint_ns = dev_pm_qos_read_value(dev); constraint_ns = dev_pm_qos_read_value(dev);
if (constraint_ns > 0) constraint_ns *= NSEC_PER_USEC;
constraint_ns *= NSEC_PER_USEC;
} }
/* 0 means "no constraint" */ if (constraint_ns < *constraint_ns_p)
if (constraint_ns == 0)
return 0;
if (constraint_ns < *constraint_ns_p || *constraint_ns_p == 0)
*constraint_ns_p = constraint_ns; *constraint_ns_p = constraint_ns;
return 0; return 0;
...@@ -69,12 +64,12 @@ static bool default_suspend_ok(struct device *dev) ...@@ -69,12 +64,12 @@ static bool default_suspend_ok(struct device *dev)
} }
td->constraint_changed = false; td->constraint_changed = false;
td->cached_suspend_ok = false; td->cached_suspend_ok = false;
td->effective_constraint_ns = -1; td->effective_constraint_ns = 0;
constraint_ns = __dev_pm_qos_read_value(dev); constraint_ns = __dev_pm_qos_read_value(dev);
spin_unlock_irqrestore(&dev->power.lock, flags); spin_unlock_irqrestore(&dev->power.lock, flags);
if (constraint_ns < 0) if (constraint_ns == 0)
return false; return false;
constraint_ns *= NSEC_PER_USEC; constraint_ns *= NSEC_PER_USEC;
...@@ -87,25 +82,25 @@ static bool default_suspend_ok(struct device *dev) ...@@ -87,25 +82,25 @@ static bool default_suspend_ok(struct device *dev)
device_for_each_child(dev, &constraint_ns, device_for_each_child(dev, &constraint_ns,
dev_update_qos_constraint); dev_update_qos_constraint);
if (constraint_ns == 0) { if (constraint_ns == PM_QOS_RESUME_LATENCY_NO_CONSTRAINT_NS) {
/* "No restriction", so the device is allowed to suspend. */ /* "No restriction", so the device is allowed to suspend. */
td->effective_constraint_ns = 0; td->effective_constraint_ns = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT_NS;
td->cached_suspend_ok = true; td->cached_suspend_ok = true;
} else if (constraint_ns < 0) { } else if (constraint_ns == 0) {
/* /*
* This triggers if one of the children that don't belong to a * This triggers if one of the children that don't belong to a
* domain has a negative PM QoS constraint and it's better not * domain has a zero PM QoS constraint and it's better not to
* to suspend then. effective_constraint_ns is negative already * suspend then. effective_constraint_ns is zero already and
* and cached_suspend_ok is false, so bail out. * cached_suspend_ok is false, so bail out.
*/ */
return false; return false;
} else { } else {
constraint_ns -= td->suspend_latency_ns + constraint_ns -= td->suspend_latency_ns +
td->resume_latency_ns; td->resume_latency_ns;
/* /*
* effective_constraint_ns is negative already and * effective_constraint_ns is zero already and cached_suspend_ok
* cached_suspend_ok is false, so if the computed value is not * is false, so if the computed value is not positive, return
* positive, return right away. * right away.
*/ */
if (constraint_ns <= 0) if (constraint_ns <= 0)
return false; return false;
...@@ -174,13 +169,10 @@ static bool __default_power_down_ok(struct dev_pm_domain *pd, ...@@ -174,13 +169,10 @@ static bool __default_power_down_ok(struct dev_pm_domain *pd,
td = &to_gpd_data(pdd)->td; td = &to_gpd_data(pdd)->td;
constraint_ns = td->effective_constraint_ns; constraint_ns = td->effective_constraint_ns;
/* /*
* Negative values mean "no suspend at all" and this runs only * Zero means "no suspend at all" and this runs only when all
* when all devices in the domain are suspended, so it must be * devices in the domain are suspended, so it must be positive.
* 0 at least.
*
* 0 means "no constraint"
*/ */
if (constraint_ns == 0) if (constraint_ns == PM_QOS_RESUME_LATENCY_NO_CONSTRAINT_NS)
continue; continue;
if (constraint_ns <= off_on_time_ns) if (constraint_ns <= off_on_time_ns)
......
...@@ -139,6 +139,9 @@ static int apply_constraint(struct dev_pm_qos_request *req, ...@@ -139,6 +139,9 @@ static int apply_constraint(struct dev_pm_qos_request *req,
switch(req->type) { switch(req->type) {
case DEV_PM_QOS_RESUME_LATENCY: case DEV_PM_QOS_RESUME_LATENCY:
if (WARN_ON(action != PM_QOS_REMOVE_REQ && value < 0))
value = 0;
ret = pm_qos_update_target(&qos->resume_latency, ret = pm_qos_update_target(&qos->resume_latency,
&req->data.pnode, action, value); &req->data.pnode, action, value);
break; break;
...@@ -189,7 +192,7 @@ static int dev_pm_qos_constraints_allocate(struct device *dev) ...@@ -189,7 +192,7 @@ static int dev_pm_qos_constraints_allocate(struct device *dev)
plist_head_init(&c->list); plist_head_init(&c->list);
c->target_value = PM_QOS_RESUME_LATENCY_DEFAULT_VALUE; c->target_value = PM_QOS_RESUME_LATENCY_DEFAULT_VALUE;
c->default_value = PM_QOS_RESUME_LATENCY_DEFAULT_VALUE; c->default_value = PM_QOS_RESUME_LATENCY_DEFAULT_VALUE;
c->no_constraint_value = PM_QOS_RESUME_LATENCY_DEFAULT_VALUE; c->no_constraint_value = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT;
c->type = PM_QOS_MIN; c->type = PM_QOS_MIN;
c->notifiers = n; c->notifiers = n;
......
...@@ -253,7 +253,7 @@ static int rpm_check_suspend_allowed(struct device *dev) ...@@ -253,7 +253,7 @@ static int rpm_check_suspend_allowed(struct device *dev)
|| (dev->power.request_pending || (dev->power.request_pending
&& dev->power.request == RPM_REQ_RESUME)) && dev->power.request == RPM_REQ_RESUME))
retval = -EAGAIN; retval = -EAGAIN;
else if (__dev_pm_qos_read_value(dev) < 0) else if (__dev_pm_qos_read_value(dev) == 0)
retval = -EPERM; retval = -EPERM;
else if (dev->power.runtime_status == RPM_SUSPENDED) else if (dev->power.runtime_status == RPM_SUSPENDED)
retval = 1; retval = 1;
......
...@@ -218,7 +218,14 @@ static ssize_t pm_qos_resume_latency_show(struct device *dev, ...@@ -218,7 +218,14 @@ static ssize_t pm_qos_resume_latency_show(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
char *buf) char *buf)
{ {
return sprintf(buf, "%d\n", dev_pm_qos_requested_resume_latency(dev)); s32 value = dev_pm_qos_requested_resume_latency(dev);
if (value == 0)
return sprintf(buf, "n/a\n");
else if (value == PM_QOS_RESUME_LATENCY_NO_CONSTRAINT)
value = 0;
return sprintf(buf, "%d\n", value);
} }
static ssize_t pm_qos_resume_latency_store(struct device *dev, static ssize_t pm_qos_resume_latency_store(struct device *dev,
...@@ -228,11 +235,21 @@ static ssize_t pm_qos_resume_latency_store(struct device *dev, ...@@ -228,11 +235,21 @@ static ssize_t pm_qos_resume_latency_store(struct device *dev,
s32 value; s32 value;
int ret; int ret;
if (kstrtos32(buf, 0, &value)) if (!kstrtos32(buf, 0, &value)) {
return -EINVAL; /*
* Prevent users from writing negative or "no constraint" values
* directly.
*/
if (value < 0 || value == PM_QOS_RESUME_LATENCY_NO_CONSTRAINT)
return -EINVAL;
if (value < 0) if (value == 0)
value = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT;
} else if (!strcmp(buf, "n/a") || !strcmp(buf, "n/a\n")) {
value = 0;
} else {
return -EINVAL; return -EINVAL;
}
ret = dev_pm_qos_update_request(dev->power.qos->resume_latency_req, ret = dev_pm_qos_update_request(dev->power.qos->resume_latency_req,
value); value);
......
...@@ -298,8 +298,8 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev) ...@@ -298,8 +298,8 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)
data->needs_update = 0; data->needs_update = 0;
} }
/* resume_latency is 0 means no restriction */ if (resume_latency < latency_req &&
if (resume_latency && resume_latency < latency_req) resume_latency != PM_QOS_RESUME_LATENCY_NO_CONSTRAINT)
latency_req = resume_latency; latency_req = resume_latency;
/* Special case when user has set very strict latency requirement */ /* Special case when user has set very strict latency requirement */
......
...@@ -27,16 +27,19 @@ enum pm_qos_flags_status { ...@@ -27,16 +27,19 @@ enum pm_qos_flags_status {
PM_QOS_FLAGS_ALL, PM_QOS_FLAGS_ALL,
}; };
#define PM_QOS_DEFAULT_VALUE -1 #define PM_QOS_DEFAULT_VALUE (-1)
#define PM_QOS_LATENCY_ANY S32_MAX
#define PM_QOS_LATENCY_ANY_NS ((s64)PM_QOS_LATENCY_ANY * NSEC_PER_USEC)
#define PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE (2000 * USEC_PER_SEC) #define PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE (2000 * USEC_PER_SEC)
#define PM_QOS_NETWORK_LAT_DEFAULT_VALUE (2000 * USEC_PER_SEC) #define PM_QOS_NETWORK_LAT_DEFAULT_VALUE (2000 * USEC_PER_SEC)
#define PM_QOS_NETWORK_THROUGHPUT_DEFAULT_VALUE 0 #define PM_QOS_NETWORK_THROUGHPUT_DEFAULT_VALUE 0
#define PM_QOS_MEMORY_BANDWIDTH_DEFAULT_VALUE 0 #define PM_QOS_MEMORY_BANDWIDTH_DEFAULT_VALUE 0
#define PM_QOS_RESUME_LATENCY_DEFAULT_VALUE 0 #define PM_QOS_RESUME_LATENCY_DEFAULT_VALUE PM_QOS_LATENCY_ANY
#define PM_QOS_RESUME_LATENCY_NO_CONSTRAINT PM_QOS_LATENCY_ANY
#define PM_QOS_RESUME_LATENCY_NO_CONSTRAINT_NS PM_QOS_LATENCY_ANY_NS
#define PM_QOS_LATENCY_TOLERANCE_DEFAULT_VALUE 0 #define PM_QOS_LATENCY_TOLERANCE_DEFAULT_VALUE 0
#define PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT (-1) #define PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT (-1)
#define PM_QOS_LATENCY_ANY ((s32)(~(__u32)0 >> 1))
#define PM_QOS_FLAG_NO_POWER_OFF (1 << 0) #define PM_QOS_FLAG_NO_POWER_OFF (1 << 0)
...@@ -173,7 +176,8 @@ static inline s32 dev_pm_qos_requested_flags(struct device *dev) ...@@ -173,7 +176,8 @@ static inline s32 dev_pm_qos_requested_flags(struct device *dev)
static inline s32 dev_pm_qos_raw_read_value(struct device *dev) static inline s32 dev_pm_qos_raw_read_value(struct device *dev)
{ {
return IS_ERR_OR_NULL(dev->power.qos) ? return IS_ERR_OR_NULL(dev->power.qos) ?
0 : pm_qos_read_value(&dev->power.qos->resume_latency); PM_QOS_RESUME_LATENCY_NO_CONSTRAINT :
pm_qos_read_value(&dev->power.qos->resume_latency);
} }
#else #else
static inline enum pm_qos_flags_status __dev_pm_qos_flags(struct device *dev, static inline enum pm_qos_flags_status __dev_pm_qos_flags(struct device *dev,
...@@ -183,9 +187,9 @@ static inline enum pm_qos_flags_status dev_pm_qos_flags(struct device *dev, ...@@ -183,9 +187,9 @@ static inline enum pm_qos_flags_status dev_pm_qos_flags(struct device *dev,
s32 mask) s32 mask)
{ return PM_QOS_FLAGS_UNDEFINED; } { return PM_QOS_FLAGS_UNDEFINED; }
static inline s32 __dev_pm_qos_read_value(struct device *dev) static inline s32 __dev_pm_qos_read_value(struct device *dev)
{ return 0; } { return PM_QOS_RESUME_LATENCY_NO_CONSTRAINT; }
static inline s32 dev_pm_qos_read_value(struct device *dev) static inline s32 dev_pm_qos_read_value(struct device *dev)
{ return 0; } { return PM_QOS_RESUME_LATENCY_NO_CONSTRAINT; }
static inline int dev_pm_qos_add_request(struct device *dev, static inline int dev_pm_qos_add_request(struct device *dev,
struct dev_pm_qos_request *req, struct dev_pm_qos_request *req,
enum dev_pm_qos_req_type type, enum dev_pm_qos_req_type type,
...@@ -231,9 +235,15 @@ static inline int dev_pm_qos_expose_latency_tolerance(struct device *dev) ...@@ -231,9 +235,15 @@ static inline int dev_pm_qos_expose_latency_tolerance(struct device *dev)
{ return 0; } { return 0; }
static inline void dev_pm_qos_hide_latency_tolerance(struct device *dev) {} static inline void dev_pm_qos_hide_latency_tolerance(struct device *dev) {}
static inline s32 dev_pm_qos_requested_resume_latency(struct device *dev) { return 0; } static inline s32 dev_pm_qos_requested_resume_latency(struct device *dev)
{
return PM_QOS_RESUME_LATENCY_NO_CONSTRAINT;
}
static inline s32 dev_pm_qos_requested_flags(struct device *dev) { return 0; } static inline s32 dev_pm_qos_requested_flags(struct device *dev) { return 0; }
static inline s32 dev_pm_qos_raw_read_value(struct device *dev) { return 0; } static inline s32 dev_pm_qos_raw_read_value(struct device *dev)
{
return PM_QOS_RESUME_LATENCY_NO_CONSTRAINT;
}
#endif #endif
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment