EPOLLER event that I don't understand

1,309 views
Skip to first unread message

gknippels

unread,
Feb 2, 2013, 4:19:07 PM2/2/13
to quick2wi...@googlegroups.com
Hi,

I'm new to the forum, and have a question:
I'm trying to read out the status of a reed switch using epoll. Eventually I would like to use it to read out my water meter and monitor water usage The switch is connected to GPIO input 0 (GPIO pin 17) of my Rapsberry Pi (512 Mb version).
The electronic wiring diagram is simple test setup (sorry for the poor schematics):

3.3 V-------------------------------470Ohm------LED--------reedswitch-------GND
                                                                    |
                                                                    |
                                                                    |
                                                                  10KOhm
                                                                    |
                                                               GPIO 17

 

I've just added the LED to visually observe when the reed switch closes/opens.
I'm using the following python 2.7 code:
 
import select
from datetime import datetime
from quick2wire.gpio import GPIOPin as Pin
from quick2wire.gpio import In, Out

pin1 = Pin(0, Pin.In, Pin.Both)
epoll = select.epoll()
epoll.register(pin1, select.EPOLLIN | select.EPOLLET)

while True:
   events = epoll.poll()
   for fileno, event in events:
      if fileno == pin1.fileno():
          print("%s: input reads %d and event %d detected!" %(datetime.now(), pin1.value, event))
          if event & select.EPOLLIN:
             print "EPOLLIN, Avialable for read."
          if event & select.EPOLLOUT:
             print "EPOLLOUT, Available for write."
          if event & select.EPOLLPRI:
             print "EPOLLPRI, Urgent data for read."
          if event & select.EPOLLERR:
             print "EPOLLERR, Error condition happened on the associated fd."
          if event & select.EPOLLHUP:
             print "EPOLLHUP, Hang up happened on the associated fd."
          if event & select.EPOLLET:
             print "EPOLLET, Set Edge Trigger behavior."
          if event & select.EPOLLONESHOT:
             print "EPOLLONESHOT, Set one shot behavior."
          if event & select.EPOLLRDNORM:
             print "EPOLLRDNORM, equivalent to EPOLLIN."
          if event & select.EPOLLRDBAND:
             print "EPOLLRDBAND, Priority data band can be read."
          if event & select.EPOLLWRNORM:
             print "EPOLLWRNORM, Equivalent to EPOLLOUT."
          if event & select.EPOLLWRBAND:
             print "EPOLLWRBAND, Priority data may be written."
          if event & select.EPOLLMSG:
             print "EPOLLMSG, ignored."

When I trigger the switch (by waving a magnet close to the switch) I get the following typical output where often (but not always the EPOLLERR is in the event. I don't understand what is causing it. I'm also not sure if it is a problem, since the electronics+script seem to behave more or less like a expected it too. But before I start working on debouncing the switch behavior I would prefer to understand EPOLLERR. Any suggestions?

2013-02-02 21:57:44.007578: input reads 1 and event 9 detected!
EPOLLIN, Avialable for read.
EPOLLERR, Error condition happened on the associated fd.
2013-02-02 21:58:09.218895: input reads 0 and event 9 detected!
EPOLLIN, Avialable for read.
EPOLLERR, Error condition happened on the associated fd.
2013-02-02 21:58:09.219966: input reads 0 and event 1 detected!
EPOLLIN, Avialable for read.
2013-02-02 21:58:09.410510: input reads 1 and event 9 detected!
EPOLLIN, Avialable for read.
EPOLLERR, Error condition happened on the associated fd.
2013-02-02 21:58:09.502444: input reads 0 and event 9 detected!
EPOLLIN, Avialable for read.
EPOLLERR, Error condition happened on the associated fd.
2013-02-02 21:58:09.588152: input reads 1 and event 9 detected!
EPOLLIN, Avialable for read.
EPOLLERR, Error condition happened on the associated fd.

Any suggestion on what could cause the EPOLLERR are appreciated

Brian Adams

unread,
Feb 2, 2013, 9:52:04 PM2/2/13
to gknippels, quick2wi...@googlegroups.com
From what I can see, this is expected behavior for files under the /sys directory, including GPIO. The EPOLLERR flag is (almost) always set when polling from files under sysfs. (The virtual files that we use to interact with GPIO are implemented by sysfs - a virtual file system that allows user space to interact with kernel data structures.)

Looking through the kernel source (at 'fs/sysfs/file.c'), Linux sets the ERROR (and PRIORITY) flags whenever an interrupt has been handled since the last read. It looks like that was done in order to allow 'select' and 'poll' to handle sysfs in a meaningful way.



--
You received this message because you are subscribed to the Google Groups "Quick2Wire Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quick2wire-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

gknippels

unread,
Feb 3, 2013, 3:22:12 PM2/3/13
to quick2wi...@googlegroups.com
Badams,

thanks for the explanation. So basically, I'm going to ignore the EPOLLERR message for further handling of the interrupts.

Guido

Op zaterdag 2 februari 2013 22:19:07 UTC+1 schreef gknippels het volgende:
Reply all
Reply to author
Forward
0 new messages