netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Lemoine <eric.lemoine@gmail.com>
To: hadi@cyberus.ca
Cc: netdev@oss.sgi.com, Patrick McHardy <kaber@trash.net>,
	openib-general@openib.org,
	"David S. Miller" <davem@davemloft.net>
Subject: Re: LLTX and netif_stop_queue
Date: Mon, 3 Jan 2005 00:30:31 +0100	[thread overview]
Message-ID: <5cac192f0501021530672a908a@mail.gmail.com> (raw)
In-Reply-To: <1104240717.1100.66.camel@jzny.localdomain>

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

On 28 Dec 2004 08:31:57 -0500, jamal <hadi@cyberus.ca> wrote:
> On Fri, 2004-12-24 at 11:10, Eric Lemoine wrote:
> 
> > Yes but requiring drivers to release a lock that they should not even
> > be aware of doesn't sound good. Another way would be to keep
> > dev->queue_lock grabbed when entering start_xmit() and let the driver
> > drop it (and re-acquire it before it returns) only if it wishes so.
> > Although I don't like this too much either, that's the best way I can
> > think of up to now...
> 
> I am not a big fan of that patch either, but i cant think of a cleaner
> way to do it.
> The violation already happens with the LLTX flag. So maybe a big warning
> that says "Do this only if you driver is LLTX enabled". The other way to
> do it is put a check to see if LLTX is enabled before releasing that
> lock - but why the extra cycles? Driver writer should know.

Two (untested) patches implementing what I described above.

The first pach (sch_generic.patch) keeps queue_lock held in
qdisc_restart() when calling hard_start_xmit() of a LLTX driver. The
second (sungem.patch) makes sungem release queue_lock after grabbing
its private tx lock.

Note that the modifications made to qdisc_restart() are not compatible
with the current LLTX drivers. All LLTX drivers must be modified along
sungem.patch's lines. Take sungem.patch as an example of how things
must be done.

Patches apply to current davem bk snapshot.

-- 
Eric

[-- Attachment #2: sch_generic.patch --]
[-- Type: application/octet-stream, Size: 1965 bytes --]

===== net/sched/sch_generic.c 1.32 vs edited =====
--- 1.32/net/sched/sch_generic.c	2004-12-28 05:51:20 +01:00
+++ edited/net/sched/sch_generic.c	2005-01-02 23:55:18 +01:00
@@ -104,9 +104,17 @@
 		 * locking again. These checks are worth it because
 		 * even uncongested locks can be quite expensive.
 		 * The driver can do trylock like here too, in case
-		 * of lock congestion it should return -1 and the packet
-		 * will be requeued.
+		 * of lock congestion it should return NETDEV_TX_LOCKED
+		 * and the packet will be requeued.
+		 * 
+		 * Note: when the driver has LLTX set queue_lock cannot
+		 * be dropped in here if we want to avoid having packets
+		 * passing eachover during transmit. queue_lock can only
+		 * be dropped in hard_start_xmit() after private tx lock 
+		 * has been grabbed. If hard_start_xmit() does release 
+		 * queue_lock it must grab it again before it returns.
 		 */
+
 		if (!nolock) {
 			if (!spin_trylock(&dev->xmit_lock)) {
 			collision:
@@ -128,12 +136,12 @@
 			}
 			/* Remember that the driver is grabbed by us. */
 			dev->xmit_lock_owner = smp_processor_id();
+
+			/* And release queue */
+			spin_unlock(&dev->queue_lock);
 		}
 		
 		{
-			/* And release queue */
-			spin_unlock(&dev->queue_lock);
-
 			if (!netif_queue_stopped(dev)) {
 				int ret;
 				if (netdev_nit)
@@ -144,14 +152,12 @@
 					if (!nolock) {
 						dev->xmit_lock_owner = -1;
 						spin_unlock(&dev->xmit_lock);
+						spin_lock(&dev->queue_lock);
 					}
-					spin_lock(&dev->queue_lock);
 					return -1;
 				}
-				if (ret == NETDEV_TX_LOCKED && nolock) {
-					spin_lock(&dev->queue_lock);
+				if (ret == NETDEV_TX_LOCKED && nolock)
 					goto collision; 
-				}
 			}
 
 			/* NETDEV_TX_BUSY - we need to requeue */
@@ -159,8 +165,8 @@
 			if (!nolock) { 
 				dev->xmit_lock_owner = -1;
 				spin_unlock(&dev->xmit_lock);
+				spin_lock(&dev->queue_lock);
 			} 
-			spin_lock(&dev->queue_lock);
 			q = dev->qdisc;
 		}
 

[-- Attachment #3: sungem.patch --]
[-- Type: application/octet-stream, Size: 1182 bytes --]

===== drivers/net/sungem.c 1.71 vs edited =====
--- 1.71/drivers/net/sungem.c	2004-11-14 10:45:36 +01:00
+++ edited/drivers/net/sungem.c	2005-01-03 00:00:22 +01:00
@@ -950,6 +950,7 @@
 	return 0;
 }
 
+/* Called with dev->queue_lock held */
 static int gem_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	struct gem *gp = dev->priv;
@@ -976,8 +977,16 @@
 		return NETDEV_TX_LOCKED;
 	}
 
+	/* We can now drop queue_lock since tx_lock protects us. But remember
+	 * that queue_lock must be reacquired before we return. Moreover we
+	 * must reacquire it before releasing tx_lock to avoid being called
+	 * with the queue stopped.
+	 */
+	spin_unlock(&dev->queue_lock);
+
 	/* This is a hard error, log it. */
 	if (TX_BUFFS_AVAIL(gp) <= (skb_shinfo(skb)->nr_frags + 1)) {
+		spin_lock(&dev->queue_lock);
 		netif_stop_queue(dev);
 		spin_unlock_irqrestore(&gp->tx_lock, flags);
 		printk(KERN_ERR PFX "%s: BUG! Tx Ring full when queue awake!\n",
@@ -1066,6 +1075,7 @@
 		       dev->name, entry, skb->len);
 	mb();
 	writel(gp->tx_new, gp->regs + TXDMA_KICK);
+	spin_lock(&dev->queue_lock);
 	spin_unlock_irqrestore(&gp->tx_lock, flags);
 
 	dev->trans_start = jiffies;

[-- Attachment #4: Type: text/plain, Size: 0 bytes --]



  reply	other threads:[~2005-01-02 23:30 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-17 21:57 LLTX and netif_stop_queue Roland Dreier
2004-12-18  5:44 ` David S. Miller
2004-12-18 15:35   ` Roland Dreier
2004-12-18 17:58     ` Roland Dreier
2004-12-18 18:26       ` Roland Dreier
2004-12-19 19:33     ` jamal
2004-12-19 19:31   ` jamal
2004-12-19 19:54     ` jamal
2004-12-19 20:02       ` Jamal Hadi Salim
2004-12-19 22:35     ` Roland Dreier
2004-12-19 23:06       ` jamal
2004-12-19 23:16         ` Roland Dreier
2004-12-22 18:49     ` Eric Lemoine
2004-12-23  4:29       ` David S. Miller
2004-12-23  4:38         ` Roland Dreier
2004-12-23  9:10         ` Eric Lemoine
2004-12-23 16:37           ` Patrick McHardy
2004-12-23 18:11             ` Eric Lemoine
2004-12-24 16:10             ` Eric Lemoine
2004-12-28 13:31               ` jamal
2005-01-02 23:30                 ` Eric Lemoine [this message]
2005-01-03  7:41                   ` Eric Lemoine
2005-01-03 15:04                   ` jamal
2005-01-03 15:48                     ` Eric Lemoine
2005-01-03 15:57                     ` Roland Dreier
2005-01-03 16:41                       ` Eric Lemoine
2005-01-03 16:54                         ` Roland Dreier
2005-01-03 17:07                           ` Eric Lemoine
2005-01-03 17:12                             ` Grant Grundler
2005-01-04  4:18                               ` jamal
2005-01-19 22:47                                 ` David S. Miller
2005-01-19 23:18                                   ` Stephen Hemminger
2005-01-19 23:41                                     ` David S. Miller
2005-01-20  0:02                                       ` [openib-general] " Jeff Garzik
2005-01-20  0:46                                         ` Stephen Hemminger
2005-01-20  0:47                                           ` David S. Miller
2005-01-20  0:47                                       ` Francois Romieu
2005-01-20  0:52                                         ` David S. Miller
2005-01-20  1:17                                           ` Francois Romieu
2005-01-20  0:46                                     ` [PATCH]: was " David S. Miller
2005-01-20  3:14                                       ` Andi Kleen
2005-01-20  7:05                                         ` David S. Miller
2005-01-20  3:43                                       ` Roland Dreier
2005-01-20  7:05                                         ` David S. Miller
2005-01-20 13:51                                           ` Tommy Christensen
2005-01-20 21:34                                             ` David S. Miller
2005-01-20 21:56                                               ` Grant Grundler
2005-01-21  1:01                                                 ` David S. Miller
2005-01-22  3:17                                                   ` Roland Dreier
2005-01-22  3:53                                                     ` David S. Miller
2005-01-20 21:41                                             ` David S. Miller
2005-01-20 16:56                                           ` Stephen Hemminger
2005-01-21 10:54                                             ` Lennert Buytenhek
2005-01-26  6:27                                               ` David S. Miller
2005-01-26 13:25                                                 ` Lennert Buytenhek
2005-01-27  6:32                                                   ` David S. Miller
2005-01-27  7:16                                                     ` Andi Kleen
2005-01-27  7:22                                                       ` David S. Miller
2005-01-27  8:26                                                         ` Andi Kleen
2005-01-20 19:16                                           ` Jeff Garzik
2005-01-20  4:01                                       ` jamal
2005-01-20  5:18                                         ` David S. Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5cac192f0501021530672a908a@mail.gmail.com \
    --to=eric.lemoine@gmail.com \
    --cc=davem@davemloft.net \
    --cc=hadi@cyberus.ca \
    --cc=kaber@trash.net \
    --cc=netdev@oss.sgi.com \
    --cc=openib-general@openib.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).