Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0cc2b4e5 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki
Browse files

PM / QoS: Fix device resume latency PM QoS

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=197323


Reported-by: default avatarReinette Chatre <reinette.chatre@intel.com>
Tested-by: default avatarReinette Chatre <reinette.chatre@intel.com>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: default avatarAlex Shi <alex.shi@linaro.org>
Cc: All applicable <stable@vger.kernel.org>
parent bb176f67
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -211,7 +211,9 @@ Description:
		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,
		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,
		it is not present.
+2 −1
Original line number Diff line number Diff line
@@ -377,7 +377,8 @@ int register_cpu(struct cpu *cpu, int num)

	per_cpu(cpu_sys_devices, num) = &cpu->dev;
	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;
}
+30 −23
Original line number Diff line number Diff line
@@ -14,23 +14,20 @@
static int dev_update_qos_constraint(struct device *dev, void *data)
{
	s64 *constraint_ns_p = data;
	s32 constraint_ns = -1;
	s64 constraint_ns = -1;

	if (dev->power.subsys_data && dev->power.subsys_data->domain_data)
		constraint_ns = dev_gpd_data(dev)->td.effective_constraint_ns;

	if (constraint_ns < 0) {
	if (constraint_ns < 0)
		constraint_ns = dev_pm_qos_read_value(dev);
		constraint_ns *= NSEC_PER_USEC;
	}
	if (constraint_ns == 0)

	if (constraint_ns == PM_QOS_RESUME_LATENCY_NO_CONSTRAINT)
		return 0;

	/*
	 * constraint_ns cannot be negative here, because the device has been
	 * suspended.
	 */
	if (constraint_ns < *constraint_ns_p || *constraint_ns_p == 0)
	constraint_ns *= NSEC_PER_USEC;

	if (constraint_ns < *constraint_ns_p || *constraint_ns_p < 0)
		*constraint_ns_p = constraint_ns;

	return 0;
@@ -63,10 +60,14 @@ static bool default_suspend_ok(struct device *dev)

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

	if (constraint_ns < 0)
	if (constraint_ns == 0)
		return false;

	if (constraint_ns == PM_QOS_RESUME_LATENCY_NO_CONSTRAINT)
		constraint_ns = -1;
	else
		constraint_ns *= NSEC_PER_USEC;

	/*
	 * We can walk the children without any additional locking, because
	 * they all have been suspended at this point and their
@@ -76,14 +77,19 @@ static bool default_suspend_ok(struct device *dev)
		device_for_each_child(dev, &constraint_ns,
				      dev_update_qos_constraint);

	if (constraint_ns < 0) {
		/* The children have no constraints. */
		td->effective_constraint_ns = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT;
		td->cached_suspend_ok = true;
	} else {
		constraint_ns -= td->suspend_latency_ns + td->resume_latency_ns;
		if (constraint_ns > 0) {
		constraint_ns -= td->suspend_latency_ns +
				td->resume_latency_ns;
		if (constraint_ns == 0)
			return false;
	}
			td->effective_constraint_ns = constraint_ns;
	td->cached_suspend_ok = constraint_ns >= 0;
			td->cached_suspend_ok = true;
		} else {
			td->effective_constraint_ns = 0;
		}
	}

	/*
	 * The children have been suspended already, so we don't need to take
@@ -145,13 +151,14 @@ static bool __default_power_down_ok(struct dev_pm_domain *pd,
		td = &to_gpd_data(pdd)->td;
		constraint_ns = td->effective_constraint_ns;
		/* default_suspend_ok() need not be called before us. */
		if (constraint_ns < 0) {
		if (constraint_ns < 0)
			constraint_ns = dev_pm_qos_read_value(pdd->dev);
			constraint_ns *= NSEC_PER_USEC;
		}
		if (constraint_ns == 0)

		if (constraint_ns == PM_QOS_RESUME_LATENCY_NO_CONSTRAINT)
			continue;

		constraint_ns *= NSEC_PER_USEC;

		/*
		 * constraint_ns cannot be negative here, because the device has
		 * been suspended.
+1 −1
Original line number Diff line number Diff line
@@ -189,7 +189,7 @@ static int dev_pm_qos_constraints_allocate(struct device *dev)
	plist_head_init(&c->list);
	c->target_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->notifiers = n;

+1 −1
Original line number Diff line number Diff line
@@ -253,7 +253,7 @@ static int rpm_check_suspend_allowed(struct device *dev)
	    || (dev->power.request_pending
			&& dev->power.request == RPM_REQ_RESUME))
		retval = -EAGAIN;
	else if (__dev_pm_qos_read_value(dev) < 0)
	else if (__dev_pm_qos_read_value(dev) == 0)
		retval = -EPERM;
	else if (dev->power.runtime_status == RPM_SUSPENDED)
		retval = 1;
Loading