Thread (101 messages) 101 messages, 11 authors, 2020-12-11

Re: [PATCH 1/2] Input: Add "inhibited" property

From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Date: 2020-05-06 00:27:51

Hi Andrzej,

On Thu, Apr 30, 2020 at 06:16:40PM +0200, Andrzej Pietrasiewicz wrote:
From: Patrik Fimml <redacted>

Userspace might want to implement a policy to temporarily disregard input
from certain devices, including not treating them as wakeup sources.

An example use case is a laptop, whose keyboard can be folded under the
screen to create tablet-like experience. The user then must hold the laptop
in such a way that it is difficult to avoid pressing the keyboard keys. It
is therefore desirable to temporarily disregard input from the keyboard,
until it is folded back. This obviously is a policy which should be kept
out of the kernel, but the kernel must provide suitable means to implement
such a policy.

This patch adds a sysfs interface for exactly this purpose.

To implement the said interface it adds an "inhibited" property to struct
input_dev and two optional methods - inhibit() and uninhibit(), and
effectively creates four states a device can be in: closed uninhibited,
closed inhibited, open uninhibited, open inhibited. It also defers calling
driver's ->open() and ->close() to until they are actually needed, e.g. it
makes no sense to prepare the underlying device for generating events
(->open()) if the device is inhibited.

              uninhibit
closed      <------------ closed
uninhibited ------------> inhibited
      | ^     inhibit        | ^
 1st  | |               1st  | |
 open | |               open | |
      | |                    | |
      | | last               | | last
      | | close              | | close
      v |     uninhibit      v |
open        <------------ open
uninhibited ------------> inhibited

The top inhibit/uninhibit transition happens when users == 0.
The bottom inhibit/uninhibit transition happens when users > 0.
The left open/close transition happens when !inhibited.
The right open/close transition happens when inhibited.
Due to all transitions being serialized with dev->mutex, it is impossible
to have "diagonal" transitions between closed uninhibited and open
inhibited or between open uninhibited and closed inhibited.

While open()/close() could be used in place of uninhibit()/inhibit(),
underlying driver implementations have very different ideas of what it
means to open/close, to suspend/resume or to pm runtime suspend/resume.
On top of that close() does not return a code, so using close() there be
no way to actually fail inhibiting.
While I totally agree that we want to allow drivers to have flexibility
in implementing open/close/inhibit/uninhibit, I believe for majority of
devices using close() in place of inhibit and open() in place of
uninhibit is a very viable solution and will allow us to realize most of
the power savings.

Can we try to fall back on open/close when uninhibit/inhbit is not
present?

I think this will also require some preliminary work in the drivers with
regard to suspend/resume, as they tend to directly check
input_dev->users when deciding whether they need to power up the
hardware/take it out of sleep. With inhibit in place we need to beef up
this condition, I'd like to have something


bool input_device_enabled(struct input_dev *dev)
{
	lockdep_assert_held(&dev->mutex);
	return !dev->inhibited && dev->users != 0;
}

or something similar.

Thanks.

-- 
Dmitry
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help