From patchwork Wed Aug 7 14:21:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nitin Katiyar X-Patchwork-Id: 1143281 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=ericsson.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ericsson.com header.i=@ericsson.com header.b="ZQgWFpVZ"; dkim-atps=neutral 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 463Lwv3JHxz9sBF for ; Wed, 7 Aug 2019 16:21:01 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id A119ADCF; Wed, 7 Aug 2019 06:20:58 +0000 (UTC) X-Original-To: ovs-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 F03AADCD for ; Wed, 7 Aug 2019 06:20:57 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from sessmg23.ericsson.net (sessmg23.ericsson.net [193.180.251.45]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id C6BD07D2 for ; Wed, 7 Aug 2019 06:20:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; d=ericsson.com; s=mailgw201801; c=relaxed/relaxed; q=dns/txt; i=@ericsson.com; t=1565158853; x=1567750853; h=From:Sender:Reply-To:Subject:Date:Message-ID:To:CC:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=fdZGFMzl2BJQJ587xV1r3QMfGIoeITrtvOxgFWAA0sg=; b=ZQgWFpVZ3G4uRsgW2ZzXLmcNAXT28VP7i5f/Pm28+Dvg8u5Y201B5o/3S6pu10Ub 2h3D1EsI0nayENS7rUsiDTmhHi4ycMkozTOMb/eNeKvx7PXrxTtrXrWCu7pmlHnx fKZsoXbF0P/tPXQgNxWZbpI/lh2ubIO1io+iAZyH7hY=; X-AuditID: c1b4fb2d-195ff70000001a6d-ec-5d4a6dc56823 Received: from ESESSMB501.ericsson.se (Unknown_Domain [153.88.183.119]) by sessmg23.ericsson.net (Symantec Mail Security) with SMTP id 85.0E.06765.5CD6A4D5; Wed, 7 Aug 2019 08:20:53 +0200 (CEST) Received: from ESESBMB504.ericsson.se (153.88.183.171) by ESESSMB501.ericsson.se (153.88.183.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Wed, 7 Aug 2019 08:20:53 +0200 Received: from ESESSHC002.ericsson.se (153.88.183.24) by ESESBMB504.ericsson.se (153.88.183.171) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA_P256) id 15.1.1713.5 via Frontend Transport; Wed, 7 Aug 2019 08:20:53 +0200 Received: from ESGSCHC008.ericsson.se (146.11.116.89) by ESESSHC002.ericsson.se (153.88.183.24) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 7 Aug 2019 08:20:52 +0200 Received: from localhost.localdomain (146.11.116.127) by smtps-ao.internal.ericsson.com (146.11.116.89) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 7 Aug 2019 14:20:47 +0800 From: Nitin Katiyar To: Date: Wed, 7 Aug 2019 19:51:37 +0530 Message-ID: <1565187697-8003-1-git-send-email-nitin.katiyar@ericsson.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [146.11.116.127] X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrLLMWRmVeSWpSXmKPExsUyM2J7ue7RXK9YgzdzdC3mfnrO6MDo8ezm f8YAxigum5TUnMyy1CJ9uwSujN8L9jIWzNaqeLezg6mBca1CFyMnh4SAiUTH0d+MXYxcHEIC Rxkldr1azALhfGWUmH+5mQ3C6WCSOLL7OhOEs4lR4uXXaVCZXYwS9xpfM4IMYxMwkNh+cRI7 iC0iICvRsOEfC4jNLBAh8an9GDOILSzgLXG0uYe1i5GDg0VARaJrujdImFfAU2Lhkd9sEDfJ SZw8NpkVIi4ocXLmE6gxEhIHX7wAGyMkoC7x5FE3E0S9ksSzb8tZJzAKzkLSMgtJywJGplWM osWpxcW56UbGeqlFmcnFxfl5enmpJZsYgYF4cMtv3R2Mq187HmIU4GBU4uF9ulU8Vog1say4 MvcQowQHs5IIr+Q5kVgh3pTEyqrUovz4otKc1OJDjNIcLErivOu9/8UICaQnlqRmp6YWpBbB ZJk4OKUaGBVZt2eyeXLIabxPq2S6VPM9JmNX4CnHnSfkGSLD9I9OOp5+Mu2qf9vsl0X3szms X+nqGP78479nxTxWZve0R7lW2kbz5/YXu/6oP7z0yMw9j6smzjfe73Hu6AwRU8s93G+fH9og vmLvvu9lHx6nzpzBL3B5vWH31Icqkz9IL9FQXGZaEjt9ykMlluKMREMt5qLiRABPG9vXQAIA AA== X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, DATE_IN_FUTURE_06_12, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Anju Thomas , Nitin Katiyar Subject: [ovs-dev] [PATCH] Do RCU synchronization at fixed interval in PMD main loop. 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 Each PMD updates the global sequence number for RCU synchronization purpose with other OVS threads. This is done at every 1025th iteration in PMD main loop. If the PMD thread is responsible for polling large number of queues that are carrying traffic, it spends a lot of time processing packets and this results in significant delay in performing the housekeeping activities. If the OVS main thread is waiting to synchronize with the PMD threads and if those threads delay performing housekeeping activities for more than 3 sec then LACP processing will be impacted and it will lead to LACP flaps. Similarly, other controls protocols run by OVS main thread are impacted. For e.g. a PMD thread polling 200 ports/queues with average of 1600 processing cycles per packet with batch size of 32 may take 10240000 (200 * 1600 * 32) cycles per iteration. In system with 2.0 GHz CPU it means more than 5 ms per iteration. So, for 1024 iterations to complete it would be more than 5 seconds. This gets worse when there are PMD threads which are less loaded. It reduces possibility of getting mutex lock in ovsrcu_try_quiesce() by heavily loaded PMD and next attempt to quiesce would be after 1024 iterations. With this patch, PMD RCU synchronization will be performed after fixed interval instead after a fixed number of iterations. This will ensure that even if the packet processing load is high the RCU synchronization will not be delayed long. Co-authored-by: Anju Thomas Signed-off-by: Nitin Katiyar Signed-off-by: Anju Thomas --- lib/dpif-netdev-perf.c | 16 ---------------- lib/dpif-netdev-perf.h | 17 +++++++++++++++++ lib/dpif-netdev.c | 27 +++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/lib/dpif-netdev-perf.c b/lib/dpif-netdev-perf.c index e7ed49e..c888e5d 100644 --- a/lib/dpif-netdev-perf.c +++ b/lib/dpif-netdev-perf.c @@ -43,22 +43,6 @@ uint64_t iter_cycle_threshold; static struct vlog_rate_limit latency_rl = VLOG_RATE_LIMIT_INIT(600, 600); -#ifdef DPDK_NETDEV -static uint64_t -get_tsc_hz(void) -{ - return rte_get_tsc_hz(); -} -#else -/* This function is only invoked from PMD threads which depend on DPDK. - * A dummy function is sufficient when building without DPDK_NETDEV. */ -static uint64_t -get_tsc_hz(void) -{ - return 1; -} -#endif - /* Histogram functions. */ static void diff --git a/lib/dpif-netdev-perf.h b/lib/dpif-netdev-perf.h index 244813f..3f2ee1c 100644 --- a/lib/dpif-netdev-perf.h +++ b/lib/dpif-netdev-perf.h @@ -187,6 +187,23 @@ struct pmd_perf_stats { char *log_reason; }; +#ifdef DPDK_NETDEV +static inline uint64_t +get_tsc_hz(void) +{ + return rte_get_tsc_hz(); +} +#else +/* This function is only invoked from PMD threads which depend on DPDK. + * A dummy function is sufficient when building without DPDK_NETDEV. */ +static inline uint64_t +get_tsc_hz(void) +{ + return 1; +} +#endif + + #ifdef __linux__ static inline uint64_t rdtsc_syscall(struct pmd_perf_stats *s) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index d0a1c58..c3d6835 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -751,6 +751,9 @@ struct dp_netdev_pmd_thread { /* Set to true if the pmd thread needs to be reloaded. */ bool need_reload; + + /* Last time (in tsc) when PMD was last quiesced */ + uint64_t last_rcu_quiesced; }; /* Interface to netdev-based datapath. */ @@ -5445,6 +5448,7 @@ pmd_thread_main(void *f_) int poll_cnt; int i; int process_packets = 0; + uint64_t rcu_quiesce_interval = 0; poll_list = NULL; @@ -5486,6 +5490,13 @@ reload: pmd->intrvl_tsc_prev = 0; atomic_store_relaxed(&pmd->intrvl_cycles, 0); cycles_counter_update(s); + + if (get_tsc_hz() > 1) { + /* Calculate ~10 ms interval. */ + rcu_quiesce_interval = get_tsc_hz() / 100; + pmd->last_rcu_quiesced = cycles_counter_get(s); + } + /* Protect pmd stats from external clearing while polling. */ ovs_mutex_lock(&pmd->perf_stats.stats_mutex); for (;;) { @@ -5493,6 +5504,19 @@ reload: pmd_perf_start_iteration(s); + /* Do RCU synchronization at fixed interval instead of doing it + * at fixed number of iterations. This ensures that synchronization + * would not be delayed long even at high load of packet + * processing. */ + + if (rcu_quiesce_interval && + ((cycles_counter_get(s) - pmd->last_rcu_quiesced) > + rcu_quiesce_interval)) { + if (!ovsrcu_try_quiesce()) { + pmd->last_rcu_quiesced = cycles_counter_get(s); + } + } + for (i = 0; i < poll_cnt; i++) { if (!poll_list[i].rxq_enabled) { @@ -5527,6 +5551,9 @@ reload: dp_netdev_pmd_try_optimize(pmd, poll_list, poll_cnt); if (!ovsrcu_try_quiesce()) { emc_cache_slow_sweep(&((pmd->flow_cache).emc_cache)); + if (rcu_quiesce_interval) { + pmd->last_rcu_quiesced = cycles_counter_get(s); + } } for (i = 0; i < poll_cnt; i++) {