[ovs-dev] [PATCH V6 2/2] odp-util: Do not rewrite fields with the same values as matched

2019-03-09 Thread Eli Britstein
To improve performance and avoid wasting resources for HW offloaded
flows, do not rewrite fields that are matched with the same value.

Signed-off-by: Eli Britstein 
Reviewed-by: Roi Dayan 
---
 lib/odp-util.c| 93 +--
 tests/mpls-xlate.at   |  2 +-
 tests/ofproto-dpif.at | 14 +++
 3 files changed, 88 insertions(+), 21 deletions(-)

diff --git a/lib/odp-util.c b/lib/odp-util.c
index 8bcbd2c30..e1e6da8d9 100644
--- a/lib/odp-util.c
+++ b/lib/odp-util.c
@@ -43,6 +43,7 @@
 #include "uuid.h"
 #include "openvswitch/vlog.h"
 #include "openvswitch/match.h"
+#include "odp-netlink-macros.h"
 
 VLOG_DEFINE_THIS_MODULE(odp_util);
 
@@ -7355,12 +7356,51 @@ commit_odp_tunnel_action(const struct flow *flow, 
struct flow *base,
 }
 }
 
+struct offsetof_sizeof {
+int offset;
+int size;
+};
+
+/* Compare the keys similary to memcmp, but each field separately.
+ * The offsets and sizes of each field is provided by offsetof_sizeof_arr
+ * argument.
+ * For fields with the same value, zero out their mask part in order not to
+ * rewrite them as it's unnecessary */
+static bool
+keycmp_mask(const void *key0, const void *key1,
+struct offsetof_sizeof *offsetof_sizeof_arr, void *mask)
+{
+int field;
+bool differ = false;
+
+for (field = 0 ; ; field++) {
+int size = offsetof_sizeof_arr[field].size;
+int offset = offsetof_sizeof_arr[field].offset;
+char *pkey0 = ((char *)key0) + offset;
+char *pkey1 = ((char *)key1) + offset;
+char *pmask = ((char *)mask) + offset;
+
+if (size == 0) {
+break;
+}
+
+if (memcmp(pkey0, pkey1, size) == 0) {
+memset(pmask, 0, size);
+} else {
+differ = true;
+}
+}
+
+return differ;
+}
+
 static bool
 commit(enum ovs_key_attr attr, bool use_masked_set,
const void *key, void *base, void *mask, size_t size,
+   struct offsetof_sizeof *offsetof_sizeof_arr,
struct ofpbuf *odp_actions)
 {
-if (memcmp(key, base, size)) {
+if (keycmp_mask(key, base, offsetof_sizeof_arr, mask)) {
 bool fully_masked = odp_mask_is_exact(attr, mask, size);
 
 if (use_masked_set && !fully_masked) {
@@ -7402,7 +7442,8 @@ commit_set_ether_action(const struct flow *flow, struct 
flow *base_flow,
 bool use_masked)
 {
 struct ovs_key_ethernet key, base, mask;
-
+struct offsetof_sizeof ovs_key_ethernet_offsetof_sizeof_arr[] =
+OVS_KEY_ETHERNET_OFFSETOF_SIZEOF_ARR;
 if (flow->packet_type != htonl(PT_ETH)) {
 return;
 }
@@ -7412,7 +7453,8 @@ commit_set_ether_action(const struct flow *flow, struct 
flow *base_flow,
 get_ethernet_key(>masks, );
 
 if (commit(OVS_KEY_ATTR_ETHERNET, use_masked,
-   , , , sizeof key, odp_actions)) {
+   , , , sizeof key,
+   ovs_key_ethernet_offsetof_sizeof_arr, odp_actions)) {
 put_ethernet_key(, base_flow);
 put_ethernet_key(, >masks);
 }
@@ -7538,6 +7580,8 @@ commit_set_ipv4_action(const struct flow *flow, struct 
flow *base_flow,
bool use_masked)
 {
 struct ovs_key_ipv4 key, mask, base;
+struct offsetof_sizeof ovs_key_ipv4_offsetof_sizeof_arr[] =
+OVS_KEY_IPV4_OFFSETOF_SIZEOF_ARR;
 
 /* Check that nw_proto and nw_frag remain unchanged. */
 ovs_assert(flow->nw_proto == base_flow->nw_proto &&
@@ -7555,7 +7599,7 @@ commit_set_ipv4_action(const struct flow *flow, struct 
flow *base_flow,
 }
 
 if (commit(OVS_KEY_ATTR_IPV4, use_masked, , , , sizeof key,
-   odp_actions)) {
+   ovs_key_ipv4_offsetof_sizeof_arr, odp_actions)) {
 put_ipv4_key(, base_flow, false);
 if (mask.ipv4_proto != 0) { /* Mask was changed by commit(). */
 put_ipv4_key(, >masks, true);
@@ -7593,6 +7637,8 @@ commit_set_ipv6_action(const struct flow *flow, struct 
flow *base_flow,
bool use_masked)
 {
 struct ovs_key_ipv6 key, mask, base;
+struct offsetof_sizeof ovs_key_ipv6_offsetof_sizeof_arr[] =
+OVS_KEY_IPV6_OFFSETOF_SIZEOF_ARR;
 
 /* Check that nw_proto and nw_frag remain unchanged. */
 ovs_assert(flow->nw_proto == base_flow->nw_proto &&
@@ -7611,7 +7657,7 @@ commit_set_ipv6_action(const struct flow *flow, struct 
flow *base_flow,
 }
 
 if (commit(OVS_KEY_ATTR_IPV6, use_masked, , , , sizeof key,
-   odp_actions)) {
+   ovs_key_ipv6_offsetof_sizeof_arr, odp_actions)) {
 put_ipv6_key(, base_flow, false);
 if (mask.ipv6_proto != 0) { /* Mask was changed by commit(). */
 put_ipv6_key(, >masks, true);
@@ -7647,13 +7693,15 @@ commit_set_arp_action(const struct flow *flow, struct 
flow *base_flow,
   struct ofpbuf *odp_actions, struct flow_wildcards *wc)
 {
 struct ovs_key_arp key, mask, base;
+struct offsetof_sizeof 

[ovs-dev] [PATCH V6 0/2] Do not rewrite fields with the same values as matched

2019-03-09 Thread Eli Britstein
This patch set avoids unnecessary rewrite actions to fields with the
same values as matched on.

Patch 1 is a pre-step of generating ovs key fields macros
Patch 2 avoids the unnecessary rewrites and adapts the tests accordingly

Differences from V5:
Generating directly offsetof/sizeof arrays instead of indirection macros.

Thanks,
Eli

Eli Britstein (2):
  Makefiles: Generate datapath ovs key fields macros
  odp-util: Do not rewrite fields with the same values as matched

 .gitignore |  1 +
 build-aux/extract-odp-netlink-macros-h | 55 +++
 include/automake.mk| 11 ++-
 lib/odp-util.c | 93 ++
 tests/mpls-xlate.at|  2 +-
 tests/ofproto-dpif.at  | 14 ++--
 6 files changed, 152 insertions(+), 24 deletions(-)
 create mode 100755 build-aux/extract-odp-netlink-macros-h

-- 
2.17.2

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