From patchwork Tue Jul 9 16:19:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 1129907 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com 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 45jnnF3HpNz9sNF for ; Wed, 10 Jul 2019 02:28:33 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 1B8AB3BED; Tue, 9 Jul 2019 16:26:49 +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 1B5393321 for ; Tue, 9 Jul 2019 16:21:19 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 5F037899 for ; Tue, 9 Jul 2019 16:21:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6F7CE8FABD; Tue, 9 Jul 2019 16:21:14 +0000 (UTC) Received: from dmarchan.remote.csb (ovpn-204-39.brq.redhat.com [10.40.204.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 47E1B90F64; Tue, 9 Jul 2019 16:21:07 +0000 (UTC) From: David Marchand To: dev@openvswitch.org Date: Tue, 9 Jul 2019 18:19:54 +0200 Message-Id: <1562689198-21481-2-git-send-email-david.marchand@redhat.com> In-Reply-To: <1562689198-21481-1-git-send-email-david.marchand@redhat.com> References: <1562689198-21481-1-git-send-email-david.marchand@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 09 Jul 2019 16:21:14 +0000 (UTC) X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: i.maximets@samsung.com Subject: [ovs-dev] [PATCH v4 1/5] dpif-netdev: Convert exit latch to flag. 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 No need for a latch here since we don't have to wait. A simple boolean flag is enough. The memory order on the reload flag is changed to rel-acq ordering to serve as a synchronisation point between the pmd threads and the control thread that asks for termination. Fixes: e4cfed38b159 ("dpif-netdev: Add poll-mode-device thread.") Signed-off-by: David Marchand Acked-by: Eelco Chaudron Acked-by: Ian Stokes Acked-by: Ilya Maximets --- Changelog since v1: - added acks, no change Changelog since RFC v2: - removed now unused latch.h inclusion Changelog since RFC v1: - added memory ordering on 'reload' atomic to serve as a synchronisation point between control thread and pmd threads --- lib/dpif-netdev.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index f4b59e4..8eeec63 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -48,7 +48,6 @@ #include "hmapx.h" #include "id-pool.h" #include "ipf.h" -#include "latch.h" #include "netdev.h" #include "netdev-offload.h" #include "netdev-provider.h" @@ -684,10 +683,10 @@ struct dp_netdev_pmd_thread { /* Current context of the PMD thread. */ struct dp_netdev_pmd_thread_ctx ctx; - struct latch exit_latch; /* For terminating the pmd thread. */ struct seq *reload_seq; uint64_t last_reload_seq; atomic_bool reload; /* Do we need to reload ports? */ + atomic_bool exit; /* For terminating the pmd thread. */ pthread_t thread; unsigned core_id; /* CPU core id of this pmd thread. */ int numa_id; /* numa node id of this pmd thread. */ @@ -1761,7 +1760,7 @@ dp_netdev_reload_pmd__(struct dp_netdev_pmd_thread *pmd) ovs_mutex_lock(&pmd->cond_mutex); seq_change(pmd->reload_seq); - atomic_store_relaxed(&pmd->reload, true); + atomic_store_explicit(&pmd->reload, true, memory_order_release); ovs_mutex_cond_wait(&pmd->cond, &pmd->cond_mutex); ovs_mutex_unlock(&pmd->cond_mutex); } @@ -5488,7 +5487,7 @@ reload: emc_cache_slow_sweep(&((pmd->flow_cache).emc_cache)); } - atomic_read_relaxed(&pmd->reload, &reload); + atomic_read_explicit(&pmd->reload, &reload, memory_order_acquire); if (reload) { break; } @@ -5509,7 +5508,7 @@ reload: ovs_mutex_unlock(&pmd->perf_stats.stats_mutex); poll_cnt = pmd_load_queues_and_ports(pmd, &poll_list); - exiting = latch_is_set(&pmd->exit_latch); + atomic_read_relaxed(&pmd->exit, &exiting); /* Signal here to make sure the pmd finishes * reloading the updated configuration. */ dp_netdev_pmd_reload_done(pmd); @@ -5928,7 +5927,7 @@ dp_netdev_configure_pmd(struct dp_netdev_pmd_thread *pmd, struct dp_netdev *dp, pmd->n_output_batches = 0; ovs_refcount_init(&pmd->ref_cnt); - latch_init(&pmd->exit_latch); + atomic_init(&pmd->exit, false); pmd->reload_seq = seq_create(); pmd->last_reload_seq = seq_read(pmd->reload_seq); atomic_init(&pmd->reload, false); @@ -5975,7 +5974,6 @@ dp_netdev_destroy_pmd(struct dp_netdev_pmd_thread *pmd) cmap_destroy(&pmd->classifiers); cmap_destroy(&pmd->flow_table); ovs_mutex_destroy(&pmd->flow_mutex); - latch_destroy(&pmd->exit_latch); seq_destroy(pmd->reload_seq); xpthread_cond_destroy(&pmd->cond); ovs_mutex_destroy(&pmd->cond_mutex); @@ -5997,7 +5995,7 @@ dp_netdev_del_pmd(struct dp_netdev *dp, struct dp_netdev_pmd_thread *pmd) pmd_free_static_tx_qid(pmd); ovs_mutex_unlock(&dp->non_pmd_mutex); } else { - latch_set(&pmd->exit_latch); + atomic_store_relaxed(&pmd->exit, true); dp_netdev_reload_pmd__(pmd); xpthread_join(pmd->thread, NULL); }