Project Home
Project Home
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Brainteaser #1 (multi-threaded NetBSD drivers): (2 Items)
   
Brainteaser #1 (multi-threaded NetBSD drivers)  
"How do you make a NetBSDdriver operate in a multi-threaded mode? (Code snippet required.)"

I did a diff between the original NetBSD drivers and the ones under sys/dev/ic/. The notes in sys/dev/doc/port_bsd.txt 
were also quite helpful.

In order to port a NetBSD driver one has to sprinkle NW_SIGLOCK() and NW_SIGUNLOCK() throughout the source because the 
interrupt handler is atomic under NetBSD but can be interrupted under QNX.
For the two drivers I looked into (i82557.c, rt2560.c) the function xxx_start() has to be called with the lock held.

Making a NetBSD driver multi-threaded can be achieved by changing the call to 
    pci_intr_establish(pc, ih, IPL_NET, fxp_intr, sc);
to 
    pci_intr_establish_exten(pc, ih, IPL_NET, fxp_intr, sc, 0);

Take a look at pci_conv_qnx.c, line 450:

void *
pci_intr_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, int level,
    int (*func)(void *), void *arg)
{
	/*
	 * By default the porting lib throws IRUPT_NOTHREAD
	 * which will pare the stack down to single threaded
	 * pulse mode.  If you're sure the driver in question
	 * does all the right things WRT locking, use
	 * pci_intr_establish_exten().
	 */
	return pci_intr_establish_exten(pc, ih, level, func, arg,
	    IRUPT_NOTHREAD);
}

BUT: As the comment above says: One has to make sure locking is correct!

Is this the code snippet you have in mind?

Re: Brainteaser #1 (multi-threaded NetBSD drivers)  
On Sun, Nov 25, 2007 at 07:51:33PM -0500, Ralf GB wrote:
> "How do you make a NetBSDdriver operate in a multi-threaded mode? (Code
> snippet required.)"
> 
> I did a diff between the original NetBSD drivers and the ones under
> sys/dev/ic/. The notes in sys/dev/doc/port_bsd.txt were also quite
> helpful.
> 
> In order to port a NetBSD driver one has to sprinkle NW_SIGLOCK() and
> NW_SIGUNLOCK() throughout the source because the interrupt handler is
> atomic under NetBSD but can be interrupted under QNX.
> For the two drivers I looked into (i82557.c, rt2560.c) the function
> xxx_start() has to be called with the lock held.
> 
> Making a NetBSD driver multi-threaded can be achieved by changing the
> call to 
>     pci_intr_establish(pc, ih, IPL_NET, fxp_intr, sc);
> to 
>     pci_intr_establish_exten(pc, ih, IPL_NET, fxp_intr, sc, 0);
> 
> Take a look at pci_conv_qnx.c, line 450:
> 
> void *
> pci_intr_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, int
> level,
>     int (*func)(void *), void *arg)
> {
> 	/*
> 	 * By default the porting lib throws IRUPT_NOTHREAD
> 	 * which will pare the stack down to single threaded
> 	 * pulse mode.  If you're sure the driver in question
> 	 * does all the right things WRT locking, use
> 	 * pci_intr_establish_exten().
> 	 */
> 	return pci_intr_establish_exten(pc, ih, level, func, arg,
> 	    IRUPT_NOTHREAD);
> }
> 
> BUT: As the comment above says: One has to make sure locking is correct!
> 
> Is this the code snippet you have in mind?
> 

A+ from me.

-seanb