[ovs-dev] [PATCH v3 2/3] dpif-netdev: Add dp_netdev_packet_rss()

Daniele Di Proietto ddiproietto at vmware.com
Mon Aug 18 20:29:04 UTC 2014


This new function uses ofpbuf_rss(), or hashes the packet 5-tuple, to get the
hash of a packet. Used by OVS_ACTION_ATTR_HASH and future commits.

Signed-off-by: Daniele Di Proietto <ddiproietto at vmware.com>
---
 lib/dpif-netdev.c | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index 7401293..4e02a6e 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -1851,6 +1851,26 @@ dp_netdev_stats_new_cb(void)
     return bucket;
 }
 
+static inline uint32_t
+dp_netdev_packet_rss(struct dpif_packet *packet, const struct miniflow *mf)
+{
+    uint32_t hash;
+
+    hash = ofpbuf_rss(&packet->ofpbuf);
+    if (OVS_UNLIKELY(!hash)) {
+        struct netdev_flow_key key;
+        if (!mf) {
+            miniflow_initialize(&key.flow, key.buf);
+            miniflow_extract(&packet->ofpbuf, NULL, &key.flow);
+            mf = &key.flow;
+        }
+
+        hash = miniflow_hash_5tuple(mf, 0);
+    }
+
+    return hash;
+}
+
 static void
 dp_netdev_count_packet(struct dp_netdev *dp, enum dp_stat_type type, int cnt)
 {
@@ -2169,22 +2189,17 @@ dp_execute_cb(void *aux_, struct dpif_packet **packets, int cnt,
 
     case OVS_ACTION_ATTR_HASH: {
         const struct ovs_action_hash *hash_act;
-        struct netdev_flow_key key;
         uint32_t hash;
 
         hash_act = nl_attr_get(a);
 
-        miniflow_initialize(&key.flow, key.buf);
-
         for (i = 0; i < cnt; i++) {
 
-            /* XXX: this is slow. Use RSS hash in the future */
-            miniflow_extract(&packets[i]->ofpbuf, md, &key.flow);
-
             if (hash_act->hash_alg == OVS_HASH_ALG_L4) {
                 /* Hash need not be symmetric, nor does it need to include
                  * L2 fields. */
-                hash = miniflow_hash_5tuple(&key.flow, hash_act->hash_basis);
+                hash = hash_2words(dp_netdev_packet_rss(packets[i], NULL),
+                                   hash_act->hash_basis);
             } else {
                 VLOG_WARN("Unknown hash algorithm specified "
                           "for the hash action.");
-- 
2.1.0.rc1




More information about the dev mailing list