From patchwork Wed Nov 16 00:46:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniele Di Proietto X-Patchwork-Id: 695372 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 3tJQfv4rVKz9s9c for ; Wed, 16 Nov 2016 11:51:03 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 7A5FCC25; Wed, 16 Nov 2016 00:46:18 +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 1E921BC2 for ; Wed, 16 Nov 2016 00:46:14 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from EX13-EDG-OU-002.vmware.com (ex13-edg-ou-002.vmware.com [208.91.0.190]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 1CE06206 for ; Wed, 16 Nov 2016 00:46:12 +0000 (UTC) Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Tue, 15 Nov 2016 16:45:50 -0800 Received: from sc9-mailhost3.vmware.com (htb-1n-eng-dhcp161.eng.vmware.com [10.33.74.161]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id A401E40215; Tue, 15 Nov 2016 16:46:10 -0800 (PST) From: Daniele Di Proietto To: Date: Tue, 15 Nov 2016 16:46:02 -0800 Message-ID: <20161116004612.79315-8-diproiettod@vmware.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161116004612.79315-1-diproiettod@vmware.com> References: <20161116004612.79315-1-diproiettod@vmware.com> MIME-Version: 1.0 Received-SPF: None (EX13-EDG-OU-002.vmware.com: diproiettod@vmware.com does not designate permitted sender hosts) X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Daniele Di Proietto Subject: [ovs-dev] [PATCH 07/17] dpif-netdev: Use a boolean instead of pmd->port_seq. 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: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org There's no need for a sequence number, since the main thread has to wait for the pmd thread, so there's no chance that an update will be undetected. A seq object will be introduced for another purpose in the next commit, and changing this to boolean makes the code more readable. Signed-off-by: Daniele Di Proietto --- lib/dpif-netdev.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 81366b2..23546b9 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -485,7 +485,7 @@ struct dp_netdev_pmd_thread { unsigned long long last_cycles; struct latch exit_latch; /* For terminating the pmd thread. */ - atomic_uint change_seq; /* For reloading pmd ports. */ + atomic_bool reload; /* Do we need to reload ports? */ pthread_t thread; unsigned core_id; /* CPU core id of this pmd thread. */ int numa_id; /* numa node id of this pmd thread. */ @@ -527,8 +527,6 @@ struct dp_netdev_pmd_thread { uint64_t cycles_zero[PMD_N_CYCLES]; }; -#define PMD_INITIAL_SEQ 1 - /* Interface to netdev-based datapath. */ struct dpif_netdev { struct dpif dpif; @@ -1202,8 +1200,6 @@ dpif_netdev_get_stats(const struct dpif *dpif, struct dpif_dp_stats *stats) static void dp_netdev_reload_pmd__(struct dp_netdev_pmd_thread *pmd) { - int old_seq; - if (pmd->core_id == NON_PMD_CORE_ID) { ovs_mutex_lock(&pmd->dp->non_pmd_mutex); ovs_mutex_lock(&pmd->port_mutex); @@ -1214,7 +1210,7 @@ dp_netdev_reload_pmd__(struct dp_netdev_pmd_thread *pmd) } ovs_mutex_lock(&pmd->cond_mutex); - atomic_add_relaxed(&pmd->change_seq, 1, &old_seq); + atomic_store_relaxed(&pmd->reload, true); ovs_mutex_cond_wait(&pmd->cond, &pmd->cond_mutex); ovs_mutex_unlock(&pmd->cond_mutex); } @@ -3131,7 +3127,6 @@ pmd_thread_main(void *f_) struct dp_netdev_pmd_thread *pmd = f_; unsigned int lc = 0; struct rxq_poll *poll_list; - unsigned int port_seq = PMD_INITIAL_SEQ; bool exiting; int poll_cnt; int i; @@ -3159,7 +3154,7 @@ reload: } if (lc++ > 1024) { - unsigned int seq; + bool reload; lc = 0; @@ -3169,9 +3164,8 @@ reload: emc_cache_slow_sweep(&pmd->flow_cache); } - atomic_read_relaxed(&pmd->change_seq, &seq); - if (seq != port_seq) { - port_seq = seq; + atomic_read_relaxed(&pmd->reload, &reload); + if (reload) { break; } } @@ -3228,6 +3222,7 @@ static void dp_netdev_pmd_reload_done(struct dp_netdev_pmd_thread *pmd) { ovs_mutex_lock(&pmd->cond_mutex); + atomic_store_relaxed(&pmd->reload, false); xpthread_cond_signal(&pmd->cond); ovs_mutex_unlock(&pmd->cond_mutex); } @@ -3322,7 +3317,7 @@ dp_netdev_configure_pmd(struct dp_netdev_pmd_thread *pmd, struct dp_netdev *dp, ovs_refcount_init(&pmd->ref_cnt); latch_init(&pmd->exit_latch); - atomic_init(&pmd->change_seq, PMD_INITIAL_SEQ); + atomic_init(&pmd->reload, false); xpthread_cond_init(&pmd->cond, NULL); ovs_mutex_init(&pmd->cond_mutex); ovs_mutex_init(&pmd->flow_mutex);