poll() in 2.6 and beyond
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 9 lines · Roland Dreier
I don't know why I continue this, but.... can you point out the line in the kernel 2.4 source for
__pollwait()where it sleeps?Or think about it. Suppose a user called
poll()with two fds, each of which belonged to a different driver. Suppose each driver slept in its poll method. If the first driver never became ready (and stayed asleep), how wouldpoll()return to user space if the second driver became ready?
Quoted 3 lines
What actually happens is that each driver registers with the kernel the wait queues that it will wake up when it becomes ready. But the core kernel is responsible for sleeping, outside of the driver code.
Could you maybe go back to the initial report, which is that after poll() gets wrong status? It's nice to argue about where the process waits, but the issue is if it gets the same status with 2.4 and 2.6, and if not which one should be fixed.
Richard: can you show this with a small demo program? I assume you didn't find this just by reading code ;-)
Bill> Could you maybe go back to the initial report, which is that Bill> after poll() gets wrong status? It's nice to argue about Bill> where the process waits, but the issue is if it gets the Bill> same status with 2.4 and 2.6, and if not which one should be Bill> fixed.
I'm sure the problem is a buggy driver. The original question represents a complete misunderstanding of how poll() is implemented, so it's no surprise that the driver breaks.
- Roland
Quoted 15 lines · Bill Davidsen
Quoted 9 lines · Roland Dreier
I don't know why I continue this, but.... can you point out the line in the kernel 2.4 source for
__pollwait()where it sleeps?Or think about it. Suppose a user called
poll()with two fds, each of which belonged to a different driver. Suppose each driver slept in its poll method. If the first driver never became ready (and stayed asleep), how wouldpoll()return to user space if the second driver became ready?Quoted 3 lines
What actually happens is that each driver registers with the kernel the wait queues that it will wake up when it becomes ready. But the core kernel is responsible for sleeping, outside of the driver code.
Quoted 7 lines
Could you maybe go back to the initial report, which is that after
poll()gets wrong status? It's nice to argue about where the process waits, but the issue is if it gets the same status with 2.4 and 2.6, and if not which one should be fixed.Richard: can you show this with a small demo program? I assume you didn't find this just by reading code ;-)
Yes. The code I attached earlier shows that the poll() in a driver gets called (correctly), then it calls poll_wait(). Unfortunately the call to poll_wait() returns immediately so that the return value from the driver's poll() is whatever it was before some event occurred that the driver was going to signal with wake_up_interruptible().
The attached code clearly demonstrates this. It doesn't even contain any code to execute wake_up_interruptible(). When an event occurs in the driver that would have set the poll_flag to POLLIN, and executed wake_up_interruptible, the old status, the stuff that was returned when poll_wait() returned immediately instead of waiting for the wake up, gets returned to the user-mode program.
Now, if the user-mode program calls poll() again, which is likely, it gets the status that was returned from the previous event so it "seems" to work. However, it is always one event behind so you need two events to recognize the first one.
I attached the module and demo program again. It clearly shows that poll_wait() gets called and then immediately returns without waiting...
Cheers,
Dick Johnson
Penguin : Linux version 2.4.24 on an i686 machine (797.90 BogoMips).
Note 96.31% of all statistics are fiction.
Quoted 9 lines · Richard B. Johnson
Quoted 3 lines
Could you maybe go back to the initial report, which is that after
poll()gets wrong status? It's nice to argue about where the process waits, but the issue is if it gets the same status with 2.4 and 2.6,and
Quoted 4 lines
if not which one should be fixed.
Richard: can you show this with a small demo program? I assume you didn't find this just by reading code ;-)
Quoted 7 lines
Yes. The code I attached earlier shows that the
poll()in a driver gets called (correctly), then it callspoll_wait(). Unfortunately the call topoll_wait()returns immediately so that the return value from the driver'spoll()is whatever it was before some event occurred that the driver was going to signal withwake_up_interruptible().
The documentation referred to earlier (http://www.xml.com/ldd/chapter/book/ch05.html#t3) clearly states that the poll function implementation for a device should:
"1. Call /poll_wait/ on one or more wait queues that could indicate a change in the poll status.
2. Return a bit mask describing operations that could be immediately performed without blocking."
What happens is if your device has data ready RIGHT NOW (without any waiting), the information regarding that is returned.
Now, if you look closely at the implementation of do_poll(), it will loop forever until any device returns that data is available (or the timeout occurs). After data is available, do_pollfd() function no longer adds the devices to the wait queue.
What this means is that the first time through each device is added to the wait queue. After the process is woken up from schedule_timeout (or the timeout occurs), then it will loop through each device again to either add that device to the wait queue again, or determine that there is data ready to be read/written, or an error or whatever. do_pollfd() then increases count, and do_poll() exits from it's loop (and wait queues are cleaned-up in sys_poll()).
So, yes, the poll_wait() returns immediately, it should not wait, and your poll method should return the device's CURRENT status in the poll mask. Don't worry, because when your device wakes the waiting process when data is ready, the device's poll function is called again and you again can return the CURRENT status.
Please let me know if I'm misunderstanding this, but quite frankly, poll_wait CANNOT wait, for the very reasons described in previous posts: when multiple devices are polled, then poll_wait is called FOR EACH DEVICE.
Cheers,
..John
Quoted 41 lines · John Muir
Quoted 9 lines · Richard B. Johnson
Quoted 3 lines
Could you maybe go back to the initial report, which is that after
poll()gets wrong status? It's nice to argue about where the process waits, but the issue is if it gets the same status with 2.4 and 2.6,and
Quoted 4 lines
if not which one should be fixed.
Richard: can you show this with a small demo program? I assume you didn't find this just by reading code ;-)
Quoted 7 lines
Yes. The code I attached earlier shows that the
poll()in a driver gets called (correctly), then it callspoll_wait(). Unfortunately the call topoll_wait()returns immediately so that the return value from the driver'spoll()is whatever it was before some event occurred that the driver was going to signal withwake_up_interruptible().The documentation referred to earlier
(http://www.xml.com/ldd/chapter/book/ch05.html#t3) clearly states that the poll function implementation for a device should:
"1. Call /poll_wait/ on one or more wait queues that could indicate a change in the poll status.
2. Return a bit mask describing operations that could be immediately performed without blocking."
What happens is if your device has data ready RIGHT NOW (without any waiting), the information regarding that is returned.Now, if you look closely at the implementation of
do_poll(), it will loop forever until any device returns that data is available (or the timeout occurs). After data is available,do_pollfd()function no longer adds the devices to the wait queue.What this means is that the first time through each device is added to the wait queue. After the process is woken up from
schedule_timeout(or the timeout occurs), then it will loop through each device again to either add that device to the wait queue again, or determine that there is data ready to be read/written, or an error or whatever.do_pollfd()then increases count, anddo_poll()exits from it's loop (and wait queues are cleaned-up insys_poll()).
Quoted 6 lines
So, yes, the
poll_wait()returns immediately, it should not wait, and your poll method should return the device's CURRENT status in the poll mask. Don't worry, because when your device wakes the waiting process when data is ready, the device's poll function is called again and you again can return the CURRENT status.
Well the device's poll function isn't getting called the second time with 2.6.0. I never checked it in 2.4.x because it always worked. This problem occurs in a driver that only returns the fact that one event occurred. When it failed to report the event when built with a newer kernel, I added diagnostics which showed that the poll in the driver was only called once --and that the return from poll_wait happened immediately.
So, if the poll_wait isn't a wait-function, but just some add-wakeup to the queue function, then its name probably should have been changed when it changed. At one time it did, truly, wait until it was awakened with wake_up_interruptible.
Quoted 9 lines
Please let me know if I'm misunderstanding this, but quite frankly,
poll_waitCANNOT wait, for the very reasons described in previous posts:
when multiple devices are polled, thenpoll_waitis called FOR EACH DEVICE.Cheers,
..John
Cheers,
Dick Johnson
Penguin : Linux version 2.4.24 on an i686 machine (797.90 BogoMips).
Note 96.31% of all statistics are fiction.
Richard> Well the device's poll function isn't getting called the Richard> second time with 2.6.0. I never checked it in 2.4.x Richard> because it always worked. This problem occurs in a Richard> driver that only returns the fact that one event Richard> occurred. When it failed to report the event when built Richard> with a newer kernel, I added diagnostics which showed Richard> that the poll in the driver was only called once --and Richard> that the return from poll_wait happened immediately.
Your driver is buggy. It's not surprising since you fundamentally don't understand the kernel interface you're trying to use.
Richard> So, if the poll_wait isn't a wait-function, but just some Richard> add-wakeup to the queue function, then its name probably Richard> should have been changed when it changed. At one time it Richard> did, truly, wait until it was awakened with Richard> wake_up_interruptible.
When did it change? Show me a kernel version where poll_wait() waited until the driver woke it up. (Kernel versions at least as far back as 1.0 are readily available from kernel.org, so it should be easy for you)
- Roland
Quoted 18 lines · Roland Dreier
Richard> Well the device's poll function isn't getting called the Richard> second time with 2.6.0. I never checked it in 2.4.x Richard> because it always worked. This problem occurs in a Richard> driver that only returns the fact that one event Richard> occurred. When it failed to report the event when built Richard> with a newer kernel, I added diagnostics which showed Richard> that the poll in the driver was only called once --and Richard> that the return from
poll_waithappened immediately.Your driver is buggy. It's not surprising since you fundamentally don't understand the kernel interface you're trying to use.
Richard> So, if the
poll_waitisn't a wait-function, but just some Richard> add-wakeup to the queue function, then its name probably Richard> should have been changed when it changed. At one time it Richard> did, truly, wait until it was awakened with Richard>wake_up_interruptible.
Quoted 7 lines
When did it change? Show me a kernel version where
poll_wait()waited until the driver woke it up. (Kernel versions at least as far back as 1.0 are readily available from kernel.org, so it should be easy for you)- Roland
I never said the DRIVER woke up, but that poll sleeps.
FLAGS UID PID PPID PRI NI SIZE RSS WCHAN STA TTY TIME COMMAND 100 0 1 0 6 0 224 148 do_select S ? 0:01 /sbin/init auto
[SNIPPED....]
40 0 115 114 9 0 1452 728 pipe_wait S ? 0:00 /usr/sbin/nmbd -D
100000 0 11109 9459 16 0 1044 476 R 1 0:00 ps -laxw
0 0 11107 9504 12 0 692 216 do_poll S 2 0:00 ./tester.... and if it DOESN'T then ps is buggy and/or the entry in /proc in buggy.
Clearly this task is sleeping in do_poll.
Cheers,
Dick Johnson
Penguin : Linux version 2.4.24 on an i686 machine (797.90 BogoMips).
Note 96.31% of all statistics are fiction.
Quoted 1 line · Richard B. Johnson
Clearly this task is sleeping in
do_poll.
I don't believe anyone ever argued that do_poll() sleeps. You were saying that poll_wait() was sleeping, that is different.
- Davide
Quoted 6 lines · Richard B. Johnson
Yes. The code I attached earlier shows that the
poll()in a driver gets called (correctly), then it callspoll_wait(). Unfortunately the call topoll_wait()returns immediately so that the return value from the driver'spoll()is whatever it was before some event occurred that the driver was going to signal withwake_up_interruptible().
You've been handed a clue enough times now that you should understand that poll_wait() does not, and has never, put the process to sleep.
If you can show a case where do_poll() returns stale data, then by all means do so. We will be happy to fix any such error in the kernel.
You say do_poll() looses the status returned from your driver's poll method. If your driver is truly returning a nonzero status from the poll() method call, then a simple read of the code in do_pollfd() will show that the only way it looses information from that event mask is if your user space is not setting that event type in pollfd.events.
If I were you, I'd check two things:
1) that your poll method is really returning a non-zero status when you think it is
2) that your user space program is really asking for all events you think it is
I think you'll find your problem is not this well-used mechanism in the kernel.
Dave
Quoted 26 lines · David Dillow
Quoted 6 lines · Richard B. Johnson
Yes. The code I attached earlier shows that the
poll()in a driver gets called (correctly), then it callspoll_wait(). Unfortunately the call topoll_wait()returns immediately so that the return value from the driver'spoll()is whatever it was before some event occurred that the driver was going to signal withwake_up_interruptible().You've been handed a clue enough times now that you should understand that
poll_wait()does not, and has never, put the process to sleep.If you can show a case where
do_poll()returns stale data, then by all means do so. We will be happy to fix any such error in the kernel.You say
do_poll()looses the status returned from your driver's poll method. If your driver is truly returning a nonzero status from thepoll()method call, then a simple read of the code indo_pollfd()will show that the only way it looses information from that event mask is if your user space is not setting that event type in pollfd.events.If I were you, I'd check two things:
1) that your poll method is really returning a non-zero status when you think it is
2) that your user space program is really asking for all events you think it is
Quoted 4 lines
I think you'll find your problem is not this well-used mechanism in the kernel.
Dave
The very great problems that exist with poll on linux-2.6.0 are being quashed by those who just like to argue. Therefore, I wrote some code that emulates the environment in which I discovered the poll failure. Experts can decide whatever they want about the inner workings of poll(). I supposed that if ps showed that a task was sleeping in poll() then it must be sleeping in poll(). So, even it that's wrong, here is irrefutable proof that there is a problem with polling events getting lost on 2.6.0. The attached code will execute without errors in 2.4.24 and below.
Here is the test code running on Linux-2.4.24
Script started on Wed Mar 3 10:24:05 2004
# make gcc -Wall -O2 -D__KERNEL__ -DMODULE -DMAJOR_NR=199 -I/usr/src/linux-2.4.24/include -c -o thingy.o thingy.c as -o rtc_hwr.o rtc_hwr.S ld -i -o driver.o thingy.o rtc_hwr.o gcc -Wall -o tester -O2 tester.c rm -f THING mknod THING c 199 0 # insmod driver.o # lsmod Module Size Used by driver 1928 0 (unused) nfs 48008 0 (autoclean) lockd 37308 0 (autoclean) [nfs] sunrpc 66236 0 (autoclean) [nfs lockd] vxidrvr 2748 0 (unused) vximsg 5328 0 [vxidrvr] ramdisk 5596 0 (unused) ipchains 42204 0 nls_cp437 4376 4 (autoclean) 3c59x 28252 1 isofs 17368 0 (unused) loop 8856 0 sr_mod 12188 0 (unused) cdrom 27936 0 [sr_mod] BusLogic 35832 7 sd_mod 10472 14 scsi_mod 56236 3 [sr_mod BusLogic sd_mod] # ./tester
You have mail in /var/spool/mail/root
# exit exit Script done on Wed Mar 3 11:05:56 2004
This ran for about 1/2 hour ( 10:24 -> 11:05) with no errors.
This is the same thing, running on this exact same machine, booted with Linux-2.6.0-test8
Script started on Wed Mar 3 13:00:18 2004
# make gcc -Wall -O2 -D__KERNEL__ -DMODULE -DMAJOR_NR=199 -I/usr/src/linux-2.6.0-test8/include -c -o thingy.o thingy.c as -o rtc_hwr.o rtc_hwr.S ld -i -o driver.o thingy.o rtc_hwr.o gcc -Wall -o tester -O2 tester.c rm -f THING mknod THING c 199 0 # insmod driver.o # ./tester ERROR: (51 != 1) Lost events : 50 ERROR: (59371 != 59369) Lost events : 52 ERROR: (75501 != 75498) Lost events : 55 ERROR: (94511 != 94509) Lost events : 57 ERROR: (164660 != 164658) Lost events : 59 ERROR: (194867 != 194864) Lost events : 62 ERROR: (206892 != 206890) Lost events : 64 ERROR: (214232 != 214230) Lost events : 66 ERROR: (308340 != 308337) Lost events : 69 ERROR: (353062 != 353059) Lost events : 72 ERROR: (444541 != 444539) Lost events : 74 ERROR: (446516 != 446514) Lost events : 76 ERROR: (447906 != 447904) Lost events : 78
# exit exit Script done on Wed Mar 3 13:04:39 2004
It ran from 13:00 to 13:04, accumulating 78 errors.
A review of the test code shows that the driver uses IRQ8 from the RTC timer chip. The driver doesn't care if some interrupt ticks are lost because it just increments a memory variable every time that an interrupt occurs. After that variable is incremented, the interrupt service routine sets a global flag to POLLIN and sends a wake_up_interruptible() to whomever is sleeping in poll(). Spin-locks are put around critical sections to prevent undefined results.
In the user-mode code, the task sleeping in poll() reads the variable using read(). The user-mode code doesn't care what the value is, only that it must be one-greater than the last one read. If it isn't, an error message is written to standard error.
Observations:
If the call to mlockall() is removed in the test-code, the behavior seems to be better, just the opposite of what one would suspect.
The priority (nice value) doesn't seem to affect anything.
The code runs without any errors on 2.4.24, 2.4.22, 2.4.21, and 2.4.18. The only source I have on this machine for 2.6.x is for 2.6.0-test8.
Cheers,
Dick Johnson
Penguin : Linux version 2.4.24 on an i686 machine (797.90 BogoMips).
Note 96.31% of all statistics are fiction.
Quoted 2 lines · Richard B. Johnson
The very great problems that exist with poll on linux-2.6.0 are being quashed by those who just like to argue.
No, the argument has always been that your understanding of poll()'s internals is not entirely correct. We have simply asked you to post code that shows poll()'s problems, which you have finally provided. Sort of.
Quoted 6 lines
Therefore,
I wrote some code that emulates the environment in which I discovered the poll failure. Experts can decide whatever they want about the inner workings ofpoll(). I supposed that ifpsshowed that a task was sleeping inpoll()then it must be sleeping inpoll().
This we all agree on -- poll() sleeps. Duh. No argument there. poll_wait() doesn't and never has, which was your original assertion.
But on to the code!
Quoted 3 lines
So, even it that's wrong, here is
irrefutable proof that there is a problem with polling events getting lost on 2.6.0.
Ahem, no, not so much. What you have here is proof that your user program is not getting control again withing 0.488ms of the interrupt happening. That does not mean poll() is loosing events.
You are definately seeing some significant latency -- 50 lost increments is ~25ms.
What else is running when you perform this test? Can you repeat with a more recent kernel? Can you repeat in single user mode, with it being the only process present? With as few extra modules loaded as possible?
I still think your problem is not poll() -- if there were problems there, bug reports would be coming out of the woodwork.
Signature · 1 line
Dave Dillow <[email protected]>
Quoted 20 lines · Dave Dillow
Quoted 2 lines · Richard B. Johnson
The very great problems that exist with poll on linux-2.6.0 are being quashed by those who just like to argue.
No, the argument has always been that your understanding of poll()'s internals is not entirely correct. We have simply asked you to post code that shows poll()'s problems, which you have finally provided. Sort of.
Quoted 6 lines
Therefore,
I wrote some code that emulates the environment in which I discovered the poll failure. Experts can decide whatever they want about the inner workings ofpoll(). I supposed that ifpsshowed that a task was sleeping inpoll()then it must be sleeping inpoll().This we all agree on --
poll()sleeps. Duh. No argument there.poll_wait()doesn't and never has, which was your original assertion.But on to the code!
Quoted 8 lines
Quoted 3 lines
So, even it that's wrong, here is
irrefutable proof that there is a problem with polling events getting lost on 2.6.0.Ahem, no, not so much. What you have here is proof that your user program is not getting control again withing 0.488ms of the interrupt happening. That does not mean
poll()is loosing events.
Well that should mean the same thing in the final wash.
Quoted 7 lines
You are definately seeing some significant latency -- 50 lost increments is ~25ms.
What else is running when you perform this test? Can you repeat with a more recent kernel? Can you repeat in single user mode, with it being the only process present? With as few extra modules loaded as possible?
I would need to install a more recent kernel and I think I should. That will mean some re-write of the module code, so I am told. I wrote the module and another Engineer, Terry Skillman, wrote the test-code and the Makefile. He also performed the tests. He says that it will not compile on a newer 2.6.x so I would have to do more work if true. I will have to put that off until Monday because I have to take a work-break.
Nothing else is running. Although there is a network board, there is no network line from the hub to that machine when the tests are made.
Quoted 5 lines
I still think your problem is not
poll()-- if there were problems there, bug reports would be coming out of the woodwork. --
Dave Dillow <[email protected]>
Cheers,
Dick Johnson
Penguin : Linux version 2.4.24 on an i686 machine (797.90 BogoMips).
Note 96.31% of all statistics are fiction.
Quoted 4 lines · Richard B. Johnson
are being quashed by those who just like to argue. Therefore, I wrote some code that emulates the environment in which I discovered the poll failure.
No. I think you wrote some code that shows the bug you have.
Your "poll()" function IS BUGGY.
Look at this:
static size_t poll(struct file *fp, struct poll_table_struct *wait)
{
size_t poll_flag;
size_t flags;
DEB(printk(KERN_INFO"%s : poll() called\n", devname));
poll_wait(fp, &pwait, wait);
DEB(printk(KERN_INFO"%s : poll() returned\n", devname));
spin_lock_irqsave(&rtc_lock, flags);
poll_flag = global_poll_flag;
*** global_poll_flag = 0;
spin_unlock_irqrestore(&rtc_lock, flags);
return poll_flag;
}you are clearing your own flag that says "there are events pending", so if you call your "poll()" function twice, on the second time it will say "there are no events pending".
You should clear the "events pending" flag only when you literally remove the event (ie at "read()" time, not at "poll()" time). Because the select() code _will_ call down to the "poll()" functions multiple times if it gets woken up for any bogus reason.
See if that fixes anything.
It may well be that 2.6.x calls down to the low-level driver "poll()" function more than it should. That would be a mis-feature, and worth looking at, but I think you should try to fix your test first, since right now the bug is questionable.
Linus
Quoted 28 lines · Linus Torvalds
Quoted 4 lines · Richard B. Johnson
are being quashed by those who just like to argue. Therefore, I wrote some code that emulates the environment in which I discovered the poll failure.
No. I think you wrote some code that shows the bug you have.
Your "
poll()" function IS BUGGY.Look at this:
static size_t poll(struct file *fp, struct poll_table_struct *wait) { size_t poll_flag; size_t flags; DEB(printk(KERN_INFO"%s : poll() called\n", devname)); poll_wait(fp, &pwait, wait); DEB(printk(KERN_INFO"%s : poll() returned\n", devname)); spin_lock_irqsave(&rtc_lock, flags); poll_flag = global_poll_flag; *** global_poll_flag = 0; spin_unlock_irqrestore(&rtc_lock, flags); return poll_flag; }
Quoted 4 lines
you are clearing your own flag that says "there are events pending", so if you call your "
poll()" function twice, on the second time it will say "there are no events pending".
But I am clearing it under a spin-lock.
Quoted 4 lines
You should clear the "events pending" flag only when you literally remove the event (ie at "
read()" time, not at "poll()" time). Because theselect()code _will_ call down to the "poll()" functions multiple times if it gets woken up for any bogus reason.
Oh wow. That is the BUG! I didn't know it could call in multiple times.
Quoted 9 lines
See if that fixes anything.
It may well be that 2.6.x calls down to the low-level driver "
poll()" function more than it should. That would be a mis-feature, and worth looking at, but I think you should try to fix your test first, since right now the bug is questionable.Linus
And YES! If I clear the flag only after it is read. It "fixes" the observed problem!
I don't know if it is a BUG or a FEATURE, but you put your finger right on it! Thanks.
Cheers,
Dick Johnson
Penguin : Linux version 2.4.24 on an i686 machine (797.90 BogoMips).
Note 96.31% of all statistics are fiction.
Quoted 3 lines · Richard B. Johnson
And YES! If I clear the flag only after it is read. It "fixes" the observed problem!
Ok. That solves one problem, but it does seem to point to the fact that 2.6.x calls down to poll() more than 2.4.x does.
It really _is_ normal to have multiple calls to "poll()" for the same fd as a result of a single "poll()" system call, but if we actually get a positive hit (ie the ->poll() call returns a bit that we consider to be a success by comparing it to what we _wanted_ to see), then we should have stopped doing that.
And since your test program always sets "POLLIN", any ->poll() call that has the POLLIN flag set should have ended up being the last one (since it would have marked a "success").
So there's still something I don't understand, and that seems to differ between 2.4.x and 2.6.x. Can anybody else see it?
Linus
Quoted 5 lines · Linus Torvalds
You should clear the "events pending" flag only when you literally remove the event (ie at "
read()" time, not at "poll()" time). Because theselect()code _will_ call down to the "poll()" functions multiple times if it gets woken up for any bogus reason.
Hmm.. The above is all still true and your poll() implementation is bad, but looking at your test program, the problematic case really shouldn't trigger (we should call poll() multiple times only when it returns zero).
To trigger that bug, you'd have to occasionally call poll() with the POLLIN bit clear in the incoming events, which your test program doesn't ever do.
Anyway, you should move the clearing to read(), but there may well be something else going on too.
What's the frequency you are programming the thing to send interrupts at?
Linus
Quoted 9 lines · Linus Torvalds
Quoted 5 lines · Linus Torvalds
You should clear the "events pending" flag only when you literally remove the event (ie at "
read()" time, not at "poll()" time). Because theselect()code _will_ call down to the "poll()" functions multiple times if it gets woken up for any bogus reason.
Quoted 8 lines
Hmm.. The above is all still true and your
poll()implementation is bad, but looking at your test program, the problematic case really shouldn't trigger (we should callpoll()multiple times only when it returns zero).To trigger that bug, you'd have to occasionally call
poll()with the POLLIN bit clear in the incoming events, which your test program doesn't ever do.
Well, when I removed the local poll_flag, using only the global one, and cleared it to zero after the long long was fetched under the lock (in the read routine), my observed problems go away.
static size_t poll(struct file *fp, struct poll_table_struct *wait)
{
DEB(printk(KERN_INFO"%s : poll() called\n", devname));
poll_wait(fp, &pwait, wait);
DEB(printk(KERN_INFO"%s : poll() returned\n", devname));
return global_poll_flag;
}static int read(struct file *fp, char *buf, size_t count, loff_t *ppos)
{
long long tmp;
size_t flags;
spin_lock_irqsave(&rtc_lock, flags);
tmp = rtc_tick;
global_poll_flag = 0;
spin_unlock_irqrestore(&rtc_lock, flags);
if(copy_to_user(buf, &tmp, sizeof(tmp)))
return -EFAULT;
return sizeof(tmp);
}Quoted 5 lines
Anyway, you should move the clearing to
read(), but there may well be something else going on too.What's the frequency you are programming the thing to send interrupts at?
2048 ticks/second, trivial to handle.
Quoted 2 lines
Linus
-
Cheers,
Dick Johnson
Penguin : Linux version 2.4.24 on an i686 machine (797.90 BogoMips).
Note 96.31% of all statistics are fiction.