From patchwork Fri Mar 10 00:52:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Zhou X-Patchwork-Id: 737204 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vfTJJ4FkCz9s7f for ; Fri, 10 Mar 2017 11:52:48 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id EBD4EBE1; Fri, 10 Mar 2017 00:52:45 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id D6618BD3 for ; Fri, 10 Mar 2017 00:52:44 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pg0-f66.google.com (mail-pg0-f66.google.com [74.125.83.66]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id B99861F0 for ; Fri, 10 Mar 2017 00:52:35 +0000 (UTC) Received: by mail-pg0-f66.google.com with SMTP id g2so3951038pge.2 for ; Thu, 09 Mar 2017 16:52:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id :content-transfer-encoding; bh=Fq6plcnGsSvzal0+s4wJ7FHHAZJ0TouTx7FHHkUmic4=; b=S50LTGsgDLmKdWcEZLjs6yVcIumbpQl4QmUhs19N3Ko3/0Y1RyiU4ZIZIhlu7HCcMQ K/Iq+5wVA4ij+TXTZvE9CZ8FRGqCVJTfd/lcxzwJOJ6OYSovyyIn8MDF8NCBsaZoPhPt Zc1sfLBV5yYi2DzhtRLCg3JFkV1K3zpq97v93NuGfCWGmAPyHQIP7tW+1KZ2O+iXjhbO UlHrwVv+g6EZIDjfq3854rpfaKAVBcZghKoRlT3Mt6yv1ct5NzxtF/DqaFarLAAuDEyg 8QI75bVdLbC8b0ZkybabnS9vSkkiqNr3eSbfcy2qFFYHLHS+J8jKY9zBBkYRWnFB9Nz/ rw5A== X-Gm-Message-State: AMke39nxN8szEwNBKogN/mdaSABAdYxwQ7JBEqsGY4HVq0rHGOLDjVMi397RalM89/lYnA== X-Received: by 10.98.62.82 with SMTP id l79mr17417788pfa.164.1489107155360; Thu, 09 Mar 2017 16:52:35 -0800 (PST) Received: from ubuntu.localdomain ([208.91.1.34]) by smtp.gmail.com with ESMTPSA id p129sm14595460pfp.118.2017.03.09.16.52.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 09 Mar 2017 16:52:34 -0800 (PST) From: Andy Zhou To: dev@openvswitch.org Date: Thu, 9 Mar 2017 16:52:27 -0800 Message-Id: <1489107147-13940-1-git-send-email-azhou@ovn.org> X-Mailer: git-send-email 1.9.1 X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH] ofproto/bond: Make bond_may_recirc() private within bond.c X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Minor refactoring to make the bond code easier to read. Signed-off-by: Andy Zhou Acked-by: Ben Pfaff --- ofproto/bond.c | 26 ++++++++++++++++++-------- ofproto/bond.h | 1 - ofproto/ofproto-dpif-xlate.c | 12 +++--------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/ofproto/bond.c b/ofproto/bond.c index ef65a2a3c1b4..d46b623f6ce8 100644 --- a/ofproto/bond.c +++ b/ofproto/bond.c @@ -926,7 +926,7 @@ bond_recirculation_account(struct bond *bond) } } -bool +static bool bond_may_recirc(const struct bond *bond) { return bond->balance == BM_TCP && bond->recirc_id; @@ -960,15 +960,25 @@ void bond_update_post_recirc_rules(struct bond *bond, uint32_t *recirc_id, uint32_t *hash_basis) { - ovs_rwlock_wrlock(&rwlock); - if (bond_may_recirc(bond)) { - *recirc_id = bond->recirc_id; - *hash_basis = bond->basis; - bond_update_post_recirc_rules__(bond, false); - } else { + bool may_recirc = bond_may_recirc(bond); + + if (may_recirc) { + /* To avoid unnecessary locking, bond_may_recirc() is first + * called outside of the 'rwlock'. After acquiring the lock, + * check again to make sure bond configuration has not been changed. */ + ovs_rwlock_wrlock(&rwlock); + may_recirc = bond_may_recirc(bond); + if (may_recirc) { + *recirc_id = bond->recirc_id; + *hash_basis = bond->basis; + bond_update_post_recirc_rules__(bond, false); + } + ovs_rwlock_unlock(&rwlock); + } + + if (!may_recirc) { *recirc_id = *hash_basis = 0; } - ovs_rwlock_unlock(&rwlock); } diff --git a/ofproto/bond.h b/ofproto/bond.h index d3a2256402da..e7c3d9bc35dd 100644 --- a/ofproto/bond.h +++ b/ofproto/bond.h @@ -122,5 +122,4 @@ void bond_rebalance(struct bond *); */ void bond_update_post_recirc_rules(struct bond *, uint32_t *recirc_id, uint32_t *hash_basis); -bool bond_may_recirc(const struct bond *); #endif /* bond.h */ diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c index 8ce6a5939df6..6dfbccc3b13e 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -1987,15 +1987,9 @@ output_normal(struct xlate_ctx *ctx, const struct xbundle *out_xbundle, struct flow_wildcards *wc = ctx->wc; struct ofport_dpif *ofport; - if (ctx->xbridge->support.odp.recirc - && bond_may_recirc(out_xbundle->bond)) { - /* To avoid unnecessary locking, bond_may_recirc() is first - * called outside of the 'rwlock'. After acquiring the lock, - * bond_update_post_recirc_rules() will check again to make - * sure bond configuration has not been changed. - * - * In case recirculation is not actually in use, 'xr.recirc_id' - * will be set to '0', Since a valid 'recirc_id' can + if (ctx->xbridge->support.odp.recirc) { + /* In case recirculation is not actually in use, 'xr.recirc_id' + * will be set to '0', since a valid 'recirc_id' can * not be zero. */ bond_update_post_recirc_rules(out_xbundle->bond, &xr.recirc_id,