On 09/12/2018 04:37 PM, Honnappa Nagarahalli wrote:
+int32_t
+rte_hash_iterator_init(const struct rte_hash *h,
+       struct rte_hash_iterator_state *state) {
+       struct rte_hash_iterator_istate *__state;
'__state' can be replaced by 's'.

+
+       RETURN_IF_TRUE(((h == NULL) || (state == NULL)), -EINVAL);
+
+       __state = (struct rte_hash_iterator_istate *)state;
+       __state->h = h;
+       __state->next = 0;
+       __state->total_entries = h->num_buckets * RTE_HASH_BUCKET_ENTRIES;
+
+       return 0;
+}
IMO, creating this API can be avoided if the initialization is handled in 
'rte_hash_iterate' function. The cost of doing this is very trivial (one extra 
'if' statement) in 'rte_hash_iterate' function. It will help keep the number of 
APIs to minimal.

      Applications would have to initialize struct rte_hash_iterator_state 
*state before calling rte_hash_iterate() anyway. Why not initializing the 
fields of a state only once?

My concern is about creating another API for every iterator API. You have a 
valid point on saving cycles as this API applies for data plane. Have you done 
any performance benchmarking with and without this API? May be we can guide our 
decision based on that.

     It's not just about creating one init function for each iterator because 
an iterator may have a couple of init functions. For example, someone may 
eventually find useful to add another init function for the conflicting-entry 
iterator that we are advocating in this patch. A possibility would be for this 
new init function to use the key of the new entry instead of its signature to 
initialize the state. Similar to what is already done in rte_hash_lookup*() 
functions. In spite of possibly having multiple init functions, there will be a 
single iterator function.

     About the performance benchmarking, the current API only requites 
applications to initialize a single 32-bit integer. But with the adoption of a 
struct for the state, the initialization will grow to 64 bytes.

As my tests showed, I do not see any impact of this.

   Ok, we are going to eliminate the init functions in v4.

diff --git a/lib/librte_hash/rte_hash.h b/lib/librte_hash/rte_hash.h
index 9e7d9315f..fdb01023e 100644
--- a/lib/librte_hash/rte_hash.h
+++ b/lib/librte_hash/rte_hash.h
@@ -14,6 +14,8 @@
    #include <stdint.h>
    #include <stddef.h>
+#include <rte_compat.h>
+
    #ifdef __cplusplus
    extern "C" {
    #endif
@@ -64,6 +66,16 @@ struct rte_hash_parameters {
    /** @internal A hash table structure. */  struct rte_hash;
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * @internal A hash table iterator state structure.
+ */
+struct rte_hash_iterator_state {
+       uint8_t space[64];
I would call this 'state'. 64 can be replaced by 'RTE_CACHE_LINE_SIZE'.

      Okay.

     I think we should not replace 64 with RTE_CACHE_LINE_SIZE because the ABI 
would change based on the architecture for which it's compiled.

Ok. May be have a #define for 64?

   Ok.

[ ]'s
Michel Machado

Reply via email to