Re: Kernel WARNING: at net/core/dev.c:1330 __netif_schedule+0x2c/0x98()

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Peter Zijlstra
Date: Thursday, July 24, 2008 - 2:10 am

On Wed, 2008-07-23 at 13:16 -0700, David Miller wrote:

Ok, then how about something like this, the idea is to wrap the per tx
lock with a read lock of the device and let the netif_tx_lock() be the
write side, therefore excluding all device locks, but not incure the
cacheline bouncing on the read side by using per-cpu counters like rcu
does.

This of course requires that netif_tx_lock() is rare, otherwise stuff
will go bounce anyway...

Probably missed a few details,.. but I think the below ought to show the
idea...

struct tx_lock {
	int busy;
	spinlock_t lock;
	unsigned long *counters;
};


int tx_lock_init(struct tx_lock *txl)
{
	txl->busy = 0;
	spin_lock_init(&txl->lock);
	txl->counters = alloc_percpu(unsigned long);

	if (!txl->counters)
		return -ENOMEM;

	return 0;
}

void __netif_tx_lock(struct netdev_queue *txq, cpu)
{
	struct net_device *dev = txq->dev;

	if (rcu_dereference(dev->tx_lock.busy)) {
		spin_lock(&dev->tx_lock.lock);
		(*percpu_ptr(dev->tx_lock.counters, cpu))++;
		spin_unlock(&dev->tx_lock.lock);
	} else
		(*percpu_ptr(dev->tx_lock.counters, cpu))++;

	spin_lock(&txq->_xmit_lock);
	txq->xmit_lock_owner = cpu;
}

void __netif_tx_unlock(struct netdev_queue *txq)
{
	struct net_device *dev = txq->dev;

	(*percpu_ptr(dev->tx_lock.counters, txq->xmit_lock_owner))--;
	txq->xmit_lock_owner = -1;
	spin_unlock(&txq->xmit_lock);
}

unsigned long tx_lock_read_counters(struct tx_lock *txl)
{
	int i;
	unsigned long counter = 0;

	/* can use online - the inc/dec are matched per cpu */
	for_each_online_cpu(i)
		counter += *percpu_ptr(txl->counters, i);

	return counter;
}

void netif_tx_lock(struct net_device *dev)
{
	spin_lock(&dev->tx_lock.lock);
	rcu_assign_pointer(dev->tx_lock.busy, 1);

	while (tx_lock_read_counters(&dev->tx_lock)
		cpu_relax();
}

void netif_tx_unlock(struct net_device *dev)
{
	rcu_assign_pointer(dev->tx_lock.busy, 0);
	smp_wmb(); /* because rcu_assign_pointer is broken */
	spin_unlock(&dev->tx_lock.lock);
}

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[GIT]: Networking, David Miller, (Sun Jul 20, 10:44 am)
Re: [GIT]: Networking, Arjan van de Ven, (Sun Jul 20, 10:59 am)
Re: [GIT]: Networking, David Miller, (Sun Jul 20, 4:52 pm)
Re: [GIT]: Networking, Linus Torvalds, (Sun Jul 20, 5:54 pm)
Re: [GIT]: Networking, David Miller, (Sun Jul 20, 6:03 pm)
Re: [GIT]: Networking, Linus Torvalds, (Sun Jul 20, 6:07 pm)
Re: [GIT]: Networking, Alexey Dobriyan, (Sun Jul 20, 6:09 pm)
Re: [GIT]: Networking, David Miller, (Sun Jul 20, 6:14 pm)
Re: [GIT]: Networking, David Miller, (Sun Jul 20, 6:17 pm)
Re: [GIT]: Networking, Patrick McHardy, (Sun Jul 20, 6:20 pm)
Re: [GIT]: Networking, Alexey Dobriyan, (Sun Jul 20, 6:22 pm)
Re: [GIT]: Networking, Alexey Dobriyan, (Sun Jul 20, 7:40 pm)
Re: [GIT]: Networking, David Miller, (Sun Jul 20, 7:48 pm)
Re: [GIT]: Networking, David Miller, (Sun Jul 20, 10:11 pm)
Re: [GIT]: Networking, Alexander Beregalov, (Mon Jul 21, 2:48 am)
Re: [GIT]: Networking, Ben Hutchings, (Mon Jul 21, 3:16 am)
Re: [GIT]: Networking, Stefan Richter, (Mon Jul 21, 4:28 am)
Re: [GIT]: Networking, James Morris, (Mon Jul 21, 4:45 am)
Re: [GIT]: Networking, Alexey Dobriyan, (Mon Jul 21, 4:57 am)
Re: [GIT]: Networking, Patrick McHardy, (Mon Jul 21, 5:05 am)
Re: [GIT]: Networking, Ingo Molnar, (Mon Jul 21, 6:50 am)
Re: [GIT]: Networking, Stefan Richter, (Mon Jul 21, 7:15 am)
Re: [GIT]: Networking, David Miller, (Mon Jul 21, 8:27 am)
Re: [GIT]: Networking, David Miller, (Mon Jul 21, 8:35 am)
Re: [GIT]: Networking, Alexander Beregalov, (Mon Jul 21, 9:04 am)
Re: [GIT]: Networking, Linus Torvalds, (Mon Jul 21, 9:49 am)
Re: [GIT]: Networking, David Miller, (Mon Jul 21, 9:53 am)
Re: [GIT]: Networking, David Miller, (Mon Jul 21, 10:28 am)
Re: [GIT]: Networking, Linus Torvalds, (Mon Jul 21, 10:40 am)
[crash] kernel BUG at net/core/dev.c:1328!, Ingo Molnar, (Mon Jul 21, 11:23 am)
Re: [crash] kernel BUG at net/core/dev.c:1328!, Linus Torvalds, (Mon Jul 21, 11:35 am)
Re: [crash] kernel BUG at net/core/dev.c:1328!, Ingo Molnar, (Mon Jul 21, 11:46 am)
Re: [crash] kernel BUG at net/core/dev.c:1328!, David Miller, (Mon Jul 21, 12:00 pm)
Re: [crash] kernel BUG at net/core/dev.c:1328!, Stefan Richter, (Mon Jul 21, 12:20 pm)
Re: [crash] kernel BUG at net/core/dev.c:1328!, Ingo Molnar, (Mon Jul 21, 12:30 pm)
Re: [crash] kernel BUG at net/core/dev.c:1328!, Ingo Molnar, (Mon Jul 21, 12:44 pm)
Re: [crash] kernel BUG at net/core/dev.c:1328!, David Miller, (Mon Jul 21, 1:11 pm)
Re: [crash] kernel BUG at net/core/dev.c:1328!, David Miller, (Mon Jul 21, 1:20 pm)
Re: [GIT]: Networking, David Miller, (Mon Jul 21, 1:32 pm)
Re: [GIT]: Networking, Patrick McHardy, (Mon Jul 21, 1:33 pm)
Re: [crash] kernel BUG at net/core/dev.c:1328!, Stefan Richter, (Mon Jul 21, 2:26 pm)
[TCP bug] stuck distcc connections in latest -git, Ingo Molnar, (Tue Jul 22, 4:21 am)
Re: [TCP bug] stuck distcc connections in latest -git, David Newall, (Tue Jul 22, 6:45 am)
Re: [TCP bug] stuck distcc connections in latest -git, Ingo Molnar, (Tue Jul 22, 6:57 am)
Re: [TCP bug] stuck distcc connections in latest -git, David Newall, (Tue Jul 22, 7:54 am)
Re: [TCP bug] stuck distcc connections in latest -git, Ingo Molnar, (Tue Jul 22, 8:34 am)
Re: [TCP bug] stuck distcc connections in latest -git, Willy Tarreau, (Tue Jul 22, 2:12 pm)
Re: [TCP bug] stuck distcc connections in latest -git, Ingo Molnar, (Wed Jul 23, 1:26 am)
Re: [GIT]: Networking, David Miller, (Wed Jul 23, 4:42 pm)
Re: Kernel WARNING: at net/core/dev.c:1330 __netif_schedul ..., Peter Zijlstra, (Thu Jul 24, 2:10 am)
Re: [regression] nf_iterate(), BUG: unable to handle kerne ..., Krzysztof Oledzki, (Thu Jul 24, 11:00 am)