[comp.unix.wizards] BSD internals/ether/software intrs

lm@arizona.edu (Larry McVoy) (01/22/88)

Hi there-
	I need some info about the BSD kernel and I'm too lazy to look.  What I
    want to know is

    a) when the ethernet driver takes an intr and gets to the point it has the
       data in its grubby little paws - does it just enqueue it?  The path
       I found (4.3 Mt Xinu BSD) was deintr/derecv/deread (I think) and the 
       last routine did a IF_ENQUEUE which does some stuff that looks like it's
       setting up a software interrupt.  The question is: does it put the data
       on a queue and let "someone" know, and then return?  It doesn't do
       anything with protocols (IP et al) right then (in interrupt context)
       does it?
    
    b) How do software interrupts in the BSD kernel work.  I don't mean user
       level signals, but kernel level signals.  When & how do they get 
       delivered?  If process A is in the kernel (intr) recieving a packet 
       that is destined for who knows who, when does the protocol code get
       executed?  Who is the cpu time charged to?

Thanks much (even if you tell me to take my own advice),

-- 
Larry McVoy	lm@arizona.edu or ...!{uwvax,sun}!arizona.edu!lm
		Use the force - read the source.

jaap@cwi.nl (Jaap Akkerhuis) (01/22/88)

In article <3522@megaron.arizona.edu> lm@megaron.arizona.edu.UUCP (Larry McVoy) writes:
 > Hi there-
 > 	I need some info about the BSD kernel and I'm too lazy to look. etc.

In that case, I'm too lazy to tell you.

chris@mimsy.UUCP (Chris Torek) (01/26/88)

In article <13676@oliveb.olivetti.com> ilcu@icoven.olivetti.com
(Daniela Papa) writes:
>I'm NOT lazy and I'd love to find a book like Lion's on BSD.......

Patience!  (But the book is not mine.)

And with that as a teaser, a bit about network software interrupts.
These are done with whatever the machine has as a software interrupt:
on the Vax and the Tahoe, using the Software Interrupt Request
Register, SIRR.  There is a macro called `setsoftnet', defined as

	#define	setsoftnet()	mtpr(SIRR, 12)

which asks the machine to generate an interrupt at IPL 12 as soon
as it may.  There is another macro called `schednetisr', which sets
a bit in a global variable and then does a setsoftnet().  This is
explained in <net/netisr.h>.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris

lm@arizona.edu (Larry McVoy) (01/29/88)

OK, ok, folks, enough already.  Let me try again.  I need some information
about the BSD kernel, I spent about an hour poking around inside, got lost
(everything is in the wrong place if you're used to SV), and I'm still a little
perplexed about something.  And BTW, folks, this info is not in TFM.

Specifically, my question is:  when do the networking protocols start processing
incoming data?  I suspect that does not happen in the lower half of the driver.
I could guess that it's something like

	event:  hardware intr from ether
	action: lower half of ether driver takes data, 
		shoves into a queue,
		schedules software intr
	event:  software intr
	action: protocol state machine starts cranking on the data

My question is (and it's a general question, applicable to intrs of any sort),
what context does the intr handler have in BSD?  How'd we get into the kernel?
Is it the same path for soft/hard intrs?

And who gets to pay for the cpu time used in intr context?

And how do software intrs rate in terms of priorities?  What spl???() will 
block them, if any?

Thank you very much, oh wizards....
-- 
Larry McVoy	lm@arizona.edu or ...!{uwvax,sun}!arizona.edu!lm
		Use the force - read the source.

decot@hpisod2.HP.COM (Dave Decot) (01/29/88)

>	I need some info about the BSD kernel and I'm too lazy to look.

So, to save yourself 10 minutes you want 70,000 other people to spend
their own 10 minutes (a total of 48 days) to look it up for you?

That's sensible.

Dave

jum@cosmo.UUCP (Uwe Mager) (01/30/88)

In article <10346@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes:
>on the Vax and the Tahoe, using the Software Interrupt Request
>Register, SIRR.  There is a macro called `setsoftnet', defined as
>
>	#define	setsoftnet()	mtpr(SIRR, 12)
>
>which asks the machine to generate an interrupt at IPL 12 as soon
>as it may.  There is another macro called `schednetisr', which sets

gee, how do they do that on a 680xx ? setting flags ?
-- 
Jens-Uwe Mager
jum@focus.UUCP || jum@cosmo.UUCP

forys@sigi.Colorado.EDU (Jeff Forys) (02/02/88)

In article <454@cosmo.UUCP> jum@cosmo.UUCP (Jens-Uwe Mager) writes:
> In article <10346@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes:
> > on the Vax and the Tahoe, using the Software Interrupt Request
> > Register, SIRR.  There is a macro called `setsoftnet', defined as
> >
> >	#define	setsoftnet()	mtpr(SIRR, 12)
> >
> > which asks the machine to generate an interrupt at IPL 12 as soon
> > as it may.  There is another macro called `schednetisr', which sets
>
> gee, how do they do that on a 680xx ? setting flags ?

What do you usually do when the hardware doesnt provide something?
Why, you emulate it with software, of course!  BSD kernels I've seen
provide software triggering of interrupt service routines to simulate
things like a Software Interrupt Request Register.  Basically, you need
a routine to add interrupts to a linked list of functions, and another
routine to process these functions later when the time is right.

So, with much abbreviated, setsoftnet() might become:

	struct {
	    func_t sw_func;		/* function to call on trigger */
	    caddr_t sw_arg;		/* arguments */
	    char priority;		/* level of interrupt */
	    struct sw_trig *sw_next;	/* next... */
	} *sw_trigger;

	add_interrupt(func, args, priority) {
		s = spl6();
		/* insert func into prioritized linked list of soft calls */
		splx(s);
	}

	process_interrupts() {
		while (1) {
			s = spl6();
			/* pull next function off queue */
			splx(s);
			if (queue empty) return;
			(*func)(args);
		}
	}

	netintr() {
		/* To raw protocol input routines */
	}

	setsoftnet() {	/* finally! */
		add_interrupt(netintr, (char *)0, 1);
	}

No two ways are identical, but you should get the general idea.  Oh, for
completeness, the call to process_interrupts() would come out of locore.
---
Jeff Forys @ UC/Boulder Engineering Research Comp Cntr (303-492-4991)
forys@boulder.Colorado.EDU  -or-  ..!{hao|nbires}!boulder!forys