diff mbox series

[ovs-dev,1/2] dpif-netdev: Refactor simple match lookup functions.

Message ID 20220630145124.3909557-1-cian.ferriter@intel.com
State Superseded
Headers show
Series [ovs-dev,1/2] dpif-netdev: Refactor simple match lookup functions. | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed
ovsrobot/intel-ovs-compilation success test: success

Commit Message

Ferriter, Cian June 30, 2022, 2:51 p.m. UTC
Move the simple match functions used during lookup to allow reuse of
these functions in the AVX512 DPIF.

Signed-off-by: Cian Ferriter <cian.ferriter@intel.com>
---
 lib/dpif-netdev-private-dpif.c | 69 +++++++++++++++++++++++++++++++
 lib/dpif-netdev-private-dpif.h | 12 ++++++
 lib/dpif-netdev.c              | 74 ----------------------------------
 3 files changed, 81 insertions(+), 74 deletions(-)

Comments

Van Haaren, Harry June 30, 2022, 3:23 p.m. UTC | #1
> -----Original Message-----
> From: dev <ovs-dev-bounces@openvswitch.org> On Behalf Of Cian Ferriter
> Sent: Thursday, June 30, 2022 3:51 PM
> To: ovs-dev@openvswitch.org
> Subject: [ovs-dev] [PATCH 1/2] dpif-netdev: Refactor simple match lookup functions.
> 
> Move the simple match functions used during lookup to allow reuse of
> these functions in the AVX512 DPIF.
>
> Signed-off-by: Cian Ferriter <cian.ferriter@intel.com>

Moving to a header to allow all DPIF impls to make use of makes sense,
tested scalar DPIF impl before/after, showing same performance.

Tested-by: Harry van Haaren <harry.van.haaren@intel.com>
diff mbox series

Patch

diff --git a/lib/dpif-netdev-private-dpif.c b/lib/dpif-netdev-private-dpif.c
index 5ae119a30..6fe0a75a7 100644
--- a/lib/dpif-netdev-private-dpif.c
+++ b/lib/dpif-netdev-private-dpif.c
@@ -167,3 +167,72 @@  dp_netdev_impl_set_default_by_name(const char *name)
     return err;
 
 }
+
+bool
+dp_netdev_simple_match_enabled(const struct dp_netdev_pmd_thread *pmd,
+                               odp_port_t in_port)
+{
+    return ccmap_find(&pmd->n_flows, odp_to_u32(in_port))
+           == ccmap_find(&pmd->n_simple_flows, odp_to_u32(in_port));
+}
+
+uint64_t
+dp_netdev_simple_match_mark(odp_port_t in_port, ovs_be16 dl_type,
+                            uint8_t nw_frag, ovs_be16 vlan_tci)
+{
+    /* Simple Match Mark:
+     *
+     * BE:
+     * +-----------------+-------------++---------+---+-----------+
+     * |     in_port     |   dl_type   || nw_frag |CFI|  VID(12)  |
+     * +-----------------+-------------++---------+---+-----------+
+     * 0                 32          47 49         51  52     63
+     *
+     * LE:
+     * +-----------------+-------------+------++-------+---+------+
+     * |     in_port     |   dl_type   |VID(8)||nw_frag|CFI|VID(4)|
+     * +-----------------+-------------+------++-------+---+------+
+     * 0                 32          47 48  55  57   59 60  61   63
+     *
+     *         Big Endian              Little Endian
+     * in_port : 32 bits [ 0..31]  in_port : 32 bits [ 0..31]
+     * dl_type : 16 bits [32..47]  dl_type : 16 bits [32..47]
+     * <empty> :  1 bit  [48..48]  vlan VID:  8 bits [48..55]
+     * nw_frag :  2 bits [49..50]  <empty> :  1 bit  [56..56]
+     * vlan CFI:  1 bit  [51..51]  nw_frag :  2 bits [57..59]
+     * vlan VID: 12 bits [52..63]  vlan CFI:  1 bit  [60..60]
+     *                             vlan VID:  4 bits [61..63]
+     *
+     * Layout is different for LE and BE in order to save a couple of
+     * network to host translations.
+     * */
+    return ((uint64_t) odp_to_u32(in_port) << 32)
+           | ((OVS_FORCE uint32_t) dl_type << 16)
+#if WORDS_BIGENDIAN
+           | (((uint16_t) nw_frag & FLOW_NW_FRAG_MASK) << VLAN_PCP_SHIFT)
+#else
+           | ((nw_frag & FLOW_NW_FRAG_MASK) << (VLAN_PCP_SHIFT - 8))
+#endif
+           | (OVS_FORCE uint16_t) (vlan_tci & htons(VLAN_VID_MASK | VLAN_CFI));
+}
+
+struct dp_netdev_flow *
+dp_netdev_simple_match_lookup(const struct dp_netdev_pmd_thread *pmd,
+                              odp_port_t in_port, ovs_be16 dl_type,
+                              uint8_t nw_frag, ovs_be16 vlan_tci)
+{
+    uint64_t mark = dp_netdev_simple_match_mark(in_port, dl_type,
+                                                nw_frag, vlan_tci);
+    uint32_t hash = hash_uint64(mark);
+    struct dp_netdev_flow *flow;
+    bool found = false;
+
+    CMAP_FOR_EACH_WITH_HASH (flow, simple_match_node,
+                             hash, &pmd->simple_match_table) {
+        if (flow->simple_match_mark == mark) {
+            found = true;
+            break;
+        }
+    }
+    return found ? flow : NULL;
+}
diff --git a/lib/dpif-netdev-private-dpif.h b/lib/dpif-netdev-private-dpif.h
index 3e38630f5..cf331cec7 100644
--- a/lib/dpif-netdev-private-dpif.h
+++ b/lib/dpif-netdev-private-dpif.h
@@ -61,6 +61,18 @@  dp_netdev_input_func dp_netdev_impl_get_default(void);
 /* Overrides the default DPIF with the user set DPIF. */
 int32_t dp_netdev_impl_set_default_by_name(const char *name);
 
+bool
+dp_netdev_simple_match_enabled(const struct dp_netdev_pmd_thread *pmd,
+                               odp_port_t in_port);
+
+uint64_t
+dp_netdev_simple_match_mark(odp_port_t in_port, ovs_be16 dl_type,
+                            uint8_t nw_frag, ovs_be16 vlan_tci);
+struct dp_netdev_flow *
+dp_netdev_simple_match_lookup(const struct dp_netdev_pmd_thread *pmd,
+                              odp_port_t in_port, ovs_be16 dl_type,
+                              uint8_t nw_frag, ovs_be16 vlan_tci);
+
 /* Available DPIF implementations below. */
 int32_t
 dp_netdev_input(struct dp_netdev_pmd_thread *pmd,
diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index d09138f2c..5d041d5c2 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -639,11 +639,6 @@  static void dp_netdev_simple_match_remove(struct dp_netdev_pmd_thread *pmd,
     OVS_REQUIRES(pmd->flow_mutex);
 
 static bool dp_netdev_flow_is_simple_match(const struct match *);
-static bool dp_netdev_simple_match_enabled(const struct dp_netdev_pmd_thread *,
-                                           odp_port_t in_port);
-static struct dp_netdev_flow *dp_netdev_simple_match_lookup(
-    const struct dp_netdev_pmd_thread *,
-    odp_port_t in_port, ovs_be16 dp_type, uint8_t nw_frag, ovs_be16 vlan_tci);
 
 /* Updates the time in PMD threads context and should be called in three cases:
  *
@@ -3873,75 +3868,6 @@  dp_netdev_get_mega_ufid(const struct match *match, ovs_u128 *mega_ufid)
     odp_flow_key_hash(&masked_flow, sizeof masked_flow, mega_ufid);
 }
 
-static uint64_t
-dp_netdev_simple_match_mark(odp_port_t in_port, ovs_be16 dl_type,
-                            uint8_t nw_frag, ovs_be16 vlan_tci)
-{
-    /* Simple Match Mark:
-     *
-     * BE:
-     * +-----------------+-------------++---------+---+-----------+
-     * |     in_port     |   dl_type   || nw_frag |CFI|  VID(12)  |
-     * +-----------------+-------------++---------+---+-----------+
-     * 0                 32          47 49         51  52     63
-     *
-     * LE:
-     * +-----------------+-------------+------++-------+---+------+
-     * |     in_port     |   dl_type   |VID(8)||nw_frag|CFI|VID(4)|
-     * +-----------------+-------------+------++-------+---+------+
-     * 0                 32          47 48  55  57   59 60  61   63
-     *
-     *         Big Endian              Little Endian
-     * in_port : 32 bits [ 0..31]  in_port : 32 bits [ 0..31]
-     * dl_type : 16 bits [32..47]  dl_type : 16 bits [32..47]
-     * <empty> :  1 bit  [48..48]  vlan VID:  8 bits [48..55]
-     * nw_frag :  2 bits [49..50]  <empty> :  1 bit  [56..56]
-     * vlan CFI:  1 bit  [51..51]  nw_frag :  2 bits [57..59]
-     * vlan VID: 12 bits [52..63]  vlan CFI:  1 bit  [60..60]
-     *                             vlan VID:  4 bits [61..63]
-     *
-     * Layout is different for LE and BE in order to save a couple of
-     * network to host translations.
-     * */
-    return ((uint64_t) odp_to_u32(in_port) << 32)
-           | ((OVS_FORCE uint32_t) dl_type << 16)
-#if WORDS_BIGENDIAN
-           | (((uint16_t) nw_frag & FLOW_NW_FRAG_MASK) << VLAN_PCP_SHIFT)
-#else
-           | ((nw_frag & FLOW_NW_FRAG_MASK) << (VLAN_PCP_SHIFT - 8))
-#endif
-           | (OVS_FORCE uint16_t) (vlan_tci & htons(VLAN_VID_MASK | VLAN_CFI));
-}
-
-static struct dp_netdev_flow *
-dp_netdev_simple_match_lookup(const struct dp_netdev_pmd_thread *pmd,
-                              odp_port_t in_port, ovs_be16 dl_type,
-                              uint8_t nw_frag, ovs_be16 vlan_tci)
-{
-    uint64_t mark = dp_netdev_simple_match_mark(in_port, dl_type,
-                                                nw_frag, vlan_tci);
-    uint32_t hash = hash_uint64(mark);
-    struct dp_netdev_flow *flow;
-    bool found = false;
-
-    CMAP_FOR_EACH_WITH_HASH (flow, simple_match_node,
-                             hash, &pmd->simple_match_table) {
-        if (flow->simple_match_mark == mark) {
-            found = true;
-            break;
-        }
-    }
-    return found ? flow : NULL;
-}
-
-static bool
-dp_netdev_simple_match_enabled(const struct dp_netdev_pmd_thread *pmd,
-                               odp_port_t in_port)
-{
-    return ccmap_find(&pmd->n_flows, odp_to_u32(in_port))
-           == ccmap_find(&pmd->n_simple_flows, odp_to_u32(in_port));
-}
-
 static void
 dp_netdev_simple_match_insert(struct dp_netdev_pmd_thread *pmd,
                               struct dp_netdev_flow *dp_flow)