Skip to contentSkip to conversation

PM / Runtime: runtime: Add sysfs option for forcing runtime suspend

RFC PATCH In review Irina Tirdea 11 participants 57 messages Sep 7, 2015 – Oct 4, 2015

Subsystems (7)
USB HID Tracing Driver core +3 more subsystems
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 PM / Runtime: runtime: Add sysfs option for forcing runtime suspend

Add new option to sysfs control interface, allowing the user to force suspend the device. This is useful for devices that need to be suspended when closing the lid of a laptop or the screen of a mobile device, while userspace still holds open handles to it and the system does not enter system suspend.

Add the "off" option to the sysfs control power interface, along with the already present "on" and "auto". When this attribute is set to "off", the device will be force suspended by calling its runtime suspend callback and disabling runtime power management so that further acceses to the device will not change the actual state. The device can be resumed by setting the attribute to "on" or "auto". The behaviour of the interface when switching only between "on" and "auto" states remains unchanged.

---

Hi,

This is a proposal for suspending devices when the closing the lid of a laptop or the screen of a mobile device.

I am testing this with a Goodix touchscreen [1] for an Android mobile device. Android has an userspace layer (power HAL) that would normally close the touchscreen when the screen is closed. Android touchscreen drivers usually provide a custom sysfs interface to allow this. This would be better implemented in a common place, to avoid code duplication and to simplify the driver code (as previosly discussed in [1]).

I know there are more ways to implement this, so I would appreciate your feedback.

Thank you,
Irina

[1] https://lkml.org/lkml/2015/9/7/329
[2] https://lkml.org/lkml/2014/7/15/928

 drivers/base/power/main.c    |   8 +++
 drivers/base/power/runtime.c | 141 ++++++++++++++++++++++++++++++++++++-------
 drivers/base/power/sysfs.c   |  22 ++++---
 drivers/usb/core/sysfs.c     |   3 +-
 include/linux/pm.h           |   8 ++-
 include/linux/pm_runtime.h   |  18 +++++-
 include/trace/events/rpm.h   |   6 +-
 7 files changed, 169 insertions(+), 37 deletions(-)
drivers/base/power/main.c +8 -0
index 9717d5f..e497c38 100644
@@ -927,6 +927,9 @@ static void device_complete(struct device *dev, pm_message_t state)
 
 	device_unlock(dev);
 
+	if (dev->power.runtime_mode == RPM_MODE_OFF)
+		pm_runtime_force_suspend(dev);
+
 	pm_runtime_put(dev);
 }
 
@@ -1596,6 +1599,11 @@ static int device_prepare(struct device *dev, pm_message_t state)
 	spin_lock_irq(&dev->power.lock);
 	dev->power.direct_complete = ret > 0 && state.event == PM_EVENT_SUSPEND;
 	spin_unlock_irq(&dev->power.lock);
+
+	if (!dev->power.direct_complete &&
+	    dev->power.runtime_mode == RPM_MODE_OFF)
+		pm_runtime_enable(dev);
+
 	return 0;
 }
 
drivers/base/power/runtime.c +118 -23

174 lines not on this page · raw message

drivers/base/power/sysfs.c +15 -7
index d2be3f9..db0630a 100644
@@ -97,31 +97,38 @@ EXPORT_SYMBOL_GPL(power_group_name);
 
 static const char ctrl_auto[] = "auto";
 static const char ctrl_on[] = "on";
+static const char ctrl_off[] = "off";
 
 static ssize_t control_show(struct device *dev, struct device_attribute *attr,
 			    char *buf)
 {
 	return sprintf(buf, "%s\n",
-				dev->power.runtime_auto ? ctrl_auto : ctrl_on);
+		       dev->power.runtime_mode == RPM_MODE_AUTO ? ctrl_auto :
+		       dev->power.runtime_mode == RPM_MODE_ON ? ctrl_on :
+		       ctrl_off);
 }
 
 static ssize_t control_store(struct device * dev, struct device_attribute *attr,
 			     const char * buf, size_t n)
 {
 	char *cp;
-	int len = n;
+	int len = n, ret = 0;
 
 	cp = memchr(buf, '\n', n);
 	if (cp)
 		len = cp - buf;
 	device_lock(dev);
 	if (len == sizeof ctrl_auto - 1 && strncmp(buf, ctrl_auto, len) == 0)
-		pm_runtime_allow(dev);
+		ret = pm_runtime_force_auto(dev);
 	else if (len == sizeof ctrl_on - 1 && strncmp(buf, ctrl_on, len) == 0)
-		pm_runtime_forbid(dev);
+		ret = pm_runtime_force_on(dev);
+	else if (len == sizeof ctrl_off - 1 && strncmp(buf, ctrl_off, len) == 0)
+		ret = pm_runtime_force_off(dev);
 	else
-		n = -EINVAL;
+		ret = -EINVAL;
 	device_unlock(dev);
+	if (ret)
+		return ret;
 	return n;
 }
 
@@ -545,11 +552,12 @@ static ssize_t rtpm_children_show(struct device *dev,
 static ssize_t rtpm_enabled_show(struct device *dev,
 				 struct device_attribute *attr, char *buf)
 {
-	if ((dev->power.disable_depth) && (dev->power.runtime_auto == false))
+	if ((dev->power.disable_depth) &&
+	    (dev->power.runtime_mode != RPM_MODE_AUTO))
 		return sprintf(buf, "disabled & forbidden\n");
 	else if (dev->power.disable_depth)
 		return sprintf(buf, "disabled\n");
-	else if (dev->power.runtime_auto == false)
+	else if (dev->power.runtime_mode != RPM_MODE_AUTO)
 		return sprintf(buf, "forbidden\n");
 	return sprintf(buf, "enabled\n");
 }
drivers/usb/core/sysfs.c +2 -1
index d269738..8165102 100644
@@ -408,7 +408,8 @@ static ssize_t level_show(struct device *dev, struct device_attribute *attr,
 	const char *p = auto_string;
 
 	warn_level();
-	if (udev->state != USB_STATE_SUSPENDED && !udev->dev.power.runtime_auto)
+	if (udev->state != USB_STATE_SUSPENDED &&
+	    udev->dev.power.runtime_mode != RPM_MODE_AUTO)
 		p = on_string;
 	return sprintf(buf, "%s\n", p);
 }
include/linux/pm.h +7 -1
index e2f1be6..69273d4 100644
@@ -542,6 +542,12 @@ struct pm_subsys_data {
 #endif
 };
 
+enum rpm_mode {
+	RPM_MODE_AUTO = 0,
+	RPM_MODE_ON,
+	RPM_MODE_OFF,
+};
+
 struct dev_pm_info {
 	pm_message_t		power_state;
 	unsigned int		can_wakeup:1;
@@ -575,12 +581,12 @@ struct dev_pm_info {
 	unsigned int		request_pending:1;
 	unsigned int		deferred_resume:1;
 	unsigned int		run_wake:1;
-	unsigned int		runtime_auto:1;
 	unsigned int		no_callbacks:1;
 	unsigned int		irq_safe:1;
 	unsigned int		use_autosuspend:1;
 	unsigned int		timer_autosuspends:1;
 	unsigned int		memalloc_noio:1;
+	enum rpm_mode		runtime_mode;
 	enum rpm_request	request;
 	enum rpm_status		runtime_status;
 	int			runtime_error;
include/linux/pm_runtime.h +16 -2
index 30e84d4..186e9f0 100644
@@ -44,8 +44,9 @@ extern int __pm_runtime_set_status(struct device *dev, unsigned int status);
 extern int pm_runtime_barrier(struct device *dev);
 extern void pm_runtime_enable(struct device *dev);
 extern void __pm_runtime_disable(struct device *dev, bool check_resume);
-extern void pm_runtime_allow(struct device *dev);
-extern void pm_runtime_forbid(struct device *dev);
+extern int pm_runtime_force_off(struct device *dev);
+extern int pm_runtime_force_on(struct device *dev);
+extern int pm_runtime_force_auto(struct device *dev);
 extern void pm_runtime_no_callbacks(struct device *dev);
 extern void pm_runtime_irq_safe(struct device *dev);
 extern void __pm_runtime_use_autosuspend(struct device *dev, bool use);
@@ -55,6 +56,16 @@ extern void pm_runtime_update_max_time_suspended(struct device *dev,
 						 s64 delta_ns);
 extern void pm_runtime_set_memalloc_noio(struct device *dev, bool enable);
 
+static inline void pm_runtime_allow(struct device *dev)
+{
+	pm_runtime_force_auto(dev);
+}
+
+static inline void pm_runtime_forbid(struct device *dev)
+{
+	pm_runtime_force_on(dev);
+}
+
 static inline bool pm_children_suspended(struct device *dev)
 {
 	return dev->power.ignore_children
@@ -155,6 +166,9 @@ static inline void pm_runtime_enable(struct device *dev) {}
 static inline void __pm_runtime_disable(struct device *dev, bool c) {}
 static inline void pm_runtime_allow(struct device *dev) {}
 static inline void pm_runtime_forbid(struct device *dev) {}
+static inline int pm_runtime_force_off(struct device *dev) { return 0; }
+static inline int pm_runtime_force_on(struct device *dev) { return 0; }
+static inline int pm_runtime_force_auto(struct device *dev) { return 0; }
 
 static inline bool pm_children_suspended(struct device *dev) { return false; }
 static inline void pm_runtime_get_noresume(struct device *dev) {}
include/trace/events/rpm.h +3 -3
index 33f85b6..ab9cc18 100644
@@ -25,7 +25,7 @@ DECLARE_EVENT_CLASS(rpm_internal,
 		__field(        int,            flags           )
 		__field(        int ,   	usage_count	)
 		__field(        int ,   	disable_depth   )
-		__field(        int ,   	runtime_auto	)
+		__field(        int ,   	runtime_mode	)
 		__field(        int ,   	request_pending	)
 		__field(        int ,   	irq_safe	)
 		__field(        int ,   	child_count 	)
@@ -37,7 +37,7 @@ DECLARE_EVENT_CLASS(rpm_internal,
 		__entry->usage_count = atomic_read(
 			&dev->power.usage_count);
 		__entry->disable_depth = dev->power.disable_depth;
-		__entry->runtime_auto = dev->power.runtime_auto;
+		__entry->runtime_mode = dev->power.runtime_mode;
 		__entry->request_pending = dev->power.request_pending;
 		__entry->irq_safe = dev->power.irq_safe;
 		__entry->child_count = atomic_read(
@@ -49,7 +49,7 @@ DECLARE_EVENT_CLASS(rpm_internal,
 			__get_str(name), __entry->flags,
 			__entry->usage_count,
 			__entry->disable_depth,
-			__entry->runtime_auto,
+			__entry->runtime_mode,
 			__entry->request_pending,
 			__entry->irq_safe,
 			__entry->child_count
Signature · 1 line
1.9.1
#1 lore raw
Quoted 2 lines · Irina Tirdea

Add new option to sysfs control interface, allowing the user to force suspend the device.

Had we thought this had been a good idea, we'd have added that thing to the interface from the start.

The problem with it is that user space generally doesn't know when it is safe to suspend a device, so it cannot force anything into runtime suspend.

Quoted 10 lines

This is useful for devices that need to be
suspended when closing the lid of a laptop or the screen of a mobile device, while userspace still holds open handles to it and the system does not enter system suspend.

Add the "off" option to the sysfs control power interface, along with the already present "on" and "auto". When this attribute is set to "off", the device will be force suspended by calling its runtime suspend callback and disabling runtime power management so that further acceses to the device will not change the actual state.

And how is user space supposed to know that it doesn't break things this way?

Quoted 20 lines

The device can be resumed by setting the attribute to "on" or "auto". The behaviour of the interface when switching only between "on" and "auto" states remains unchanged.

---

Hi,

This is a proposal for suspending devices when the closing the lid of a laptop or the screen of a mobile device.

I am testing this with a Goodix touchscreen [1] for an Android mobile device. Android has an userspace layer (power HAL) that would normally close the touchscreen when the screen is closed. Android touchscreen drivers usually provide a custom sysfs interface to allow this. This would be better implemented in a common place, to avoid code duplication and to simplify the driver code (as previosly discussed in [1]).

Quoted 2 lines

I know there are more ways to implement this, so I would appreciate your feedback.

So the feedback is that this is not going to work in general. Please use a different approach.

Thanks,
Rafael

#2 lore raw
Quoted 11 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Rafael J. Wysocki
Sent: 08 September, 2015 0:20
To: Tirdea, Irina
Cc: Alan Stern; [email protected]; [email protected]; [email protected]; Brown, Len; Pavel Machek; Purdila, Octavian; Dmitry Torokhov
Subject: Re: [RFC PATCH] PM / Runtime: runtime: Add sysfs option for forcing runtime suspend

On Monday, September 07, 2015 11:42:41 PM Irina Tirdea wrote:

Quoted 9 lines
Quoted 2 lines

Add new option to sysfs control interface, allowing the user to force suspend the device.

Had we thought this had been a good idea, we'd have added that thing to the interface from the start.

The problem with it is that user space generally doesn't know when it is safe to suspend a device, so it cannot force anything into runtime suspend.

Yes, this is generally true.

However, in the scenario I mentioned this is exactly what is happening. When turning off the screen of a mobile device, the user space
is the one that suspends the devices that are not needed in order to save power (like touchscreens). Each such driver export an enable/disable attribute that calls the same code as resume/suspend (e.g. touchscreen drivers ads7846, ad7877 and most Android drivers not merged upstream). This adds more complexity to every driver by adding one more logical power state. It would be good to have a common interface instead of doing this in every driver.

I might have not used "forced" in the proper way here. What I mean by it is that the device can be runtime suspended while ignoring the runtime usage count.

Quoted 5 lines
Quoted 5 lines

This is useful for devices that need to be
suspended when closing the lid of a laptop or the screen of a mobile device, while user space still holds open handles to it and the system does not enter system suspend.

Quoted 9 lines
Quoted 5 lines

Add the "off" option to the sysfs control power interface, along with the already present "on" and "auto". When this attribute is set to "off", the device will be force suspended by calling its runtime suspend callback and disabling runtime power management so that further accesses to the device will not change the actual state.

And how is user space supposed to know that it doesn't break things this way?

In this implementation, user space is only allowed to change the states bottom-up in the sysfs hierarchy (it cannot force suspend a device if it has children that have not been suspended by user space).

Another way to do this is to keep runtime power management enabled but to force the usage count to 0 while the device is set to runtime mode "off".

Quoted 20 lines
Quoted 20 lines

The device can be resumed by setting the attribute to "on" or "auto". The behavior of the interface when switching only between "on" and "auto" states remains unchanged.

---

Hi,

This is a proposal for suspending devices when the closing the lid of a laptop or the screen of a mobile device.

I am testing this with a Goodix touchscreen [1] for an Android mobile device. Android has an user space layer (power HAL) that would normally close the touchscreen when the screen is closed. Android touchscreen drivers usually provide a custom sysfs interface to allow this. This would be better implemented in a common place, to avoid code duplication and to simplify the driver code (as previously discussed in [1]).

Quoted 6 lines
Quoted 2 lines

I know there are more ways to implement this, so I would appreciate your feedback.

So the feedback is that this is not going to work in general. Please use a different approach.

Would it work if this would be a capability that individual drivers need to declare?

In the previous discussion thread , there were a couple of options mentioned, but none seemed to reach a consensus. You mentioned adding a "more aggressive runtime PM mode" [1]. I'm not sure how this would work except for adding a sysfs attribute that would trigger a runtime suspend while ignoring usage count. Would that be a better direction?

Thank you,
Irina

[1] http://marc.info/?l=linux-input&m=140564626306396&w=2

Quoted 7 lines

Thanks,
Rafael

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
Quoted 2 lines · Irina

However, in the scenario I mentioned this is exactly what is happening. When turning off the screen of a mobile device, the user space

Would you explain why user space doesn't simply stop using those devices, which in turn will make them idle? There are obvious cases like keyboards or SCSI hosts where the kernel controls stuff, but could you state where you expect this to be most useful?
Or why devices cannot be closed, e.g. you need to be sure settings be not lost or is it something else?

Quoted 7 lines

is the one that suspends the devices that are not needed in order to save power (like touchscreens). Each such driver export an enable/disable attribute that calls the same code as resume/suspend (e.g. touchscreen drivers ads7846, ad7877 and most Android drivers not merged upstream). This adds more complexity to every driver by adding one more logical power state. It would be good to have a common interface instead of doing this in every

Now these are two distinct questions.

1. a common interface
2. a capability implemented in common code

It is important to keep that apart. I suppose if we want this at all #1 is a given. #2 however may be impossible in a generic manner

Quoted 2 lines

I might have not used "forced" in the proper way here. What I mean by it is that the device can be runtime suspended while ignoring the runtime usage count.

That is highly problematic. You'd need to audit the locking in every driver. Right now elevating the count means that suspend()/resume() cannot race with user space, as in the case of the system suspending user space is frozen.

Quoted 3 lines

In this implementation, user space is only allowed to change the states bottom-up in the sysfs hierarchy (it cannot force suspend a device if it has children that have not been suspended by user space).

That is obviously not enough. Take the worst case: we are flashing some firmware. Or far more harmless: a key is has been pressed on a keyboard

Quoted 2 lines

Would it work if this would be a capability that individual drivers need to declare?

For some drivers. But it needs support in the driver. Right now we can make a device idle by calling close(). In fact we can benefit for example in mice from this. But it needs support in the drivers.

Quoted 3 lines

In the previous discussion thread , there were a couple of options mentioned, but none seemed to reach a consensus. You mentioned adding a "more aggressive runtime PM mode" [1]. I'm not sure how

That would have to be done on a per driver base.

Quoted 3 lines

this would work except for adding a sysfs attribute that would trigger a runtime suspend while ignoring usage count. Would that be a better direction?

No. If we want this at all, we need a new callback to notify drivers that user space is temporarily uninterested in a device. And the reverse of course.
The power model is good. We must not assume that devices can be suspended at will. If we do this at all, we ought to see it as giving strong hints to drivers when a device can be considered idle.

Regards
Oliver

#50 lore raw
In reply to Tirdea, Irina
Quoted 11 lines · Irina

In the previous discussion thread , there were a couple of options mentioned, but none seemed to reach a consensus. You mentioned adding a "more aggressive runtime PM mode" [1]. I'm not sure how this would work except for adding a sysfs attribute that would trigger a runtime suspend while ignoring usage count. Would that be a better direction?

Thank you,
Irina

[1] http://marc.info/?l=linux-input&m=140564626306396&w=2

Purely as a matter of interest, in that email Rafael also mentioned that he and I had discussed a way to disable remote wakeup during runtime suspend. Oddly enough, the method we decided upon was to add an "off" option to /sys/.../power/control. :-)

It would not put the device into runtime suspend immediately, like you are proposing. Instead it would mean the same as the "auto" mode, except that remote wakeup should be disabled during runtime suspend.

We never got around to implementing this, however.

Alan Stern

#51 lore raw
Quoted 12 lines · Alan Stern
Quoted 10 lines · Irina

In the previous discussion thread , there were a couple of options mentioned, but none seemed to reach a consensus. You mentioned adding a "more aggressive runtime PM mode" [1]. I'm not sure how this would work except for adding a sysfs attribute that would trigger a runtime suspend while ignoring usage count. Would that be a better direction?

Thank you,
Irina

Quoted 6 lines
Quoted 1 line

[1] http://marc.info/?l=linux-input&m=140564626306396&w=2

Purely as a matter of interest, in that email Rafael also mentioned that he and I had discussed a way to disable remote wakeup during runtime suspend. Oddly enough, the method we decided upon was to add an "off" option to /sys/.../power/control. :-)

Wasn't that /sys/devices/.../power/wakeup rather?

Quoted 5 lines

It would not put the device into runtime suspend immediately, like you are proposing. Instead it would mean the same as the "auto" mode, except that remote wakeup should be disabled during runtime suspend.

We never got around to implementing this, however.

I don't think this is what we discussed then really.

There is a fundamental problem with forcing things into runtime suspend from user space, because that may happen in a wrong time. In other words, the kernel can't guarantee that the device would actually be able to go into runtime suspend when requested.

Thanks,
Rafael

#52 lore raw
Quoted 8 lines · Rafael J. Wysocki
Quoted 6 lines
Quoted 1 line

[1] http://marc.info/?l=linux-input&m=140564626306396&w=2

Purely as a matter of interest, in that email Rafael also mentioned that he and I had discussed a way to disable remote wakeup during runtime suspend. Oddly enough, the method we decided upon was to add an "off" option to /sys/.../power/control. :-)

Wasn't that /sys/devices/.../power/wakeup rather?

Not the way I remember. Of course, it's possible that we misunderstood each other at the time.

Quoted 4 lines
Quoted 4 lines

It would not put the device into runtime suspend immediately, like you are proposing. Instead it would mean the same as the "auto" mode, except that remote wakeup should be disabled during runtime suspend.

Quoted 8 lines
Quoted 1 line

We never got around to implementing this, however.

I don't think this is what we discussed then really.

There is a fundamental problem with forcing things into runtime suspend from user space, because that may happen in a wrong time. In other words, the kernel can't guarantee that the device would actually be able to go into runtime suspend when requested.

Exactly. What we discussed at LinuxCon wasn't forcing things into runtime suspend; it was disabling remote wakeup during runtime suspend.

And even though the topic was quite different from Irina's proposal, we ended up settling on the same API (according to my recollection).

Alan Stern

#53 lore raw

Hi,

Quoted 27 lines · Alan Stern
Quoted 8 lines · Rafael J. Wysocki
Quoted 6 lines
Quoted 1 line

[1] http://marc.info/?l=linux-input&m=140564626306396&w=2

Purely as a matter of interest, in that email Rafael also mentioned that he and I had discussed a way to disable remote wakeup during runtime suspend. Oddly enough, the method we decided upon was to add an "off" option to /sys/.../power/control. :-)

Wasn't that /sys/devices/.../power/wakeup rather?

Not the way I remember. Of course, it's possible that we misunderstood each other at the time.

Quoted 4 lines
Quoted 4 lines

It would not put the device into runtime suspend immediately, like you are proposing. Instead it would mean the same as the "auto" mode, except that remote wakeup should be disabled during runtime suspend.

Quoted 8 lines
Quoted 1 line

We never got around to implementing this, however.

I don't think this is what we discussed then really.

There is a fundamental problem with forcing things into runtime suspend from user space, because that may happen in a wrong time. In other words, the kernel can't guarantee that the device would actually be able to go into runtime suspend when requested.

Quoted 5 lines

Exactly. What we discussed at LinuxCon wasn't forcing things into runtime suspend; it was disabling remote wakeup during runtime suspend.

And even though the topic was quite different from Irina's proposal, we ended up settling on the same API (according to my recollection).

So I remember that differently.

My idea was to add a third value to /sys/devices/.../power/wakeup (in addition to "disabled" and "enabled") so user space can indicate that remote wakeup should not be enabled for runtime suspend for the device (since there's no way to indicate that today). I don't see how /sys/devices/.../power/control might help here to be honest.

Thanks,
Rafael

#4 lore raw
In reply to Oliver Neukum
Quoted 1 line · Oliver Neukum

On Tue, 2015-09-08 at 01:10 +0000, Tirdea, Irina wrote:

[cut]

Quoted 10 lines
Quoted 3 lines

this would work except for adding a sysfs attribute that would trigger a runtime suspend while ignoring usage count. Would that be a better direction?

No. If we want this at all, we need a new callback to notify drivers that user space is temporarily uninterested in a device. And the reverse of course.
The power model is good. We must not assume that devices can be suspended at will. If we do this at all, we ought to see it as giving strong hints to drivers when a device can be considered idle.

This is a good summary in my view.

The only thing we can add, realistically, is an interface for user space to "kick" drivers to check if the devices they handle may be suspended at this point (or to run their ->runtime_idle callbacks IOW).

That would be quite similar to autosuspend except that the "kick" will come from user space rather than from a timer function in the kernel.

Thanks,
Rafael

#5 lore raw
Quoted 18 lines · Rafael J. Wysocki
Quoted 1 line · Oliver Neukum

On Tue, 2015-09-08 at 01:10 +0000, Tirdea, Irina wrote:

[cut]

Quoted 10 lines
Quoted 3 lines

this would work except for adding a sysfs attribute that would trigger a runtime suspend while ignoring usage count. Would that be a better direction?

No. If we want this at all, we need a new callback to notify drivers that user space is temporarily uninterested in a device. And the reverse of course.
The power model is good. We must not assume that devices can be suspended at will. If we do this at all, we ought to see it as giving strong hints to drivers when a device can be considered idle.

This is a good summary in my view.

Quoted 7 lines

The only thing we can add, realistically, is an interface for user space to "kick" drivers to check if the devices they handle may be suspended at this point (or to run their ->runtime_idle callbacks IOW).

That would be quite similar to autosuspend except that the "kick" will come from user space rather than from a timer function in the kernel.

Apologize for interrupting the discussion!

Unless I miss the point, I assumes the above is somewhat already achievable via sysfs when changing the value of the auto-suspend timeout, since it triggers a call to pm_runtime_set_autosuspend_delay()...

Also, according to the discussion so far, it seems like we are on agreement that we should really think twice when considering to extend the sysfs interface for runtime PM.

Quoted 1 line

From the change-log/description to $subject patch, I fail to

understand *why* the regular runtime PM *autosuspend* feature isn't sufficient. Perhaps Irina can elaborate more on the use case, to help me get a better understanding of the issue!?

Kind regards
Uffe

#6 lore raw

Hi,

Quoted 27 lines · Ulf Hansson
Quoted 18 lines · Rafael J. Wysocki
Quoted 1 line · Oliver Neukum

On Tue, 2015-09-08 at 01:10 +0000, Tirdea, Irina wrote:

[cut]

Quoted 10 lines
Quoted 3 lines

this would work except for adding a sysfs attribute that would trigger a runtime suspend while ignoring usage count. Would that be a better direction?

No. If we want this at all, we need a new callback to notify drivers that user space is temporarily uninterested in a device. And the reverse of course.
The power model is good. We must not assume that devices can be suspended at will. If we do this at all, we ought to see it as giving strong hints to drivers when a device can be considered idle.

This is a good summary in my view.

Quoted 7 lines

The only thing we can add, realistically, is an interface for user space to "kick" drivers to check if the devices they handle may be suspended at this point (or to run their ->runtime_idle callbacks IOW).

That would be quite similar to autosuspend except that the "kick" will come from user space rather than from a timer function in the kernel.

Quoted 6 lines

Apologize for interrupting the discussion!

Unless I miss the point, I assumes the above is somewhat already achievable via sysfs when changing the value of the auto-suspend timeout, since it triggers a call to pm_runtime_set_autosuspend_delay()...

Well, from the initial comment in drivers/base/power/sysfs.c:

*
* NOTE: The autosuspend_delay_ms attribute and the autosuspend_delay
* value are used only if the driver calls pm_runtime_use_autosuspend().
*

Some drivers don't do that and they would be the primary target audience for the new interface (if we agreed that it was useful after all).

Quoted 3 lines

Also, according to the discussion so far, it seems like we are on agreement that we should really think twice when considering to extend the sysfs interface for runtime PM.

That certainly is correct and not limited to runtime PM. :-)

Quoted 4 lines

From the change-log/description to $subject patch, I fail to understand *why* the regular runtime PM *autosuspend* feature isn't sufficient. Perhaps Irina can elaborate more on the use case, to help me get a better understanding of the issue!?

My understanding is that the idea would be to trigger an attempt to suspend via a specific event (eg. lid closes) rather then via an inactivity timer.

Thanks,
Rafael

#55 lore raw
In reply to Alan Stern
Quoted 3 lines · Alan Stern

It would not put the device into runtime suspend immediately, like you are proposing. Instead it would mean the same as the "auto" mode, except that remote wakeup should be disabled during runtime suspend.

Hi,

this proposal is incomplete. If you don't want remote wakeup you imply that input is no longer needed or possible. If that is already known, we can just as well inform the driver, so that it can cease IO for input.

Yet that is not necessarily the only scenario. For example if you run a screensaver, you might not care for where the user touches the screen, but the event as such is valuable.

Regards
Oliver

#7 lore raw
In reply to Rafael J. Wysocki
Quoted 55 lines · Rafael J. Wysocki

Hi,

Quoted 27 lines · Ulf Hansson
Quoted 18 lines · Rafael J. Wysocki
Quoted 1 line · Oliver Neukum

On Tue, 2015-09-08 at 01:10 +0000, Tirdea, Irina wrote:

[cut]

Quoted 10 lines
Quoted 3 lines

this would work except for adding a sysfs attribute that would trigger a runtime suspend while ignoring usage count. Would that be a better direction?

No. If we want this at all, we need a new callback to notify drivers that user space is temporarily uninterested in a device. And the reverse of course.
The power model is good. We must not assume that devices can be suspended at will. If we do this at all, we ought to see it as giving strong hints to drivers when a device can be considered idle.

This is a good summary in my view.

Quoted 7 lines

The only thing we can add, realistically, is an interface for user space to "kick" drivers to check if the devices they handle may be suspended at this point (or to run their ->runtime_idle callbacks IOW).

That would be quite similar to autosuspend except that the "kick" will come from user space rather than from a timer function in the kernel.

Quoted 6 lines

Apologize for interrupting the discussion!

Unless I miss the point, I assumes the above is somewhat already achievable via sysfs when changing the value of the auto-suspend timeout, since it triggers a call to pm_runtime_set_autosuspend_delay()...

Well, from the initial comment in drivers/base/power/sysfs.c:

*
* NOTE: The autosuspend_delay_ms attribute and the autosuspend_delay
* value are used only if the driver calls pm_runtime_use_autosuspend().
*

Some drivers don't do that and they would be the primary target audience for the new interface (if we agreed that it was useful after all).

Quoted 3 lines

Also, according to the discussion so far, it seems like we are on agreement that we should really think twice when considering to extend the sysfs interface for runtime PM.

That certainly is correct and not limited to runtime PM. :-)

Quoted 9 lines
Quoted 4 lines

From the change-log/description to $subject patch, I fail to understand *why* the regular runtime PM *autosuspend* feature isn't sufficient. Perhaps Irina can elaborate more on the use case, to help me get a better understanding of the issue!?

My understanding is that the idea would be to trigger an attempt to suspend via a specific event (eg. lid closes) rather then via an inactivity timer.

The best example and actually the very specific problem we want to solve is handling touchscreens on a phone / tablet. When the screen is turned off, it is ideal to suspend the touchscreen for two reasons: to lower the power consumption as much as possible and to prevent interrupts to wake-up the CPU when the user touches the device, and thus save even more power as we allow the CPU to stay in deep idle states for longer periods.

Note that when the screen is turned-on again, we want to resume the touchscreen so that it can send events again.

This is different then the lid closes examples, as in that case the user can not generate new events and thus the usual autosuspend feature is probably good enough (if the suspend power and autosuspend power consumption is similar).

#8 lore raw

Hi,

Quoted 74 lines · Octavian Purdila
Quoted 55 lines · Rafael J. Wysocki

Hi,

Quoted 27 lines · Ulf Hansson
Quoted 18 lines · Rafael J. Wysocki
Quoted 1 line · Oliver Neukum

On Tue, 2015-09-08 at 01:10 +0000, Tirdea, Irina wrote:

[cut]

Quoted 10 lines
Quoted 3 lines

this would work except for adding a sysfs attribute that would trigger a runtime suspend while ignoring usage count. Would that be a better direction?

No. If we want this at all, we need a new callback to notify drivers that user space is temporarily uninterested in a device. And the reverse of course.
The power model is good. We must not assume that devices can be suspended at will. If we do this at all, we ought to see it as giving strong hints to drivers when a device can be considered idle.

This is a good summary in my view.

Quoted 7 lines

The only thing we can add, realistically, is an interface for user space to "kick" drivers to check if the devices they handle may be suspended at this point (or to run their ->runtime_idle callbacks IOW).

That would be quite similar to autosuspend except that the "kick" will come from user space rather than from a timer function in the kernel.

Quoted 6 lines

Apologize for interrupting the discussion!

Unless I miss the point, I assumes the above is somewhat already achievable via sysfs when changing the value of the auto-suspend timeout, since it triggers a call to pm_runtime_set_autosuspend_delay()...

Well, from the initial comment in drivers/base/power/sysfs.c:

*
* NOTE: The autosuspend_delay_ms attribute and the autosuspend_delay
* value are used only if the driver calls pm_runtime_use_autosuspend().
*

Some drivers don't do that and they would be the primary target audience for the new interface (if we agreed that it was useful after all).

Quoted 3 lines

Also, according to the discussion so far, it seems like we are on agreement that we should really think twice when considering to extend the sysfs interface for runtime PM.

That certainly is correct and not limited to runtime PM. :-)

Quoted 9 lines
Quoted 4 lines

From the change-log/description to $subject patch, I fail to understand *why* the regular runtime PM *autosuspend* feature isn't sufficient. Perhaps Irina can elaborate more on the use case, to help me get a better understanding of the issue!?

My understanding is that the idea would be to trigger an attempt to suspend via a specific event (eg. lid closes) rather then via an inactivity timer.

The best example and actually the very specific problem we want to solve is handling touchscreens on a phone / tablet. When the screen is turned off, it is ideal to suspend the touchscreen for two reasons: to lower the power consumption as much as possible and to prevent interrupts to wake-up the CPU when the user touches the device, and thus save even more power as we allow the CPU to stay in deep idle states for longer periods.

Quoted 2 lines

Note that when the screen is turned-on again, we want to resume the touchscreen so that it can send events again.

In fact, then, what you need seems to be the feature discussed by Alan and me some time ago allowing remote wakeup do be disabled for runtime PM from user space as that in combination with autosuspend should address your use case.

Quoted 4 lines

This is different then the lid closes examples, as in that case the user can not generate new events and thus the usual autosuspend feature is probably good enough (if the suspend power and autosuspend power consumption is similar).

Autosuspend just means checking the device state periodically and suspending it if idle (not in use). It doesn't affect the energy consumption in the suspended state.

Thanks,
Rafael

#9 lore raw
Quoted 2 lines · Rafael J. Wysocki
Quoted 2 lines

Note that when the screen is turned-on again, we want to resume the touchscreen so that it can send events again.

Why is it impractical to close the fd for the touchscreen?

Quoted 5 lines

In fact, then, what you need seems to be the feature discussed by Alan and me some time ago allowing remote wakeup do be disabled for runtime PM from user space as that in combination with autosuspend should address your use case.

I'd doubt that. Suppose you put the phone into your pocket while the device isn't suspended. The continuous stream of spurious events will keep it awake.
The ability to disable remote wakeup is necessary but not sufficient.

Regards
Oliver

#56 lore raw
In reply to Oliver Neukum
Quoted 11 lines · Oliver Neukum
Quoted 3 lines · Alan Stern

It would not put the device into runtime suspend immediately, like you are proposing. Instead it would mean the same as the "auto" mode, except that remote wakeup should be disabled during runtime suspend.

Hi,

this proposal is incomplete. If you don't want remote wakeup you imply that input is no longer needed or possible. If that is already known, we can just as well inform the driver, so that it can cease IO for input.

Like I said, it was never implemented. For that reason, it was never completely fleshed out.

Quoted 3 lines

Yet that is not necessarily the only scenario. For example if you run a screensaver, you might not care for where the user touches the screen, but the event as such is valuable.

I suspect it's not worth the effort to distinguish between getting an event with all the details and merely knowing that an event occurred.

Alan Stern

#10 lore raw
In reply to Oliver Neukum
Quoted 6 lines · Oliver Neukum
Quoted 2 lines · Rafael J. Wysocki
Quoted 2 lines

Note that when the screen is turned-on again, we want to resume the touchscreen so that it can send events again.

Why is it impractical to close the fd for the touchscreen?

I am not sure, but I think it is this way due to historical reasons. On Android devices early-suspend was used originally to save power when the screen was turned-off but the device was not suspend. Later Android moved to power HAL [1] and run-time PM for some devices, however that is not sufficient for touchscreen.

i2c touchscreen devices usually have two low-power states: a deep power state where event collection is disabled and the device needs to be poked via i2c to restart collecting events and a shallow power state where the device reduces the internal polling rate after it is idle for some time. The latter it is usually implemented directly in hardware. That means that you can't really implemented auto-suspend with the deep power state, since the device can not resume itself.

To address this limitation, Android used early suspend (and then the power HAL mechanism) where the upper layers signals when you can turn on or off certain devices.

I have added Colin and Arve to this thread who maybe can answer this better.

Quoted 8 lines
Quoted 4 lines

In fact, then, what you need seems to be the feature discussed by Alan and me some time ago allowing remote wakeup do be disabled for runtime PM from user space as that in combination with autosuspend should address your use case.

I'd doubt that. Suppose you put the phone into your pocket while the device isn't suspended. The continuous stream of spurious events will keep it awake.

I agree.

Quoted 2 lines

The ability to disable remote wakeup is necessary but not sufficient.

I don't know enough about remote wake-up, but do we even need to use it for this kind of devices?

#14 lore raw
In reply to Rafael J. Wysocki
Quoted 8 lines · Rafael J. Wysocki
Quoted 8 lines

The best example and actually the very specific problem we want to solve is handling touchscreens on a phone / tablet. When the screen is turned off, it is ideal to suspend the touchscreen for two reasons: to lower the power consumption as much as possible and to prevent interrupts to wake-up the CPU when the user touches the device, and thus save even more power as we allow the CPU to stay in deep idle states for longer periods.

Quoted 7 lines
Quoted 2 lines

Note that when the screen is turned-on again, we want to resume the touchscreen so that it can send events again.

In fact, then, what you need seems to be the feature discussed by Alan and me some time ago allowing remote wakeup do be disabled for runtime PM from user space as that in combination with autosuspend should address your use case.

That, plus they want the touchscreen to go into runtime suspend whenever the screen is off (was this not the main reason for the patch?).

It seems to me that it should be possible to arrange for this to happen simply by making userspace close the touchscreen device when the screen is turned off. Or am I missing something?

Alan Stern

#54 lore raw
In reply to Rafael J. Wysocki
Quoted 36 lines · Rafael J. Wysocki

Hi,

Quoted 27 lines · Alan Stern
Quoted 8 lines · Rafael J. Wysocki
Quoted 6 lines
Quoted 1 line

[1] http://marc.info/?l=linux-input&m=140564626306396&w=2

Purely as a matter of interest, in that email Rafael also mentioned that he and I had discussed a way to disable remote wakeup during runtime suspend. Oddly enough, the method we decided upon was to add an "off" option to /sys/.../power/control. :-)

Wasn't that /sys/devices/.../power/wakeup rather?

Not the way I remember. Of course, it's possible that we misunderstood each other at the time.

Quoted 4 lines
Quoted 4 lines

It would not put the device into runtime suspend immediately, like you are proposing. Instead it would mean the same as the "auto" mode, except that remote wakeup should be disabled during runtime suspend.

Quoted 8 lines
Quoted 1 line

We never got around to implementing this, however.

I don't think this is what we discussed then really.

There is a fundamental problem with forcing things into runtime suspend from user space, because that may happen in a wrong time. In other words, the kernel can't guarantee that the device would actually be able to go into runtime suspend when requested.

Quoted 5 lines

Exactly. What we discussed at LinuxCon wasn't forcing things into runtime suspend; it was disabling remote wakeup during runtime suspend.

And even though the topic was quite different from Irina's proposal, we ended up settling on the same API (according to my recollection).

Quoted 7 lines

So I remember that differently.

My idea was to add a third value to /sys/devices/.../power/wakeup (in addition to "disabled" and "enabled") so user space can indicate that remote wakeup should not be enabled for runtime suspend for the device (since there's no way to indicate that today). I don't see how /sys/devices/.../power/control might help here to be honest.

You're right, that does make more sense than what I was thinking. My memory must have gotten messed up. RAM corruption, no doubt... I think I need an EDAC brain. :-)

Alan Stern

#11 lore raw
In reply to Octavian Purdila
Quoted 22 lines · Octavian Purdila
Quoted 6 lines · Oliver Neukum
Quoted 2 lines · Rafael J. Wysocki
Quoted 2 lines

Note that when the screen is turned-on again, we want to resume the touchscreen so that it can send events again.

Why is it impractical to close the fd for the touchscreen?

I am not sure, but I think it is this way due to historical reasons. On Android devices early-suspend was used originally to save power when the screen was turned-off but the device was not suspend. Later Android moved to power HAL [1] and run-time PM for some devices, however that is not sufficient for touchscreen.

i2c touchscreen devices usually have two low-power states: a deep power state where event collection is disabled and the device needs to be poked via i2c to restart collecting events and a shallow power state where the device reduces the internal polling rate after it is idle for some time. The latter it is usually implemented directly in hardware. That means that you can't really implemented auto-suspend with the deep power state, since the device can not resume itself.

Quoted 14 lines

To address this limitation, Android used early suspend (and then the power HAL mechanism) where the upper layers signals when you can turn on or off certain devices.

I have added Colin and Arve to this thread who maybe can answer this better.

Quoted 8 lines
Quoted 4 lines

In fact, then, what you need seems to be the feature discussed by Alan and me some time ago allowing remote wakeup do be disabled for runtime PM from user space as that in combination with autosuspend should address your use case.

I'd doubt that. Suppose you put the phone into your pocket while the device isn't suspended. The continuous stream of spurious events will keep it awake.

Why would they be regarded as spurious then? They are just regular touch panel events in that case, aren't they?

Quoted 7 lines

I agree.

Quoted 2 lines

The ability to disable remote wakeup is necessary but not sufficient.

I don't know enough about remote wake-up, but do we even need to use it for this kind of devices?

Well, if the device is capable of generating wakeup events while suspended, the current expected behavior is to do that, but of course that needs to be enabled by the driver/bus type too.

Thanks,
Rafael

#15 lore raw
In reply to Alan Stern
Quoted 13 lines · Alan Stern
Quoted 11 lines · Rafael J. Wysocki
Quoted 10 lines

The best example and actually the very specific problem we want to solve is handling touchscreens on a phone / tablet. When the screen is turned off, it is ideal to suspend the touchscreen for two reasons: to lower the power consumption as much as possible and to prevent interrupts to wake-up the CPU when the user touches the device, and thus save even more power as we allow the CPU to stay in deep idle states for longer periods.

Note that when the screen is turned-on again, we want to resume the touchscreen so that it can send events again.

Quoted 8 lines
Quoted 4 lines

In fact, then, what you need seems to be the feature discussed by Alan and me some time ago allowing remote wakeup do be disabled for runtime PM from user space as that in combination with autosuspend should address your use case.

That, plus they want the touchscreen to go into runtime suspend whenever the screen is off (was this not the main reason for the patch?).

Right.

Quoted 3 lines

It seems to me that it should be possible to arrange for this to happen simply by making userspace close the touchscreen device when the screen is turned off. Or am I missing something?

Honestly, I don't know.

Octavian, Irina, any reasons why things can't be done as Alan is suggesting?

Thanks,
Rafael

#16 lore raw
Quoted 26 lines · Rafael J. Wysocki
Quoted 13 lines · Alan Stern
Quoted 11 lines · Rafael J. Wysocki
Quoted 10 lines

The best example and actually the very specific problem we want to solve is handling touchscreens on a phone / tablet. When the screen is turned off, it is ideal to suspend the touchscreen for two reasons: to lower the power consumption as much as possible and to prevent interrupts to wake-up the CPU when the user touches the device, and thus save even more power as we allow the CPU to stay in deep idle states for longer periods.

Note that when the screen is turned-on again, we want to resume the touchscreen so that it can send events again.

Quoted 8 lines
Quoted 4 lines

In fact, then, what you need seems to be the feature discussed by Alan and me some time ago allowing remote wakeup do be disabled for runtime PM from user space as that in combination with autosuspend should address your use case.

That, plus they want the touchscreen to go into runtime suspend whenever the screen is off (was this not the main reason for the patch?).

Right.

Quoted 7 lines
Quoted 3 lines

It seems to me that it should be possible to arrange for this to happen simply by making userspace close the touchscreen device when the screen is turned off. Or am I missing something?

Honestly, I don't know.

Octavian, Irina, any reasons why things can't be done as Alan is suggesting?

Early Android used early suspend, which notified various kernel drivers that the screen was turning off so they could go into low power states. That meant there was no reason to close the touchscreen fd - the kernel already knew about the screen off event. We then got rid of the early suspend hack and moved everything into userspace using the power HAL and sysfs files. Getting rid of the touchscreen sysfs files and closing the touchscreen on screen off was on the nice-to-have list, but hasn't made it onto anybody's todo list.

#12 lore raw
In reply to Rafael J. Wysocki
Quoted 9 lines · Rafael J. Wysocki
Quoted 3 lines
Quoted 3 lines

I'd doubt that. Suppose you put the phone into your pocket while the device isn't suspended. The continuous stream of spurious

events

Quoted 1 line
Quoted 1 line

will keep it awake.

Why would they be regarded as spurious then? They are just regular touch panel
events in that case, aren't they?

These events are not expected to be caused by the user's hand.

But it raises a design question; whose job it is to handle such information?
It makes no sense to gather events from a touchscreen if you suspect the phone is randomly rubbing at things or to take video from a camera if you know that the lid is closed covering the lens. I think we can agree to that.

The thing is that we handle all other availability in kernel space. You can argue that user space has an agreed interface (evdev, V4L or whatever) and it is the kernel's job to react if it learns that a device becomes temporarily unavailable and this is merely a question of adding an interface to the kernel by which user space can feed such information to the kernel.

Regards
Oliver

#13 lore raw
In reply to Rafael J. Wysocki
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

In fact, then, what you need seems to be the feature discussed by Alan and me some time ago allowing remote wakeup do be disabled for runtime PM from user space as that in combination with autosuspend should address your use case.

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

I'd doubt that. Suppose you put the phone into your pocket while the device isn't suspended. The continuous stream of spurious events will keep it awake.

Why would they be regarded as spurious then? They are just regular touch panel events in that case, aren't they?

From userspace... they are spurious. Userspace does not known that

your device is commonly placed into the pocket, and the events it sees are not from user.

I have mainline X/mate running on n900 cellphone. And this means battery life is in "2 hours" range.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#17 lore raw
In reply to Alan Stern
Quoted 18 lines · Alan Stern
Quoted 8 lines · Rafael J. Wysocki
Quoted 8 lines

The best example and actually the very specific problem we want to solve is handling touchscreens on a phone / tablet. When the screen is turned off, it is ideal to suspend the touchscreen for two reasons: to lower the power consumption as much as possible and to prevent interrupts to wake-up the CPU when the user touches the device, and thus save even more power as we allow the CPU to stay in deep idle states for longer periods.

Quoted 7 lines
Quoted 2 lines

Note that when the screen is turned-on again, we want to resume the touchscreen so that it can send events again.

In fact, then, what you need seems to be the feature discussed by Alan and me some time ago allowing remote wakeup do be disabled for runtime PM from user space as that in combination with autosuspend should address your use case.

Quoted 7 lines

That, plus they want the touchscreen to go into runtime suspend whenever the screen is off (was this not the main reason for the patch?).

It seems to me that it should be possible to arrange for this to happen simply by making userspace close the touchscreen device when the screen is turned off. Or am I missing something?

Well... that's not what existing userspace expects. Your X windows server will not close the touchscreen.

..and it would be nice to have enough hardware abstraction in the kernel so that X can be used on phones...

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#18 lore raw
Quoted 9 lines · Pavel Machek
Quoted 9 lines
Quoted 4 lines

In fact, then, what you need seems to be the feature discussed by Alan and me some time ago allowing remote wakeup do be disabled for runtime PM from user space as that in combination with autosuspend should address your use case.

That, plus they want the touchscreen to go into runtime suspend whenever the screen is off (was this not the main reason for the patch?).

Quoted 6 lines
Quoted 3 lines

It seems to me that it should be possible to arrange for this to happen simply by making userspace close the touchscreen device when the screen is turned off. Or am I missing something?

Well... that's not what existing userspace expects. Your X windows server will not close the touchscreen.

Surely that's a userspace issue, rather than a kernel problem? The X server does have some notion of power management and power savings; why not extend that notion to include touchscreens?

Quoted 2 lines

..and it would be nice to have enough hardware abstraction in the kernel so that X can be used on phones...

What -- not Wayland?! :-)

Alan Stern

#19 lore raw
Quoted 15 lines · Alan Stern
Quoted 13 lines · Pavel Machek
Quoted 12 lines
Quoted 4 lines

In fact, then, what you need seems to be the feature discussed by Alan and me some time ago allowing remote wakeup do be disabled for runtime PM from user space as that in combination with autosuspend should address your use case.

That, plus they want the touchscreen to go into runtime suspend whenever the screen is off (was this not the main reason for the patch?).

It seems to me that it should be possible to arrange for this to happen simply by making userspace close the touchscreen device when the screen is turned off. Or am I missing something?

Quoted 6 lines
Quoted 2 lines

Well... that's not what existing userspace expects. Your X windows server will not close the touchscreen.

Surely that's a userspace issue, rather than a kernel problem? The X server does have some notion of power management and power savings; why not extend that notion to include touchscreens?

It is not really practical: there are many consumers of input events, if we build infrastructure to control it and proxy all users through it, why not have it in kernel? Plus, there are users of input events directly in the kernel, such as legacy VT/keyboard, or Android/ChromeOS cpufreq_interactive governor that monitors user activity and bumps up CPU speed when user actively interacts with the device. They would keep input devices active even though user might not be actually able to use some input devices.

Thanks.

Signature · 1 line
Dmitry
#20 lore raw
Quoted 23 lines · Dmitry Torokhov
Quoted 15 lines · Alan Stern
Quoted 13 lines · Pavel Machek
Quoted 12 lines
Quoted 4 lines

In fact, then, what you need seems to be the feature discussed by Alan and me some time ago allowing remote wakeup do be disabled for runtime PM from user space as that in combination with autosuspend should address your use case.

That, plus they want the touchscreen to go into runtime suspend whenever the screen is off (was this not the main reason for the patch?).

It seems to me that it should be possible to arrange for this to happen simply by making userspace close the touchscreen device when the screen is turned off. Or am I missing something?

Quoted 6 lines
Quoted 2 lines

Well... that's not what existing userspace expects. Your X windows server will not close the touchscreen.

Surely that's a userspace issue, rather than a kernel problem? The X server does have some notion of power management and power savings; why not extend that notion to include touchscreens?

Quoted 8 lines

It is not really practical: there are many consumers of input events, if we build infrastructure to control it and proxy all users through it, why not have it in kernel? Plus, there are users of input events directly in the kernel, such as legacy VT/keyboard, or Android/ChromeOS cpufreq_interactive governor that monitors user activity and bumps up CPU speed when user actively interacts with the device. They would keep input devices active even though user might not be actually able to use some input devices.

It sounds like you are suggesting there should be a general mechanism for userspace to tell the kernel (or the input core) to ignore all events from a particular input device -- or even from all input devices -- thereby allowing those devices to go to low power.

I don't like to think of this as "forcing runtime suspend". It's more like telling the kernel that a device is no longer being used, so the natural runtime PM mechanism can put it in runtime suspend.

Perhaps another way to think about it is that these input devices should not increment their runtime usage counter as part of the open routine; they should use something other than the number of open file references to indicate when they can go into runtime suspend. (I'm not sure what else they should use, though.)

Alan Stern

#21 lore raw
Quoted 34 lines · Alan Stern
Quoted 23 lines · Dmitry Torokhov
Quoted 15 lines · Alan Stern
Quoted 13 lines · Pavel Machek
Quoted 12 lines
Quoted 4 lines

In fact, then, what you need seems to be the feature discussed by Alan and me some time ago allowing remote wakeup do be disabled for runtime PM from user space as that in combination with autosuspend should address your use case.

That, plus they want the touchscreen to go into runtime suspend whenever the screen is off (was this not the main reason for the patch?).

It seems to me that it should be possible to arrange for this to happen simply by making userspace close the touchscreen device when the screen is turned off. Or am I missing something?

Quoted 6 lines
Quoted 2 lines

Well... that's not what existing userspace expects. Your X windows server will not close the touchscreen.

Surely that's a userspace issue, rather than a kernel problem? The X server does have some notion of power management and power savings; why not extend that notion to include touchscreens?

Quoted 8 lines

It is not really practical: there are many consumers of input events, if we build infrastructure to control it and proxy all users through it, why not have it in kernel? Plus, there are users of input events directly in the kernel, such as legacy VT/keyboard, or Android/ChromeOS cpufreq_interactive governor that monitors user activity and bumps up CPU speed when user actively interacts with the device. They would keep input devices active even though user might not be actually able to use some input devices.

Quoted 4 lines

It sounds like you are suggesting there should be a general mechanism for userspace to tell the kernel (or the input core) to ignore all events from a particular input device -- or even from all input devices -- thereby allowing those devices to go to low power.

Yes. In ChromeOS we have a custim "inhibit" control that:

1. Tells input core to ignore all events form a given device
2. Allows driver to put device in low power mode if driver desires to do so. The driver can do it via runtime PM or on it's own. Usually on it's own since when using runtime PM userspace may disable it, which may not be desirable.

I would love to have something generic instead of input-specific.

Quoted 4 lines

I don't like to think of this as "forcing runtime suspend". It's more like telling the kernel that a device is no longer being used, so the natural runtime PM mechanism can put it in runtime suspend.

I'd call it "accelerating" runtime suspend. Userspace tells the kernel that it intends not to use given device and kernel reacts accordingly.

Quoted 6 lines

Perhaps another way to think about it is that these input devices should not increment their runtime usage counter as part of the open routine; they should use something other than the number of open file references to indicate when they can go into runtime suspend. (I'm not sure what else they should use, though.)

I do not really want input specific support; as I mentioned before we have something like that in ChromeOS kernels but I was hesitant bringing it upstream as I believe it is not necessarily input device specific and I would love to have it implemented at device core level.

Thanks.

Signature · 1 line
Dmitry
#22 lore raw
Quoted 16 lines · Dmitry Torokhov
Quoted 4 lines

It sounds like you are suggesting there should be a general mechanism for userspace to tell the kernel (or the input core) to ignore all events from a particular input device -- or even from all input devices -- thereby allowing those devices to go to low power.

Yes. In ChromeOS we have a custim "inhibit" control that:

1. Tells input core to ignore all events form a given device
2. Allows driver to put device in low power mode if driver desires to do so. The driver can do it via runtime PM or on it's own. Usually on it's own since when using runtime PM userspace may disable it, which may not be desirable.

I would love to have something generic instead of input-specific.

Quoted 1 line
Quoted 6 lines
Quoted 3 lines

I don't like to think of this as "forcing runtime suspend". It's more like telling the kernel that a device is no longer being used, so the natural runtime PM mechanism can put it in runtime suspend.

I'd call it "accelerating" runtime suspend. Userspace tells the kernel that it intends not to use given device and kernel reacts accordingly.

Okay.

Quoted 10 lines
Quoted 5 lines

Perhaps another way to think about it is that these input devices should not increment their runtime usage counter as part of the open routine; they should use something other than the number of open file references to indicate when they can go into runtime suspend. (I'm not sure what else they should use, though.)

I do not really want input specific support; as I mentioned before we have something like that in ChromeOS kernels but I was hesitant bringing it upstream as I believe it is not necessarily input device specific and I would love to have it implemented at device core level.

That's not a bad idea. On the other hand, there must be lots of devices which would not be suitable for this. Disk drives, for instance.

What happens if the "inhibit" control is turned on and the driver puts the device into runtime suspend, but then an I/O request arrives?

If the I/O request originated from userspace, it means the user is violating the terms of the "inhibit" control. Should the request simply fail?

What if the I/O request originated from somewhere in the kernel, not from the user?

Or maybe the driver would want to carry out the request, overriding the "inhibit" control temporarily. Does it simply turn off the control, meaning that the device won't go back into runtime suspend until userspace turns the control on again?

Or if the driver doesn't turn off the "inhibit" control, then how does it know when it can safely put the device back into runtime suspend?

Qustions like these make me think that this mechanism is best suited for a kind of device that doesn't handle I/O requests. In other words, something that just reports events as they occur -- which is another way of describing an input device!

Alan Stern

#23 lore raw
Quoted 33 lines · Alan Stern
Quoted 16 lines · Dmitry Torokhov
Quoted 4 lines

It sounds like you are suggesting there should be a general mechanism for userspace to tell the kernel (or the input core) to ignore all events from a particular input device -- or even from all input devices -- thereby allowing those devices to go to low power.

Yes. In ChromeOS we have a custim "inhibit" control that:

1. Tells input core to ignore all events form a given device
2. Allows driver to put device in low power mode if driver desires to do so. The driver can do it via runtime PM or on it's own. Usually on it's own since when using runtime PM userspace may disable it, which may not be desirable.

I would love to have something generic instead of input-specific.

Quoted 1 line
Quoted 6 lines
Quoted 3 lines

I don't like to think of this as "forcing runtime suspend". It's more like telling the kernel that a device is no longer being used, so the natural runtime PM mechanism can put it in runtime suspend.

I'd call it "accelerating" runtime suspend. Userspace tells the kernel that it intends not to use given device and kernel reacts accordingly.

Okay.

Quoted 6 lines
Quoted 5 lines

Perhaps another way to think about it is that these input devices should not increment their runtime usage counter as part of the open routine; they should use something other than the number of open file references to indicate when they can go into runtime suspend. (I'm not sure what else they should use, though.)

Quoted 8 lines
Quoted 4 lines

I do not really want input specific support; as I mentioned before we have something like that in ChromeOS kernels but I was hesitant bringing it upstream as I believe it is not necessarily input device specific and I would love to have it implemented at device core level.

That's not a bad idea. On the other hand, there must be lots of devices which would not be suitable for this. Disk drives, for instance.

Of course.

Quoted 7 lines

What happens if the "inhibit" control is turned on and the driver puts the device into runtime suspend, but then an I/O request arrives?

If the I/O request originated from userspace, it means the user is violating the terms of the "inhibit" control. Should the request simply fail?

What user? User that inhibited it or user that tried to use the device?

Quoted 3 lines

What if the I/O request originated from somewhere in the kernel, not from the user?

I think we should treat in-kernel users as all other users.

Quoted 7 lines

Or maybe the driver would want to carry out the request, overriding the "inhibit" control temporarily. Does it simply turn off the control, meaning that the device won't go back into runtime suspend until userspace turns the control on again?

Quoted 8 lines

Or if the driver doesn't turn off the "inhibit" control, then how does it know when it can safely put the device back into runtime suspend?

Qustions like these make me think that this mechanism is best suited for a kind of device that doesn't handle I/O requests. In other words, something that just reports events as they occur -- which is another way of describing an input device!

Or maybe IIO device. Or hwmon. Or something else. I think if we allow drivers (or subsystems) to opt in into this mechanism it will solve much of worries about disks and similar devices that indeed not very suitable for such mechanism.

Thanks.

-
Dmitry

#24 lore raw
Quoted 8 lines · Dmitry Torokhov
Quoted 6 lines

What happens if the "inhibit" control is turned on and the driver puts the device into runtime suspend, but then an I/O request arrives?

If the I/O request originated from userspace, it means the user is violating the terms of the "inhibit" control. Should the request simply fail?

What user? User that inhibited it or user that tried to use the device?

Normally they would be the same. But even if they aren't, someone has violated the kernel interface: The first user told the kernel a particular device wasn't going to be used, and then the second user tried to use it.

Of course, this issue doesn't arise for devices that merely report external events.

Quoted 21 lines
Quoted 2 lines

What if the I/O request originated from somewhere in the kernel, not from the user?

I think we should treat in-kernel users as all other users.

Quoted 7 lines

Or maybe the driver would want to carry out the request, overriding the "inhibit" control temporarily. Does it simply turn off the control, meaning that the device won't go back into runtime suspend until userspace turns the control on again?

Quoted 8 lines

Or if the driver doesn't turn off the "inhibit" control, then how does it know when it can safely put the device back into runtime suspend?

Qustions like these make me think that this mechanism is best suited for a kind of device that doesn't handle I/O requests. In other words, something that just reports events as they occur -- which is another way of describing an input device!

Quoted 4 lines

Or maybe IIO device. Or hwmon. Or something else. I think if we allow drivers (or subsystems) to opt in into this mechanism it will solve much of worries about disks and similar devices that indeed not very suitable for such mechanism.

Should the mechanism really be per-device? Or would it be more useful to have a single "inhibit" setting that affected all the relevant devices at once?

The runtime-PM "usage" value for these devices is a little tricky to calculate. It should be nonzero if there are any open files _and_ the device isn't "inhibited". I don't know the best way to represent that kind of condition in the runtime PM framework.

Alan Stern

#49 lore raw
In reply to Alan Stern
Quoted 15 lines · Alan Stern
Quoted 13 lines · Pavel Machek
Quoted 12 lines
Quoted 4 lines

In fact, then, what you need seems to be the feature discussed by Alan and me some time ago allowing remote wakeup do be disabled for runtime PM from user space as that in combination with autosuspend should address your use case.

That, plus they want the touchscreen to go into runtime suspend whenever the screen is off (was this not the main reason for the patch?).

It seems to me that it should be possible to arrange for this to happen simply by making userspace close the touchscreen device when the screen is turned off. Or am I missing something?

Quoted 6 lines
Quoted 2 lines

Well... that's not what existing userspace expects. Your X windows server will not close the touchscreen.

Surely that's a userspace issue, rather than a kernel problem? The X server does have some notion of power management and power savings; why not extend that notion to include touchscreens?

Well... once upon a time, it was kernel job to mask differences between different hardware platforms.

In a way, the hardware is "buggy" -- if your mouse clicked randomly when you were not holding it in your hand it would be buggy... and it would be nice for kernel to fix that "bug".

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#25 lore raw
In reply to Alan Stern
Quoted 40 lines · Alan Stern
Quoted 8 lines · Dmitry Torokhov
Quoted 6 lines

What happens if the "inhibit" control is turned on and the driver puts the device into runtime suspend, but then an I/O request arrives?

If the I/O request originated from userspace, it means the user is violating the terms of the "inhibit" control. Should the request simply fail?

What user? User that inhibited it or user that tried to use the device?

Normally they would be the same. But even if they aren't, someone has violated the kernel interface: The first user told the kernel a particular device wasn't going to be used, and then the second user tried to use it.

Of course, this issue doesn't arise for devices that merely report external events.

Quoted 21 lines
Quoted 2 lines

What if the I/O request originated from somewhere in the kernel, not from the user?

I think we should treat in-kernel users as all other users.

Quoted 15 lines

Or maybe the driver would want to carry out the request, overriding the "inhibit" control temporarily. Does it simply turn off the control, meaning that the device won't go back into runtime suspend until userspace turns the control on again?

Or if the driver doesn't turn off the "inhibit" control, then how does it know when it can safely put the device back into runtime suspend?

Qustions like these make me think that this mechanism is best suited for a kind of device that doesn't handle I/O requests. In other words, something that just reports events as they occur -- which is another way of describing an input device!

Quoted 8 lines
Quoted 4 lines

Or maybe IIO device. Or hwmon. Or something else. I think if we allow drivers (or subsystems) to opt in into this mechanism it will solve much of worries about disks and similar devices that indeed not very suitable for such mechanism.

Should the mechanism really be per-device? Or would it be more useful to have a single "inhibit" setting that affected all the relevant devices at once?

Definitely per device. Consider your laptop with external monitor and keyboard connected. When you close the lid you want to inhibit internal keyboard, touchpad and touchscreen while leaving external keyboard and mouse working.

That's just one scenario.

Thanks.

Signature · 1 line
Dmitry
#26 lore raw
In reply to Alan Stern
Quoted 9 lines · Alan Stern
Quoted 7 lines · Dmitry Torokhov
Quoted 6 lines

What happens if the "inhibit" control is turned on and the driver puts the device into runtime suspend, but then an I/O request arrives?

If the I/O request originated from userspace, it means the user is violating the terms of the "inhibit" control. Should the request simply fail?

Quoted 6 lines
Quoted 1 line

What user? User that inhibited it or user that tried to use the device?

Normally they would be the same. But even if they aren't, someone has violated the kernel interface: The first user told the kernel a particular device wasn't going to be used, and then the second user tried to use it.

If we assume that user space speaks with a uniform voice on that issue, it can just as well close the device. It seems to me that declaring a device idle is a privileged operation.

Quoted 2 lines

Of course, this issue doesn't arise for devices that merely report external events.

Indeed. We can handle output to suspended devices by waking them. I don't see why this case is different. We are talking about input only.

Quoted 4 lines

The runtime-PM "usage" value for these devices is a little tricky to calculate. It should be nonzero if there are any open files _and_ the device isn't "inhibited". I don't know the best way to represent that kind of condition in the runtime PM framework.

Does that make sense in the generic framework at all? I still think that drivers should cease IO for input in such cases. That should involve a common callback, but no counter.

Regards
Oliver

#27 lore raw
Quoted 4 lines · Oliver Neukum

Indeed. We can handle output to suspended devices by waking them. I don't see why this case is different. We are talking about input only.

Quoted 8 lines
Quoted 4 lines

The runtime-PM "usage" value for these devices is a little tricky to calculate. It should be nonzero if there are any open files _and_ the device isn't "inhibited". I don't know the best way to represent that kind of condition in the runtime PM framework.

Does that make sense in the generic framework at all? I still think that drivers should cease IO for input in such cases. That should involve a common callback, but no counter.

I'm not sure I understand what you're saying. Are you suggesting that this "inhibit" mechanism should involve a new callback different from the existing runtime-PM callbacks? And when this new callback is invoked, drivers should cancel existing input requests (these devices are input-only) and go to low power?

This would create a parallel runtime-PM mechanism which is independent of the existing one. Is that really a good idea?

Alan Stern

#28 lore raw
Quoted 11 lines · Alan Stern
Quoted 9 lines · Oliver Neukum

Indeed. We can handle output to suspended devices by waking them. I don't see why this case is different. We are talking about input only.

Quoted 4 lines

The runtime-PM "usage" value for these devices is a little tricky to calculate. It should be nonzero if there are any open files _and_ the device isn't "inhibited". I don't know the best way to represent that kind of condition in the runtime PM framework.

Quoted 6 lines
Quoted 3 lines

Does that make sense in the generic framework at all? I still think that drivers should cease IO for input in such cases. That should involve a common callback, but no counter.

I'm not sure I understand what you're saying. Are you suggesting that this "inhibit" mechanism should involve a new callback different from

Yes, there is no necessary relation to power management. If you put your phone into your pocket, you will want to inhibit the touchscreen even if that doesn't save power.

Quoted 3 lines

the existing runtime-PM callbacks? And when this new callback is invoked, drivers should cancel existing input requests (these devices are input-only) and go to low power?

Cancel, yes, going to low power is a consequence which needn't bother the power subsystem. You need a callback. If there are spurious events, the current heuristics will keep devices awake. You must discard them anyway, as they are spurious. There's no point in transporting over the bus at all. We can cease IO for input.

Quoted 2 lines

This would create a parallel runtime-PM mechanism which is independent of the existing one. Is that really a good idea?

It isn't strictly PM. It helps PM to do a better job, but conceptually it is independent.

Regards
Oliver

#29 lore raw
Quoted 7 lines · Oliver Neukum
Quoted 2 lines

I'm not sure I understand what you're saying. Are you suggesting that this "inhibit" mechanism should involve a new callback different from

Yes, there is no necessary relation to power management. If you put your phone into your pocket, you will want to inhibit the touchscreen even if that doesn't save power.

Quoted 6 lines
Quoted 3 lines

the existing runtime-PM callbacks? And when this new callback is invoked, drivers should cancel existing input requests (these devices are input-only) and go to low power?

Cancel, yes, going to low power is a consequence which needn't bother the power subsystem.

Going to low power needn't involve the power subsystem? That sounds weird.

Quoted 10 lines

You need a callback. If there are spurious
events, the current heuristics will keep devices awake. You must discard them anyway, as they are spurious. There's no point in transporting over the bus at all. We can cease IO for input.

Quoted 2 lines

This would create a parallel runtime-PM mechanism which is independent of the existing one. Is that really a good idea?

It isn't strictly PM. It helps PM to do a better job, but conceptually it is independent.

So my next question is: _How_ can this help PM to do a better job? That is, what are the mechanisms?

One you have already stated: Lack of spurious events will help prevent unwanted wakeups (or unwanted failures to go to sleep).

But Dmitry made a stronger claim: Inhibiting an input device should allow the device to go to low power. I would like to know how we can implement this cleanly. The most straightforward approach is to use runtime PM, but it's not obvious how this can be made to work with the current API.

Alan Stern

#30 lore raw
Quoted 7 lines · Alan Stern
Quoted 2 lines · Oliver Neukum

Cancel, yes, going to low power is a consequence which needn't bother the power subsystem.

Going to low power needn't involve the power subsystem? That sounds weird.

Think of it like rfkill. It makes sense to suspend an rfkilled device. It still is the job of the driver to report that its device is idle.

Quoted 5 lines
Quoted 5 lines

You need a callback. If there are spurious
events, the current heuristics will keep devices awake. You must discard them anyway, as they are spurious. There's no point in transporting over the bus at all. We can cease IO for input.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

This would create a parallel runtime-PM mechanism which is independent of the existing one. Is that really a good idea?

It isn't strictly PM. It helps PM to do a better job, but conceptually it is independent.

So my next question is: _How_ can this help PM to do a better job? That is, what are the mechanisms?

"inhibit" -> driver stops input -> driver sets PM count to zero -> PM subsystem acts

To go from the first to the second step a callback is needed

Quoted 2 lines

One you have already stated: Lack of spurious events will help prevent unwanted wakeups (or unwanted failures to go to sleep).

That too. We also save CPU cycles.

Quoted 5 lines

But Dmitry made a stronger claim: Inhibiting an input device should allow the device to go to low power. I would like to know how we can implement this cleanly. The most straightforward approach is to use runtime PM, but it's not obvious how this can be made to work with the current API.

Yes, we can use the current API.
The key is that you think of the mechanism as induced idleness, not forced suspend. We already have a perfectly working mechanism for suspending idle devices.

Regards
Oliver

#31 lore raw
Quoted 24 lines · Oliver Neukum
Quoted 7 lines · Alan Stern
Quoted 2 lines · Oliver Neukum

Cancel, yes, going to low power is a consequence which needn't bother the power subsystem.

Going to low power needn't involve the power subsystem? That sounds weird.

Think of it like rfkill. It makes sense to suspend an rfkilled device. It still is the job of the driver to report that its device is idle.

Quoted 11 lines
Quoted 10 lines

You need a callback. If there are spurious
events, the current heuristics will keep devices awake. You must discard them anyway, as they are spurious. There's no point in transporting over the bus at all. We can cease IO for input.

Quoted 2 lines

This would create a parallel runtime-PM mechanism which is independent of the existing one. Is that really a good idea?

It isn't strictly PM. It helps PM to do a better job, but conceptually it is independent.

Quoted 8 lines
Quoted 2 lines

So my next question is: _How_ can this help PM to do a better job? That is, what are the mechanisms?

"inhibit" -> driver stops input -> driver sets PM count to zero -> PM subsystem acts

To go from the first to the second step a callback is needed

The IIO drivers use this model. The application keeps the fd open but there is a buffer enable switch to enable / disable input. Based on that trigger drivers use pm runtime put operations to induce PM idleness (and pm runtime get to wakeup the device).

Quoted 16 lines
Quoted 2 lines

One you have already stated: Lack of spurious events will help prevent unwanted wakeups (or unwanted failures to go to sleep).

That too. We also save CPU cycles.

Quoted 5 lines

But Dmitry made a stronger claim: Inhibiting an input device should allow the device to go to low power. I would like to know how we can implement this cleanly. The most straightforward approach is to use runtime PM, but it's not obvious how this can be made to work with the current API.

Yes, we can use the current API.
The key is that you think of the mechanism as induced idleness, not forced suspend. We already have a perfectly working mechanism for suspending idle devices.

#32 lore raw
In reply to Oliver Neukum
Quoted 11 lines · Oliver Neukum
Quoted 7 lines · Alan Stern
Quoted 2 lines · Oliver Neukum

Cancel, yes, going to low power is a consequence which needn't bother the power subsystem.

Going to low power needn't involve the power subsystem? That sounds weird.

Think of it like rfkill. It makes sense to suspend an rfkilled device. It still is the job of the driver to report that its device is idle.

Reporting that the device is idle _does_ involve the power subsystem. But never mind...

Quoted 5 lines
Quoted 2 lines

So my next question is: _How_ can this help PM to do a better job? That is, what are the mechanisms?

"inhibit" -> driver stops input -> driver sets PM count to zero -> PM subsystem acts

Your third step here poses problems. There is no runtime-PM API a driver or subsystem can use to set its usage counter to 0. All it can do is increment or decrement the counter.

Quoted 13 lines

To go from the first to the second step a callback is needed

Quoted 2 lines

One you have already stated: Lack of spurious events will help prevent unwanted wakeups (or unwanted failures to go to sleep).

That too. We also save CPU cycles.

Quoted 5 lines

But Dmitry made a stronger claim: Inhibiting an input device should allow the device to go to low power. I would like to know how we can implement this cleanly. The most straightforward approach is to use runtime PM, but it's not obvious how this can be made to work with the current API.

Quoted 4 lines

Yes, we can use the current API.
The key is that you think of the mechanism as induced idleness, not forced suspend. We already have a perfectly working mechanism for suspending idle devices.

After thinking some more about this, here's what I've got.

Let's talk about input-only devices being in an "idle" state or a "running" state:

When the device is in the idle state, its driver does not communicate with the device. In particular, the driver does not monitor for events or report them to the rest of the kernel. It is appropriate to put the device in runtime suspend with remote wakeup disabled.

When the device is in the running state, its driver receives event reports from the device and propagates them forward. The subsystem/driver may choose to put the device in runtime suspend between events with remote wakeup enabled (like we do for USB keyboards if no LEDs are on) or it may choose to leave the device at full power the whole time.

The idea is that a device is in the idle state whenever the open file count is 0 _or_ it is "inhibited"; otherwise it is in the running state.

I tried to come up with a way to do some of this work in a central core. All I could think of was that the core should detect state changes and inform the subsystem/driver when they occur. Everything else (starting and stopping I/O, adjusting the runtime-PM usage counter) would have to be done by the subsystem/driver.

The problem is that a core generally isn't aware of when a file reference is opened or released. Only the driver is. Which means there's nothing that the core can do here; the driver and subsystem have to manage pretty much the whole thing. A simple example:

open()

{
	mutex_lock(&dev->open_mutex);
	if (dev->open_count++ == 0 && !dev->inhibited) {
		pm_runtime_get_sync(dev);
		start_io(dev);
	}
	mutex_unlock(&dev->open_mutex);
}

release()

{
	mutex_lock(&dev->open_mutex);
	if (--dev->open_count == 0 && !dev->inhibited) {
		stop_io(dev);
		pm_runtime_put(dev);
	}
	mutex_unlock(&dev->open_mutex);
}

inhibit()

{
	mutex_lock(&dev->open_mutex);
	dev->inhibited = true;
	if (dev->open_count > 0) {
		stop_io(dev);
		pm_runtime_put(dev);
	}
	mutex_unlock(&dev->open_mutex);
}

uninhibit()

{
	mutex_lock(&dev->open_mutex);
	dev->inhibited = false;
	if (dev->open_count > 0) {
		pm_runtime_get_sync(dev);
		start_io(dev);
	}
	mutex_unlock(&dev->open_mutex);
}

This doesn't leave much room for the PM core or anything else.

Alan Stern

#33 lore raw
Quoted 120 lines · Alan Stern
Quoted 11 lines · Oliver Neukum
Quoted 7 lines · Alan Stern
Quoted 2 lines · Oliver Neukum

Cancel, yes, going to low power is a consequence which needn't bother the power subsystem.

Going to low power needn't involve the power subsystem? That sounds weird.

Think of it like rfkill. It makes sense to suspend an rfkilled device. It still is the job of the driver to report that its device is idle.

Reporting that the device is idle _does_ involve the power subsystem. But never mind...

Quoted 5 lines
Quoted 2 lines

So my next question is: _How_ can this help PM to do a better job? That is, what are the mechanisms?

"inhibit" -> driver stops input -> driver sets PM count to zero -> PM subsystem acts

Your third step here poses problems. There is no runtime-PM API a driver or subsystem can use to set its usage counter to 0. All it can do is increment or decrement the counter.

Quoted 13 lines

To go from the first to the second step a callback is needed

Quoted 2 lines

One you have already stated: Lack of spurious events will help prevent unwanted wakeups (or unwanted failures to go to sleep).

That too. We also save CPU cycles.

Quoted 5 lines

But Dmitry made a stronger claim: Inhibiting an input device should allow the device to go to low power. I would like to know how we can implement this cleanly. The most straightforward approach is to use runtime PM, but it's not obvious how this can be made to work with the current API.

Quoted 4 lines

Yes, we can use the current API.
The key is that you think of the mechanism as induced idleness, not forced suspend. We already have a perfectly working mechanism for suspending idle devices.

After thinking some more about this, here's what I've got.

Let's talk about input-only devices being in an "idle" state or a "running" state:

When the device is in the idle state, its driver does not communicate with the device. In particular, the driver does not monitor for events or report them to the rest of the kernel. It is appropriate to put the device in runtime suspend with remote wakeup disabled.

When the device is in the running state, its driver receives event reports from the device and propagates them forward. The subsystem/driver may choose to put the device in runtime suspend between events with remote wakeup enabled (like we do for USB keyboards if no LEDs are on) or it may choose to leave the device at full power the whole time.

The idea is that a device is in the idle state whenever the open file count is 0 _or_ it is "inhibited"; otherwise it is in the running state.

I tried to come up with a way to do some of this work in a central core. All I could think of was that the core should detect state changes and inform the subsystem/driver when they occur. Everything else (starting and stopping I/O, adjusting the runtime-PM usage counter) would have to be done by the subsystem/driver.

The problem is that a core generally isn't aware of when a file reference is opened or released. Only the driver is. Which means there's nothing that the core can do here; the driver and subsystem have to manage pretty much the whole thing. A simple example:

open()

{
	mutex_lock(&dev->open_mutex);
	if (dev->open_count++ == 0 && !dev->inhibited) {
		pm_runtime_get_sync(dev);
		start_io(dev);
	}
	mutex_unlock(&dev->open_mutex);
}

release()

{
	mutex_lock(&dev->open_mutex);
	if (--dev->open_count == 0 && !dev->inhibited) {
		stop_io(dev);
		pm_runtime_put(dev);
	}
	mutex_unlock(&dev->open_mutex);
}

inhibit()

{
	mutex_lock(&dev->open_mutex);
	dev->inhibited = true;
	if (dev->open_count > 0) {
		stop_io(dev);
		pm_runtime_put(dev);
	}
	mutex_unlock(&dev->open_mutex);
}

uninhibit()

{
	mutex_lock(&dev->open_mutex);
	dev->inhibited = false;
	if (dev->open_count > 0) {
		pm_runtime_get_sync(dev);
		start_io(dev);
	}
	mutex_unlock(&dev->open_mutex);
}
Quoted 1 line

This doesn't leave much room for the PM core or anything else.

We are missing the "no remote wakeup" bit now (well, there is a PM QoS flag, but it isn't very useful, so I'd prefer to replace it with a "no remote wakeup" bit in struct dev_pm_info or something similar).

That is actually quite important, because (a) we can save energy but not configuring the device to do remote wakeup in the first place and (b) that may involve more than just the driver (for example, disabling PCI or ACPI remote wakeup involves the bus type or similar).

So it looks like we need to be able to distinguish between "runtime suspend with remote wakeup" and "runtime suspend without remote wakeup".

And if we do the latter, we may not even need the "inhibit" thing any more, because suspended devices without that are not configured to do remote wakeup cannot really signal anything in the majority of cases.

Thanks,
Rafael

#34 lore raw
Quoted 9 lines · Rafael J. Wysocki

We are missing the "no remote wakeup" bit now (well, there is a PM QoS flag, but it isn't very useful, so I'd prefer to replace it with a "no remote wakeup" bit in struct dev_pm_info or something similar).

That is actually quite important, because (a) we can save energy but not configuring the device to do remote wakeup in the first place and (b) that may involve more than just the driver (for example, disabling PCI or ACPI remote wakeup involves the bus type or similar).

Quoted 6 lines

So it looks like we need to be able to distinguish between "runtime suspend with remote wakeup" and "runtime suspend without remote wakeup".

And if we do the latter, we may not even need the "inhibit" thing any more, because suspended devices without that are not configured to do remote wakeup cannot really signal anything in the majority of cases.

That works only for drivers that use autosuspend to go to low power in between events. It doesn't work for drivers that remain at full power as long as the device file is open. That kind of driver does require an "inhibit" interface.

Alan Stern

#35 lore raw
Quoted 14 lines · Alan Stern
Quoted 12 lines · Rafael J. Wysocki

We are missing the "no remote wakeup" bit now (well, there is a PM QoS flag, but it isn't very useful, so I'd prefer to replace it with a "no remote wakeup" bit in struct dev_pm_info or something similar).

That is actually quite important, because (a) we can save energy but not configuring the device to do remote wakeup in the first place and (b) that may involve more than just the driver (for example, disabling PCI or ACPI remote wakeup involves the bus type or similar).

So it looks like we need to be able to distinguish between "runtime suspend with remote wakeup" and "runtime suspend without remote wakeup".

Quoted 8 lines
Quoted 3 lines

And if we do the latter, we may not even need the "inhibit" thing any more, because suspended devices without that are not configured to do remote wakeup cannot really signal anything in the majority of cases.

That works only for drivers that use autosuspend to go to low power in between events. It doesn't work for drivers that remain at full power as long as the device file is open. That kind of driver does require an "inhibit" interface.

Or an interface allowing user space to trigger pm_request_idle() for them.

So user space would change the "no remote wakeup" setting and then do the "try to suspend now" thing.

Thanks,
Rafael

#36 lore raw
Quoted 24 lines · Rafael J. Wysocki
Quoted 14 lines · Alan Stern
Quoted 12 lines · Rafael J. Wysocki

We are missing the "no remote wakeup" bit now (well, there is a PM QoS flag, but it isn't very useful, so I'd prefer to replace it with a "no remote wakeup" bit in struct dev_pm_info or something similar).

That is actually quite important, because (a) we can save energy but not configuring the device to do remote wakeup in the first place and (b) that may involve more than just the driver (for example, disabling PCI or ACPI remote wakeup involves the bus type or similar).

So it looks like we need to be able to distinguish between "runtime suspend with remote wakeup" and "runtime suspend without remote wakeup".

Quoted 8 lines
Quoted 3 lines

And if we do the latter, we may not even need the "inhibit" thing any more, because suspended devices without that are not configured to do remote wakeup cannot really signal anything in the majority of cases.

That works only for drivers that use autosuspend to go to low power in between events. It doesn't work for drivers that remain at full power as long as the device file is open. That kind of driver does require an "inhibit" interface.

Quoted 4 lines

Or an interface allowing user space to trigger pm_request_idle() for them.

So user space would change the "no remote wakeup" setting and then do the "try to suspend now" thing.

So something like:

echo on >/sys/.../power/control (in case the device was
already in runtime suspend with wakeups enabled)
echo off >/sys/.../power/wakeup
echo auto >/sys/.../power/control

This should work. But it would require that the driver doesn't increment the usage counter when the device file is opened. I can imagine this might lead to trouble if you're dealing with hardware that doesn't support remote wakeup very well. The driver wouldn't be able to work around the hardware issue by incrementing the usage counter.

In real life this might not be a serious issue. I don't know.

Alan Stern

#37 lore raw
Quoted 31 lines · Alan Stern
Quoted 24 lines · Rafael J. Wysocki
Quoted 14 lines · Alan Stern
Quoted 12 lines · Rafael J. Wysocki

We are missing the "no remote wakeup" bit now (well, there is a PM QoS flag, but it isn't very useful, so I'd prefer to replace it with a "no remote wakeup" bit in struct dev_pm_info or something similar).

That is actually quite important, because (a) we can save energy but not configuring the device to do remote wakeup in the first place and (b) that may involve more than just the driver (for example, disabling PCI or ACPI remote wakeup involves the bus type or similar).

So it looks like we need to be able to distinguish between "runtime suspend with remote wakeup" and "runtime suspend without remote wakeup".

Quoted 8 lines
Quoted 3 lines

And if we do the latter, we may not even need the "inhibit" thing any more, because suspended devices without that are not configured to do remote wakeup cannot really signal anything in the majority of cases.

That works only for drivers that use autosuspend to go to low power in between events. It doesn't work for drivers that remain at full power as long as the device file is open. That kind of driver does require an "inhibit" interface.

Quoted 4 lines

Or an interface allowing user space to trigger pm_request_idle() for them.

So user space would change the "no remote wakeup" setting and then do the "try to suspend now" thing.

Quoted 6 lines

So something like:

echo on >/sys/.../power/control (in case the device was
already in runtime suspend with wakeups enabled)
echo off >/sys/.../power/wakeup
echo auto >/sys/.../power/control

That, or there may be an additional value, say "aggressive", to write to the control file in which case it becomes just

echo aggressive >/sys/.../power/control

Quoted 3 lines

This should work. But it would require that the driver doesn't increment the usage counter when the device file is opened.

Right.

Quoted 3 lines

I can imagine this might lead to trouble if you're dealing with hardware that doesn't support remote wakeup very well. The driver wouldn't be able to work around the hardware issue by incrementing the usage counter.

Or the "aggressive" mode wouldn't work for it.

Quoted 1 line

In real life this might not be a serious issue. I don't know.

Me neither.

Thanks,
Rafael

#38 lore raw
Quoted 39 lines · Rafael J. Wysocki
Quoted 31 lines · Alan Stern
Quoted 24 lines · Rafael J. Wysocki
Quoted 14 lines · Alan Stern
Quoted 12 lines · Rafael J. Wysocki

We are missing the "no remote wakeup" bit now (well, there is a PM QoS flag, but it isn't very useful, so I'd prefer to replace it with a "no remote wakeup" bit in struct dev_pm_info or something similar).

That is actually quite important, because (a) we can save energy but not configuring the device to do remote wakeup in the first place and (b) that may involve more than just the driver (for example, disabling PCI or ACPI remote wakeup involves the bus type or similar).

So it looks like we need to be able to distinguish between "runtime suspend with remote wakeup" and "runtime suspend without remote wakeup".

Quoted 8 lines
Quoted 3 lines

And if we do the latter, we may not even need the "inhibit" thing any more, because suspended devices without that are not configured to do remote wakeup cannot really signal anything in the majority of cases.

That works only for drivers that use autosuspend to go to low power in between events. It doesn't work for drivers that remain at full power as long as the device file is open. That kind of driver does require an "inhibit" interface.

Quoted 4 lines

Or an interface allowing user space to trigger pm_request_idle() for them.

So user space would change the "no remote wakeup" setting and then do the "try to suspend now" thing.

Quoted 6 lines

So something like:

echo on >/sys/.../power/control (in case the device was
already in runtime suspend with wakeups enabled)
echo off >/sys/.../power/wakeup
echo auto >/sys/.../power/control

Quoted 4 lines

That, or there may be an additional value, say "aggressive", to write to the control file in which case it becomes just

echo aggressive >/sys/.../power/control

That said I suppose that the "off" value for the "wakeup" file might also be useful in some other cases, so it likely is a better approach.

Thanks,
Rafael

#39 lore raw
Quoted 6 lines · Rafael J. Wysocki
Quoted 6 lines
Quoted 6 lines

So something like:

echo on >/sys/.../power/control (in case the device was
already in runtime suspend with wakeups enabled)
echo off >/sys/.../power/wakeup
echo auto >/sys/.../power/control

Cases where the driver wants to avoid runtime suspend (while the device is active) because of bad wakeup support in the hardware can be handled easily enough. The runtime-idle or runtime-suspend callback routine can check whether wakeup == off; if it isn't then the callback should return -EBUSY. Thus the driver can prevent runtime suspend without any need to increment the usage counter.

Quoted 7 lines
Quoted 4 lines

That, or there may be an additional value, say "aggressive", to write to the control file in which case it becomes just

echo aggressive >/sys/.../power/control

That said I suppose that the "off" value for the "wakeup" file might also be useful in some other cases, so it likely is a better approach.

We still need some sort of "inhibit" callback for cases where the driver doesn't want to go into runtime suspend but does want to turn off all I/O. Should this callback be triggered when the user writes "off" to power/wakeup, or when the user writes "inhibit" to power/control, or should there be a separate sysfs attribute?

Alan Stern

#40 lore raw
Quoted 9 lines · Alan Stern
Quoted 6 lines · Rafael J. Wysocki
Quoted 6 lines
Quoted 6 lines

So something like:

echo on >/sys/.../power/control (in case the device was
already in runtime suspend with wakeups enabled)
echo off >/sys/.../power/wakeup
echo auto >/sys/.../power/control

Quoted 6 lines

Cases where the driver wants to avoid runtime suspend (while the device is active) because of bad wakeup support in the hardware can be handled easily enough. The runtime-idle or runtime-suspend callback routine can check whether wakeup == off; if it isn't then the callback should return -EBUSY. Thus the driver can prevent runtime suspend without any need to increment the usage counter.

Right.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

That, or there may be an additional value, say "aggressive", to write to the control file in which case it becomes just

echo aggressive >/sys/.../power/control

Quoted 8 lines
Quoted 2 lines

That said I suppose that the "off" value for the "wakeup" file might also be useful in some other cases, so it likely is a better approach.

We still need some sort of "inhibit" callback for cases where the driver doesn't want to go into runtime suspend but does want to turn off all I/O. Should this callback be triggered when the user writes "off" to power/wakeup, or when the user writes "inhibit" to power/control, or should there be a separate sysfs attribute?

My first thought is that if there is a separate attribute, then it only actually makes sense for devices that generate input events, while the "off" thing may be generally useful in principle (eg. it may indicate to disable PME for the device to the PCI layer etc).

OTOH, the additional "inhibit" attribute may only be exposed if the corresponding callback is present, so I'm not really sure.

Question is, though, what's the use case for turning off I/O when we don't go into runtime suspend. After all, runtime suspend need not mean putting the device into any kind of low-power state and the "off" thing may very well be defined to mean that all input is discarded if the device is runtime-suspended and the device is not configured to do remote wakeup then.

Thanks,
Rafael

#41 lore raw
Quoted 16 lines · Rafael J. Wysocki
Quoted 9 lines · Alan Stern
Quoted 6 lines · Rafael J. Wysocki
Quoted 6 lines
Quoted 6 lines

So something like:

echo on >/sys/.../power/control (in case the device was
already in runtime suspend with wakeups enabled)
echo off >/sys/.../power/wakeup
echo auto >/sys/.../power/control

Quoted 5 lines

We still need some sort of "inhibit" callback for cases where the driver doesn't want to go into runtime suspend but does want to turn off all I/O. Should this callback be triggered when the user writes "off" to power/wakeup, or when the user writes "inhibit" to power/control, or should there be a separate sysfs attribute?

Quoted 4 lines

My first thought is that if there is a separate attribute, then it only actually makes sense for devices that generate input events, while the "off" thing may be generally useful in principle (eg. it may indicate to disable PME for the device to the PCI layer etc).

I'm not sure how much sense that distinction makes. It seems to me the only time you want to ignore potential wakeup events is if you want to ignore _all_ input. Which is basically what "inhibit" means.

This suggests we forget about power/wakeup == "off" and introduce an "inhibit" attribute instead.

Quoted 2 lines

OTOH, the additional "inhibit" attribute may only be exposed if the corresponding callback is present, so I'm not really sure.

It could be a separate attribute, or it could be a new entry for power/control. Come to think of it, a separate attribute might be better. Otherwise we would lose track of whether runtime suspend was permitted (the "on" vs. "auto" distinction) when the device was inhibited. I can imagine someone might want to forbid runtime suspend but still inhibit a device.

However, I agree that there's no point registering a separate attribute or accepting a write of "inhibit" to power/control if there's no corresponding callback.

Quoted 6 lines

Question is, though, what's the use case for turning off I/O when we don't go into runtime suspend. After all, runtime suspend need not mean putting the device into any kind of low-power state and the "off" thing may very well be defined to mean that all input is discarded if the device is runtime-suspended and the device is not configured to do remote wakeup then.

Well, I suppose there might be a driver that supports inhibit but doesn't support runtime PM, unlikely as that seems. Or the driver might support both but the user might leave power/control == "on" while inhibiting the device.

Alan Stern

#47 lore raw
In reply to Rafael J. Wysocki

Hi!

Quoted 19 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

That, or there may be an additional value, say "aggressive", to write to the control file in which case it becomes just

echo aggressive >/sys/.../power/control

Quoted 8 lines
Quoted 2 lines

That said I suppose that the "off" value for the "wakeup" file might also be useful in some other cases, so it likely is a better approach.

We still need some sort of "inhibit" callback for cases where the driver doesn't want to go into runtime suspend but does want to turn off all I/O. Should this callback be triggered when the user writes "off" to power/wakeup, or when the user writes "inhibit" to power/control, or should there be a separate sysfs attribute?

My first thought is that if there is a separate attribute, then it only actually makes sense for devices that generate input events, while the "off" thing may be generally useful in principle (eg. it may indicate to disable PME for the device to the PCI layer etc).

Quoted 5 lines

OTOH, the additional "inhibit" attribute may only be exposed if the corresponding callback is present, so I'm not really sure.

Question is, though, what's the use case for turning off I/O when we don't go into runtime suspend. After all, runtime suspend need not mean putting

Well... In "cellphone goes to pocket" case, you want to turn off I/O even if the touchscreen can not support runtime suspend.

See parents in the thread for explanation.

Pavel

#42 lore raw
In reply to Alan Stern
Quoted 18 lines · Alan Stern
Quoted 16 lines · Rafael J. Wysocki
Quoted 14 lines · Alan Stern
Quoted 6 lines · Rafael J. Wysocki
Quoted 6 lines
Quoted 6 lines

So something like:

echo on >/sys/.../power/control (in case the device was
already in runtime suspend with wakeups enabled)
echo off >/sys/.../power/wakeup
echo auto >/sys/.../power/control

We still need some sort of "inhibit" callback for cases where the driver doesn't want to go into runtime suspend but does want to turn off all I/O. Should this callback be triggered when the user writes "off" to power/wakeup, or when the user writes "inhibit" to power/control, or should there be a separate sysfs attribute?

Quoted 8 lines
Quoted 4 lines

My first thought is that if there is a separate attribute, then it only actually makes sense for devices that generate input events, while the "off" thing may be generally useful in principle (eg. it may indicate to disable PME for the device to the PCI layer etc).

I'm not sure how much sense that distinction makes. It seems to me the only time you want to ignore potential wakeup events is if you want to ignore _all_ input. Which is basically what "inhibit" means.

The other case I had in mind is specific to the PCI layer and might be better served by adding an "ignore PME" flag to PCI devices.

Quoted 2 lines

This suggests we forget about power/wakeup == "off" and introduce an "inhibit" attribute instead.

If we do that, can it still be regarded as a PM attribute?

And what about the corresponding callback? Should that be a PM callback or a general one?

Quoted 21 lines
Quoted 2 lines

OTOH, the additional "inhibit" attribute may only be exposed if the corresponding callback is present, so I'm not really sure.

It could be a separate attribute, or it could be a new entry for power/control. Come to think of it, a separate attribute might be better. Otherwise we would lose track of whether runtime suspend was permitted (the "on" vs. "auto" distinction) when the device was inhibited. I can imagine someone might want to forbid runtime suspend but still inhibit a device.

However, I agree that there's no point registering a separate attribute or accepting a write of "inhibit" to power/control if there's no corresponding callback.

Quoted 6 lines

Question is, though, what's the use case for turning off I/O when we don't go into runtime suspend. After all, runtime suspend need not mean putting the device into any kind of low-power state and the "off" thing may very well be defined to mean that all input is discarded if the device is runtime-suspended and the device is not configured to do remote wakeup then.

Quoted 4 lines

Well, I suppose there might be a driver that supports inhibit but doesn't support runtime PM, unlikely as that seems. Or the driver might support both but the user might leave power/control == "on" while inhibiting the device.

That sounds like a general rather than PM-related mechanism then.

I guess we need a real use case for that last thing or it will be rather difficult to convince Greg to accept the patch. :-)

Thanks,
Rafael

#48 lore raw
In reply to Pavel Machek
Quoted 1 line · Pavel Machek

Hi!

Hi,

Quoted 22 lines
Quoted 22 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

That, or there may be an additional value, say "aggressive", to write to the control file in which case it becomes just

echo aggressive >/sys/.../power/control

Quoted 8 lines
Quoted 2 lines

That said I suppose that the "off" value for the "wakeup" file might also be useful in some other cases, so it likely is a better approach.

We still need some sort of "inhibit" callback for cases where the driver doesn't want to go into runtime suspend but does want to turn off all I/O. Should this callback be triggered when the user writes "off" to power/wakeup, or when the user writes "inhibit" to power/control, or should there be a separate sysfs attribute?

My first thought is that if there is a separate attribute, then it only actually makes sense for devices that generate input events, while the "off" thing may be generally useful in principle (eg. it may indicate to disable PME for the device to the PCI layer etc).

OTOH, the additional "inhibit" attribute may only be exposed if the corresponding callback is present, so I'm not really sure.

Quoted 7 lines
Quoted 2 lines

Question is, though, what's the use case for turning off I/O when we don't go into runtime suspend. After all, runtime suspend need not mean putting

Well... In "cellphone goes to pocket" case, you want to turn off I/O even if the touchscreen can not support runtime suspend.

See parents in the thread for explanation.

You seem to be confusing the ability to go into low-power states with supporting runtime PM. The latter by no means requires the former.

Also "cellphone goes to pocket" is really two different cases. One is when the user indicated "I'm not going to use the phone going forward" somehow (like by pressing a screen-off button) and one is when (s)he didn't.

In the second case we really have no reason to discard any input and in the first one we may as well go straight for runtime suspend (or even for system suspend for that matter).

Thanks,
Rafael

#43 lore raw
In reply to Rafael J. Wysocki
Quoted 4 lines · Rafael J. Wysocki
Quoted 2 lines

This suggests we forget about power/wakeup == "off" and introduce an "inhibit" attribute instead.

If we do that, can it still be regarded as a PM attribute?

Why not? Consider this: Is there any reason to support inhibit when CONFIG_PM is disabled? I can't come up with any.

Quoted 2 lines

And what about the corresponding callback? Should that be a PM callback or a general one?

Well, if "inhibit" is a PM attribute then the callback should be a PM callback. :-)

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

Question is, though, what's the use case for turning off I/O when we don't go into runtime suspend. After all, runtime suspend need not mean putting the device into any kind of low-power state and the "off" thing may very well be defined to mean that all input is discarded if the device is runtime-suspended and the device is not configured to do remote wakeup then.

Quoted 6 lines
Quoted 4 lines

Well, I suppose there might be a driver that supports inhibit but doesn't support runtime PM, unlikely as that seems. Or the driver might support both but the user might leave power/control == "on" while inhibiting the device.

That sounds like a general rather than PM-related mechanism then.

I don't follow your reasoning.

Quoted 2 lines

I guess we need a real use case for that last thing or it will be rather difficult to convince Greg to accept the patch. :-)

The hard part is to come up with a design that Greg agrees with. If the design is okay, there's no reason not to accept the patch.

One of the questions amounts to this: Do we want to allow situations where input is inhibited but the user prevents the device from going into runtime suspend by setting power/control = "on"? If the answer is Yes then "inhibit" should be a separate attribute. Otherwise, we can just let "inhibit" be another setting in power/control.

Another question is: Do we want to make it easy for drivers to support inhibit while still incrementing their PM usage counter every time the device file is opened? If we do then inhibit must be considered separate from runtime suspend, because a device _can't_ go directly into runtime suspend when the usage counter is > 1. If we don't then we will most likely have to change the runtime-PM support in some drivers before they can implement inhibit.

Alan Stern

#44 lore raw

Hi Alan,

Quoted 9 lines · Alan Stern
Quoted 4 lines · Rafael J. Wysocki
Quoted 2 lines

This suggests we forget about power/wakeup == "off" and introduce an "inhibit" attribute instead.

If we do that, can it still be regarded as a PM attribute?

Why not? Consider this: Is there any reason to support inhibit when CONFIG_PM is disabled? I can't come up with any.

Well, the "I don't want any input from you now, because the phone is going into a pocket" case?

It isn't stticlty dependent on PM.

Quoted 13 lines
Quoted 2 lines

And what about the corresponding callback? Should that be a PM callback or a general one?

Well, if "inhibit" is a PM attribute then the callback should be a PM callback. :-)

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

Question is, though, what's the use case for turning off I/O when we don't go into runtime suspend. After all, runtime suspend need not mean putting the device into any kind of low-power state and the "off" thing may very well be defined to mean that all input is discarded if the device is runtime-suspended and the device is not configured to do remote wakeup then.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Well, I suppose there might be a driver that supports inhibit but doesn't support runtime PM, unlikely as that seems. Or the driver might support both but the user might leave power/control == "on" while inhibiting the device.

That sounds like a general rather than PM-related mechanism then.

I don't follow your reasoning.

Support for "inhibit" and lack of runtime PM support means that the feature has nothing to do with PM any more AFAICS.

That's why I think it may be regarded by more than just PM. It should make runtime PM behave in a specific way if supported, but then it should work withot it too, shouldn't it?

Quoted 11 lines
Quoted 2 lines

I guess we need a real use case for that last thing or it will be rather difficult to convince Greg to accept the patch. :-)

The hard part is to come up with a design that Greg agrees with. If the design is okay, there's no reason not to accept the patch.

One of the questions amounts to this: Do we want to allow situations where input is inhibited but the user prevents the device from going into runtime suspend by setting power/control = "on"? If the answer is Yes then "inhibit" should be a separate attribute. Otherwise, we can just let "inhibit" be another setting in power/control.

I think that the answer really is "yes" in general as long as it makes sense to discard input without closing the device.

My understanding of "inhibit" would be "discard all input including any wakeup events from now on". It would be quite natural for runtime suspend to trigger if that is set (unless disabled or not supported, of course), but I don't think that this should be a requirement.

Quoted 7 lines

Another question is: Do we want to make it easy for drivers to support inhibit while still incrementing their PM usage counter every time the device file is opened? If we do then inhibit must be considered separate from runtime suspend, because a device _can't_ go directly into runtime suspend when the usage counter is > 1. If we don't then we will most likely have to change the runtime-PM support in some drivers before they can implement inhibit.

My opinion is that "inhibit" should affect PM, but should not require PM to function (there's no technical reason for that).

Thanks,
Rafael

#45 lore raw
Quoted 8 lines · Rafael J. Wysocki

Hi Alan,

Quoted 5 lines · Alan Stern
Quoted 3 lines · Rafael J. Wysocki
Quoted 2 lines

This suggests we forget about power/wakeup == "off" and introduce an "inhibit" attribute instead.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

If we do that, can it still be regarded as a PM attribute?

Why not? Consider this: Is there any reason to support inhibit when CONFIG_PM is disabled? I can't come up with any.

Well, the "I don't want any input from you now, because the phone is going into a pocket" case?

But who would make a phone without CONFIG_PM? If you're sufficiently unconcerned about power usage that you turn off CONFIG_PM, then you probably don't care about getting excess input events either.

Quoted 1 line

It isn't stticlty dependent on PM.

No, not strictly. But it is closely enough related that people shouldn't mind if it becomes part of the PM code.

Quoted 11 lines
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Well, I suppose there might be a driver that supports inhibit but doesn't support runtime PM, unlikely as that seems. Or the driver might support both but the user might leave power/control == "on" while inhibiting the device.

That sounds like a general rather than PM-related mechanism then.

I don't follow your reasoning.

Support for "inhibit" and lack of runtime PM support means that the feature has nothing to do with PM any more AFAICS.

My example above referred to support in a single driver, not support in the system as a whole. By the same reasoning, since some drivers support system sleep but not runtime PM, system sleep must have nothing to do with PM. :-)

Quoted 3 lines

That's why I think it may be regarded by more than just PM. It should make runtime PM behave in a specific way if supported, but then it should work withot it too, shouldn't it?

If you want inhibit to be part of the device core rather than the PM core, that's okay with me.

Quoted 2 lines

My opinion is that "inhibit" should affect PM, but should not require PM to function (there's no technical reason for that).

All right. Then a design should be straightforward.

Alan Stern

#46 lore raw

Hi!

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

This suggests we forget about power/wakeup == "off" and introduce an "inhibit" attribute instead.

If we do that, can it still be regarded as a PM attribute?

Why not? Consider this: Is there any reason to support inhibit when CONFIG_PM is disabled? I can't come up with any.

Quoted 6 lines
Quoted 2 lines

Well, the "I don't want any input from you now, because the phone is going into a pocket" case?

But who would make a phone without CONFIG_PM? If you're sufficiently unconcerned about power usage that you turn off CONFIG_PM, then you probably don't care about getting excess input events either.

Well.. .excess input events means that your phone now sends (meaningful, thanks to advanced predictions) messages to your friends...

Better not do that.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html