linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Behavior of poll() within a module
@ 2001-10-23 12:53 Richard B. Johnson
  2001-10-23 13:33 ` Mike Jagdis
  0 siblings, 1 reply; 8+ messages in thread
From: Richard B. Johnson @ 2001-10-23 12:53 UTC (permalink / raw)
  To: Linux kernel


What is the intended behavior of poll within a module when
two or more tasks are sleeping in poll? Specifically, when
wake_up_interruptible is executed from a module, are all
tasks awakened or is only one? If only one, is it the
first task to call poll/select or the last, which is awakened
first? 


Cheers,
Dick Johnson

Penguin : Linux version 2.4.1 on an i686 machine (799.53 BogoMips).

    I was going to compile a list of innovations that could be
    attributed to Microsoft. Once I realized that Ctrl-Alt-Del
    was handled in the BIOS, I found that there aren't any.



^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: Behavior of poll() within a module
@ 2001-10-23 15:58 Manfred Spraul
  2001-10-23 17:17 ` Richard B. Johnson
  0 siblings, 1 reply; 8+ messages in thread
From: Manfred Spraul @ 2001-10-23 15:58 UTC (permalink / raw)
  To: "Richard B. Johnson"; +Cc: linux-kernel

>
> The following actual module code:
>
> static unsigned int vxi_poll(struct file *fp, struct poll_table_struct *wait)
> {
>     unsigned long flags;
>     unsigned int mask;
>     DEB(printk("vxi_poll\n"));
>     info->poll_active++;
>     poll_wait(fp, &info->wait, wait);
>     spin_lock_irqsave(&vxi_lock, flags);
>     mask = info->poll_mask;
>     if(!--info->poll_active)
>         info->poll_mask = 0;
>     spin_unlock_irqrestore(&vxi_lock, flags);
>     DEB(printk("vxi_poll returns\n"));
>     return mask;
> }
Which module is that? I can't find it in Linus tree.
Is "info" a global variable?

* poll is called without any SMP locking, "info->poll_active++" is not SMP safe. Use atomic_inc, or even better just delete that
line.
* Clearing poll_mask during poll is wrong.
poll should return the events that are currently available, i.e. what would happen if read() or write() would be called now.

read() on a non-blocking file handle would return immediately with 1 or more bytes read --> set POLLIN
write() on a non-blocking file handle would return immediately with a nonzero byte count written--> set POLLOUT.
The clearing of poll_mask must occur during read() and write() if these conditions are not true anymore.

--
    Manfred





^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2001-10-24  9:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-23 12:53 Behavior of poll() within a module Richard B. Johnson
2001-10-23 13:33 ` Mike Jagdis
2001-10-23 14:13   ` Richard B. Johnson
2001-10-24  9:52     ` Mike Jagdis
2001-10-23 15:58 Manfred Spraul
2001-10-23 17:17 ` Richard B. Johnson
2001-10-23 18:02   ` Manfred Spraul
2001-10-23 18:16     ` Richard B. Johnson

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).