[ovs-dev] [PATCH v4 1/2] packet-dpif: Add dpif_packet_{get, set}_hash()

Daniele Di Proietto ddiproietto at vmware.com
Wed Aug 20 00:11:57 UTC 2014


These function are used to stored the packet hash. 'netdev-dpdk' automatically
set this value to the RSS hash returned by the NIC. Other 'netdev's set it to 0
(which is an invalid hash value), so that callers can compute the hash on their
own.

If DPDK support is enabled, struct dpif_packet's member 'dp_hash' is removed
and 'pkt.hash.rss' from DPDK mbuf is used

This commit also configure DPDK devices to compute RSS hash for UDP and IPv6
packets

Signed-off-by: Daniele Di Proietto <ddiproietto at vmware.com>
---
 lib/dpif-netdev.c  |  2 +-
 lib/netdev-bsd.c   |  1 +
 lib/netdev-dpdk.c  |  3 ++-
 lib/netdev-dummy.c |  1 +
 lib/netdev-linux.c |  1 +
 lib/odp-execute.c  |  5 +++--
 lib/packet-dpif.c  |  2 +-
 lib/packet-dpif.h  | 21 +++++++++++++++++++++
 8 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index 7401293..8f8e8a8 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -2217,7 +2217,7 @@ dp_execute_cb(void *aux_, struct dpif_packet **packets, int cnt,
                 recirc_md.recirc_id = nl_attr_get_u32(a);
 
                 /* Hash is private to each packet */
-                recirc_md.dp_hash = packets[i]->dp_hash;
+                recirc_md.dp_hash = dpif_packet_get_dp_hash(packets[i]);
 
                 dp_netdev_input(dp, &recirc_pkt, 1, &recirc_md);
             }
diff --git a/lib/netdev-bsd.c b/lib/netdev-bsd.c
index 16efc3d..82f61ff 100644
--- a/lib/netdev-bsd.c
+++ b/lib/netdev-bsd.c
@@ -647,6 +647,7 @@ netdev_bsd_rxq_recv(struct netdev_rxq *rxq_, struct dpif_packet **packets,
         dpif_packet_delete(packet);
     } else {
         dp_packet_pad(buffer);
+        dpif_packet_set_dp_hash(packet, 0);
         packets[0] = packet;
         *c = 1;
     }
diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
index a8f041b..23cf410 100644
--- a/lib/netdev-dpdk.c
+++ b/lib/netdev-dpdk.c
@@ -96,7 +96,8 @@ static const struct rte_eth_conf port_conf = {
     .rx_adv_conf = {
         .rss_conf = {
             .rss_key = NULL,
-            .rss_hf = ETH_RSS_IPV4_TCP | ETH_RSS_IPV4 | ETH_RSS_IPV6,
+            .rss_hf = ETH_RSS_IPV4_TCP | ETH_RSS_IPV4 | ETH_RSS_IPV6
+                    | ETH_RSS_IPV4_UDP | ETH_RSS_IPV6_TCP | ETH_RSS_IPV6_UDP,
         },
     },
     .txmode = {
diff --git a/lib/netdev-dummy.c b/lib/netdev-dummy.c
index 8d1c298..110363f 100644
--- a/lib/netdev-dummy.c
+++ b/lib/netdev-dummy.c
@@ -808,6 +808,7 @@ netdev_dummy_rxq_recv(struct netdev_rxq *rxq_, struct dpif_packet **arr,
 
     /* This performs a (sometimes unnecessary) copy */
     arr[0] = dpif_packet_clone_from_ofpbuf(packet);
+    dpif_packet_set_dp_hash(arr[0], 0);
     ofpbuf_delete(packet);
     *c = 1;
     return 0;
diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index e50392a..45788cc 100644
--- a/lib/netdev-linux.c
+++ b/lib/netdev-linux.c
@@ -1015,6 +1015,7 @@ netdev_linux_rxq_recv(struct netdev_rxq *rxq_, struct dpif_packet **packets,
         dpif_packet_delete(packet);
     } else {
         dp_packet_pad(buffer);
+        dpif_packet_set_dp_hash(packet, 0);
         packets[0] = packet;
         *c = 1;
     }
diff --git a/lib/odp-execute.c b/lib/odp-execute.c
index e1e9b57..bfcd6ac 100644
--- a/lib/odp-execute.c
+++ b/lib/odp-execute.c
@@ -136,7 +136,8 @@ odp_execute_set_action(struct dpif_packet *packet, const struct nlattr *a,
         break;
 
     case OVS_KEY_ATTR_DP_HASH:
-        packet->dp_hash = md->dp_hash = nl_attr_get_u32(a);
+        md->dp_hash = nl_attr_get_u32(a);
+        dpif_packet_set_dp_hash(packet, md->dp_hash);
         break;
 
     case OVS_KEY_ATTR_RECIRC_ID:
@@ -251,7 +252,7 @@ odp_execute_actions__(void *dp, struct dpif_packet **packets, int cnt,
                     }
 
                     /* We also store the hash value with each packet */
-                    packets[i]->dp_hash = hash ? hash : 1;
+                    dpif_packet_set_dp_hash(packets[i], hash ? hash : 1);
                 }
             } else {
                 /* Assert on unknown hash algorithm.  */
diff --git a/lib/packet-dpif.c b/lib/packet-dpif.c
index 9f1880b..3a912e1 100644
--- a/lib/packet-dpif.c
+++ b/lib/packet-dpif.c
@@ -62,7 +62,7 @@ dpif_packet_clone(struct dpif_packet *p)
 
     newp = dpif_packet_clone_from_ofpbuf(&p->ofpbuf);
 
-    newp->dp_hash = p->dp_hash;
+    dpif_packet_set_dp_hash(newp, dpif_packet_get_dp_hash(p));
 
     return newp;
 }
diff --git a/lib/packet-dpif.h b/lib/packet-dpif.h
index f11ecd8..89f048e 100644
--- a/lib/packet-dpif.h
+++ b/lib/packet-dpif.h
@@ -27,7 +27,9 @@ extern "C" {
 
 struct dpif_packet {
     struct ofpbuf ofpbuf;       /* Packet data. */
+#ifndef DPDK_NETDEV
     uint32_t dp_hash;           /* Packet hash. */
+#endif
 };
 
 struct dpif_packet *dpif_packet_new_with_headroom(size_t size,
@@ -44,6 +46,25 @@ static inline void dpif_packet_delete(struct dpif_packet *p)
     ofpbuf_delete(buf);
 }
 
+static inline uint32_t dpif_packet_get_dp_hash(struct dpif_packet *p)
+{
+#ifdef DPDK_NETDEV
+    return p->ofpbuf.mbuf.pkt.hash.rss;
+#else
+    return p->dp_hash;
+#endif
+}
+
+static inline void dpif_packet_set_dp_hash(struct dpif_packet *p,
+                                           uint32_t hash)
+{
+#ifdef DPDK_NETDEV
+    p->ofpbuf.mbuf.pkt.hash.rss = hash;
+#else
+    p->dp_hash = hash;
+#endif
+}
+
 #ifdef  __cplusplus
 }
 #endif
-- 
2.1.0.rc1




More information about the dev mailing list