From patchwork Tue Jul 18 06:28:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tonghao Zhang X-Patchwork-Id: 789920 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="n/2IRq8x"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xBVbf3lQgz9s3w for ; Tue, 18 Jul 2017 16:28:30 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751396AbdGRG22 (ORCPT ); Tue, 18 Jul 2017 02:28:28 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:36072 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750931AbdGRG20 (ORCPT ); Tue, 18 Jul 2017 02:28:26 -0400 Received: by mail-pf0-f196.google.com with SMTP id a11so1564676pfj.3 for ; Mon, 17 Jul 2017 23:28:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QxIi06Xf+Lc2OFP2HiYzPUs9NzjSybgZkSMFtOXnoz8=; b=n/2IRq8xtnH7YaQC7dpXs4cRKnnVX+YyoF27I1qEbxuHWZTyRX9HSZt0ZvInmYSUZs 0gRKM+N/6mdl412UV05MJgN0AV6b/6gJPsm54DUpOIUbdMH097B+Ekm4Tdn5J0RVNHxX XauGJYggBYIjWv4UpItG8c/p/Od0dYU+DC60ohjieq7nB7UzUFQvt2bW65Ir2k9jqAgZ oqgsN6Fl2VQ2HHi3EwomNggBO6GYAVd0U4RxSEkwTQRUuPz7ftcJ2FurfaJOrN8WLTm+ GIwJbQS2NTbdOfFeqBOEh0LOGLEgmmqsW0388HChMW5G05mqepCbab0yggsRtSdl3TMG 4gMA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=QxIi06Xf+Lc2OFP2HiYzPUs9NzjSybgZkSMFtOXnoz8=; b=S5Pib5/gjV/09A/9VS7vHD5ib3bewo9aUbxHSmmOeMKzC0RXHrGWt5/PMrckjSy+6h FzjS06JWDkU9NtmaHFwnAM+SHZo+3Xs/p+dVjk13Jjoaa98mRvARES7PKyC2kXVQnNnB +KAEsURn30yHfuGLXVxjUdPJNKg+ucYhCylBgsLf2dX3D6vf/RNUf8JkBCxREC1WBXkg Bf6OjrgCG9sDbpfhx+z2/0+oIZOAZxiiI1DiKOUIGDNN9XqR3MT99Jd7c8HyF0CVGxwg TqCpQG6fwbXc/3M5GiywFOxSF8N73wbJ7Q/D5J1BCk9aGfV2tFKSYbXPOAhIBu7kOfFO +4qw== X-Gm-Message-State: AIVw111IrlhogzAGrGBj6cn8mMJ+yXE5XFptMHspKVMxdCJsq6MhIn7i Li2+3EAbNoUJpQAKi74= X-Received: by 10.98.77.6 with SMTP id a6mr30307pfb.221.1500359305235; Mon, 17 Jul 2017 23:28:25 -0700 (PDT) Received: from local.opencloud.tech.localdomain ([106.120.127.10]) by smtp.gmail.com with ESMTPSA id m8sm2011445pgs.24.2017.07.17.23.28.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Jul 2017 23:28:24 -0700 (PDT) From: Tonghao Zhang To: netdev@vger.kernel.org Cc: dev@openvswitch.org, pshelar@ovn.org, Tonghao Zhang Subject: [PATCH v2 2/2] openvswitch: Optimize operations for OvS flow_stats. Date: Mon, 17 Jul 2017 23:28:06 -0700 Message-Id: <1500359286-36597-2-git-send-email-xiangxia.m.yue@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1500359286-36597-1-git-send-email-xiangxia.m.yue@gmail.com> References: <1500359286-36597-1-git-send-email-xiangxia.m.yue@gmail.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When calling the flow_free() to free the flow, we call many times (cpu_possible_mask, eg. 128 as default) cpumask_next(). That will take up our CPU usage if we call the flow_free() frequently. When we put all packets to userspace via upcall, and OvS will send them back via netlink to ovs_packet_cmd_execute(will call flow_free). The test topo is shown as below. VM01 sends TCP packets to VM02, and OvS forward packtets. When testing, we use perf to report the system performance. VM01 --- OvS-VM --- VM02 Without this patch, perf-top show as below: The flow_free() is 3.02% CPU usage. 4.23% [kernel] [k] _raw_spin_unlock_irqrestore 3.62% [kernel] [k] __do_softirq 3.16% [kernel] [k] __memcpy 3.02% [kernel] [k] flow_free 2.42% libc-2.17.so [.] __memcpy_ssse3_back 2.18% [kernel] [k] copy_user_generic_unrolled 2.17% [kernel] [k] find_next_bit When applied this patch, perf-top show as below: Not shown on the list anymore. 4.11% [kernel] [k] _raw_spin_unlock_irqrestore 3.79% [kernel] [k] __do_softirq 3.46% [kernel] [k] __memcpy 2.73% libc-2.17.so [.] __memcpy_ssse3_back 2.25% [kernel] [k] copy_user_generic_unrolled 1.89% libc-2.17.so [.] _int_malloc 1.53% ovs-vswitchd [.] xlate_actions With this patch, the TCP throughput(we dont use Megaflow Cache + Microflow Cache) between VMs is 1.18Gbs/sec up to 1.30Gbs/sec (maybe ~10% performance imporve). This patch adds cpumask struct, the cpu_used_mask stores the cpu_id that the flow used. And we only check the flow_stats on the cpu we used, and it is unncessary to check all possible cpu when getting, cleaning, and updating the flow_stats. Adding the cpu_used_mask to sw_flow struct does’t increase the cacheline number. Signed-off-by: Tonghao Zhang Acked-by: Pravin B Shelar --- net/openvswitch/flow.c | 7 ++++--- net/openvswitch/flow.h | 2 ++ net/openvswitch/flow_table.c | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/net/openvswitch/flow.c b/net/openvswitch/flow.c index 89aeb32..cfb652a 100644 --- a/net/openvswitch/flow.c +++ b/net/openvswitch/flow.c @@ -72,7 +72,7 @@ void ovs_flow_stats_update(struct sw_flow *flow, __be16 tcp_flags, const struct sk_buff *skb) { struct flow_stats *stats; - int cpu = smp_processor_id(); + unsigned int cpu = smp_processor_id(); int len = skb->len + (skb_vlan_tag_present(skb) ? VLAN_HLEN : 0); stats = rcu_dereference(flow->stats[cpu]); @@ -117,6 +117,7 @@ void ovs_flow_stats_update(struct sw_flow *flow, __be16 tcp_flags, rcu_assign_pointer(flow->stats[cpu], new_stats); + cpumask_set_cpu(cpu, &flow->cpu_used_mask); goto unlock; } } @@ -144,7 +145,7 @@ void ovs_flow_stats_get(const struct sw_flow *flow, memset(ovs_stats, 0, sizeof(*ovs_stats)); /* We open code this to make sure cpu 0 is always considered */ - for (cpu = 0; cpu < nr_cpu_ids; cpu = cpumask_next(cpu, cpu_possible_mask)) { + for (cpu = 0; cpu < nr_cpu_ids; cpu = cpumask_next(cpu, &flow->cpu_used_mask)) { struct flow_stats *stats = rcu_dereference_ovsl(flow->stats[cpu]); if (stats) { @@ -168,7 +169,7 @@ void ovs_flow_stats_clear(struct sw_flow *flow) int cpu; /* We open code this to make sure cpu 0 is always considered */ - for (cpu = 0; cpu < nr_cpu_ids; cpu = cpumask_next(cpu, cpu_possible_mask)) { + for (cpu = 0; cpu < nr_cpu_ids; cpu = cpumask_next(cpu, &flow->cpu_used_mask)) { struct flow_stats *stats = ovsl_dereference(flow->stats[cpu]); if (stats) { diff --git a/net/openvswitch/flow.h b/net/openvswitch/flow.h index a9bc1c8..1875bba 100644 --- a/net/openvswitch/flow.h +++ b/net/openvswitch/flow.h @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -219,6 +220,7 @@ struct sw_flow { */ struct sw_flow_key key; struct sw_flow_id id; + struct cpumask cpu_used_mask; struct sw_flow_mask *mask; struct sw_flow_actions __rcu *sf_acts; struct flow_stats __rcu *stats[]; /* One for each CPU. First one diff --git a/net/openvswitch/flow_table.c b/net/openvswitch/flow_table.c index ea7a807..80ea2a7 100644 --- a/net/openvswitch/flow_table.c +++ b/net/openvswitch/flow_table.c @@ -98,6 +98,8 @@ struct sw_flow *ovs_flow_alloc(void) RCU_INIT_POINTER(flow->stats[0], stats); + cpumask_set_cpu(0, &flow->cpu_used_mask); + return flow; err: kmem_cache_free(flow_cache, flow); @@ -141,7 +143,7 @@ static void flow_free(struct sw_flow *flow) if (flow->sf_acts) ovs_nla_free_flow_actions((struct sw_flow_actions __force *)flow->sf_acts); /* We open code this to make sure cpu 0 is always considered */ - for (cpu = 0; cpu < nr_cpu_ids; cpu = cpumask_next(cpu, cpu_possible_mask)) + for (cpu = 0; cpu < nr_cpu_ids; cpu = cpumask_next(cpu, &flow->cpu_used_mask)) if (flow->stats[cpu]) kmem_cache_free(flow_stats_cache, (struct flow_stats __force *)flow->stats[cpu]);