* select() on /dev/input/eventX not level-triggered?
@ 2011-05-19 23:50 Pavel Machek
2011-05-23 18:13 ` Dmitry Torokhov
0 siblings, 1 reply; 5+ messages in thread
From: Pavel Machek @ 2011-05-19 23:50 UTC (permalink / raw)
To: kernel list, linux-input
Hi!
I'm debugging strange behaviour on /dev/input/eventX ... it seems that
select is not behaving level-triggered as it apparently should. I can
reproduce it when hitting windows & alt keys.
Now, I really should rewrite it into C, first, but perhaps someone has
an idea?
Pavel
#!/usr/bin/python
# Thanks to mechomaniac.com
# GPLv2
# Copyright 2011 Pavel Machek
import struct
import time
import select
import os
import random
#
# format of the event structure (int, int, short, short, int)
inputEventFormat = 'iihhi'
inputEventSize = 16
file = open("/dev/input/event5", "rb") # standard binary file input
while 1:
( i, o, e ) = select.select( [file], [], [], 0.5 )
if i == []:
print "timeout event"
continue
event = file.read(inputEventSize)
time.sleep(1)
(time1, time2, type, code, value) = struct.unpack(inputEventFormat, event)
print "type ", type, " code ", code, " value ", value
file.close()
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: select() on /dev/input/eventX not level-triggered?
2011-05-19 23:50 select() on /dev/input/eventX not level-triggered? Pavel Machek
@ 2011-05-23 18:13 ` Dmitry Torokhov
2011-05-23 20:06 ` Pavel Machek
0 siblings, 1 reply; 5+ messages in thread
From: Dmitry Torokhov @ 2011-05-23 18:13 UTC (permalink / raw)
To: Pavel Machek; +Cc: kernel list, linux-input
On Fri, May 20, 2011 at 01:50:51AM +0200, Pavel Machek wrote:
> Hi!
>
> I'm debugging strange behaviour on /dev/input/eventX ... it seems that
> select is not behaving level-triggered as it apparently should. I can
> reproduce it when hitting windows & alt keys.
>
> Now, I really should rewrite it into C, first, but perhaps someone has
> an idea?
Is this with next or with mainline? In next we try not to signal that FD
is ready unless we have full packet in the buffer...
FWIW I see python indeed not reading the tail of events (btw the format
should be 'llhhi' and the size on 64 bit arches is 24, not 16) but when
I hacked evtest to use select and non-blockign read it all worked
properly.
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: select() on /dev/input/eventX not level-triggered?
2011-05-23 18:13 ` Dmitry Torokhov
@ 2011-05-23 20:06 ` Pavel Machek
2011-05-23 20:49 ` Dmitry Torokhov
0 siblings, 1 reply; 5+ messages in thread
From: Pavel Machek @ 2011-05-23 20:06 UTC (permalink / raw)
To: Dmitry Torokhov; +Cc: kernel list, linux-input
On Mon 2011-05-23 11:13:12, Dmitry Torokhov wrote:
> On Fri, May 20, 2011 at 01:50:51AM +0200, Pavel Machek wrote:
> > Hi!
> >
> > I'm debugging strange behaviour on /dev/input/eventX ... it seems that
> > select is not behaving level-triggered as it apparently should. I can
> > reproduce it when hitting windows & alt keys.
> >
> > Now, I really should rewrite it into C, first, but perhaps someone has
> > an idea?
(Ok, so we agree that select() should mark descriptor as ready as
long as data are available... right?)
> Is this with next or with mainline? In next we try not to signal that FD
> is ready unless we have full packet in the buffer...
2.6.39-rcX mainline.
> FWIW I see python indeed not reading the tail of events (btw the format
> should be 'llhhi' and the size on 64 bit arches is 24, not 16) but when
> I hacked evtest to use select and non-blockign read it all worked
> properly.
It was on x32, but I'll fix that, thanks.
Difference was I'm not using non-blocking read(). It is unusual but
should work AFAICT. Just read one packet when select shows its ready;
if there's more than one, don't loop around read, but rely on select
returning immediately.
I did verify it on strace, so it should not be python artefact.
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: select() on /dev/input/eventX not level-triggered?
2011-05-23 20:06 ` Pavel Machek
@ 2011-05-23 20:49 ` Dmitry Torokhov
2011-05-23 21:20 ` Pavel Machek
0 siblings, 1 reply; 5+ messages in thread
From: Dmitry Torokhov @ 2011-05-23 20:49 UTC (permalink / raw)
To: Pavel Machek; +Cc: kernel list, linux-input
On Mon, May 23, 2011 at 10:06:22PM +0200, Pavel Machek wrote:
> On Mon 2011-05-23 11:13:12, Dmitry Torokhov wrote:
> > On Fri, May 20, 2011 at 01:50:51AM +0200, Pavel Machek wrote:
> > > Hi!
> > >
> > > I'm debugging strange behaviour on /dev/input/eventX ... it seems that
> > > select is not behaving level-triggered as it apparently should. I can
> > > reproduce it when hitting windows & alt keys.
> > >
> > > Now, I really should rewrite it into C, first, but perhaps someone has
> > > an idea?
>
> (Ok, so we agree that select() should mark descriptor as ready as
> long as data are available... right?)
>
> > Is this with next or with mainline? In next we try not to signal that FD
> > is ready unless we have full packet in the buffer...
>
> 2.6.39-rcX mainline.
>
> > FWIW I see python indeed not reading the tail of events (btw the format
> > should be 'llhhi' and the size on 64 bit arches is 24, not 16) but when
> > I hacked evtest to use select and non-blockign read it all worked
> > properly.
>
> It was on x32, but I'll fix that, thanks.
>
> Difference was I'm not using non-blocking read().
Does not matter.
> It is unusual but
> should work AFAICT. Just read one packet when select shows its ready;
> if there's more than one, don't loop around read, but rely on select
> returning immediately.
>
> I did verify it on strace, so it should not be python artefact.
It is artefact of your program, you buffering your input. Use:
file = open("/dev/input/event3", "rb", 0)
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: select() on /dev/input/eventX not level-triggered?
2011-05-23 20:49 ` Dmitry Torokhov
@ 2011-05-23 21:20 ` Pavel Machek
0 siblings, 0 replies; 5+ messages in thread
From: Pavel Machek @ 2011-05-23 21:20 UTC (permalink / raw)
To: Dmitry Torokhov; +Cc: kernel list, linux-input
On Mon 2011-05-23 13:49:10, Dmitry Torokhov wrote:
> On Mon, May 23, 2011 at 10:06:22PM +0200, Pavel Machek wrote:
> > On Mon 2011-05-23 11:13:12, Dmitry Torokhov wrote:
> > > On Fri, May 20, 2011 at 01:50:51AM +0200, Pavel Machek wrote:
> > Difference was I'm not using non-blocking read().
>
> Does not matter.
>
> > It is unusual but
> > should work AFAICT. Just read one packet when select shows its ready;
> > if there's more than one, don't loop around read, but rely on select
> > returning immediately.
> >
> > I did verify it on strace, so it should not be python artefact.
>
> It is artefact of your program, you buffering your input. Use:
>
> file = open("/dev/input/event3", "rb", 0)
Oops, yes, you are right, that solves it. Thanks... and sorry for the
noise.
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-05-23 21:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-19 23:50 select() on /dev/input/eventX not level-triggered? Pavel Machek
2011-05-23 18:13 ` Dmitry Torokhov
2011-05-23 20:06 ` Pavel Machek
2011-05-23 20:49 ` Dmitry Torokhov
2011-05-23 21:20 ` Pavel Machek
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.