linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Constantine Gavrilov <const-g@optibase.com>
To: Linux Kernel <linux-kernel@vger.kernel.org>
Subject: Problems implementing poll call
Date: Thu, 17 Oct 2002 13:12:29 +0200	[thread overview]
Message-ID: <3DAE9B1D.5030600@optibase.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 222 bytes --]


-- 
----------------------------------------
Constantine Gavrilov
Linux Leader
Optibase Ltd
7 Shenkar St, Herzliya 46120, Israel
Phone: (972-9)-970-9140
Fax:   (972-9)-958-6099
----------------------------------------




[-- Attachment #2: let.txt --]
[-- Type: text/plain, Size: 2625 bytes --]

Hi,

I have a problem implementing poll method.

I have written a driver for MPEG encoder card. The user-space SDK needs to be able to wait for a certain event that is reported by the interrupt handler. I have done it using ioctl method, like this:

	u32 timeout=milliseconds * HZ / 1000;

	set_bit(0, &dev->fintwait);
	if(test_bit(0, &dev->fintwait)) {
		interruptible_sleep_on_timeout(&dev->interrupt_queue,timeout);

		if (signal_pending(current)) {
			printk(KERN_ERR "optenc: IntWait restarted by signal\n");
			return -ERESTARTSYS;
		}

		if(test_bit(0, &dev->fintwait)) {
			printk(KERN_ERR "optenc: intwait timeout\n");
			..//returns wait timeout
		}
		else {
			...//returns wait OK
		}
	}
	//returns wait OK
	
The interrupt handler wakes up the queue and updates dev->fintwait like this:

	clear_bit(0, &dev->fintwait);
	wake_up_interruptible(&dev->interrupt_queue);
	

It worked very well for me. I wanted to implement the same wait using the poll method. So, my poll function looks like this:

unsigned int optenc_poll(struct file *filp, poll_table *wait_table)
{
	unsigned int mask = 0;
	struct mydev *dev = filp->private_data;
	
	set_bit(0, &dev->fintwait);
	if(test_bit(0, &dev->fintwait)) {
		poll_wait(filp, &dev->interrupt_queue, wait_table);
		if(test_bit(0, &dev->fintwait))
			return mask;
		else {
			mask |= POLLIN |POLLRDNORM;
			return mask;
		}
	}
	else {
		mask |= POLLIN |POLLRDNORM;
		return mask;
	}
}

Seems straightforward and the same thing as above. But, I have the following problems:

a) I have a lot of calls with wait_table = NULL and poll_wait does not block. I always do select on one file descriptor only and I never use zero timeout, so I do not understand the reason for it.

b) Even when wait_table is not NULL, poll_wait returns before (!!) interrupt handler wakes up the queue. I have checked it with printk. It always like this:

	set_bit
	poll_wait
	poll_wait returns and test_bit is true
	wake_up and clear_bit

It is like poll_wait does not seem to block and I have spurious calles with wait_table == NULL. Any ideas?


Just to verify, the user-space wait function looks like this :

BOOL Wait(int timeout)
{

	fd_set set;
	struct timeval tv;
	int retval;

	FD_ZERO(&set);
	FD_SET(fd, &set);
	tv.tv_sec = timeout/1000;
	tv.tv_usec = (timeout%1000)*1000;

	int rc=select(fd+1, &set, NULL, NULL, &tv);
	if(rc == -1) {
		PERROR("select");
		return FALSE;
	}
	if(rc == 1)
		return TRUE;
	else
		return FALSE;
}

I use 2.4.18-pre7ac1 and I have also checked stock RedHat's 2.4.9-34.

             reply	other threads:[~2002-10-17 11:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-17 11:12 Constantine Gavrilov [this message]
  -- strict thread matches above, loose matches on Subject: below --
2002-10-20 16:20 Problems implementing poll call Constantine Gavrilov
2002-10-20 20:31 ` Dan Maas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3DAE9B1D.5030600@optibase.com \
    --to=const-g@optibase.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).