From patchwork Tue Feb 13 13:57:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 872856 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=) 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 3zgkd83kCXz9t5Y for ; Wed, 14 Feb 2018 00:57:47 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 481B0DC9; Tue, 13 Feb 2018 13:57:45 +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 54B20D99 for ; Tue, 13 Feb 2018 13:57:44 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wr0-f195.google.com (mail-wr0-f195.google.com [209.85.128.195]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id A41E018A for ; Tue, 13 Feb 2018 13:57:43 +0000 (UTC) Received: by mail-wr0-f195.google.com with SMTP id 34so8448038wre.13 for ; Tue, 13 Feb 2018 05:57:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=jVMR20Amulh7TWXw4PN+CYAsjl1VoyEyoou1uqzSSX8=; b=gQSInBUxV0LoMXn8U+geqz7fJXj/rb2Sv9E+XBUhmlUjNlCzxi/ax2MnnRRSWs3ZoX nNiL6UkUDh0dS2Ng0tsTr9lfsdiEWy+y9lYijyFb6n5n9rzSCNPCgYINOk1WBIN01IGE Ibj9fciQwtdRiTGK6OoKtFw0MYmcTU5sCkzJ47+P+Ycl9C+QVkfV/10qAH2ndCUMHMPv 1YpTAchK8YgOyjTr6MHYaUvlhs2vCqonb8Uq9NuiDOOruE6YKm+/R8jZJ3vhq5+QYrTp rYZCvz/6PU6ieEskaMAVCspCprQrrBbsHEW7wa3Br03uGqwV4mNo3OyIKVlKXx1wXSQb 9rxA== X-Gm-Message-State: APf1xPAJvFEMxM+MVqj4Mmw7qHG9sOJJcHwRc4hPBsZjrWXFx9Qa+mgj FuV3g6Ry7rPuXyWneD4GvGkmSACbIkA= X-Google-Smtp-Source: AH8x226b2Xi+olFevFjmkjddGStdj3m7Ce+3piL1YdJsSxLB/ujb4S6f+gMQ72UFBWlQGzS6aPULnQ== X-Received: by 10.223.187.144 with SMTP id q16mr1294612wrg.67.1518530261932; Tue, 13 Feb 2018 05:57:41 -0800 (PST) Received: from redhat.com (red-hat-inc.vlan404.asr1.mad1.gblx.net. [64.215.113.190]) by smtp.gmail.com with ESMTPSA id b9sm7366488wmc.14.2018.02.13.05.57.40 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 13 Feb 2018 05:57:40 -0800 (PST) From: Jakub Sitnicki To: dev@openvswitch.org Date: Tue, 13 Feb 2018 14:57:40 +0100 Message-Id: <20180213135740.9341-1-jkbs@redhat.com> X-Mailer: git-send-email 2.14.3 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [RFC] ovn-northd: Store computed logical flow hash in SBDB. 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 Each time ovn-northd processes the NBDB contents it has to compute the hash of every logical flow stored in the SBDB in order to identify ones that need adding to or deleting from SBDB (build_lflows()). Avoid it by storing the logical flow hash together with its fields the moment we first add it to SBDB. This saves us the hash computations afterwards, every time ovn-northd processes the logical flows to find candidates for removal/addition. In a simple micro-benchmark that adds 15 logical switches with 100 logical ports each, perf tool shows a drop of 7% in CPU cycles ('cycles:ppp' event) spent in ovn_lflow_find() where we compute the hash of each logical flow found in SBDB: Children Self Command Shared Object Symbol before: 10.61% 0.17% ovn-northd ovn-northd [.] ovn_lflow_find after: 2.82% 0.19% ovn-northd ovn-northd [.] ovn_lflow_find Signed-off-by: Jakub Sitnicki Acked-by: Mark Michelson --- ovn/northd/ovn-northd.c | 9 +++++---- ovn/ovn-sb.ovsschema | 7 +++++-- ovn/ovn-sb.xml | 5 +++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/ovn/northd/ovn-northd.c b/ovn/northd/ovn-northd.c index 4d95a3d9d..dcb9939d9 100644 --- a/ovn/northd/ovn-northd.c +++ b/ovn/northd/ovn-northd.c @@ -2331,7 +2331,7 @@ ovn_lflow_add_at(struct hmap *lflow_map, struct ovn_datapath *od, static struct ovn_lflow * ovn_lflow_find(struct hmap *lflows, struct ovn_datapath *od, enum ovn_stage stage, uint16_t priority, - const char *match, const char *actions) + const char *match, const char *actions, uint32_t hash) { struct ovn_lflow target; ovn_lflow_init(&target, od, stage, priority, @@ -2339,8 +2339,7 @@ ovn_lflow_find(struct hmap *lflows, struct ovn_datapath *od, NULL, NULL); struct ovn_lflow *lflow; - HMAP_FOR_EACH_WITH_HASH (lflow, hmap_node, ovn_lflow_hash(&target), - lflows) { + HMAP_FOR_EACH_WITH_HASH (lflow, hmap_node, hash, lflows) { if (ovn_lflow_equal(lflow, &target)) { return lflow; } @@ -6014,7 +6013,7 @@ build_lflows(struct northd_context *ctx, struct hmap *datapaths, = !strcmp(sbflow->pipeline, "ingress") ? P_IN : P_OUT; struct ovn_lflow *lflow = ovn_lflow_find( &lflows, od, ovn_stage_build(dp_type, pipeline, sbflow->table_id), - sbflow->priority, sbflow->match, sbflow->actions); + sbflow->priority, sbflow->match, sbflow->actions, sbflow->hash); if (lflow) { ovn_lflow_destroy(&lflows, lflow); } else { @@ -6034,6 +6033,7 @@ build_lflows(struct northd_context *ctx, struct hmap *datapaths, sbrec_logical_flow_set_priority(sbflow, lflow->priority); sbrec_logical_flow_set_match(sbflow, lflow->match); sbrec_logical_flow_set_actions(sbflow, lflow->actions); + sbrec_logical_flow_set_hash(sbflow, lflow->hmap_node.hash); /* Trim the source locator lflow->where, which looks something like * "ovn/northd/ovn-northd.c:1234", down to just the part following the @@ -6782,6 +6782,7 @@ main(int argc, char *argv[]) add_column_noalert(ovnsb_idl_loop.idl, &sbrec_logical_flow_col_priority); add_column_noalert(ovnsb_idl_loop.idl, &sbrec_logical_flow_col_match); add_column_noalert(ovnsb_idl_loop.idl, &sbrec_logical_flow_col_actions); + add_column_noalert(ovnsb_idl_loop.idl, &sbrec_logical_flow_col_hash); ovsdb_idl_add_table(ovnsb_idl_loop.idl, &sbrec_table_multicast_group); add_column_noalert(ovnsb_idl_loop.idl, diff --git a/ovn/ovn-sb.ovsschema b/ovn/ovn-sb.ovsschema index 2abcc6b70..b6a145431 100644 --- a/ovn/ovn-sb.ovsschema +++ b/ovn/ovn-sb.ovsschema @@ -1,7 +1,7 @@ { "name": "OVN_Southbound", - "version": "1.15.0", - "cksum": "70426956 13327", + "version": "1.16.0", + "cksum": "340822255 13518", "tables": { "SB_Global": { "columns": { @@ -70,6 +70,9 @@ "maxInteger": 65535}}}, "match": {"type": "string"}, "actions": {"type": "string"}, + "hash": {"type": {"key": {"type": "integer", + "minInteger": 0, + "maxInteger": 4294967295}}}, "external_ids": { "type": {"key": "string", "value": "string", "min": 0, "max": "unlimited"}}}, diff --git a/ovn/ovn-sb.xml b/ovn/ovn-sb.xml index f000b166c..073a4c11d 100644 --- a/ovn/ovn-sb.xml +++ b/ovn/ovn-sb.xml @@ -1767,6 +1767,11 @@ tcp.flags = RST; + + Cached value of a hash computed over selected fields of this logical flow + by ovn-northd. + + Human-readable name for this flow's stage in the pipeline.