netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/3][NET_BATCH] net core use batching
@ 2007-10-08 18:26 jamal
  2007-10-08 19:46 ` Waskiewicz Jr, Peter P
  0 siblings, 1 reply; 79+ messages in thread
From: jamal @ 2007-10-08 18:26 UTC (permalink / raw)
  To: David Miller
  Cc: krkumar2, johnpol, herbert, kaber, shemminger, jagana,
	Robert.Olsson, rick.jones2, xma, gaagaan, netdev, rdreier,
	peter.p.waskiewicz.jr, mcarlson, jeff, mchan, general, kumarkr,
	tgraf, randy.dunlap, sri

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

This patch adds the usage of batching within the core.

cheers,
jamal


[-- Attachment #2: 02-net-core-use-batching.patch --]
[-- Type: text/x-patch, Size: 4790 bytes --]

[NET_BATCH] net core use batching

This patch adds the usage of batching within the core.
Performance results demonstrating improvement are provided separately.

I have #if-0ed some of the old functions so the patch is more readable.
A future patch will remove all if-0ed content.
Patrick McHardy eyeballed a bug that will cause re-ordering in case
of a requeue.

Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca>

---
commit 63381156b35719a364d0f81fec487e6263fb5467
tree 615dfb5f8617a8a4edffbb965e81a75c60597319
parent 8b9960cfbb98d48c0ac30b2c00d27c25217adb26
author Jamal Hadi Salim <hadi@cyberus.ca> Mon, 08 Oct 2007 09:10:14 -0400
committer Jamal Hadi Salim <hadi@cyberus.ca> Mon, 08 Oct 2007 09:10:14 -0400

 net/sched/sch_generic.c |  116 +++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 106 insertions(+), 10 deletions(-)

diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
index 95ae119..96bfdcb 100644
--- a/net/sched/sch_generic.c
+++ b/net/sched/sch_generic.c
@@ -56,6 +56,7 @@ static inline int qdisc_qlen(struct Qdisc *q)
 	return q->q.qlen;
 }
 
+#if 0
 static inline int dev_requeue_skb(struct sk_buff *skb, struct net_device *dev,
 				  struct Qdisc *q)
 {
@@ -110,6 +111,97 @@ static inline int handle_dev_cpu_collision(struct sk_buff *skb,
 
 	return ret;
 }
+#endif
+
+static inline int handle_dev_cpu_collision(struct net_device *dev)
+{
+	if (unlikely(dev->xmit_lock_owner == smp_processor_id())) {
+		if (net_ratelimit())
+			printk(KERN_WARNING
+				"Dead loop on netdevice %s, fix it urgently!\n",
+				dev->name);
+		return 1;
+	}
+	__get_cpu_var(netdev_rx_stat).cpu_collision++;
+	return 0;
+}
+
+static inline int
+dev_requeue_skbs(struct sk_buff_head *skbs, struct net_device *dev,
+	       struct Qdisc *q)
+{
+
+	struct sk_buff *skb;
+
+	while ((skb = __skb_dequeue_tail(skbs)) != NULL)
+		q->ops->requeue(skb, q);
+
+	netif_schedule(dev);
+	return 0;
+}
+
+static inline int
+xmit_islocked(struct sk_buff_head *skbs, struct net_device *dev,
+	    struct Qdisc *q)
+{
+	int ret = handle_dev_cpu_collision(dev);
+
+	if (ret) {
+		if (!skb_queue_empty(skbs))
+			skb_queue_purge(skbs);
+		return qdisc_qlen(q);
+	}
+
+	return dev_requeue_skbs(skbs, dev, q);
+}
+
+static int xmit_count_skbs(struct sk_buff *skb)
+{
+	int count = 0;
+	for (; skb; skb = skb->next) {
+		count += skb_shinfo(skb)->nr_frags;
+		count += 1;
+	}
+	return count;
+}
+
+static int xmit_get_pkts(struct net_device *dev,
+			   struct Qdisc *q,
+			   struct sk_buff_head *pktlist)
+{
+	struct sk_buff *skb;
+	int count = dev->xmit_win;
+
+	if (count  && dev->gso_skb) {
+		skb = dev->gso_skb;
+		dev->gso_skb = NULL;
+		count -= xmit_count_skbs(skb);
+		__skb_queue_tail(pktlist, skb);
+	}
+
+	while (count > 0) {
+		skb = q->dequeue(q);
+		if (!skb)
+			break;
+
+		count -= xmit_count_skbs(skb);
+		__skb_queue_tail(pktlist, skb);
+	}
+
+	return skb_queue_len(pktlist);
+}
+
+static int xmit_prepare_pkts(struct net_device *dev,
+			     struct sk_buff_head *tlist)
+{
+	struct sk_buff *skb;
+	struct sk_buff_head *flist = &dev->blist;
+
+	while ((skb = __skb_dequeue(tlist)) != NULL)
+		xmit_prepare_skb(skb, dev);
+
+	return skb_queue_len(flist);
+}
 
 /*
  * NOTE: Called under dev->queue_lock with locally disabled BH.
@@ -130,22 +222,23 @@ static inline int handle_dev_cpu_collision(struct sk_buff *skb,
  *				>0 - queue is not empty.
  *
  */
+
 static inline int qdisc_restart(struct net_device *dev)
 {
 	struct Qdisc *q = dev->qdisc;
-	struct sk_buff *skb;
-	int ret;
+	int ret = 0;
 
-	/* Dequeue packet */
-	if (unlikely((skb = dev_dequeue_skb(dev, q)) == NULL))
-		return 0;
+	ret = xmit_get_pkts(dev, q, &dev->blist);
 
+	if (!ret)
+		return 0;
 
-	/* And release queue */
+	/* We got em packets */
 	spin_unlock(&dev->queue_lock);
 
+	/* bye packets ....*/
 	HARD_TX_LOCK(dev, smp_processor_id());
-	ret = dev_hard_start_xmit(skb, dev);
+	ret = dev_batch_xmit(dev);
 	HARD_TX_UNLOCK(dev);
 
 	spin_lock(&dev->queue_lock);
@@ -158,8 +251,8 @@ static inline int qdisc_restart(struct net_device *dev)
 		break;
 
 	case NETDEV_TX_LOCKED:
-		/* Driver try lock failed */
-		ret = handle_dev_cpu_collision(skb, dev, q);
+		/* Driver lock failed */
+		ret = xmit_islocked(&dev->blist, dev, q);
 		break;
 
 	default:
@@ -168,7 +261,7 @@ static inline int qdisc_restart(struct net_device *dev)
 			printk(KERN_WARNING "BUG %s code %d qlen %d\n",
 			       dev->name, ret, q->q.qlen);
 
-		ret = dev_requeue_skb(skb, dev, q);
+		ret = dev_requeue_skbs(&dev->blist, dev, q);
 		break;
 	}
 
@@ -564,6 +657,9 @@ void dev_deactivate(struct net_device *dev)
 
 	skb = dev->gso_skb;
 	dev->gso_skb = NULL;
+	if (!skb_queue_empty(&dev->blist))
+		skb_queue_purge(&dev->blist);
+	dev->xmit_win = 1;
 	spin_unlock_bh(&dev->queue_lock);
 
 	kfree_skb(skb);

^ permalink raw reply related	[flat|nested] 79+ messages in thread

end of thread, other threads:[~2007-10-12 18:29 UTC | newest]

Thread overview: 79+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-08 18:26 [PATCH 2/3][NET_BATCH] net core use batching jamal
2007-10-08 19:46 ` Waskiewicz Jr, Peter P
2007-10-08 20:48   ` jamal
2007-10-08 21:26     ` [ofa-general] " David Miller
2007-10-08 22:34       ` jamal
2007-10-08 22:36         ` [ofa-general] " Waskiewicz Jr, Peter P
2007-10-08 22:33     ` Waskiewicz Jr, Peter P
2007-10-08 23:40       ` jamal
2007-10-09  1:13         ` Jeff Garzik
2007-10-09  1:41           ` [ofa-general] " David Miller
2007-10-09  2:01             ` Herbert Xu
2007-10-09  2:03               ` Herbert Xu
2007-10-09  2:04                 ` Herbert Xu
2007-10-09  2:15                   ` jamal
2007-10-09  2:16                     ` Herbert Xu
2007-10-09  2:19                       ` [ofa-general] " jamal
2007-10-09  2:20                         ` Herbert Xu
2007-10-09  2:45                   ` [ofa-general] " David Miller
2007-10-09  2:43                 ` David Miller
2007-10-09  2:46                   ` Herbert Xu
2007-10-09  2:12             ` [ofa-general] " Jeff Garzik
2007-10-09  2:46               ` David Miller
2007-10-09 18:48               ` [ofa-general] " Waskiewicz Jr, Peter P
2007-10-09 19:04                 ` Jeff Garzik
2007-10-09 19:07                   ` Waskiewicz Jr, Peter P
2007-10-09  2:14             ` [ofa-general] " jamal
2007-10-09  2:16               ` Herbert Xu
2007-10-09  2:47                 ` [ofa-general] " David Miller
2007-10-09 16:51             ` Andi Kleen
2007-10-09 18:22               ` Stephen Hemminger
2007-10-09 18:30                 ` Andi Kleen
2007-10-09 20:43               ` David Miller
2007-10-09 20:53                 ` Stephen Hemminger
2007-10-09 21:22                   ` David Miller
2007-10-09 21:56                     ` jamal
2007-10-10  0:04                       ` David Miller
2007-10-10  0:37                         ` Andi Kleen
2007-10-10  0:50                           ` David Miller
2007-10-10  9:16                             ` Andi Kleen
2007-10-10  9:25                               ` David Miller
2007-10-10 10:23                                 ` Andi Kleen
2007-10-10 10:44                                   ` David Miller
2007-10-10 13:08                                     ` jamal
2007-10-10 22:37                                       ` David Miller
2007-10-10 15:35                                     ` Waskiewicz Jr, Peter P
2007-10-10 16:02                                       ` Andi Kleen
2007-10-10 16:42                                         ` Waskiewicz Jr, Peter P
2007-10-10  9:53                               ` Herbert Xu
2007-10-12 16:08                           ` Brandeburg, Jesse
2007-10-12 17:05                             ` Stephen Hemminger
2007-10-12 18:29                               ` Andi Kleen
2007-10-12 18:27                             ` Andi Kleen
2007-10-10 16:02                         ` Bill Fink
2007-10-10 22:53                           ` David Miller
2007-10-11  6:52                 ` Krishna Kumar2
2007-10-09  1:31         ` Jeff Garzik
2007-10-09 10:58       ` [ofa-general] " Krishna Kumar2
2007-10-09 11:02         ` David Miller
2007-10-09 11:20           ` [ofa-general] " Krishna Kumar2
2007-10-09 11:21           ` Krishna Kumar2
2007-10-09 11:24             ` David Miller
2007-10-09 12:44               ` [ofa-general] " Jeff Garzik
2007-10-09 12:55                 ` Herbert Xu
2007-10-09 13:00                   ` Jeff Garzik
2007-10-09 20:14                 ` David Miller
2007-10-09 20:20                   ` [ofa-general] " Jeff Garzik
2007-10-09 21:25                     ` David Miller
2007-10-09 20:22               ` [ofa-general] " Roland Dreier
2007-10-09 20:51                 ` David Miller
2007-10-09 21:40                   ` Roland Dreier
2007-10-09 22:44                   ` [ofa-general] " Roland Dreier
2007-10-09 22:46                     ` [ofa-general] [PATCH 1/4] IPoIB: Fix unused variable warning Roland Dreier
2007-10-09 22:47                       ` [ofa-general] [PATCH 2/4] ibm_emac: Convert to use napi_struct independent of struct net_device Roland Dreier
2007-10-09 22:47                       ` [PATCH 3/4] ibm_new_emac: Nuke SET_MODULE_OWNER() use Roland Dreier
2007-10-09 22:48                       ` [PATCH 4/4] ibm_emac: Convert to use napi_struct independent of struct net_device Roland Dreier
2007-10-09 22:51                         ` [ofa-general] " Roland Dreier
2007-10-09 23:17                       ` [PATCH 1/4] IPoIB: Fix unused variable warning David Miller
2007-10-10  0:32                         ` Jeff Garzik
2007-10-10  0:47                       ` [ofa-general] " Jeff Garzik

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).