diff mbox series

[ovs-dev,v11,08/10] odp-execute: Add ISA implementation of push_vlan action.

Message ID 20220714175158.3709150-9-emma.finn@intel.com
State Superseded
Headers show
Series Actions Infrastructure + Optimizations | expand

Checks

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

Commit Message

Emma Finn July 14, 2022, 5:51 p.m. UTC
This commit adds the AVX512 implementation of the
push_vlan action.

Signed-off-by: Emma Finn <emma.finn@intel.com>
Acked-by: Eelco Chaudron <echaudro@redhat.com>
---
 lib/odp-execute-avx512.c | 54 ++++++++++++++++++++++++++++++++++++++++
 lib/odp-execute.c        | 22 +++++++++-------
 2 files changed, 67 insertions(+), 9 deletions(-)

Comments

Eelco Chaudron July 15, 2022, 8:07 a.m. UTC | #1
On 14 Jul 2022, at 19:51, Emma Finn wrote:

> This commit adds the AVX512 implementation of the
> push_vlan action.
>
> Signed-off-by: Emma Finn <emma.finn@intel.com>
> Acked-by: Eelco Chaudron <echaudro@redhat.com>
> ---

Thanks for fixing all the comments!

Acked-by: Eelco Chaudron <echaudro@redhat.com>

//Eelco
diff mbox series

Patch

diff --git a/lib/odp-execute-avx512.c b/lib/odp-execute-avx512.c
index d929abe68..90a5a7416 100644
--- a/lib/odp-execute-avx512.c
+++ b/lib/odp-execute-avx512.c
@@ -154,6 +154,58 @@  action_avx512_pop_vlan(struct dp_packet_batch *batch,
     }
 }
 
+/* This function performs the same operation on each packet in the batch as
+ * the scalar eth_push_vlan() function. */
+static void
+action_avx512_push_vlan(struct dp_packet_batch *batch, const struct nlattr *a)
+{
+    struct dp_packet *packet;
+    const struct ovs_action_push_vlan *vlan = nl_attr_get(a);
+    ovs_be16 tpid, tci;
+
+    /* This shuffle mask is used below, and each position tells where to
+     * move the bytes to. So here, the fourth byte in v_ether is moved to
+     * byte location 0 in v_shift. The fifth is moved to 1, etc., etc.
+     * The 0xFF is special it tells to fill that position with 0. */
+    static const uint8_t vlan_push_shuffle_mask[16] = {
+        4, 5, 6, 7, 8, 9, 10, 11,
+        12, 13, 14, 15, 0xFF, 0xFF, 0xFF, 0xFF
+    };
+
+    /* Load the shuffle mask in v_index. */
+    __m128i v_index = _mm_loadu_si128((void *) vlan_push_shuffle_mask);
+
+    DP_PACKET_BATCH_FOR_EACH (i, packet, batch) {
+        tpid = vlan->vlan_tpid;
+        tci = vlan->vlan_tci;
+
+        /* As we are about to insert the VLAN_HEADER we now need to adjust all
+         * the offsets. */
+        avx512_dp_packet_resize_l2(packet, VLAN_HEADER_LEN);
+
+        char *pkt_data = (char *) dp_packet_data(packet);
+
+        /* Build up the VLAN TCI/TPID in a single uint32_t. */
+        const uint32_t tci_proc = tci & htons(~VLAN_CFI);
+        const uint32_t tpid_tci = (tci_proc << 16) | tpid;
+
+        /* Load the first 128-bits of the packet into the v_ether register.
+         * Note that this includes the 4 unused bytes (VLAN_HEADER_LEN). */
+        __m128i v_ether = _mm_loadu_si128((void *) pkt_data);
+
+        /* Move(shuffle) the veth_dst and veth_src data to create room for
+         * the vlan header. */
+        __m128i v_shift = _mm_shuffle_epi8(v_ether, v_index);
+
+        /* Copy(insert) the 32-bit VLAN header, tpid_tci, at the 3rd 32-bit
+         * word offset, i.e. ofssetof(vlan_eth_header, veth_type) */
+        __m128i v_vlan_hdr = _mm_insert_epi32(v_shift, tpid_tci, 3);
+
+        /* Write back the modified ethernet header. */
+        _mm_storeu_si128((void *) pkt_data, v_vlan_hdr);
+    }
+}
+
 int
 action_avx512_init(struct odp_execute_action_impl *self OVS_UNUSED)
 {
@@ -164,6 +216,8 @@  action_avx512_init(struct odp_execute_action_impl *self OVS_UNUSED)
     /* Set function pointers for actions that can be applied directly, these
      * are identified by OVS_ACTION_ATTR_*. */
     self->funcs[OVS_ACTION_ATTR_POP_VLAN] = action_avx512_pop_vlan;
+    self->funcs[OVS_ACTION_ATTR_PUSH_VLAN] = action_avx512_push_vlan;
+
     return 0;
 }
 
diff --git a/lib/odp-execute.c b/lib/odp-execute.c
index ff16e9bf3..a65110138 100644
--- a/lib/odp-execute.c
+++ b/lib/odp-execute.c
@@ -846,6 +846,17 @@  action_pop_vlan(struct dp_packet_batch *batch,
     }
 }
 
+static void
+action_push_vlan(struct dp_packet_batch *batch, const struct nlattr *a)
+{
+    struct dp_packet *packet;
+    const struct ovs_action_push_vlan *vlan = nl_attr_get(a);
+
+    DP_PACKET_BATCH_FOR_EACH (i, packet, batch) {
+        eth_push_vlan(packet, vlan->vlan_tpid, vlan->vlan_tci);
+    }
+}
+
 /* Implementation of the scalar actions impl init function. Build up the
  * array of func ptrs here. */
 int
@@ -854,6 +865,7 @@  odp_action_scalar_init(struct odp_execute_action_impl *self)
     /* Set function pointers for actions that can be applied directly, these
      * are identified by OVS_ACTION_ATTR_*. */
     self->funcs[OVS_ACTION_ATTR_POP_VLAN] = action_pop_vlan;
+    self->funcs[OVS_ACTION_ATTR_PUSH_VLAN] = action_push_vlan;
 
     return 0;
 }
@@ -1051,15 +1063,6 @@  odp_execute_actions(void *dp, struct dp_packet_batch *batch, bool steal,
             break;
         }
 
-        case OVS_ACTION_ATTR_PUSH_VLAN: {
-            const struct ovs_action_push_vlan *vlan = nl_attr_get(a);
-
-            DP_PACKET_BATCH_FOR_EACH (i, packet, batch) {
-                eth_push_vlan(packet, vlan->vlan_tpid, vlan->vlan_tci);
-            }
-            break;
-        }
-
         case OVS_ACTION_ATTR_PUSH_MPLS: {
             const struct ovs_action_push_mpls *mpls = nl_attr_get(a);
 
@@ -1212,6 +1215,7 @@  odp_execute_actions(void *dp, struct dp_packet_batch *batch, bool steal,
         case __OVS_ACTION_ATTR_MAX:
         /* The following actions are handled by the scalar implementation. */
         case OVS_ACTION_ATTR_POP_VLAN:
+        case OVS_ACTION_ATTR_PUSH_VLAN:
             OVS_NOT_REACHED();
         }