Skip to contentSkip to conversation

hash: added rte_hash_clear that clears all keys

PATCH Bruce Richardson 2 participants 3 messages Mar 6, 2015 1 message not in the archive

lore
Share & tools
lore
#0 lore raw
Quoted 3 lines · Tomas Vestelind

I added rte_hash_clear which clear the map from all previously added keys.

This patch is now quite old and needs an update to add the new API to the rte_hash_version.map. A unit test for the new function would also be good to have. Otherwise patch content looks ok. Is an updated V2 planned?

Regards,
/Bruce

Quoted 52 lines
Signed-off-by Tomas Vestelind <tomas.vestelind at gmail.com>
---
 lib/librte_hash/rte_hash.c |   14 ++++++++++++++
 lib/librte_hash/rte_hash.h |   10 ++++++++++
 2 files changed, 24 insertions(+)
lib/librte_hash/rte_hash.c +14 -0
index 2108c4f..917a6c1 100644
@@ -507,3 +507,17 @@ rte_hash_keys(const struct rte_hash *h, void *keys)
 
     return found_keys;
 }
+
+void
+rte_hash_clear(const struct rte_hash *h)
+{
+    unsigned int bucket, entry;
+
+    /* Clear all entries by invalidating each signature */
+    for (bucket = 0; bucket < h->num_buckets; bucket++) {
+        hash_sig_t *sig = get_sig_tbl_bucket(h, bucket);
+        for (entry = 0; entry < h->bucket_entries; entry++) {
+            sig[entry] = NULL_SIGNATURE;
+        }
+    }
+}
lib/librte_hash/rte_hash.h +10 -0
index e0fb28f..b84137e 100644
@@ -318,6 +318,16 @@ rte_hash_lookup_bulk(const struct rte_hash *h, const void **keys,
  */
 unsigned int
 rte_hash_keys(const struct rte_hash *h, void *keys);
+
+/**
+ * Clear all keys. This operation is not multi-thread safe and should only be
+ * called from one thread.
+ *
+ * @param h
+ *   Hash table to clear.
+ */
+void
+rte_hash_clear(const struct rte_hash *h);
 #ifdef __cplusplus
 }
 #endif
Signature · 1 line
1.7.10.4
#1 lore raw

Hi Bruce!

Oh yea, this patch is quite old :)

I'm currently not working actively with DPDK. If no one else wants to do it, I could do the update and add a unit test

/Tomas

Quoted 65 lines · Bruce Richardson
Quoted 3 lines · Tomas Vestelind

I added rte_hash_clear which clear the map from all previously added keys.

This patch is now quite old and needs an update to add the new API to the rte_hash_version.map. A unit test for the new function would also be good to have. Otherwise patch content looks ok. Is an updated V2 planned?

Regards,
/Bruce

Quoted 52 lines
Signed-off-by Tomas Vestelind <tomas.vestelind at gmail.com>
---
  lib/librte_hash/rte_hash.c |   14 ++++++++++++++
  lib/librte_hash/rte_hash.h |   10 ++++++++++
  2 files changed, 24 insertions(+)
lib/librte_hash/rte_hash.c +14 -0
index 2108c4f..917a6c1 100644
@@ -507,3 +507,17 @@ rte_hash_keys(const struct rte_hash *h, void *keys)
 
      return found_keys;
  }
+
+void
+rte_hash_clear(const struct rte_hash *h)
+{
+    unsigned int bucket, entry;
+
+    /* Clear all entries by invalidating each signature */
+    for (bucket = 0; bucket < h->num_buckets; bucket++) {
+        hash_sig_t *sig = get_sig_tbl_bucket(h, bucket);
+        for (entry = 0; entry < h->bucket_entries; entry++) {
+            sig[entry] = NULL_SIGNATURE;
+        }
+    }
+}
lib/librte_hash/rte_hash.h +10 -0
index e0fb28f..b84137e 100644
@@ -318,6 +318,16 @@ rte_hash_lookup_bulk(const struct rte_hash *h, const void **keys,
   */
  unsigned int
  rte_hash_keys(const struct rte_hash *h, void *keys);
+
+/**
+ * Clear all keys. This operation is not multi-thread safe and should only be
+ * called from one thread.
+ *
+ * @param h
+ *   Hash table to clear.
+ */
+void
+rte_hash_clear(const struct rte_hash *h);
  #ifdef __cplusplus
  }
  #endif
Signature · 1 line
1.7.10.4
#3 lore raw
In reply to a message not in the archive
Quoted 8 lines · Tomas Vestelind

Hi Bruce!

Oh yea, this patch is quite old :)

I'm currently not working actively with DPDK. If no one else wants to do it, I could do the update and add a unit test

/Tomas

Hi Tomas,

no pressure, since there doesn't appear to be pressing interest in this enhancement and since we are now passed feature freeze for 2.0.
However, contributions for our next release are always welcome!

Regards,
/Bruce

Quoted 68 lines · Bruce Richardson
Quoted 64 lines · Tomas Vestelind
Quoted 3 lines

I added rte_hash_clear which clear the map from all previously added keys.

This patch is now quite old and needs an update to add the new API to the rte_hash_version.map. A unit test for the new function would also be good to have. Otherwise patch content looks ok. Is an updated V2 planned?

Regards,
/Bruce

Quoted 51 lines
Signed-off-by Tomas Vestelind <tomas.vestelind at gmail.com>
---
 lib/librte_hash/rte_hash.c |   14 ++++++++++++++
 lib/librte_hash/rte_hash.h |   10 ++++++++++
 2 files changed, 24 insertions(+)
lib/librte_hash/rte_hash.c +14 -0
index 2108c4f..917a6c1 100644
@@ -507,3 +507,17 @@ rte_hash_keys(const struct rte_hash *h, void *keys)
     return found_keys;
 }
+
+void
+rte_hash_clear(const struct rte_hash *h)
+{
+    unsigned int bucket, entry;
+
+    /* Clear all entries by invalidating each signature */
+    for (bucket = 0; bucket < h->num_buckets; bucket++) {
+        hash_sig_t *sig = get_sig_tbl_bucket(h, bucket);
+        for (entry = 0; entry < h->bucket_entries; entry++) {
+            sig[entry] = NULL_SIGNATURE;
+        }
+    }
+}
lib/librte_hash/rte_hash.h +10 -0
index e0fb28f..b84137e 100644
@@ -318,6 +318,16 @@ rte_hash_lookup_bulk(const struct rte_hash *h, const void **keys,
  */
 unsigned int
 rte_hash_keys(const struct rte_hash *h, void *keys);
+
+/**
+ * Clear all keys. This operation is not multi-thread safe and should only be
+ * called from one thread.
+ *
+ * @param h
+ *   Hash table to clear.
+ */
+void
+rte_hash_clear(const struct rte_hash *h);
 #ifdef __cplusplus
 }
 #endif
Signature · 1 line
1.7.10.4