Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 3 Aug 1998 16:14:41 -0600 (MDT)
From:      chanders@timing.com (Craig Anderson)
To:        freebsd-hackers@FreeBSD.ORG
Subject:   Device driver synchronization with spl?
Message-ID:  <199808032214.QAA02199@count.timing.com>

next in thread | raw e-mail | index | archive | help

I would like an explanation of how the spl functions are used to
sychronize a driver that uses interrupts.  Code fragments from a
driver I'm working on are at the end of the messages.  The interrupt
handler is installed on irq 11.

Here are my assumptions (guesses) so far.

1) gt401read() calls splgt401() to add a mask for irq 11.
2) After splgt401() the interrupt function gt401intr will not run.
   This prevents a wakeup being lost between checking the data count
   and sleeping for data to show up.
3) The tsleep() causes another process to run with an interrupt
   mask that will allow gt401intr() to run.
4) irq 11 happens and the handler gt401intr() is run.
5) gt401intr() updates the data count and issues the wakeup.
6) gt401read() returns from the tsleep() and sees that there is now data.


Some questions.
1) Is my understanding of the spl usage good enough?
2) If this is correct, what should splgt401() look like?
   My guess here, after looking at /usr/src/sys/i386/include/spl.h is
     GENSPL(splbio, cpl |= some_mask)
   where some_mask is appropriate for irq11.  If this is right what should
   some_mask be?


driver code fragments
---------------------
static int
gt401read (dev_t dev,
	   struct uio* uio,
	   int flag)
{
...
	s = splgt401();

	while (gt401Unit[0].rbuf_count == 0) {
		status = tsleep(gt401Unit[0].sleep_address,
				PRIBIO | PCATCH,
				"gt401",
				i_timeout);
		if (!((status == 0) || (status == EWOULDBLOCK))) {
			splx(s);
			return(status);
		}
	}
	splx(s);


void
gt401intr(int unit)
{
...
  ++gt401Unit[0].rbuf_count;
...
  wakeup (gt401Unit[0].sleep_address);

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199808032214.QAA02199>