netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jay Vosburgh <fubar@us.ibm.com>
To: netdev@vger.kernel.org, jgarzik@pobox.com
Cc: andy@greyhouse.net, Jay Vosburgh <fubar@us.ibm.com>
Subject: [PATCH 2/6] Convert balance-rr transmit to new locking
Date: Wed, 17 Oct 2007 17:37:47 -0700	[thread overview]
Message-ID: <11926678762641-git-send-email-fubar@us.ibm.com> (raw)
In-Reply-To: <11926678763205-git-send-email-fubar@us.ibm.com>

	Change locking in balance-rr transmit processing to use a free
running counter to determine which slave to transmit on.  Instead, a
free-running counter is maintained, and modulo arithmetic used to select
a slave for transmit.

	This removes lock operations from the TX path, and eliminates
a deadlock introduced by the conversion to work queues.

Signed-off-by: Andy Gospodarek <andy@greyhouse.net>
Signed-off-by: Jay Vosburgh <fubar@us.ibm.com>
---
 drivers/net/bonding/bond_main.c |   25 ++++++++++++-------------
 drivers/net/bonding/bonding.h   |    1 +
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index ed361d6..862ed8e 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -4057,8 +4057,7 @@ static int bond_xmit_roundrobin(struct sk_buff *skb, struct net_device *bond_dev
 {
 	struct bonding *bond = bond_dev->priv;
 	struct slave *slave, *start_at;
-	int i;
-	int res = 1;
+	int i, slave_no, res = 1;
 
 	read_lock(&bond->lock);
 
@@ -4066,29 +4065,29 @@ static int bond_xmit_roundrobin(struct sk_buff *skb, struct net_device *bond_dev
 		goto out;
 	}
 
-	read_lock(&bond->curr_slave_lock);
-	slave = start_at = bond->curr_active_slave;
-	read_unlock(&bond->curr_slave_lock);
+	/*
+	 * Concurrent TX may collide on rr_tx_counter; we accept that
+	 * as being rare enough not to justify using an atomic op here
+	 */
+	slave_no = bond->rr_tx_counter++ % bond->slave_cnt;
 
-	if (!slave) {
-		goto out;
+	bond_for_each_slave(bond, slave, i) {
+		slave_no--;
+		if (slave_no < 0) {
+			break;
+		}
 	}
 
+	start_at = slave;
 	bond_for_each_slave_from(bond, slave, i, start_at) {
 		if (IS_UP(slave->dev) &&
 		    (slave->link == BOND_LINK_UP) &&
 		    (slave->state == BOND_STATE_ACTIVE)) {
 			res = bond_dev_queue_xmit(bond, skb, slave->dev);
-
-			write_lock(&bond->curr_slave_lock);
-			bond->curr_active_slave = slave->next;
-			write_unlock(&bond->curr_slave_lock);
-
 			break;
 		}
 	}
 
-
 out:
 	if (res) {
 		/* no suitable interface, frame not sent */
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index a8f2384..d1ed14b 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -197,6 +197,7 @@ struct bonding {
 	int      (*xmit_hash_policy)(struct sk_buff *, struct net_device *, int);
 	__be32   master_ip;
 	u16      flags;
+	u16      rr_tx_counter;
 	struct   ad_bond_info ad_info;
 	struct   alb_bond_info alb_info;
 	struct   bond_params params;
-- 
1.5.3.4.206.g58ba4-dirty


  reply	other threads:[~2007-10-18  0:37 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-18  0:37 [PATCH 0/6] bonding workqueue and lock rework Jay Vosburgh
2007-10-18  0:37 ` [PATCH 1/6] Convert bonding timers to workqueues Jay Vosburgh
2007-10-18  0:37   ` [PATCH] Two small fixes to IPoIB support for bonding: Jay Vosburgh
2007-10-18  0:37     ` Jay Vosburgh [this message]
2007-10-18  0:37       ` [PATCH 3/6] Convert miimon to new locking Jay Vosburgh
2007-10-18  0:37         ` [PATCH 4/6] Convert locks to _bh, rework alb locking for " Jay Vosburgh
2007-10-18  0:37           ` [PATCH 5/6] Convert more locks to _bh, acquire rtnl, " Jay Vosburgh
2007-10-18  0:37             ` [PATCH 6/6] Acquire correct locks in alb for promisc change Jay Vosburgh
2007-10-18  1:15     ` [PATCH] Two small fixes to IPoIB support for bonding: Jay Vosburgh
2007-10-24  0:42   ` [PATCH 1/6] Convert bonding timers to workqueues Jeff Garzik
2007-10-24  1:00     ` Jay Vosburgh
2007-10-24  1:13       ` Andy Gospodarek
2007-10-24  1:19         ` Jeff Garzik
  -- strict thread matches above, loose matches on Subject: below --
2007-10-11  4:14 [PATCH 0/6] bonding workqueue and lock rework Jay Vosburgh
2007-10-11  4:14 ` [PATCH 1/6] Convert bonding timers to workqueues Jay Vosburgh
2007-10-11  4:14   ` [PATCH 2/6] Convert balance-rr transmit to new locking Jay Vosburgh

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=11926678762641-git-send-email-fubar@us.ibm.com \
    --to=fubar@us.ibm.com \
    --cc=andy@greyhouse.net \
    --cc=jgarzik@pobox.com \
    --cc=netdev@vger.kernel.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).