From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mta123.f1.k8.com.br (mta123.f1.k8.com.br [187.73.32.199]) by dpdk.org (Postfix) with ESMTP id CD52611A4 for ; Tue, 4 Sep 2018 21:37:09 +0200 (CEST) Received: from [192.168.1.4] (pool-173-48-214-200.bstnma.fios.verizon.net [173.48.214.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtpz.f1.k8.com.br (Postfix) with ESMTPSA id 3EBFE60251; Tue, 4 Sep 2018 19:36:56 +0000 (UTC) X-DKIM: OpenDKIM Filter v2.6.8 smtpz.f1.k8.com.br 3EBFE60251 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=digirati.com.br; s=default; t=1536089827; bh=09QGTh7ITns+2UJp4FegaXQ0jCLtUuKQibx/pYVql10=; h=Subject:To:From:Date:Feedback-ID; b=yR5AzIXpbEV80aLowkvvq8U43VgGIH4h6zxJoQCMOIUbOk0VBCw4HV3CNOsnV2Ewh hdCW0Hlx/UkVSfmYxY/3iIUg698qXzEEQLU0EssJVJpxN93ZOfvkGSuLkUban0Dg6G mZwsu2wUrezysVDKFZCIFGQz4IjRUffahI9Z0QwQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=k8.com.br; s=default; t=1536089827; bh=09QGTh7ITns+2UJp4FegaXQ0jCLtUuKQibx/pYVql10=; h=Subject:To:From:Date:Feedback-ID; b=Hhg+oxNo3eg/7r4ue8/1HRrfM8ydkc7tbbSl9AWUfVlRVcE6SqOD5B9v3IKwIyNok GhNtjACxkV9P33EXl9flfkyuARkFJBq1HXN3pDNRu5iUsZmAs0kwlfAQCgTVNzDThZ G5U/1cDzwTVZnxQrFhz9vaTA3UZt9njvtmqL6jqs= To: Honnappa Nagarahalli , Qiaobin Fu , "bruce.richardson@intel.com" , "pablo.de.lara.guarch@intel.com" Cc: "dev@dpdk.org" , "doucette@bu.edu" , "keith.wiles@intel.com" , "sameh.gobriel@intel.com" , "charlie.tai@intel.com" , "stephen@networkplumber.org" , nd , "yipeng1.wang@intel.com" References: <20180831165101.20026-1-qiaobinf@bu.edu> From: Michel Machado Organization: Digirati Internet LTDA. Message-ID: <8ff2d6be-df5b-51cb-95e9-f227127b7d45@digirati.com.br> Date: Tue, 4 Sep 2018 15:36:54 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-HN-S: bWljaGVsQGRpZ2lyYXRpLmNvbS5icg== X-HN-R: eWlwZW5nMS53YW5nQGludGVsLmNvbSxuZEBhcm0uY29tLHN0ZXBoZW5AbmV0d29ya3BsdW1iZXIub3JnLGNoYXJsaWUudGFpQGludGVsLmNvbSxzYW1laC5nb2JyaWVsQGludGVsLmNvbSxrZWl0aC53aWxlc0BpbnRlbC5jb20sZG91Y2V0dGVAYnUuZWR1LGRldkBkcGRrLm9yZyxwYWJsby5kZS5sYXJhLmd1YXJjaEBpbnRlbC5jb20sYnJ1Y2UucmljaGFyZHNvbkBpbnRlbC5jb20scWlhb2JpbmZAYnUuZWR1LEhvbm5hcHBhLk5hZ2FyYWhhbGxpQGFybS5jb20= Feedback-ID: MjAxODA5MDQ=:bWljaGVsQGRpZ2lyYXRpLmNvbS5icg==:ZGlnaXJhdGkuY29tLmJy:k8networks X-Mailman-Approved-At: Thu, 06 Sep 2018 15:08:09 +0200 Subject: Re: [dpdk-dev] [PATCH v3] hash table: add an iterator over conflicting entries X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Sep 2018 19:37:10 -0000 Hi Honnappa, On 09/02/2018 06:05 PM, Honnappa Nagarahalli wrote: > +/* istate stands for internal state. */ struct rte_hash_iterator_istate > +{ > + const struct rte_hash *h; > This can be outside of this structure. This will help keep the API definitions consistent with existing APIs. Please see further comments below. Discussed later. > + uint32_t next; > + uint32_t total_entries; > +}; > This structure can be moved to rte_cuckoo_hash.h file. What's the purpose of moving this struct to a header file since it's only used in the C file rte_cuckoo_hash.c? > +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? > int32_t > -rte_hash_iterate(const struct rte_hash *h, const void **key, void **data, uint32_t *next) > +rte_hash_iterate( > + struct rte_hash_iterator_state *state, const void **key, void **data) > > IMO, as suggested above, do not store 'struct rte_hash *h' in 'struct rte_hash_iterator_state'. Instead, change the API definition as follows: > rte_hash_iterate(const struct rte_hash *h, const void **key, void **data, struct rte_hash_iterator_state *state) > > This will help keep the API signature consistent with existing APIs. > > This is an ABI change. Please take a look at https://doc.dpdk.org/guides/contributing/versioning.html. The ABI will change in a way or another, so why not going for a single state instead of requiring parameters that are already needed for the initialization of the state? Thank you for the link. We'll check how to proceed with the ABI change. > { > + struct rte_hash_iterator_istate *__state; > '__state' can be replaced with 's'. Gaƫtan Rivet has already pointed this out in his review of this version of our patch. > uint32_t bucket_idx, idx, position; > struct rte_hash_key *next_key; > > - RETURN_IF_TRUE(((h == NULL) || (next == NULL)), -EINVAL); > + RETURN_IF_TRUE(((state == NULL) || (key == NULL) || > + (data == NULL)), -EINVAL); > + > + __state = (struct rte_hash_iterator_istate *)state; > > - const uint32_t total_entries = h->num_buckets * RTE_HASH_BUCKET_ENTRIES; > /* Out of bounds */ > - if (*next >= total_entries) > + if (__state->next >= __state->total_entries) > return -ENOENT; > > 'if (__state->next == 0)' is required to avoid creating 'rte_hash_iterator_init' API. The argument to keep _init() is presented above in this email. > /* Calculate bucket and index of current iterator */ > - bucket_idx = *next / RTE_HASH_BUCKET_ENTRIES; > - idx = *next % RTE_HASH_BUCKET_ENTRIES; > + bucket_idx = __state->next / RTE_HASH_BUCKET_ENTRIES; > + idx = __state->next % RTE_HASH_BUCKET_ENTRIES; > > /* If current position is empty, go to the next one */ > - while (h->buckets[bucket_idx].key_idx[idx] == EMPTY_SLOT) { > - (*next)++; > + while (__state->h->buckets[bucket_idx].key_idx[idx] == EMPTY_SLOT) { > + __state->next++; > /* End of table */ > - if (*next == total_entries) > + if (__state->next == __state->total_entries) > return -ENOENT; > - bucket_idx = *next / RTE_HASH_BUCKET_ENTRIES; > - idx = *next % RTE_HASH_BUCKET_ENTRIES; > + bucket_idx = __state->next / RTE_HASH_BUCKET_ENTRIES; > + idx = __state->next % RTE_HASH_BUCKET_ENTRIES; > } > - __hash_rw_reader_lock(h); > + __hash_rw_reader_lock(__state->h); > /* Get position of entry in key table */ > - position = h->buckets[bucket_idx].key_idx[idx]; > - next_key = (struct rte_hash_key *) ((char *)h->key_store + > - position * h->key_entry_size); > + position = __state->h->buckets[bucket_idx].key_idx[idx]; > + next_key = (struct rte_hash_key *) ((char *)__state->h->key_store + > + position * __state->h->key_entry_size); > /* Return key and data */ > *key = next_key->key; > *data = next_key->pdata; > > - __hash_rw_reader_unlock(h); > + __hash_rw_reader_unlock(__state->h); > > /* Increment iterator */ > - (*next)++; > + __state->next++; > This comment is not related to this change, it is better to place this inside the lock. Even though __state->next does not depend on the lock? > return position - 1; > } > + > +/* istate stands for internal state. */ struct > +rte_hash_iterator_conflict_entries_istate { > + const struct rte_hash *h; > This can be moved outside of this structure. Discussed earlier. > + uint32_t vnext; > + uint32_t primary_bidx; > + uint32_t secondary_bidx; > +}; > + > +int32_t __rte_experimental > +rte_hash_iterator_conflict_entries_init_with_hash(const struct rte_hash *h, > + hash_sig_t sig, struct rte_hash_iterator_state *state) { > + struct rte_hash_iterator_conflict_entries_istate *__state; > + > + RETURN_IF_TRUE(((h == NULL) || (state == NULL)), -EINVAL); > + > + __state = (struct rte_hash_iterator_conflict_entries_istate *)state; > + __state->h = h; > + __state->vnext = 0; > + > + /* Get the primary bucket index given the precomputed hash value. */ > + __state->primary_bidx = sig & h->bucket_bitmask; > + /* Get the secondary bucket index given the precomputed hash value. */ > + __state->secondary_bidx = > + rte_hash_secondary_hash(sig) & h->bucket_bitmask; > + > + return 0; > +} > IMO, as mentioned above, it is possible to avoid creating this API. Discussed earlier. > + > +int32_t __rte_experimental > +rte_hash_iterate_conflict_entries( > + struct rte_hash_iterator_state *state, const void **key, void **data) > Signature of this API can be changed as follows: > rte_hash_iterate_conflict_entries( > struct rte_hash *h, const void **key, void **data, struct rte_hash_iterator_state *state) Discussed earlier. > +{ > + struct rte_hash_iterator_conflict_entries_istate *__state; > + > + RETURN_IF_TRUE(((state == NULL) || (key == NULL) || > + (data == NULL)), -EINVAL); > + > + __state = (struct rte_hash_iterator_conflict_entries_istate *)state; > + > + while (__state->vnext < RTE_HASH_BUCKET_ENTRIES * 2) { > + uint32_t bidx = __state->vnext < RTE_HASH_BUCKET_ENTRIES ? > + __state->primary_bidx : __state->secondary_bidx; > + uint32_t next = __state->vnext & (RTE_HASH_BUCKET_ENTRIES - 1); > > take the reader lock before reading bucket entry Thanks for pointing this out. We are going to do so. The lock came in as we go through the versions of this patch. > + uint32_t position = __state->h->buckets[bidx].key_idx[next]; > + struct rte_hash_key *next_key; > + > + /* Increment iterator. */ > + __state->vnext++; > + > + /* > + * The test below is unlikely because this iterator is meant > + * to be used after a failed insert. > + */ > + if (unlikely(position == EMPTY_SLOT)) > + continue; > + > + /* Get the entry in key table. */ > + next_key = (struct rte_hash_key *) ( > + (char *)__state->h->key_store + > + position * __state->h->key_entry_size); > + /* Return key and data. */ > + *key = next_key->key; > + *data = next_key->pdata; > give the reader lock We'll do so. > + > + return position - 1; > + } > + > + return -ENOENT; > +} > 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 > #include > > +#include > + > #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. [ ]'s Michel Machado