Introduce ovsport_lookup_by_name and ovsport_lookup_by_qos routines in
order to speed-up ovs port lookup based on port name or qos.

https://bugzilla.redhat.com/show_bug.cgi?id=2129742
Tested-by: Rodolfo Alonso <ralon...@redhat.com>
Signed-off-by: Lorenzo Bianconi <lorenzo.bianc...@redhat.com>
---
 controller/binding.c        | 45 +++++++++++++++++--------------------
 controller/binding.h        |  3 ++-
 controller/ovn-controller.c | 19 ++++++++++++----
 controller/ovsport.c        | 32 ++++++++++++++++++++++++++
 controller/ovsport.h        |  5 +++++
 5 files changed, 75 insertions(+), 29 deletions(-)

diff --git a/controller/binding.c b/controller/binding.c
index 1ac44b915..f375109d9 100644
--- a/controller/binding.c
+++ b/controller/binding.c
@@ -36,6 +36,7 @@
 #include "lport.h"
 #include "ovn-controller.h"
 #include "patch.h"
+#include "ovsport.h"
 
 VLOG_DEFINE_THIS_MODULE(binding);
 
@@ -213,7 +214,7 @@ get_qos_egress_interface_name(struct shash *bridge_mappings,
 #define OVN_QOS_MAX_RATE    34359738360
 static void
 add_ovs_qos_table_entry(struct ovsdb_idl_txn *ovs_idl_txn,
-                        const struct ovsrec_port_table *port_table,
+                        struct ovsdb_idl_index *ovsrec_port_by_name,
                         struct shash *bridge_mappings,
                         struct qos_queue *q)
 {
@@ -223,14 +224,8 @@ add_ovs_qos_table_entry(struct ovsdb_idl_txn *ovs_idl_txn,
         return;
     }
 
-    const struct ovsrec_port *port = NULL, *iter;
-    OVSREC_PORT_TABLE_FOR_EACH (iter, port_table) {
-        if (!strcmp(iter->name, port_name)) {
-            port = iter;
-            break;
-        }
-    }
-
+    const struct ovsrec_port *port =
+        ovsport_lookup_by_name(ovsrec_port_by_name, port_name);
     if (!port) {
         return;
     }
@@ -280,21 +275,16 @@ add_ovs_qos_table_entry(struct ovsdb_idl_txn *ovs_idl_txn,
 }
 
 static void
-remove_stale_ovs_qos_entry(const struct ovsrec_port_table *port_table,
-                           const struct ovsrec_qos_table *qos_table,
+remove_stale_ovs_qos_entry(const struct ovsrec_qos_table *qos_table,
                            const struct sbrec_port_binding_table *pb_table,
+                           struct ovsdb_idl_index *ovsrec_port_by_qos,
                            struct shash *network_mappings,
                            struct smap *egress_ifaces)
 {
     const struct ovsrec_qos *qos, *qos_next;
     OVSREC_QOS_TABLE_FOR_EACH_SAFE (qos, qos_next, qos_table) {
-        const struct ovsrec_port *port = NULL, *iter;
-        OVSREC_PORT_TABLE_FOR_EACH (iter, port_table) {
-            if (iter->qos == qos) {
-                port = iter;
-                break;
-            }
-        }
+        const struct ovsrec_port *port =
+            ovsport_lookup_by_qos(ovsrec_port_by_qos, qos);
         if (!port) {
             continue;
         }
@@ -349,9 +339,10 @@ remove_stale_ovs_qos_entry(const struct ovsrec_port_table 
*port_table,
 static void
 configure_ovs_qos(struct hmap *queue_map,
                   struct ovsdb_idl_txn *ovs_idl_txn,
-                  const struct ovsrec_port_table *port_table,
                   const struct ovsrec_qos_table *qos_table,
                   const struct sbrec_port_binding_table *pb_table,
+                  struct ovsdb_idl_index *ovsrec_port_by_name,
+                  struct ovsdb_idl_index *ovsrec_port_by_qos,
                   struct shash *bridge_mappings,
                   struct smap *egress_ifaces)
 
@@ -380,13 +371,13 @@ configure_ovs_qos(struct hmap *queue_map,
     }
 
     /* Remove stale QoS entries. */
-    remove_stale_ovs_qos_entry(port_table, qos_table, pb_table,
+    remove_stale_ovs_qos_entry(qos_table, pb_table, ovsrec_port_by_qos,
                                &pb_network_mappings, egress_ifaces);
 
     struct qos_queue *q;
     HMAP_FOR_EACH (q, node, queue_map) {
         /* Add new QoS entries. */
-        add_ovs_qos_table_entry(ovs_idl_txn, port_table,
+        add_ovs_qos_table_entry(ovs_idl_txn, ovsrec_port_by_name,
                                 bridge_mappings, q);
     }
 
@@ -2079,8 +2070,10 @@ binding_run(struct binding_ctx_in *b_ctx_in, struct 
binding_ctx_out *b_ctx_out)
     }
 
     configure_ovs_qos(&qos_map, b_ctx_in->ovs_idl_txn,
-                      b_ctx_in->port_table, b_ctx_in->qos_table,
+                      b_ctx_in->qos_table,
                       b_ctx_in->port_binding_table,
+                      b_ctx_in->ovsrec_port_by_name,
+                      b_ctx_in->ovsrec_port_by_qos,
                       &bridge_mappings,
                       b_ctx_out->egress_ifaces);
 
@@ -2554,8 +2547,10 @@ binding_handle_ovs_interface_changes(struct 
binding_ctx_in *b_ctx_in,
         add_ovs_bridge_mappings(b_ctx_in->ovs_table, b_ctx_in->bridge_table,
                                 &bridge_mappings);
         configure_ovs_qos(&qos_map, b_ctx_in->ovs_idl_txn,
-                          b_ctx_in->port_table, b_ctx_in->qos_table,
+                          b_ctx_in->qos_table,
                           b_ctx_in->port_binding_table,
+                          b_ctx_in->ovsrec_port_by_name,
+                          b_ctx_in->ovsrec_port_by_qos,
                           &bridge_mappings,
                           b_ctx_out->egress_ifaces);
         shash_destroy(&bridge_mappings);
@@ -3071,8 +3066,10 @@ delete_done:
         }
 
         configure_ovs_qos(&qos_map, b_ctx_in->ovs_idl_txn,
-                          b_ctx_in->port_table, b_ctx_in->qos_table,
+                          b_ctx_in->qos_table,
                           b_ctx_in->port_binding_table,
+                          b_ctx_in->ovsrec_port_by_name,
+                          b_ctx_in->ovsrec_port_by_qos,
                           &bridge_mappings,
                           b_ctx_out->egress_ifaces);
 
diff --git a/controller/binding.h b/controller/binding.h
index 6fc199aea..6419f090d 100644
--- a/controller/binding.h
+++ b/controller/binding.h
@@ -46,7 +46,8 @@ struct binding_ctx_in {
     struct ovsdb_idl_index *sbrec_datapath_binding_by_key;
     struct ovsdb_idl_index *sbrec_port_binding_by_datapath;
     struct ovsdb_idl_index *sbrec_port_binding_by_name;
-    const struct ovsrec_port_table *port_table;
+    struct ovsdb_idl_index *ovsrec_port_by_name;
+    struct ovsdb_idl_index *ovsrec_port_by_qos;
     const struct ovsrec_qos_table *qos_table;
     const struct sbrec_port_binding_table *port_binding_table;
     const struct ovsrec_bridge *br_int;
diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c
index 4bc1baf93..4949de29d 100644
--- a/controller/ovn-controller.c
+++ b/controller/ovn-controller.c
@@ -1509,9 +1509,6 @@ init_binding_ctx(struct engine_node *node,
         = chassis_lookup_by_name(sbrec_chassis_by_name, chassis_id);
     ovs_assert(chassis);
 
-    const struct ovsrec_port_table *port_table =
-        EN_OVSDB_GET(engine_get_input("OVS_port", node));
-
     struct ed_type_ovs_interface_shadow *iface_shadow =
         engine_get_input_data("ovs_interface_shadow", node);
 
@@ -1536,6 +1533,14 @@ init_binding_ctx(struct engine_node *node,
                 engine_get_input("SB_port_binding", node),
                 "datapath");
 
+    struct ovsdb_idl_index *ovsrec_port_by_name =
+        engine_ovsdb_node_get_index(
+                engine_get_input("OVS_port", node), "name");
+
+    struct ovsdb_idl_index *ovsrec_port_by_qos =
+        engine_ovsdb_node_get_index(
+                engine_get_input("OVS_port", node), "qos");
+
     struct controller_engine_ctx *ctrl_ctx = engine_get_context()->client_ctx;
 
     b_ctx_in->ovnsb_idl_txn = engine_get_context()->ovnsb_idl_txn;
@@ -1543,7 +1548,8 @@ init_binding_ctx(struct engine_node *node,
     b_ctx_in->sbrec_datapath_binding_by_key = sbrec_datapath_binding_by_key;
     b_ctx_in->sbrec_port_binding_by_datapath = sbrec_port_binding_by_datapath;
     b_ctx_in->sbrec_port_binding_by_name = sbrec_port_binding_by_name;
-    b_ctx_in->port_table = port_table;
+    b_ctx_in->ovsrec_port_by_name = ovsrec_port_by_name;
+    b_ctx_in->ovsrec_port_by_qos = ovsrec_port_by_qos;
     b_ctx_in->iface_table = iface_shadow->iface_table;
     b_ctx_in->iface_table_external_ids_old =
         &iface_shadow->iface_table_external_ids_old;
@@ -4486,6 +4492,9 @@ main(int argc, char *argv[])
     struct ovsdb_idl_index *ovsrec_port_by_name
         = ovsdb_idl_index_create1(ovs_idl_loop.idl,
                                   &ovsrec_port_col_name);
+    struct ovsdb_idl_index *ovsrec_port_by_qos
+        = ovsdb_idl_index_create1(ovs_idl_loop.idl,
+                                  &ovsrec_port_col_qos);
     struct ovsdb_idl_index *ovsrec_flow_sample_collector_set_by_id
         = ovsdb_idl_index_create2(ovs_idl_loop.idl,
                                   &ovsrec_flow_sample_collector_set_col_bridge,
@@ -4840,6 +4849,8 @@ main(int argc, char *argv[])
                                 sbrec_chassis_template_var_index_by_chassis);
     engine_ovsdb_node_add_index(&en_ovs_flow_sample_collector_set, "id",
                                 ovsrec_flow_sample_collector_set_by_id);
+    engine_ovsdb_node_add_index(&en_ovs_port, "name", ovsrec_port_by_name);
+    engine_ovsdb_node_add_index(&en_ovs_port, "qos", ovsrec_port_by_qos);
 
     struct ed_type_lflow_output *lflow_output_data =
         engine_get_internal_data(&en_lflow_output);
diff --git a/controller/ovsport.c b/controller/ovsport.c
index ec38c3fca..ba260dee6 100644
--- a/controller/ovsport.c
+++ b/controller/ovsport.c
@@ -216,6 +216,38 @@ ovsrec_port * ovsport_lookup_by_interface(
                                         interfaces, 1);
 }
 
+const struct ovsrec_port *
+ovsport_lookup_by_name(struct ovsdb_idl_index *ovsrec_port_by_name,
+                       const char *name)
+{
+    const struct ovsrec_port *port =
+        ovsrec_port_index_init_row(ovsrec_port_by_name);
+    ovsrec_port_index_set_name(port, name);
+
+    const struct ovsrec_port *retval =
+        ovsrec_port_index_find(ovsrec_port_by_name, port);
+
+    ovsrec_port_index_destroy_row(port);
+
+    return retval;
+}
+
+const struct ovsrec_port *
+ovsport_lookup_by_qos(struct ovsdb_idl_index *ovsrec_port_by_qos,
+                      const struct ovsrec_qos *qos)
+{
+    const struct ovsrec_port *port =
+        ovsrec_port_index_init_row(ovsrec_port_by_qos);
+    ovsrec_port_index_set_qos(port, qos);
+
+    const struct ovsrec_port *retval =
+        ovsrec_port_index_find(ovsrec_port_by_qos, port);
+
+    ovsrec_port_index_destroy_row(port);
+
+    return retval;
+}
+
 /* Update an interface map column with the key/value pairs present in the
  * provided smap, only applying changes when necessary. */
 static void
diff --git a/controller/ovsport.h b/controller/ovsport.h
index e355ff7ff..dfd4f13f0 100644
--- a/controller/ovsport.h
+++ b/controller/ovsport.h
@@ -33,6 +33,7 @@ struct ovsrec_bridge;
 struct ovsrec_port;
 struct ovsrec_interface;
 struct ovsdb_idl_index;
+struct ovsrec_qos;
 
 void ovsport_create(struct ovsdb_idl_txn *ovs_idl_txn,
                     const struct ovsrec_bridge *bridge,
@@ -56,5 +57,9 @@ const struct ovsrec_port * ovsport_lookup_by_interfaces(
         const size_t n_interfaces);
 const struct ovsrec_port * ovsport_lookup_by_interface(
         struct ovsdb_idl_index *, struct ovsrec_interface *);
+const struct ovsrec_port * ovsport_lookup_by_name(
+        struct ovsdb_idl_index *, const char *);
+const struct ovsrec_port * ovsport_lookup_by_qos(
+        struct ovsdb_idl_index *, const struct ovsrec_qos *);
 
 #endif /* lib/ovsport.h */
-- 
2.39.2

_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to