[ovs-dev] [PATCH v6 1/8] dpif-netdev: Refactor dp_netdev_flow_offload_put()

Sriharsha Basavapatna sriharsha.basavapatna at broadcom.com
Sun Jul 12 19:26:18 UTC 2020


This patch refactors dp_netdev_flow_offload_put() to prepare for
changes to support partial action offload, in subsequent patches.

- Move mark allocation code into a separate wrapper function, outside of
  dp_netdev_flow_offload_put() to improve readability and to facilitate
  more changes in this function to support partial action offload.

- We need to get the in-port's netdev-type (e.g, vhost) to determine if
  the flow should be offloaded on the egress device instead. To facilitate
  such changes, netdev_ports_get() is moved ahead of mark allocation.

Reviewed-by: Hemal Shah <hemal.shah at broadcom.com>
Signed-off-by: Sriharsha Basavapatna <sriharsha.basavapatna at broadcom.com>
---
 lib/dpif-netdev.c | 73 +++++++++++++++++++++++++++++------------------
 1 file changed, 45 insertions(+), 28 deletions(-)

diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index 629a0cb53..f26caef6d 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -2499,6 +2499,43 @@ dp_netdev_flow_offload_del(struct dp_flow_offload_item *offload)
     return mark_to_flow_disassociate(offload->pmd, offload->flow);
 }
 
+static int
+dp_netdev_alloc_flow_mark(struct dp_netdev_flow *flow, bool modification,
+                          uint32_t *markp)
+{
+    uint32_t mark;
+
+    if (modification) {
+        mark = flow->mark;
+        ovs_assert(mark != INVALID_FLOW_MARK);
+        *markp = mark;
+        return 0;
+    }
+
+    /*
+     * If a mega flow has already been offloaded (from other PMD
+     * instances), do not offload it again.
+     */
+    mark = megaflow_to_mark_find(&flow->mega_ufid);
+    if (mark != INVALID_FLOW_MARK) {
+        VLOG_DBG("Flow has already been offloaded with mark %u\n", mark);
+        if (flow->mark != INVALID_FLOW_MARK) {
+            ovs_assert(flow->mark == mark);
+        } else {
+            mark_to_flow_associate(mark, flow);
+        }
+        return 1;
+    }
+
+    mark = flow_mark_alloc();
+    if (mark == INVALID_FLOW_MARK) {
+        VLOG_ERR("Failed to allocate flow mark!\n");
+    }
+
+    *markp = mark;
+    return 0;
+}
+
 /*
  * There are two flow offload operations here: addition and modification.
  *
@@ -2527,38 +2564,18 @@ dp_netdev_flow_offload_put(struct dp_flow_offload_item *offload)
         return -1;
     }
 
-    if (modification) {
-        mark = flow->mark;
-        ovs_assert(mark != INVALID_FLOW_MARK);
-    } else {
-        /*
-         * If a mega flow has already been offloaded (from other PMD
-         * instances), do not offload it again.
-         */
-        mark = megaflow_to_mark_find(&flow->mega_ufid);
-        if (mark != INVALID_FLOW_MARK) {
-            VLOG_DBG("Flow has already been offloaded with mark %u\n", mark);
-            if (flow->mark != INVALID_FLOW_MARK) {
-                ovs_assert(flow->mark == mark);
-            } else {
-                mark_to_flow_associate(mark, flow);
-            }
-            return 0;
-        }
+    port = netdev_ports_get(in_port, dpif_type_str);
+    if (!port) {
+        return -1;
+    }
 
-        mark = flow_mark_alloc();
-        if (mark == INVALID_FLOW_MARK) {
-            VLOG_ERR("Failed to allocate flow mark!\n");
-            return -1;
-        }
+    if (dp_netdev_alloc_flow_mark(flow, modification, &mark)) {
+            /* flow already offloaded */
+            netdev_close(port);
+            return 0;
     }
     info.flow_mark = mark;
 
-    port = netdev_ports_get(in_port, dpif_type_str);
-    if (!port || netdev_vport_is_vport_class(port->netdev_class)) {
-        netdev_close(port);
-        goto err_free;
-    }
     /* Taking a global 'port_mutex' to fulfill thread safety restrictions for
      * the netdev-offload-dpdk module. */
     ovs_mutex_lock(&pmd->dp->port_mutex);
-- 
2.25.0.rc2



More information about the dev mailing list