packet-dpif: Add dpif_packet_{get, set}_hash()
authorDaniele Di Proietto <ddiproietto@vmware.com>
Fri, 29 Aug 2014 23:06:42 +0000 (16:06 -0700)
committerPravin B Shelar <pshelar@nicira.com>
Fri, 29 Aug 2014 23:32:21 +0000 (16:32 -0700)
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@vmware.com>
Acked-by: Pravin B Shelar <pshelar@nicira.com>
lib/dpif-netdev.c
lib/netdev-bsd.c
lib/netdev-dpdk.c
lib/netdev-dummy.c
lib/netdev-linux.c
lib/odp-execute.c
lib/packet-dpif.c
lib/packet-dpif.h

index 3d09326..a2868b1 100644 (file)
@@ -2221,7 +2221,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);
             }
index 16efc3d..82f61ff 100644 (file)
@@ -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;
     }
index dc472a1..c166ed6 100644 (file)
@@ -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 = {
index dd78818..e3cf72d 100644 (file)
@@ -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;
index 35b1c16..d8a76f9 100644 (file)
@@ -1014,6 +1014,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;
     }
index e1e9b57..bfcd6ac 100644 (file)
@@ -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.  */
index 9f1880b..3a912e1 100644 (file)
@@ -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;
 }
index f11ecd8..89f048e 100644 (file)
@@ -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