On Mon, May 14, 2018 at 07:23:20PM -0700, Han Zhou wrote:
> This patch implements the engine which will be used in future patches
> for ovn-controller incremental processing.
> 
> Signed-off-by: Han Zhou <[email protected]>

Thanks a lot for working on this.  I read through it in detail and I
have some comments.  Most of my comments are trivial, so I'll just
append them in the form of an incremental diff that I hope you will fold
in.

I don't think that engine_get_input() makes sense as an inline
function.  I would prefer to see it in the .c file.

I am not sure whether engine_add_input() makes sense as an inline.

I think I won't have serious comments on the technique until I've read
more of the patches.

--8<--------------------------cut here-------------------------->8--

diff --git a/ovn/lib/inc-proc-eng.c b/ovn/lib/inc-proc-eng.c
index 54c7fd6b9723..4699702ae740 100644
--- a/ovn/lib/inc-proc-eng.c
+++ b/ovn/lib/inc-proc-eng.c
@@ -67,18 +67,14 @@ engine_run(struct engine_node *node, uint64_t run_id)
     }
     node->run_id = run_id;
 
-    if (node->changed) {
-        node->changed = false;
-    }
+    node->changed = false;
     if (!node->n_inputs) {
         node->run(node);
         VLOG_DBG("node: %s, changed: %d", node->name, node->changed);
         return;
     }
 
-    size_t i;
-
-    for (i = 0; i < node->n_inputs; i++) {
+    for (size_t i = 0; i < node->n_inputs; i++) {
         engine_run(node->inputs[i].node, run_id);
     }
 
@@ -88,7 +84,7 @@ engine_run(struct engine_node *node, uint64_t run_id)
     if (engine_force_recompute) {
         need_recompute = true;
     } else {
-        for (i = 0; i < node->n_inputs; i++) {
+        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) {
@@ -104,7 +100,7 @@ engine_run(struct engine_node *node, uint64_t run_id)
                  engine_force_recompute ? "forced" : "triggered");
         node->run(node);
     } else if (need_compute) {
-        for (i = 0; i < node->n_inputs; i++) {
+        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);
@@ -120,6 +116,4 @@ engine_run(struct engine_node *node, uint64_t run_id)
     }
 
     VLOG_DBG("node: %s, changed: %d", node->name, node->changed);
-
 }
-
diff --git a/ovn/lib/inc-proc-eng.h b/ovn/lib/inc-proc-eng.h
index 3e0ec167636d..b09ce9f7c7c0 100644
--- a/ovn/lib/inc-proc-eng.h
+++ b/ovn/lib/inc-proc-eng.h
@@ -20,11 +20,11 @@
 /* The Incremental Processing Engine is a framework for incrementally
  * processing changes from different inputs. The main user is ovn-controller.
  * To compute desired states (e.g. openflow rules) based on many inputs (e.g.
- * south-bound DB tables, local OVSDB interfaces, etc.), it is straighforward
+ * south-bound DB tables, local OVSDB interfaces, etc.), it is straightforward
  * to recompute everything when there is any change in any inputs, but it
  * is inefficient when the size of the input data becomes large. Instead,
  * tracking the changes and update the desired states based on what's changed
- * is more efficient and scalable. However, it is not straighforward to
+ * is more efficient and scalable. However, it is not straightforward to
  * implement the change-based processing when there are a big number of
  * inputs. In addition, what makes it more complicated is that intermediate
  * results needs to be computed, which needs to be reused in different part
@@ -40,7 +40,7 @@
  *
  * The engine is composed of engine_nodes. Each engine_node is either
  * an input, an output or both (intermediate result). Each engine node
- * maintains its own data, which is persistent across interations. Each node
+ * maintains its own data, which is persistent across interactions. Each node
  * has zero to ENGINE_MAX_INPUT inputs, which creates a DAG (directed
  * acyclic graph). For each input of each engine_node, there is a
  * change_handler to process changes of that input, and update the data
@@ -65,8 +65,7 @@
 struct engine_node;
 
 struct engine_node_input {
-
-    /* the input node */
+    /* The input node. */
     struct engine_node *node;
 
     /* Change handler for changes of the input node. The changes may need to be
@@ -78,58 +77,54 @@ struct engine_node_input {
 };
 
 struct engine_node {
-
     /* A unique id to distinguish each iteration of the engine_run(). */
     uint64_t run_id;
 
-    /* A unique name for each node */
-    char* name;
+    /* A unique name for each node. */
+    char *name;
 
-    /* Number of inputs of this node */
+    /* Number of inputs of this node. */
     size_t n_inputs;
 
-    /* Inputs of this node */
+    /* Inputs of this node. */
     struct engine_node_input inputs[ENGINE_MAX_INPUT];
 
     /* Data of this node. It is vague and interpreted by the related functions.
      * The content of the data should be changed only by the change_handlers
      * and run() function of the current node. Users should ensure that the
      * data is read-only in change-handlers of the nodes that depends on this
-     * node. */ 
+     * node. */
     void *data;
 
-    /* Whether the data is changed in the last engine run */
+    /* Whether the data changed in the last engine run. */
     bool changed;
 
-    /* Context data for the engine processing, such as OVSDB IDLs */
+    /* Context data for the engine processing, such as OVSDB IDLs. */
     void *context;
 
     /* Method to initialize data. It may be NULL. */
-    void (*init)(struct engine_node *node);
+    void (*init)(struct engine_node *);
 
     /* Method to clean up data. It may be NULL. */
-    void (*cleanup)(struct engine_node *node);
+    void (*cleanup)(struct engine_node *);
 
-    /* Fully processing all inputs of this node and regenerate the data
-     * of this node */
-    void (*run)(struct engine_node *node);
+    /* Fully processes all inputs of this node and regenerates the data
+     * of this node. */
+    void (*run)(struct engine_node *);
 };
 
 /* Initialize the data for the engine nodes recursively. It calls each node's
  * init() method if not NULL. It should be called before the main loop. */
-void
-engine_init(struct engine_node *node);
+void engine_init(struct engine_node *);
 
 /* Execute the processing recursively, which should be called in the main
  * loop. */
-void
-engine_run(struct engine_node *node, uint64_t run_id);
+void engine_run(struct engine_node *, uint64_t run_id);
 
 /* Clean up the data for the engine nodes recursively. It calls each node's
  * cleanup() method if not NULL. It should be called before the program
  * terminates. */
-void
-engine_cleanup(struct engine_node *node);
+void engine_cleanup(struct engine_node *);
 
 /* Get the input node with <name> for <node> */
 static inline struct engine_node *
@@ -147,7 +142,7 @@ engine_get_input(const char *input_name, struct engine_node 
*node)
 /* Add an input (dependency) for <node>, with corresponding change_handler,
  * which can be NULL. If the change_handler is NULL, the engine will not
  * be able to process the change incrementally, and will fall back to call
- * the run method to recompute */
+ * the run method to recompute. */
 static inline void
 engine_add_input(struct engine_node *node, struct engine_node *input,
     bool (*change_handler)(struct engine_node *node))
@@ -162,10 +157,9 @@ engine_add_input(struct engine_node *node, struct 
engine_node *input,
  * in circumstances when we are not sure there is change or not, or
  * when there is change but the engine couldn't be executed in that
  * iteration, and the change can't be tracked across iterations */
-void
-engine_set_force_recompute(bool val);
+void engine_set_force_recompute(bool val);
 
-/* Macro to define an engine node */
+/* Macro to define an engine node. */
 #define ENGINE_NODE(NAME, NAME_STR, CTX) \
     struct engine_node en_##NAME = { \
         .name = NAME_STR, \
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to