From patchwork Tue May 14 16:33:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 1099602 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 453NYj1K3fz9s9T for ; Wed, 15 May 2019 02:34:17 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 0D690E4A; Tue, 14 May 2019 16:33:46 +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 01C08E1B for ; Tue, 14 May 2019 16:33:44 +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 7D4E383A for ; Tue, 14 May 2019 16:33:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 12263308425B; Tue, 14 May 2019 16:33:44 +0000 (UTC) Received: from dmarchan.remote.csb (ovpn-116-80.ams2.redhat.com [10.36.116.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id 95EC01975C; Tue, 14 May 2019 16:33:42 +0000 (UTC) From: David Marchand To: dev@openvswitch.org Date: Tue, 14 May 2019 18:33:26 +0200 Message-Id: <1557851610-5602-2-git-send-email-david.marchand@redhat.com> In-Reply-To: <1557851610-5602-1-git-send-email-david.marchand@redhat.com> References: <1557851610-5602-1-git-send-email-david.marchand@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 14 May 2019 16:33:44 +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] [RFC v2 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 --- lib/dpif-netdev.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) --- Changelog since v1: - added memory ordering on 'reload' atomic to serve as a synchronisation point between control thread and pmd threads diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 5a6f2ab..37366e2 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -681,10 +681,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. */ @@ -1756,7 +1756,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); } @@ -5468,7 +5468,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; } @@ -5479,7 +5479,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); @@ -5898,7 +5898,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); @@ -5945,7 +5945,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); @@ -5967,7 +5966,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); } From patchwork Tue May 14 16:33:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 1099603 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 453NZM4P7nz9sML for ; Wed, 15 May 2019 02:34:51 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id AC37CE4D; Tue, 14 May 2019 16:33:47 +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 D2FAFE3C for ; Tue, 14 May 2019 16:33:46 +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 5610D83A for ; Tue, 14 May 2019 16:33:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E20B8309265B; Tue, 14 May 2019 16:33:45 +0000 (UTC) Received: from dmarchan.remote.csb (ovpn-116-80.ams2.redhat.com [10.36.116.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6EC801975C; Tue, 14 May 2019 16:33:44 +0000 (UTC) From: David Marchand To: dev@openvswitch.org Date: Tue, 14 May 2019 18:33:27 +0200 Message-Id: <1557851610-5602-3-git-send-email-david.marchand@redhat.com> In-Reply-To: <1557851610-5602-1-git-send-email-david.marchand@redhat.com> References: <1557851610-5602-1-git-send-email-david.marchand@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Tue, 14 May 2019 16:33:45 +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] [RFC v2 2/5] dpif-netdev: Trigger parallel pmd reloads. 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 pmd reloads are currently serialised in each steps calling reload_affected_pmds. Any pmd processing packets, waiting on a mutex etc... will make other pmd threads wait for a delay that can be undeterministic when syscalls adds up. Switch to a little busy loop on the control thread using an atomic count. The memory order on this atomic is rel-acq to have an explicit synchronisation between the pmd threads and the control thread. Signed-off-by: David Marchand --- lib/dpif-netdev.c | 50 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 13 deletions(-) --- Changelog since v1: - added memory ordering on 'reloading_pmds' atomic to serve as a synchronisation point between pmd threads and control thread diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 37366e2..4febd8b 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -335,6 +335,9 @@ struct dp_netdev { /* The time that a packet can wait in output batch for sending. */ atomic_uint32_t tx_flush_interval; + /* Count of pmds currently reloading */ + atomic_uint32_t reloading_pmds; + /* Meters. */ struct ovs_mutex meter_locks[N_METER_LOCKS]; struct dp_meter *meters[MAX_METERS]; /* Meter bands. */ @@ -647,9 +650,6 @@ struct dp_netdev_pmd_thread { struct ovs_refcount ref_cnt; /* Every reference must be refcount'ed. */ struct cmap_node node; /* In 'dp->poll_threads'. */ - pthread_cond_t cond; /* For synchronizing pmd thread reload. */ - struct ovs_mutex cond_mutex; /* Mutex for condition variable. */ - /* Per thread exact-match cache. Note, the instance for cpu core * NON_PMD_CORE_ID can be accessed by multiple threads, and thusly * need to be protected by 'non_pmd_mutex'. Every other instance @@ -1525,6 +1525,8 @@ create_dp_netdev(const char *name, const struct dpif_class *class, atomic_init(&dp->emc_insert_min, DEFAULT_EM_FLOW_INSERT_MIN); atomic_init(&dp->tx_flush_interval, DEFAULT_TX_FLUSH_INTERVAL); + atomic_init(&dp->reloading_pmds, 0); + cmap_init(&dp->poll_threads); dp->pmd_rxq_assign_cyc = true; @@ -1754,11 +1756,8 @@ dp_netdev_reload_pmd__(struct dp_netdev_pmd_thread *pmd) return; } - ovs_mutex_lock(&pmd->cond_mutex); seq_change(pmd->reload_seq); atomic_store_explicit(&pmd->reload, true, memory_order_release); - ovs_mutex_cond_wait(&pmd->cond, &pmd->cond_mutex); - ovs_mutex_unlock(&pmd->cond_mutex); } static uint32_t @@ -4641,9 +4640,31 @@ rxq_scheduling(struct dp_netdev *dp, bool pinned) OVS_REQUIRES(dp->port_mutex) } static void +wait_reloading_pmds(struct dp_netdev *dp) +{ + uint32_t reloading; + + do { + atomic_read_explicit(&dp->reloading_pmds, &reloading, + memory_order_acquire); + } while (reloading != 0); +} + +static void reload_affected_pmds(struct dp_netdev *dp) { struct dp_netdev_pmd_thread *pmd; + unsigned int pmd_count = 0; + + CMAP_FOR_EACH (pmd, node, &dp->poll_threads) { + if (pmd->core_id == NON_PMD_CORE_ID) { + continue; + } + if (pmd->need_reload) { + pmd_count++; + } + } + atomic_store_relaxed(&dp->reloading_pmds, pmd_count); CMAP_FOR_EACH (pmd, node, &dp->poll_threads) { if (pmd->need_reload) { @@ -4652,6 +4673,10 @@ reload_affected_pmds(struct dp_netdev *dp) pmd->need_reload = false; } } + + if (pmd_count != 0) { + wait_reloading_pmds(dp); + } } static void @@ -5813,11 +5838,12 @@ dpif_netdev_enable_upcall(struct dpif *dpif) static void dp_netdev_pmd_reload_done(struct dp_netdev_pmd_thread *pmd) { - ovs_mutex_lock(&pmd->cond_mutex); + uint32_t old; + atomic_store_relaxed(&pmd->reload, false); pmd->last_reload_seq = seq_read(pmd->reload_seq); - xpthread_cond_signal(&pmd->cond); - ovs_mutex_unlock(&pmd->cond_mutex); + atomic_sub_explicit(&pmd->dp->reloading_pmds, 1, &old, + memory_order_release); } /* Finds and refs the dp_netdev_pmd_thread on core 'core_id'. Returns @@ -5902,8 +5928,6 @@ dp_netdev_configure_pmd(struct dp_netdev_pmd_thread *pmd, struct dp_netdev *dp, pmd->reload_seq = seq_create(); pmd->last_reload_seq = seq_read(pmd->reload_seq); atomic_init(&pmd->reload, false); - xpthread_cond_init(&pmd->cond, NULL); - ovs_mutex_init(&pmd->cond_mutex); ovs_mutex_init(&pmd->flow_mutex); ovs_mutex_init(&pmd->port_mutex); cmap_init(&pmd->flow_table); @@ -5946,8 +5970,6 @@ dp_netdev_destroy_pmd(struct dp_netdev_pmd_thread *pmd) cmap_destroy(&pmd->flow_table); ovs_mutex_destroy(&pmd->flow_mutex); seq_destroy(pmd->reload_seq); - xpthread_cond_destroy(&pmd->cond); - ovs_mutex_destroy(&pmd->cond_mutex); ovs_mutex_destroy(&pmd->port_mutex); free(pmd); } @@ -5967,7 +5989,9 @@ dp_netdev_del_pmd(struct dp_netdev *dp, struct dp_netdev_pmd_thread *pmd) ovs_mutex_unlock(&dp->non_pmd_mutex); } else { atomic_store_relaxed(&pmd->exit, true); + atomic_store_relaxed(&dp->reloading_pmds, 1); dp_netdev_reload_pmd__(pmd); + wait_reloading_pmds(dp); xpthread_join(pmd->thread, NULL); } From patchwork Tue May 14 16:33:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 1099604 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 453NbG4bYPz9s9T for ; Wed, 15 May 2019 02:35:38 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 84BADE5C; Tue, 14 May 2019 16:33:50 +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 9E855E57 for ; Tue, 14 May 2019 16:33:48 +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 361B583A for ; Tue, 14 May 2019 16:33:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BBF1281DE5; Tue, 14 May 2019 16:33:47 +0000 (UTC) Received: from dmarchan.remote.csb (ovpn-116-80.ams2.redhat.com [10.36.116.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id 479451975C; Tue, 14 May 2019 16:33:46 +0000 (UTC) From: David Marchand To: dev@openvswitch.org Date: Tue, 14 May 2019 18:33:28 +0200 Message-Id: <1557851610-5602-4-git-send-email-david.marchand@redhat.com> In-Reply-To: <1557851610-5602-1-git-send-email-david.marchand@redhat.com> References: <1557851610-5602-1-git-send-email-david.marchand@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 14 May 2019 16:33:47 +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] [RFC v2 3/5] dpif-netdev: Do not sleep when swapping queues. 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 When swapping queues from a pmd thread to another (q0 polled by pmd0/q1 polled by pmd1 -> q1 polled by pmd0/q0 polled by pmd1), the current "Step 5" puts both pmds to sleep waiting for the control thread to wake them up later. Prefer to make them spin in such a case to avoid sleeping an undeterministic amount of time. Signed-off-by: David Marchand --- lib/dpif-netdev.c | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 4febd8b..254a50e 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -684,6 +684,7 @@ struct dp_netdev_pmd_thread { struct seq *reload_seq; uint64_t last_reload_seq; atomic_bool reload; /* Do we need to reload ports? */ + atomic_bool wait_for_reload; /* Can we busy wait for the next reload? */ atomic_bool exit; /* For terminating the pmd thread. */ pthread_t thread; unsigned core_id; /* CPU core id of this pmd thread. */ @@ -4897,6 +4898,33 @@ reconfigure_datapath(struct dp_netdev *dp) HMAP_FOR_EACH_SAFE (poll, poll_next, node, &pmd->poll_list) { if (poll->rxq->pmd != pmd) { dp_netdev_del_rxq_from_pmd(pmd, poll); + + /* This pmd might sleep after this step reload if it has no + * rxq remaining. Can we tell it to busy wait for new rxq at + * Step 6 ? */ + if (hmap_count(&pmd->poll_list) == 0) { + HMAP_FOR_EACH (port, node, &dp->ports) { + int qid; + + if (!netdev_is_pmd(port->netdev)) { + continue; + } + + for (qid = 0; qid < port->n_rxq; qid++) { + struct dp_netdev_rxq *q = &port->rxqs[qid]; + + if (q->pmd == pmd) { + atomic_store_relaxed(&q->pmd->wait_for_reload, + true); + break; + } + } + + if (qid != port->n_rxq) { + break; + } + } + } } } ovs_mutex_unlock(&pmd->port_mutex); @@ -5414,7 +5442,9 @@ pmd_thread_main(void *f_) struct pmd_perf_stats *s = &pmd->perf_stats; unsigned int lc = 0; struct polled_queue *poll_list; + bool wait_for_reload = false; bool exiting; + bool reload; int poll_cnt; int i; int process_packets = 0; @@ -5442,9 +5472,16 @@ reload: } if (!poll_cnt) { - while (seq_read(pmd->reload_seq) == pmd->last_reload_seq) { - seq_wait(pmd->reload_seq, pmd->last_reload_seq); - poll_block(); + /* Don't sleep, control thread will ask for a reload shortly. */ + if (wait_for_reload) { + do { + atomic_read_relaxed(&pmd->reload, &reload); + } while (!reload); + } else { + while (seq_read(pmd->reload_seq) == pmd->last_reload_seq) { + seq_wait(pmd->reload_seq, pmd->last_reload_seq); + poll_block(); + } } lc = UINT_MAX; } @@ -5483,8 +5520,6 @@ reload: } if (lc++ > 1024) { - bool reload; - lc = 0; coverage_try_clear(); @@ -5504,6 +5539,7 @@ reload: ovs_mutex_unlock(&pmd->perf_stats.stats_mutex); poll_cnt = pmd_load_queues_and_ports(pmd, &poll_list); + atomic_read_relaxed(&pmd->wait_for_reload, &wait_for_reload); atomic_read_relaxed(&pmd->exit, &exiting); /* Signal here to make sure the pmd finishes * reloading the updated configuration. */ @@ -5840,6 +5876,7 @@ dp_netdev_pmd_reload_done(struct dp_netdev_pmd_thread *pmd) { uint32_t old; + atomic_store_relaxed(&pmd->wait_for_reload, false); atomic_store_relaxed(&pmd->reload, false); pmd->last_reload_seq = seq_read(pmd->reload_seq); atomic_sub_explicit(&pmd->dp->reloading_pmds, 1, &old, From patchwork Tue May 14 16:33:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 1099605 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 453Nbq0xKSz9s9T for ; Wed, 15 May 2019 02:36:07 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 3CE5CE70; Tue, 14 May 2019 16:33:52 +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 05963E63 for ; Tue, 14 May 2019 16:33:51 +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 88DCB87D for ; Tue, 14 May 2019 16:33:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1FCCE300502A; Tue, 14 May 2019 16:33:50 +0000 (UTC) Received: from dmarchan.remote.csb (ovpn-116-80.ams2.redhat.com [10.36.116.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4DE741975D; Tue, 14 May 2019 16:33:47 +0000 (UTC) From: David Marchand To: dev@openvswitch.org Date: Tue, 14 May 2019 18:33:29 +0200 Message-Id: <1557851610-5602-5-git-send-email-david.marchand@redhat.com> In-Reply-To: <1557851610-5602-1-git-send-email-david.marchand@redhat.com> References: <1557851610-5602-1-git-send-email-david.marchand@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Tue, 14 May 2019 16:33:50 +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] [RFC v2 4/5] dpif-netdev: Only reload static tx qid when needed. 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 pmd->static_tx_qid is allocated under a mutex by the different pmd threads. Unconditionally reallocating it will make those pmd threads sleep when contention occurs. During "normal" reloads like for rebalancing queues between pmd threads, this can make pmd threads waste time on this. Reallocating the tx qid is only needed when removing other pmd threads as it is the only situation when the qid pool can become uncontiguous. Add a flag to instruct the pmd to reload tx qid for this case which is Step 1 in current code. Signed-off-by: David Marchand --- lib/dpif-netdev.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 254a50e..77e3f0c 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -685,6 +685,7 @@ struct dp_netdev_pmd_thread { uint64_t last_reload_seq; atomic_bool reload; /* Do we need to reload ports? */ atomic_bool wait_for_reload; /* Can we busy wait for the next reload? */ + atomic_bool reload_tx_qid; /* Do we need to reload static_tx_qid? */ atomic_bool exit; /* For terminating the pmd thread. */ pthread_t thread; unsigned core_id; /* CPU core id of this pmd thread. */ @@ -4721,6 +4722,7 @@ reconfigure_pmd_threads(struct dp_netdev *dp) pmd->core_id)) { hmapx_add(&to_delete, pmd); } else if (need_to_adjust_static_tx_qids) { + atomic_store_relaxed(&pmd->reload_tx_qid, true); pmd->need_reload = true; } } @@ -5443,6 +5445,7 @@ pmd_thread_main(void *f_) unsigned int lc = 0; struct polled_queue *poll_list; bool wait_for_reload = false; + bool reload_tx_qid; bool exiting; bool reload; int poll_cnt; @@ -5457,9 +5460,9 @@ pmd_thread_main(void *f_) dpdk_set_lcore_id(pmd->core_id); poll_cnt = pmd_load_queues_and_ports(pmd, &poll_list); dfc_cache_init(&pmd->flow_cache); -reload: pmd_alloc_static_tx_qid(pmd); +reload: atomic_count_init(&pmd->pmd_overloaded, 0); /* List port/core affinity */ @@ -5540,17 +5543,22 @@ reload: poll_cnt = pmd_load_queues_and_ports(pmd, &poll_list); atomic_read_relaxed(&pmd->wait_for_reload, &wait_for_reload); + atomic_read_relaxed(&pmd->reload_tx_qid, &reload_tx_qid); atomic_read_relaxed(&pmd->exit, &exiting); /* Signal here to make sure the pmd finishes * reloading the updated configuration. */ dp_netdev_pmd_reload_done(pmd); - pmd_free_static_tx_qid(pmd); + if (reload_tx_qid) { + pmd_free_static_tx_qid(pmd); + pmd_alloc_static_tx_qid(pmd); + } if (!exiting) { goto reload; } + pmd_free_static_tx_qid(pmd); dfc_cache_uninit(&pmd->flow_cache); free(poll_list); pmd_free_cached_ports(pmd); @@ -5877,6 +5885,7 @@ dp_netdev_pmd_reload_done(struct dp_netdev_pmd_thread *pmd) uint32_t old; atomic_store_relaxed(&pmd->wait_for_reload, false); + atomic_store_relaxed(&pmd->reload_tx_qid, false); atomic_store_relaxed(&pmd->reload, false); pmd->last_reload_seq = seq_read(pmd->reload_seq); atomic_sub_explicit(&pmd->dp->reloading_pmds, 1, &old, From patchwork Tue May 14 16:33:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 1099606 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 453NcM1TdSz9s9T for ; Wed, 15 May 2019 02:36:35 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 01B64E71; Tue, 14 May 2019 16:33:54 +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 A6CCCE75 for ; Tue, 14 May 2019 16:33:52 +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 58F0387E for ; Tue, 14 May 2019 16:33:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EBE2F3058951; Tue, 14 May 2019 16:33:51 +0000 (UTC) Received: from dmarchan.remote.csb (ovpn-116-80.ams2.redhat.com [10.36.116.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id 78C181975C; Tue, 14 May 2019 16:33:50 +0000 (UTC) From: David Marchand To: dev@openvswitch.org Date: Tue, 14 May 2019 18:33:30 +0200 Message-Id: <1557851610-5602-6-git-send-email-david.marchand@redhat.com> In-Reply-To: <1557851610-5602-1-git-send-email-david.marchand@redhat.com> References: <1557851610-5602-1-git-send-email-david.marchand@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 14 May 2019 16:33:52 +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] [RFC v2 5/5] dpif-netdev: Catch reloads faster. 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 Looking at the reload flag only every 1024 loops can be a long time under load, since we might be handling 32 packets per iteration, which means 32k packets. Look at the flag every loop, no major performance impact seen. Signed-off-by: David Marchand --- lib/dpif-netdev.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 77e3f0c..933d91b 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -5486,7 +5486,6 @@ reload: poll_block(); } } - lc = UINT_MAX; } pmd->intrvl_tsc_prev = 0; @@ -5530,12 +5529,13 @@ reload: if (!ovsrcu_try_quiesce()) { emc_cache_slow_sweep(&((pmd->flow_cache).emc_cache)); } + } - atomic_read_explicit(&pmd->reload, &reload, memory_order_acquire); - if (reload) { - break; - } + atomic_read_explicit(&pmd->reload, &reload, memory_order_acquire); + if (OVS_UNLIKELY(reload)) { + break; } + pmd_perf_end_iteration(s, rx_packets, tx_packets, pmd_perf_metrics_enabled(pmd)); }