linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Henrik Rydberg" <rydberg@euromail.se>
To: Bill Gatliff <bgat@billgatliff.com>
Cc: linux-input@vger.kernel.org
Subject: Re: [PATCH] input: evdev: Add a read() callback
Date: Tue, 22 Feb 2011 10:14:33 +0100	[thread overview]
Message-ID: <20110222091433.GA2183@polaris.bitmath.org> (raw)
In-Reply-To: <1298297930-3937-1-git-send-email-bgat@billgatliff.com>

Hi Bill,

Some additional comments inline.

On Mon, Feb 21, 2011 at 08:18:50AM -0600, Bill Gatliff wrote:
> Some devices, like accelerometers, can manufacture as many input
> events as userspace can consume.  The traditional method for limiting
> the number of input events sent to userspace by such devices is to use
> a kernel thread looping around an idle timer, to "throttle" the
> creation and queuing of input events to a manageable rate.  Such
> drivers often also provide a sysfs attribute (or similar means) that
> allows userspace to indicate a desired event rate.
>
> Some operating systems and/or applications e.g. Android, might prefer
> to control input event creation rates themselves.  They frequently
> attempt to do so by implementing a userspace polling thread that loops
> around an idle timer; this idle timer throttles the rate of calls to
> the input devices' read() method, which (at least in theory) limits
> the rate of input events arriving at the application to a desired
> level.

In addition, we do have open/close and EV_ABS fuzz ioctl as two
existing, user-controllable throttling techniques. Additional filter
possibilities might do the trick?

> The enclosed patch address all of the above problems by implementing
> an advisory callback from the evdev read() and poll() methods to the
> associated input device driver.  The driver may then choose to
> populate the input event buffer at that time, rather than on a
> schedule implemented by a polling loop, sysfs trigger, or other means.

As already stated, this does not play very well with the event model.

> Use of this callback by a driver naturally synchronizes the generation
> of input events to requests from userspace, because the driver now
> "knows" when userspace is attempting to retrieve an input event and
> can therefore produce one just-in-time.  It also allows the driver to
> easily match the rate of input event generation, by simply sampling the
> hardware only during this callback.

The same effect could be achieved if the driver could simply ask the
input core if the read buffers are being emptied or not.

> If an input device driver chooses to use only the read() callback as
> its signal to produce an input event, then the driver need not
> implement a polling kernel thread or other means of pacing its event
> generation rate.

There is a generic polled input device for that.

> The driver also has no need to provide a sysfs
> attribute to allow userspace to request a polling rate or to trigger a
> measurement: userspace must only read() or poll() the interface at the
> desired rate.  This can greatly simplify input device driver
> implementation, while conveniently leaving the incoming event rate and
> synchronization issues completely up to the application. (See POSIX.1b
> interval timers and scheduler options for APIs allowing precise timing
> within user applications).

Right, rate adaption should be transparent and automatic.

> Finally, input device drivers might choose to implement a holdoff
> timer that gets reset in the read() callback; expiration of this timer
> would mean that userspace is no longer actively reading from the
> device, even though the interface itself might still be open.  In such
> cases the driver might wish to invoke a power-management method to
> idle the hardware until the next  callback occurs.

Or userspace could actually close the device to accomplish the desired
effect with existing infrastructure.

> Polled devices like accelerometers and compasses (and perhaps some
> types of pushbuttons or switch inputs) will get the most benefit from
> utilizing the read() callback.  Other devices, like USB keyboards and
> mice, will have no use for it and may safely ignore it.

Thanks,
Henrik

      parent reply	other threads:[~2011-02-22  9:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-21 14:18 [PATCH] input: evdev: Add a read() callback Bill Gatliff
2011-02-22  0:23 ` Mark Brown
2011-02-22  4:07   ` Bill Gatliff
2011-02-22  4:33     ` Mark Brown
2011-02-22 13:13       ` Jonathan Cameron
2011-02-26  2:49         ` Bill Gatliff
2011-02-26  2:46       ` Bill Gatliff
2011-02-26  9:45         ` Mark Brown
2011-02-22  9:14 ` Henrik Rydberg [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110222091433.GA2183@polaris.bitmath.org \
    --to=rydberg@euromail.se \
    --cc=bgat@billgatliff.com \
    --cc=linux-input@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).