From patchwork Thu Nov 14 17:05:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceara X-Patchwork-Id: 1194974 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) 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 Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="e93skVL6"; 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 47DSXq0Q7lz9s7T for ; Fri, 15 Nov 2019 04:05:30 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id AF7CDCD5; Thu, 14 Nov 2019 17:05:27 +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 DE2D7CA4 for ; Thu, 14 Nov 2019 17:05:25 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by smtp1.linuxfoundation.org (Postfix) with ESMTP id 067B7623 for ; Thu, 14 Nov 2019 17:05:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573751123; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=u8iCwiQBi+REsdTejRIa8W3FzuSQ6dXOt0n1thyemSM=; b=e93skVL67W2o++/Pd4IgiQ30s9PsbZ11onbk2MeiaoQo/HfEsnDREpm+J64q1bnCYD0j6V xM2zEBVt2QCT3k8SvWLki0ZnFRouN2a6bzZbg/FyRb732nWjKZEz3zBOx+6zTP37eyev02 KBORstAFQ3nuxSFPaa6+Jpz8eSMMueQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-403-xXvok4s9MIOHW0P7uV4DrA-1; Thu, 14 Nov 2019 12:05:20 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id DDEF718A476D; Thu, 14 Nov 2019 17:05:18 +0000 (UTC) Received: from dceara.remote.csb (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 15E1D5D6AE; Thu, 14 Nov 2019 17:05:17 +0000 (UTC) From: Dumitru Ceara To: dev@openvswitch.org Date: Thu, 14 Nov 2019 18:05:11 +0100 Message-Id: <20191114170455.30391.22041.stgit@dceara.remote.csb> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: xXvok4s9MIOHW0P7uV4DrA-1 X-Mimecast-Spam-Score: 0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,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: hzhou@ovn.org Subject: [ovs-dev] [PATCH v3 ovn 1/4] ovn-controller: Refactor I-P engine_run() tracking. 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 This commit simplifies the logic of calling engine_run and engine_need_run in order to reduce the number of external variables required to track the result of the last engine execution. The engine code is also refactored a bit and the engine_run() function is split in different functions that handle computing/recomputing a node. Signed-off-by: Dumitru Ceara --- controller/ovn-controller.c | 33 ++++++----- lib/inc-proc-eng.c | 124 +++++++++++++++++++++++++++++-------------- lib/inc-proc-eng.h | 7 ++ 3 files changed, 107 insertions(+), 57 deletions(-) diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c index 9ab98be..3922f3d 100644 --- a/controller/ovn-controller.c +++ b/controller/ovn-controller.c @@ -1942,7 +1942,6 @@ main(int argc, char *argv[]) &pending_pkt); uint64_t engine_run_id = 0; - uint64_t old_engine_run_id = 0; bool engine_run_done = true; unsigned int ovs_cond_seqno = UINT_MAX; @@ -1952,10 +1951,11 @@ main(int argc, char *argv[]) exiting = false; restart = false; while (!exiting) { + engine_run_id++; + update_sb_db(ovs_idl_loop.idl, ovnsb_idl_loop.idl); update_ssl_config(ovsrec_ssl_table_get(ovs_idl_loop.idl)); ofctrl_set_probe_interval(get_ofctrl_probe_interval(ovs_idl_loop.idl)); - old_engine_run_id = engine_run_id; struct ovsdb_idl_txn *ovs_idl_txn = ovsdb_idl_loop_run(&ovs_idl_loop); unsigned int new_ovs_cond_seqno @@ -2047,12 +2047,12 @@ main(int argc, char *argv[]) if (engine_run_done) { engine_set_abort_recompute(true); engine_run_done = engine_run(&en_flow_output, - ++engine_run_id); + engine_run_id); } } else { engine_set_abort_recompute(false); engine_run_done = true; - engine_run(&en_flow_output, ++engine_run_id); + engine_run(&en_flow_output, engine_run_id); } } stopwatch_stop(CONTROLLER_LOOP_STOPWATCH_NAME, @@ -2095,17 +2095,20 @@ main(int argc, char *argv[]) } } - if (old_engine_run_id == engine_run_id || !engine_run_done) { - if (!engine_run_done || engine_need_run(&en_flow_output)) { - VLOG_DBG("engine did not run, force recompute next time: " - "br_int %p, chassis %p", br_int, chassis); - engine_set_force_recompute(true); - poll_immediate_wake(); - } else { - VLOG_DBG("engine did not run, and it was not needed" - " either: br_int %p, chassis %p", - br_int, chassis); - } + if (engine_need_run(&en_flow_output, engine_run_id)) { + VLOG_DBG("engine did not run, force recompute next time: " + "br_int %p, chassis %p", br_int, chassis); + engine_set_force_recompute(true); + poll_immediate_wake(); + } else if (!engine_run_done) { + VLOG_DBG("engine was aborted, force recompute next time: " + "br_int %p, chassis %p", br_int, chassis); + engine_set_force_recompute(true); + poll_immediate_wake(); + } else if (!engine_has_run(&en_flow_output, engine_run_id)) { + VLOG_DBG("engine did not run, and it was not needed" + " either: br_int %p, chassis %p", + br_int, chassis); } else { engine_set_force_recompute(false); } diff --git a/lib/inc-proc-eng.c b/lib/inc-proc-eng.c index 1064a08..8a085e2 100644 --- a/lib/inc-proc-eng.c +++ b/lib/inc-proc-eng.c @@ -129,14 +129,72 @@ engine_ovsdb_node_add_index(struct engine_node *node, const char *name, } bool -engine_run(struct engine_node *node, uint64_t run_id) +engine_has_run(struct engine_node *node, uint64_t run_id) +{ + return node->run_id == run_id; +} + +/* Do a full recompute (or at least try). If we're not allowed then + * mark the node as "aborted". + */ +static bool +engine_recompute(struct engine_node *node, bool forced, bool allowed) +{ + VLOG_DBG("node: %s, recompute (%s)", node->name, + forced ? "forced" : "triggered"); + + if (!allowed) { + VLOG_DBG("node: %s, recompute aborted", node->name); + return false; + } + + node->run(node); + VLOG_DBG("node: %s, changed: %d", node->name, node->changed); + return true; +} + +/* Return true if the node could be computed without triggerring a full + * recompute. + */ +static bool +engine_compute(struct engine_node *node, bool recompute_allowed) +{ + for (size_t i = 0; i < node->n_inputs; i++) { + /* If the input node data changed call its change handler. */ + if (node->inputs[i].node->changed) { + VLOG_DBG("node: %s, handle change for input %s", + node->name, node->inputs[i].node->name); + + /* If the input change can't be handled incrementally, run + * the node handler. + */ + if (!node->inputs[i].change_handler(node)) { + VLOG_DBG("node: %s, can't handle change for input %s, " + "fall back to recompute", + node->name, node->inputs[i].node->name); + if (!engine_recompute(node, false, recompute_allowed)) { + return false; + } + } + } + } + + return true; +} + +bool engine_run(struct engine_node *node, uint64_t run_id) { if (node->run_id == run_id) { + /* The node was already updated in this run (could be input for + * multiple other nodes). Stop processing. + */ return true; } - node->run_id = run_id; + /* Initialize the node for this run. */ + node->run_id = run_id; node->changed = false; + if (!node->n_inputs) { node->run(node); VLOG_DBG("node: %s, changed: %d", node->name, node->changed); @@ -150,59 +208,45 @@ engine_run(struct engine_node *node, uint64_t run_id) } bool need_compute = false; - bool need_recompute = false; if (engine_force_recompute) { - need_recompute = true; - } else { - for (size_t i = 0; i < node->n_inputs; i++) { - if (node->inputs[i].node->changed) { - need_compute = true; - if (!node->inputs[i].change_handler) { - need_recompute = true; - break; - } - } - } + return engine_recompute(node, true, !engine_abort_recompute); } - if (need_recompute) { - VLOG_DBG("node: %s, recompute (%s)", node->name, - engine_force_recompute ? "forced" : "triggered"); - if (engine_abort_recompute) { - VLOG_DBG("node: %s, recompute aborted", node->name); - return false; - } - node->run(node); - } else if (need_compute) { - for (size_t i = 0; i < node->n_inputs; i++) { - if (node->inputs[i].node->changed) { - VLOG_DBG("node: %s, handle change for input %s", - node->name, node->inputs[i].node->name); - if (!node->inputs[i].change_handler(node)) { - VLOG_DBG("node: %s, can't handle change for input %s, " - "fall back to recompute", - node->name, node->inputs[i].node->name); - if (engine_abort_recompute) { - VLOG_DBG("node: %s, recompute aborted", node->name); - return false; - } - node->run(node); - break; - } + /* If any of the inputs updated data but there is no change_handler, then + * recompute the current node too. + */ + for (size_t i = 0; i < node->n_inputs; i++) { + if (node->inputs[i].node->changed) { + need_compute = true; + + /* Trigger a recompute if we don't have a change handler. */ + if (!node->inputs[i].change_handler) { + return engine_recompute(node, false, !engine_abort_recompute); } } } + if (need_compute) { + /* If we couldn't compute the node we either aborted or triggered + * a full recompute. In any case, stop processing. + */ + return engine_compute(node, !engine_abort_recompute); + } + VLOG_DBG("node: %s, changed: %d", node->name, node->changed); return true; } bool -engine_need_run(struct engine_node *node) +engine_need_run(struct engine_node *node, uint64_t run_id) { size_t i; + if (node->run_id == run_id) { + return false; + } + if (!node->n_inputs) { node->run(node); VLOG_DBG("input node: %s, changed: %d", node->name, node->changed); @@ -210,7 +254,7 @@ engine_need_run(struct engine_node *node) } for (i = 0; i < node->n_inputs; i++) { - if (engine_need_run(node->inputs[i].node)) { + if (engine_need_run(node->inputs[i].node, run_id)) { return true; } } diff --git a/lib/inc-proc-eng.h b/lib/inc-proc-eng.h index 3a69dc2..abd41b2 100644 --- a/lib/inc-proc-eng.h +++ b/lib/inc-proc-eng.h @@ -130,9 +130,9 @@ bool engine_run(struct engine_node *, uint64_t run_id); * terminates. */ void engine_cleanup(struct engine_node *); -/* Check if engine needs to run, i.e. any change to be processed. */ +/* Check if engine needs to run but didn't. */ bool -engine_need_run(struct engine_node *); +engine_need_run(struct engine_node *, uint64_t run_id); /* Get the input node with for */ struct engine_node * engine_get_input(const char *input_name, @@ -159,6 +159,9 @@ const struct engine_context * engine_get_context(void); void engine_set_context(const struct engine_context *); +/* Return true if the engine has run for 'node' in the 'run_id' iteration. */ +bool engine_has_run(struct engine_node *node, uint64_t run_id); + struct ed_ovsdb_index { const char *name; struct ovsdb_idl_index *index;