My Freebsd driver hangs in poll function after some time (problem with poll)

My Freebsd driver hangs in poll function after some time (problem with poll)

Post by Andrey Koubyche » Thu, 06 Feb 2003 18:16:15



Hello everyone,

I have the following problem. I've ported a Linux driver  for small device
(led, keypad and lcd in-one on PPBUS)  on Freebsd. 8 hours of intensive
usage shown no errors. But later I've found that this driver can hang the
system. But experimenting I've found that the reason is somewhere in 'poll'
function. I'm using it with Freebsd 4.5, single cpu and single process that
select on /dev/kpd0 (keypad) with timeout 1 sec. Aproximately after 4 days
system hangs. If I start more processes and call select more intensively it
hangs on the second day.
Here is this * poll function. Maybe you can see something. I'm not an
advanced Freebsd driver writer , simply read handbook and looked into
sources:
...
struct selinfo mysip;
int mainlock; // for my fake MUTEX
...
static  int
lcd_kpd_poll(
 dev_t dev,
 int events,
 struct proc *p) {

 int revents=0;
 MUTEX_ENTER(mainlock);
/*
I've not found mutexes in kernel so I used a simple spinlock.  Could this be
a reason in single cpu machine ?
    #define MUTEX_ENTER(x) {while(x) DELAY(1);x=1;}
    #define MUTEX_EXIT(x) {x=0;}
*/
 if (!kpd_dev) revents =  POLLHUP;
else{
     if (events & (POLLIN | POLLRDNORM)) {
        /*  check if there are already keys in the queue */
         if (lcd_keyevents_pending(&key_queue)) {
             revents =events & (POLLIN | POLLRDNORM);}
         else{
                 selrecord(p, &mysip);
                /*
                This selrecord is a black box for me :)  When I query keypad
and key is pressed I put it in query and
                do selwakeup(&mysip);
                */
                if (lcd_keyevents_pending(&key_queue)) {                 //
here I check if I have a key in queue
                   revents =events & (POLLIN | POLLRDNORM);
                }
         }
    }

Quote:}

MUTEX_EXIT(mainlock); // release mutex
return revents;

Quote:}

Thank you for your attention

--
Best regards,
Andrey Koubychev

 
 
 

My Freebsd driver hangs in poll function after some time (problem with poll)

Post by Andrey Koubyche » Wed, 19 Feb 2003 18:02:41


Solution was to use simplelock instead of home made mutexes

--
Best regards,
Andrey Koubychev

 
 
 

My Freebsd driver hangs in poll function after some time (problem with poll)

Post by FreeBSD/Ghoste » Wed, 19 Feb 2003 18:15:40



> Solution was to use simplelock instead of home made mutexes

        ok

--
In Corning, Iowa, it's a misdemeanor for a man to ask his wife to ride
in any motor vehicle.