linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Jeff Brown <jeffbrown@android.com>
Cc: rydberg@euromail.se, djkurtz@google.com,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 4/4] input: evdev: Make device readable only when it contains a complete packet.
Date: Mon, 4 Apr 2011 14:36:59 -0700	[thread overview]
Message-ID: <20110404213659.GC984@core.coreip.homeip.net> (raw)
In-Reply-To: <1301727259-5185-4-git-send-email-jeffbrown@android.com>

On Fri, Apr 01, 2011 at 11:54:19PM -0700, Jeff Brown wrote:
> This patch modifies evdev so that it only becomes readable when
> the buffer contains an EV_SYN event other than SYN_MT_REPORT.

I think we should target SYN_REPORT directly. SYN_CONFIG is unused and
SYN_DROPPED is not interesting till next SYN_REPORT anyway. Given the
changes to the previous patch I have the following:


Input: evdev - only signal polls on full packets

From: Jeff Brown <jeffbrown@android.com>

This patch modifies evdev so that it only becomes readable when
the buffer contains an EV_SYN/SYN_REPORT event.

On SMP systems, it is possible for an evdev client blocked on poll()
to wake up and read events from the evdev ring buffer at the same
rate as they are enqueued.  This can result in high CPU usage,
particularly for MT devices, because the client ends up reading
events one at a time instead of reading complete packets.

We eliminate this problem by making the device readable only when
the buffer contains at least one complete packet.  This causes
clients to block until the entire packet is available.

Signed-off-by: Jeff Brown <jeffbrown@android.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
---

 drivers/input/evdev.c |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)


diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index f1c0910..5398761 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -41,6 +41,7 @@ struct evdev {
 struct evdev_client {
 	unsigned int head;
 	unsigned int tail;
+	unsigned int last_syn;	/* position of the last EV_SYN/SYN_REPORT */
 	spinlock_t buffer_lock; /* protects access to buffer, head and tail */
 	struct fasync_struct *fasync;
 	struct evdev *evdev;
@@ -72,12 +73,16 @@ static void evdev_pass_event(struct evdev_client *client,
 		client->buffer[client->tail].type = EV_SYN;
 		client->buffer[client->tail].code = SYN_DROPPED;
 		client->buffer[client->tail].value = 0;
+
+		client->last_syn = client->tail;
 	}
 
 	spin_unlock(&client->buffer_lock);
 
-	if (event->type == EV_SYN)
+	if (event->type == EV_SYN && event->code == SYN_REPORT) {
+		client->last_syn = client->head;
 		kill_fasync(&client->fasync, SIGIO, POLL_IN);
+	}
 }
 
 /*
@@ -387,12 +392,12 @@ static ssize_t evdev_read(struct file *file, char __user *buffer,
 	if (count < input_event_size())
 		return -EINVAL;
 
-	if (client->head == client->tail && evdev->exist &&
+	if (client->last_syn == client->tail && evdev->exist &&
 	    (file->f_flags & O_NONBLOCK))
 		return -EAGAIN;
 
 	retval = wait_event_interruptible(evdev->wait,
-		client->head != client->tail || !evdev->exist);
+		client->last_syn != client->tail || !evdev->exist);
 	if (retval)
 		return retval;
 
@@ -421,7 +426,7 @@ static unsigned int evdev_poll(struct file *file, poll_table *wait)
 	poll_wait(file, &evdev->wait, wait);
 
 	mask = evdev->exist ? POLLOUT | POLLWRNORM : POLLHUP | POLLERR;
-	if (client->head != client->tail)
+	if (client->last_syn != client->tail)
 		mask |= POLLIN | POLLRDNORM;
 
 	return mask;

Thanks.

-- 
Dmitry

  reply	other threads:[~2011-04-04 21:37 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-02  6:54 [PATCH v2 1/4] input: Set default events per packet Jeff Brown
2011-04-02  6:54 ` [PATCH v2 2/4] hid: hid-input: Remove obsolete default events per packet setting Jeff Brown
2011-04-05 12:20   ` Henrik Rydberg
2011-04-02  6:54 ` [PATCH v2 3/4] input: evdev: Indicate buffer overrun with SYN_DROPPED Jeff Brown
2011-04-04 21:33   ` Dmitry Torokhov
2011-04-04 21:52     ` Jeffrey Brown
2011-04-05 11:41     ` Henrik Rydberg
2011-04-02  6:54 ` [PATCH v2 4/4] input: evdev: Make device readable only when it contains a complete packet Jeff Brown
2011-04-04 21:36   ` Dmitry Torokhov [this message]
2011-04-04 22:16     ` Jeffrey Brown
2011-04-04 22:46       ` Dmitry Torokhov
2011-04-05  0:34         ` Jeffrey Brown
2011-04-05 12:03           ` Henrik Rydberg
2011-04-05 16:32             ` Dmitry Torokhov
2011-04-05 16:38           ` Dmitry Torokhov
2011-04-11 20:15             ` Jeffrey Brown
2011-04-05 12:16 ` [PATCH v2 1/4] input: Set default events per packet Henrik Rydberg

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=20110404213659.GC984@core.coreip.homeip.net \
    --to=dmitry.torokhov@gmail.com \
    --cc=djkurtz@google.com \
    --cc=jeffbrown@android.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rydberg@euromail.se \
    /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).