Improvements over rte hash and tests
cover Improvements over rte hash and tests
This patch set depends on another rte hash patch set:
http://patchwork.dpdk.org/cover/46106/
This patch set includes three commits to improve rte_hash and its unit tests.
1. Remove unnecessary pause code in rte_reset function. 2 and 3. Improve the unit test.
Yipeng Wang (3):
hash: fix unnecessary pause
test/hash: change multiwriter test to use jhash
test/hash: add readwrite test for ext table
lib/librte_hash/rte_cuckoo_hash.c | 6 ++-- test/test/test_hash_multiwriter.c | 15 ++++++--- test/test/test_hash_readwrite.c | 70 ++++++++++++++++++++++++++++++++------- 3 files changed, 71 insertions(+), 20 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/3 hash: fix unnecessary pause
There is a rte_pause in hash table reset function. Since the loop is not a polling loop on shared data structure, the rte_pause is not needed.
--- lib/librte_hash/rte_cuckoo_hash.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/librte_hash/rte_cuckoo_hash.c +2 -2
@@ -521,14 +521,14 @@ rte_hash_reset(struct rte_hash *h)/* clear the free ring */ while (rte_ring_dequeue (h->free_slots, &ptr) ==0 ) -rte_pause (); +continue ;/* clear free extendable bucket ring and memory */ if (h->ext_table_support) {memset (h->buckets_ext,0 , h->num_buckets *sizeof (struct rte_hash_bucket ));while (rte_ring_dequeue (h->free_ext_bkts, &ptr) ==0 ) -rte_pause (); +continue ; }/* Repopulate the free slots ring. Entry zero is reserved for key misses */
Signature · 1 line
2.7.4
PATCH 2/3 test/hash: change multiwriter test to use jhash
In reply to Yipeng WangWith sequential key, the test will cover more corner cases with jhash instead of crc hash, since jhash generates more random hash pattern on sequential key. It is useful for functional verification.
--- test/test/test_hash_multiwriter.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
test/test/test_hash_multiwriter.c +11 -4
@@ -12,6 +12,7 @@#include <rte_malloc.h> #include <rte_random.h> #include <rte_spinlock.h> +#include <rte_jhash.h> #include "test.h"
@@ -95,7 +96,7 @@ test_hash_multiwriter_worker(void *arg)static int -test_hash_multiwriter (void ) +test_hash_multiwriter (int use_jhash) {unsigned int i, rounded_nb_total_tsx_insertion;static unsigned calledCount =1 ;
@@ -108,10 +109,14 @@ test_hash_multiwriter(void)struct rte_hash_parameters hash_params = { .entries = nb_entries, .key_len =sizeof (uint32_t ), - .hash_func = rte_hash_crc, .hash_func_init_val =0 , .socket_id =rte_socket_id (), }; +if (use_jhash) + hash_params.hash_func = rte_jhash; +else + hash_params.hash_func = rte_hash_crc; +if (use_htm) hash_params.extra_flag =RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT
@@ -259,6 +264,8 @@ test_hash_multiwriter(void)static int test_hash_multiwriter_main (void ) { +int use_jhash =1 ; +if (rte_lcore_count () ==1 ) {printf ("More than one lcore is required to do multiwriter test\n" );return 0 ;
@@ -278,13 +285,13 @@ test_hash_multiwriter_main(void)printf ("Test multi-writer with Hardware transactional memory\n" ); use_htm =1 ; -if (test_hash_multiwriter () <0 ) +if (test_hash_multiwriter (use_jhash) <0 )return -1 ; }printf ("Test multi-writer without Hardware transactional memory\n" ); use_htm =0 ; -if (test_hash_multiwriter () <0 ) +if (test_hash_multiwriter (use_jhash) <0 )return -1 ;return 0 ;
Signature · 1 line
2.7.4
Re: [PATCH v1 2/3] test/hash: change multiwriter test to use jhash
Quoted 10 lines · Yipeng Wang
With sequential key, the test will cover more corner cases with jhash instead of crc hash, since jhash generates more random hash pattern on sequential key. It is useful for functional verification.
Signed-off-by Yipeng Wang <[email protected]>--- test/test/test_hash_multiwriter.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
Looking at the code in the patch, it appears the function is always now called with use_jhash == 1. Why not just do a one-line change to switch the hard-coded crc hash to jhash, rather than hardcoding that later in the file and having a branch with a never-taken leg?
/Bruce
PATCH 3/3 test/hash: add readwrite test for ext table
In reply to Yipeng WangThis commit improves the readwrite test to consider extendable table feature and add more functional tests to cover more corner cases.
--- test/test/test_hash_readwrite.c | 70 ++++++++++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 12 deletions(-)
test/test/test_hash_readwrite.c +58 -12
@@ -21,6 +21,8 @@#define TOTAL_ENTRY (16*1024*1024)#define TOTAL_INSERT (15*1024*1024) +#define TOTAL_INSERT_EXT (16*1024*1024) +#define NUM_TEST 3unsigned int core_cnt[NUM_TEST ] = {2 ,4 ,8 };
@@ -59,8 +61,10 @@ test_hash_readwrite_worker(__attribute__((unused)) void *arg)uint64_t i, offset;uint32_t lcore_id =rte_lcore_id ();uint64_t begin, cycles; -int ret; +int *ret; + ret =rte_malloc (NULL ,sizeof (int ) * + tbl_rw_test_param.num_insert,0 );for (i =0 ; i <rte_lcore_count (); i++) {if (slave_core_ids[i] == lcore_id)break ;
@@ -79,13 +83,30 @@ test_hash_readwrite_worker(__attribute__((unused)) void *arg) tbl_rw_test_param.keys + i) > 0)break ; - ret =rte_hash_add_key (tbl_rw_test_param.h, + ret[i - offset] =rte_hash_add_key (tbl_rw_test_param.h, tbl_rw_test_param.keys + i); -if (ret <0 ) +if (ret[i - offset] <0 ) +break ; + +/* lookup a random key */ +uint32_t rand =rte_rand () % (i +1 - offset); + +if (rte_hash_lookup (tbl_rw_test_param.h, + tbl_rw_test_param.keys + rand) != ret[rand]) +break ; + + +if (rte_hash_del_key (tbl_rw_test_param.h, + tbl_rw_test_param.keys + rand) != ret[rand]) +break ; + + ret[rand] =rte_hash_add_key (tbl_rw_test_param.h, + tbl_rw_test_param.keys + rand); +if (ret[rand] <0 )break ;if (rte_hash_lookup (tbl_rw_test_param.h, - tbl_rw_test_param.keys + i) != ret) + tbl_rw_test_param.keys + rand) != ret[rand])break ; }
@@ -100,7 +121,7 @@ test_hash_readwrite_worker(__attribute__((unused)) void *arg) }static int -init_params (int use_htm,int use_jhash) +init_params (int use_ext,int use_htm,int use_jhash) {unsigned int i;
@@ -127,6 +148,13 @@ init_params(int use_htm, int use_jhash) hash_params.extra_flag =RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY ; +if (use_ext) + hash_params.extra_flag |= +RTE_HASH_EXTRA_FLAGS_EXT_TABLE ; +else + hash_params.extra_flag &= + ~RTE_HASH_EXTRA_FLAGS_EXT_TABLE ; + hash_params.name ="tests" ; handle =rte_hash_create (&hash_params);
@@ -165,7 +193,7 @@ init_params(int use_htm, int use_jhash) }static int -test_hash_readwrite_functional (int use_htm) +test_hash_readwrite_functional (int use_ext,int use_htm) {unsigned int i;const void *next_key;
@@ -176,6 +204,7 @@ test_hash_readwrite_functional(int use_htm)uint32_t lost_keys =0 ;int use_jhash =1 ;int slave_cnt =rte_lcore_count () -1 ; +uint32_t tot_insert =0 ;rte_atomic64_init (&gcycles);rte_atomic64_clear (&gcycles);
@@ -183,11 +212,16 @@ test_hash_readwrite_functional(int use_htm)rte_atomic64_init (&ginsertions);rte_atomic64_clear (&ginsertions); -if (init_params (use_htm, use_jhash) !=0 ) +if (init_params (use_ext, use_htm, use_jhash) !=0 ) goto err; +if (use_ext) + tot_insert =TOTAL_INSERT_EXT ; +else + tot_insert =TOTAL_INSERT ; + tbl_rw_test_param.num_insert = -TOTAL_INSERT / slave_cnt; + tot_insert / slave_cnt; tbl_rw_test_param.rounded_tot_insert = tbl_rw_test_param.num_insert
@@ -343,7 +377,7 @@ test_hash_readwrite_perf(struct perf *perf_results, int use_htm,rte_atomic64_init (&gwrite_cycles);rte_atomic64_clear (&gwrite_cycles); -if (init_params (use_htm, use_jhash) !=0 ) +if (init_params (0 , use_htm, use_jhash) !=0 ) goto err;/*
@@ -577,7 +611,7 @@ test_hash_readwrite_main(void)* than writer threads. This is to timing either reader threads or * writer threads for performance numbers. */ -int use_htm, reader_faster; +int use_htm, use_ext, reader_faster;unsigned int i =0 , core_id =0 ;if (rte_lcore_count () <=2 ) {
@@ -600,7 +634,13 @@ test_hash_readwrite_main(void)printf ("Test read-write with Hardware transactional memory\n" ); use_htm =1 ; -if (test_hash_readwrite_functional (use_htm) <0 ) + use_ext =0 ; + +if (test_hash_readwrite_functional (use_ext, use_htm) <0 ) +return -1 ; + + use_ext =1 ; +if (test_hash_readwrite_functional (use_ext, use_htm) <0 )return -1 ; reader_faster =1 ;
@@ -619,8 +659,14 @@ test_hash_readwrite_main(void)printf ("Test read-write without Hardware transactional memory\n" ); use_htm =0 ; -if (test_hash_readwrite_functional (use_htm) <0 ) + use_ext =0 ; +if (test_hash_readwrite_functional (use_ext, use_htm) <0 )return -1 ; + + use_ext =1 ; +if (test_hash_readwrite_functional (use_ext, use_htm) <0 ) +return -1 ; + reader_faster =1 ;if (test_hash_readwrite_perf (&non_htm_results, use_htm, reader_faster) <0 )
Signature · 1 line
2.7.4
Re: [PATCH v1 3/3] test/hash: add readwrite test for ext table
Quoted 8 lines · Yipeng Wang
This commit improves the readwrite test to consider extendable table feature and add more functional tests to cover more corner cases.
Signed-off-by Yipeng Wang <[email protected]> ---
test/test/test_hash_readwrite.c| 70 ++++++++++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 12 deletions(-)
With the extension of this test case, and the addition of other test cases by Honnappa in the other patch sets in this release, we are building up quite a large set of hash table autotests, some of whose meaning and use is a bit obscure. Are there any hash tests that you feel could be removed at this point, to simplify things?
/Bruce
Re: [PATCH v1 3/3] test/hash: add readwrite test for ext table
Thanks for the comment Bruce,
I agree with you. As I think about it, I believe the old scaling test can be removed since currently the multiwriter is supported inside the library, and we already have the multiwriter test.
I will post a V2 version of this patch series to remove that test.
Quoted 23 lines
-----Original Message-----
From: Richardson, Bruce
Sent: Wednesday, October 24, 2018 1:37 PM
To: Wang, Yipeng1 <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Gobriel, Sameh <[email protected]>
Subject: Re: [PATCH v1 3/3] test/hash: add readwrite test for ext tableQuoted 8 lines · Yipeng Wang
This commit improves the readwrite test to consider extendable table feature and add more functional tests to cover more corner cases.
Signed-off-by Yipeng Wang <[email protected]> ---
test/test/test_hash_readwrite.c| 70 ++++++++++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 12 deletions(-)With the extension of this test case, and the addition of other test cases by Honnappa in the other patch sets in this release, we are building up quite a large set of hash table autotests, some of whose meaning and use is a bit obscure. Are there any hash tests that you feel could be removed at this point, to simplify things?
/Bruce
Re: [PATCH v1 3/3] test/hash: add readwrite test for ext table
In reply to Bruce RichardsonQuoted 10 lines · Yipeng Wang
Quoted 8 lines
This commit improves the readwrite test to consider extendable table feature and add more functional tests to cover more corner cases.
Signed-off-by Yipeng Wang <[email protected]> ---
test/test/test_hash_readwrite.c| 70 ++++++++++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 12 deletions(-)
Quoted 6 lines
With the extension of this test case, and the addition of other test cases by Honnappa in the other patch sets in this release, we are building up quite a large set of hash table autotests, some of whose meaning and use is a bit obscure. Are there any hash tests that you feel could be removed at this point, to simplify things?
(this comment does not apply to this patch)
Looks like your concern is about maintenance of the test code.
IMO, we need to reduce the number of configuration flags in this library which should reduce the number of test cases.
The flags I think that are not necessary are:RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT - The tests prove that this gives significant performance boost. IMO, if the platform supports it, it should be enabled without user consent (I am not an expert on TSX). RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY - Most use cases require this support. Only use case where this is not required is a single thread doing both inserts and lookups. Even if such a use case is valid, the lock over head should be small.
Quoted 1 line
/Bruce
Re: [PATCH v1 3/3] test/hash: add readwrite test for ext table
Quoted 16 lines · Honnappa Nagarahalli
Quoted 10 lines · Yipeng Wang
Quoted 8 lines
This commit improves the readwrite test to consider extendable table feature and add more functional tests to cover more corner cases.
Signed-off-by Yipeng Wang <[email protected]> ---
test/test/test_hash_readwrite.c| 70 ++++++++++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 12 deletions(-)Quoted 6 lines
With the extension of this test case, and the addition of other test cases by Honnappa in the other patch sets in this release, we are building up quite a large set of hash table autotests, some of whose meaning and use is a bit obscure. Are there any hash tests that you feel could be removed at this point, to simplify things?
Quoted 7 lines
(this comment does not apply to this patch)
Looks like your concern is about maintenance of the test code.
IMO, we need to reduce the number of configuration flags in this library which should reduce the number of test cases.
The flags I think that are not necessary are:RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT- The tests prove that this gives significant performance boost. IMO, if the platform supports it, it should be enabled without user consent (I am not an expert on TSX).RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY- Most use cases require this support. Only use case where this is not required is a single thread doing both inserts and lookups. Even if such a use case is valid, the lock over head should be small.
I agree with the idea. What I suggest is that only a single flag should be needed, and that only for the uncommon case, i.e. where we do not need any locking of the hash-table. Otherwise the hash should be thread safe by default and using the most effective locking mechanism for the platform.
Unfortunately, doing this requires an ABI change, but since it only should affect the create function, it should be doable with function versioning to keep backward compatibility.
/Bruce
Re: [PATCH v1 3/3] test/hash: add readwrite test for ext table
Quoted 24 lines
Quoted 15 lines
Quoted 9 lines · Yipeng Wang
Quoted 8 lines
This commit improves the readwrite test to consider extendable table feature and add more functional tests to cover more corner cases.
Signed-off-by Yipeng Wang <[email protected]> ---
test/test/test_hash_readwrite.c| 70 ++++++++++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 12 deletions(-)Quoted 6 lines
With the extension of this test case, and the addition of other test cases by Honnappa in the other patch sets in this release, we are building up quite a large set of hash table autotests, some of whose meaning and use is a bit obscure. Are there any hash tests that you feel could be removed at this point, to simplify things?
Quoted 3 lines
(this comment does not apply to this patch) Looks like your concern is about maintenance of the test code.
IMO, we need to reduce the number of configuration flags in this librarywhich should reduce the number of test cases.
Quoted 2 lines
The flags I think that are not necessary are:
RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT- The tests prove thatthis gives significant performance boost. IMO, if the platform supports it, it should be enabled without user consent (I am not an expert on TSX).
Quoted 1 line
RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY- Most use cases require this
Quoted 9 lines
support. Only use case where this is not required is a single thread doing both inserts and lookups. Even if such a use case is valid, the lock over head should be small.
Quoted 1 line
I agree with the idea. What I suggest is that only a single flag should be needed, and that only for the uncommon case, i.e. where we do not need any locking of the hash-table. Otherwise the hash should be thread safe by default and using the most effective locking mechanism for the platform.
RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF - should take care of this.
Quoted 4 lines
Unfortunately, doing this requires an ABI change, but since it only should affect the create function, it should be doable with function versioning to keep backward compatibility.
Looks simple enough. Version the rte_hash_create function and map the existing function to 18.08. The new version of the function will always enable hw_trans_mem_support and rw_concurrency. Should we check to see if these flags are set by the user and print a warning message about deprecation of these flags in the newer version of the function?
Quoted 1 line
/Bruce
Re: [PATCH v1 3/3] test/hash: add readwrite test for ext table
In reply to Bruce RichardsonQuoted 30 lines · Honnappa Nagarahalli
Quoted 16 lines
Quoted 10 lines · Yipeng Wang
Quoted 8 lines
This commit improves the readwrite test to consider extendable table feature and add more functional tests to cover more corner cases.
Signed-off-by Yipeng Wang <[email protected]> ---
test/test/test_hash_readwrite.c| 70 ++++++++++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 12 deletions(-)Quoted 6 lines
With the extension of this test case, and the addition of other test cases by Honnappa in the other patch sets in this release, we are building up quite a large set of hash table autotests, some of whose meaning and use is a bit obscure. Are there any hash tests that you feel could be removed at this point, to simplify things?
Quoted 3 lines
(this comment does not apply to this patch) Looks like your concern is about maintenance of the test code.
IMO, we need to reduce the number of configuration flags in this librarywhich should reduce the number of test cases.
Quoted 2 lines
The flags I think that are not necessary are:
RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT- The tests prove thatthis gives significant performance boost. IMO, if the platform supports it, it should be enabled without user consent (I am not an expert on TSX).
Quoted 1 line
RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY- Most use cases require thissupport. Only use case where this is not required is a single thread doing both inserts and lookups. Even if such a use case is valid, the lock over head should be small.
Quoted 1 line
Quoted 9 lines
I agree with the idea. What I suggest is that only a single flag should be needed, and that only for the uncommon case, i.e. where we do not need any locking of the hash-table. Otherwise the hash should be thread safe by default and using the most effective locking mechanism for the platform.
Unfortunately, doing this requires an ABI change, but since it only should affect the create function, it should be doable with function versioning to keep backward compatibility.
I have made the changes. It seems to be working fine. I will post it once internal review completes.
We made this change (SHA: 9d033dac7d7cacca9559e0381f99b4c730e80979) to support 'no free on delete'. This was done by introducing another configuration flag 'RTE_HASH_EXTRA_FLAGS_NO_FREE_ON_DEL'. IMO, it makes sense to keep delete and free as two different operations always and deprecate 'free during delete' support. We can provide backward compatibility by making ABI change instead of introducing another configuration flag.
Quoted 1 line
/Bruce
cover hash: deprecate lock ellision and read/write concurreny flags
In reply to Yipeng WangVarious configuration flags in rte_hash library result in increase of number of test cases. Configuration flags for enabling transactional memory use and read/write concurrency are not required. These features should be supported by default. Please refer to [1] for more context.
This patch marks these flags for deprecation in 19.02 release and cleans up the test cases.
[1] http://mails.dpdk.org/archives/dev/2018-October/117268.html
Honnappa Nagarahalli (3):
hash: deprecate lock ellision and read/write concurreny flags test/hash: stop using lock ellision and read/write concurreny flags doc/hash: deprecate lock ellision and read/write concurreny flags
doc/guides/rel_notes/deprecation.rst | 5 + lib/librte_hash/rte_cuckoo_hash.c | 319 ++++++++++++++++++++++++++- lib/librte_hash/rte_hash.h | 20 +- lib/librte_hash/rte_hash_version.map | 7 + test/test/test_hash_multiwriter.c | 20 +- test/test/test_hash_perf.c | 40 ++-- test/test/test_hash_readwrite.c | 84 ++----- test/test/test_hash_readwrite_lf.c | 189 ++++------------ 8 files changed, 430 insertions(+), 254 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/3 hash: deprecate lock ellision and read/write concurreny flags
Hash library should provide read/write concurrency by default as most of the use cases require read/write concurrency. Hence the flag RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY is deprecated. The library will decide if locking is required to provide the concurrency based on other configuration flags.
If a lock is used to provide the read/write concurrency, best possible locking mechanism available on the platform should be used. Hence, the flag RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT is deprecated. The library will use transactional memory if the platform supports it.
--- lib/librte_hash/rte_cuckoo_hash.c | 319 ++++++++++++++++++++++++++- lib/librte_hash/rte_hash.h | 22 +- lib/librte_hash/rte_hash_version.map | 7 + 3 files changed, 345 insertions(+), 3 deletions(-)
lib/librte_hash/rte_cuckoo_hash.c +318 -1
@@ -121,7 +121,7 @@ get_alt_bucket_index(const struct rte_hash *h, }struct rte_hash * -rte_hash_create (const struct rte_hash_parameters *params) +rte_hash_create_v20 (const struct rte_hash_parameters *params) {struct rte_hash *h =NULL ;struct rte_tailq_entry *te =NULL ;
@@ -446,6 +446,323 @@ rte_hash_create(const struct rte_hash_parameters *params)rte_free (tbl_chng_cnt);return NULL ; } +VERSION_SYMBOL (rte_hash_create, _v20,2.0 ); + +struct rte_hash * +rte_hash_create_v1811 (const struct rte_hash_parameters *params) +{ +struct rte_hash *h =NULL ; +struct rte_tailq_entry *te =NULL ; +struct rte_hash_list *hash_list; +struct rte_ring *r =NULL ; +struct rte_ring *r_ext =NULL ; +char hash_name[RTE_HASH_NAMESIZE ]; +void *k =NULL ; +void *buckets =NULL ; +void *buckets_ext =NULL ; +char ring_name[RTE_RING_NAMESIZE ]; +char ext_ring_name[RTE_RING_NAMESIZE ]; +unsigned num_key_slots; +unsigned i; +unsigned int use_local_cache =0 ; +unsigned int ext_table_support =0 ; +unsigned int readwrite_concur_support =1 ; +unsigned int writer_takes_lock =1 ; +unsigned int no_free_on_del =0 ; +uint32_t *tbl_chng_cnt =NULL ; +unsigned int readwrite_concur_lf_support =0 ; + +rte_hash_function default_hash_func = (rte_hash_function )rte_jhash; + + hash_list =RTE_TAILQ_CAST (rte_hash_tailq.head, rte_hash_list); + +if (params ==NULL ) { +RTE_LOG (ERR ,HASH ,"rte_hash_create has no parameters\n" ); +return NULL ; + } + +/* Check for valid parameters */ +if ((params->entries >RTE_HASH_ENTRIES_MAX ) || + (params->entries <RTE_HASH_BUCKET_ENTRIES ) || + (params->key_len ==0 )) { + rte_errno =EINVAL ; +RTE_LOG (ERR ,HASH ,"rte_hash_create has invalid parameters\n" ); +return NULL ; + } + +/* Validate correct usage of extra options */ +if ((params->extra_flag &RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF ) && + (params->extra_flag &RTE_HASH_EXTRA_FLAGS_EXT_TABLE )) { + rte_errno =EINVAL ; +RTE_LOG (ERR ,HASH ,"rte_hash_create: extendable bucket " +"feature not supported with rw concurrency " +"lock free\n" ); +return NULL ; + } + +/* Check extra flags field to check extra options. */ +if (params->extra_flag &RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD ) + use_local_cache =1 ; + +if (params->extra_flag &RTE_HASH_EXTRA_FLAGS_EXT_TABLE ) + ext_table_support =1 ; + +if (params->extra_flag &RTE_HASH_EXTRA_FLAGS_NO_FREE_ON_DEL ) + no_free_on_del =1 ; + +if (params->extra_flag &RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF ) { +/* Do not use lock for RW concurrency */ + readwrite_concur_support =0 ; + readwrite_concur_lf_support =1 ; +/* Enable not freeing internal memory/index on delete */ + no_free_on_del =1 ; + } + +if ((params->extra_flag &RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF ) && + !(params->extra_flag &RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD )) + writer_takes_lock =0 ; + +/* Store all keys and leave the first entry as a dummy entry for lookup_bulk */ +if (use_local_cache) +/* +* Increase number of slots by total number of indices +* that can be stored in the lcore caches +* except for the first cache +*/ + num_key_slots = params->entries + (RTE_MAX_LCORE -1 ) * + (LCORE_CACHE_SIZE -1 ) +1 ; +else + num_key_slots = params->entries +1 ; + +snprintf (ring_name,sizeof (ring_name),"HT_%s" , params->name); +/* Create ring (Dummy slot index is not enqueued) */ + r =rte_ring_create (ring_name,rte_align32pow2 (num_key_slots), + params->socket_id,0 ); +if (r ==NULL ) { +RTE_LOG (ERR ,HASH ,"memory allocation failed\n" ); + goto err; + } + +const uint32_t num_buckets =rte_align32pow2 (params->entries) / +RTE_HASH_BUCKET_ENTRIES ; + +/* Create ring for extendable buckets. */ +if (ext_table_support) { +snprintf (ext_ring_name,sizeof (ext_ring_name),"HT_EXT_%s" , + params->name); + r_ext =rte_ring_create (ext_ring_name, +rte_align32pow2 (num_buckets +1 ), + params->socket_id,0 ); + +if (r_ext ==NULL ) { +RTE_LOG (ERR ,HASH ,"ext buckets memory allocation " +"failed\n" ); + goto err; + } + } + +snprintf (hash_name,sizeof (hash_name),"HT_%s" , params->name); + +rte_rwlock_write_lock (RTE_EAL_TAILQ_RWLOCK ); + +/* guarantee there's no existing: this is normally already checked +* by ring creation above */ + TAILQ_FOREACH(te, hash_list, next) { + h = (struct rte_hash *) te->data; +if (strncmp (params->name, h->name,RTE_HASH_NAMESIZE ) ==0 ) +break ; + } + h =NULL ; +if (te !=NULL ) { + rte_errno =EEXIST ; + te =NULL ; + goto err_unlock; + } + + te =rte_zmalloc ("HASH_TAILQ_ENTRY" ,sizeof (*te),0 ); +if (te ==NULL ) { +RTE_LOG (ERR ,HASH ,"tailq entry allocation failed\n" ); + goto err_unlock; + } + + h = (struct rte_hash *)rte_zmalloc_socket (hash_name,sizeof (struct rte_hash ), +RTE_CACHE_LINE_SIZE , params->socket_id); + +if (h ==NULL ) { +RTE_LOG (ERR ,HASH ,"memory allocation failed\n" ); + goto err_unlock; + } + + buckets =rte_zmalloc_socket (NULL , + num_buckets *sizeof (struct rte_hash_bucket ), +RTE_CACHE_LINE_SIZE , params->socket_id); + +if (buckets ==NULL ) { +RTE_LOG (ERR ,HASH ,"buckets memory allocation failed\n" ); + goto err_unlock; + } + +/* Allocate same number of extendable buckets */ +if (ext_table_support) { + buckets_ext =rte_zmalloc_socket (NULL , + num_buckets *sizeof (struct rte_hash_bucket ), +RTE_CACHE_LINE_SIZE , params->socket_id); +if (buckets_ext ==NULL ) { +RTE_LOG (ERR ,HASH ,"ext buckets memory allocation " +"failed\n" ); + goto err_unlock; + } +/* Populate ext bkt ring. We reserve 0 similar to the +* key-data slot, just in case in future we want to +* use bucket index for the linked list and 0 means NULL +* for next bucket +*/ +for (i =1 ; i <= num_buckets; i++) +rte_ring_sp_enqueue (r_ext, (void *)((uintptr_t ) i)); + } + +const uint32_t key_entry_size = +RTE_ALIGN (sizeof (struct rte_hash_key ) + params->key_len, +KEY_ALIGNMENT ); +const uint64_t key_tbl_size = (uint64_t ) key_entry_size * num_key_slots; + + k =rte_zmalloc_socket (NULL , key_tbl_size, +RTE_CACHE_LINE_SIZE , params->socket_id); + +if (k ==NULL ) { +RTE_LOG (ERR ,HASH ,"memory allocation failed\n" ); + goto err_unlock; + } + + tbl_chng_cnt =rte_zmalloc_socket (NULL ,sizeof (uint32_t ), +RTE_CACHE_LINE_SIZE , params->socket_id); + +if (tbl_chng_cnt ==NULL ) { +RTE_LOG (ERR ,HASH ,"memory allocation failed\n" ); + goto err_unlock; + } + +/* +* If x86 architecture is used, select appropriate compare function, +* which may use x86 intrinsics, otherwise use memcmp +*/ +#if defined(RTE_ARCH_X86 ) || defined(RTE_ARCH_ARM64 ) +/* Select function to compare keys */ +switch (params->key_len) { +case 16 : + h->cmp_jump_table_idx =KEY_16_BYTES ; +break ; +case 32 : + h->cmp_jump_table_idx =KEY_32_BYTES ; +break ; +case 48 : + h->cmp_jump_table_idx =KEY_48_BYTES ; +break ; +case 64 : + h->cmp_jump_table_idx =KEY_64_BYTES ; +break ; +case 80 : + h->cmp_jump_table_idx =KEY_80_BYTES ; +break ; +case 96 : + h->cmp_jump_table_idx =KEY_96_BYTES ; +break ; +case 112 : + h->cmp_jump_table_idx =KEY_112_BYTES ; +break ; +case 128 : + h->cmp_jump_table_idx =KEY_128_BYTES ; +break ; +default : +/* If key is not multiple of 16, use generic memcmp */ + h->cmp_jump_table_idx =KEY_OTHER_BYTES ; + } +#else + h->cmp_jump_table_idx =KEY_OTHER_BYTES ; +#endif + +if (use_local_cache) { + h->local_free_slots =rte_zmalloc_socket (NULL , +sizeof (struct lcore_cache ) *RTE_MAX_LCORE , +RTE_CACHE_LINE_SIZE , params->socket_id); + } + +/* Default hash function */ +#if defined(RTE_ARCH_X86 ) + default_hash_func = (rte_hash_function )rte_hash_crc; +#elif defined(RTE_ARCH_ARM64 ) +if (rte_cpu_get_flag_enabled (RTE_CPUFLAG_CRC32 )) + default_hash_func = (rte_hash_function )rte_hash_crc; +#endif +/* Setup hash context */ +snprintf (h->name,sizeof (h->name),"%s" , params->name); + h->entries = params->entries; + h->key_len = params->key_len; + h->key_entry_size = key_entry_size; + h->hash_func_init_val = params->hash_func_init_val; + + h->num_buckets = num_buckets; + h->bucket_bitmask = h->num_buckets -1 ; + h->buckets = buckets; + h->buckets_ext = buckets_ext; + h->free_ext_bkts = r_ext; + h->hash_func = (params->hash_func ==NULL ) ? + default_hash_func : params->hash_func; + h->key_store = k; + h->free_slots = r; + h->tbl_chng_cnt = tbl_chng_cnt; + *h->tbl_chng_cnt =0 ; + h->hw_trans_mem_support =rte_tm_supported (); + h->use_local_cache = use_local_cache; + h->readwrite_concur_support = readwrite_concur_support; + h->ext_table_support = ext_table_support; + h->writer_takes_lock = writer_takes_lock; + h->no_free_on_del = no_free_on_del; + h->readwrite_concur_lf_support = readwrite_concur_lf_support; + +#if defined(RTE_ARCH_X86 ) +if (rte_cpu_get_flag_enabled (RTE_CPUFLAG_SSE2 )) + h->sig_cmp_fn =RTE_HASH_COMPARE_SSE ; + else +#endif + h->sig_cmp_fn =RTE_HASH_COMPARE_SCALAR ; + +if (h->writer_takes_lock) { + h->readwrite_lock =rte_malloc (NULL ,sizeof (rte_rwlock_t), +RTE_CACHE_LINE_SIZE ); +if (h->readwrite_lock ==NULL ) + goto err_unlock; + +rte_rwlock_init (h->readwrite_lock); + } + +/* Populate free slots ring. Entry zero is reserved for key misses. */ +for (i =1 ; i < num_key_slots; i++) +rte_ring_sp_enqueue (r, (void *)((uintptr_t ) i)); + + te->data = (void *) h; +TAILQ_INSERT_TAIL (hash_list, te, next); +rte_rwlock_write_unlock (RTE_EAL_TAILQ_RWLOCK ); + +return h; +err_unlock: +rte_rwlock_write_unlock (RTE_EAL_TAILQ_RWLOCK ); +err: +rte_ring_free (r); +rte_ring_free (r_ext); +rte_free (te); +rte_free (h); +rte_free (buckets); +rte_free (buckets_ext); +rte_free (k); +rte_free (tbl_chng_cnt); +return NULL ; +} +BIND_DEFAULT_SYMBOL (rte_hash_create, _v1811,18.11 ); +MAP_STATIC_SYMBOL ( + struct rte_hash *rte_hash_create( +const struct rte_hash_parameters *params), + rte_hash_create_v1811);void rte_hash_free (struct rte_hash *h)
lib/librte_hash/rte_hash.h +20 -2
@@ -30,13 +30,27 @@ extern "C" {#define RTE_HASH_LOOKUP_BULK_MAX 64#define RTE_HASH_LOOKUP_MULTI_MAX RTE_HASH_LOOKUP_BULK_MAX -/** Enable Hardware transactional memory support. */ +/** +* @deprecated +* This define will be removed in the next release. +* If the target platform supports hardware transactional memory +* it will be used without user consent as it provides the best possible +* performance. +* +* Enable Hardware transactional memory support. +*/ #define RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT 0x01/** Default behavior of insertion, single writer/multi writer */ #define RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD 0x02 -/** Flag to support reader writer concurrency */ +/** +* @deprecated +* This define will be removed in the next release. +* This library should be thread-safe by default. +* +* Flag to support reader writer concurrency +*/ #define RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY 0x04/** Flag to indicate the extendabe bucket table feature should be used */
@@ -105,6 +119,10 @@ struct rte_hash;*/ struct rte_hash *rte_hash_create (const struct rte_hash_parameters *params); +struct rte_hash * +rte_hash_create_v20 (const struct rte_hash_parameters *params); +struct rte_hash * +rte_hash_create_v1811 (const struct rte_hash_parameters *params);/** * Set a new hash compare function other than the default one.
lib/librte_hash/rte_hash_version.map +7 -0
@@ -54,6 +54,13 @@ DPDK_18.08 { } DPDK_16.07; +DPDK_18.11 { + global: + + rte_hash_create; + +} DPDK_18.08; + EXPERIMENTAL { global:
Signature · 1 line
2.17.1
Re: [PATCH 1/3] hash: deprecate lock ellision and read/write concurreny flags
Quoted 35 lines · Honnappa Nagarahalli
Hash library should provide read/write concurrency by default as most of the use cases require read/write concurrency. Hence the flag
RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCYis deprecated. The library will decide if locking is required to provide the concurrency based on other configuration flags.If a lock is used to provide the read/write concurrency, best possible locking mechanism available on the platform should be used. Hence, the flag
RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORTis deprecated. The library will use transactional memory if the platform supports it.Signed-off-by Honnappa Nagarahalli <[email protected]>Reviewed-by Dharmik Thakkar <[email protected]>Reviewed-by Gavin Hu <[email protected]>--- lib/librte_hash/rte_cuckoo_hash.c | 319 ++++++++++++++++++++++++++- lib/librte_hash/rte_hash.h | 22 +- lib/librte_hash/rte_hash_version.map | 7 + 3 files changed, 345 insertions(+), 3 deletions(-)lib/librte_hash/rte_cuckoo_hash.c +1
-1@@ -121,7 +121,7 @@ get_alt_bucket_index(const struct rte_hash *h, }struct rte_hash * -rte_hash_create (const struct rte_hash_parameters *params) +rte_hash_create_v20 (const struct rte_hash_parameters *params) {struct rte_hash *h =NULL ;struct rte_tailq_entry *te =NULL ;
lib/librte_hash/rte_cuckoo_hash.c rte_hash_create(const struct rte_hash_parameters *params) · line 450
Quoted 5 lines
lib/librte_hash/rte_cuckoo_hash.c +2
-0@@ -446,6 +446,323 @@ rte_hash_create(const struct rte_hash_parameters *params)rte_free (tbl_chng_cnt);return NULL ; } +VERSION_SYMBOL (rte_hash_create, _v20,2.0 ); +
To make reviewing this easier, can I ask if in V2 you can put the v18.11 function first, before the existing one. Hopefully that means that the "new" function from git's point of view is the existing one, showing it as a block add that we can pretty much skip reviewing. The benefit of this is that the changes in the v1811 should then show as line-by-line diffs in the patch, so we can easily review the changes made in the new case. It's hard to spot them in the whole function below.
Quoted 39 lines
lib/librte_hash/rte_cuckoo_hash.c +39
-0+struct rte_hash * +rte_hash_create_v1811 (const struct rte_hash_parameters *params) +{ +struct rte_hash *h =NULL ; +struct rte_tailq_entry *te =NULL ; +struct rte_hash_list *hash_list; +struct rte_ring *r =NULL ; +struct rte_ring *r_ext =NULL ; +char hash_name[RTE_HASH_NAMESIZE ]; +void *k =NULL ; +void *buckets =NULL ; +void *buckets_ext =NULL ; +char ring_name[RTE_RING_NAMESIZE ]; +char ext_ring_name[RTE_RING_NAMESIZE ]; +unsigned num_key_slots; +unsigned i; +unsigned int use_local_cache =0 ; +unsigned int ext_table_support =0 ; +unsigned int readwrite_concur_support =1 ; +unsigned int writer_takes_lock =1 ; +unsigned int no_free_on_del =0 ; +uint32_t *tbl_chng_cnt =NULL ; +unsigned int readwrite_concur_lf_support =0 ; + +rte_hash_function default_hash_func = (rte_hash_function )rte_jhash; + + hash_list =RTE_TAILQ_CAST (rte_hash_tailq.head, rte_hash_list); + +if (params ==NULL ) { +RTE_LOG (ERR ,HASH ,"rte_hash_create has no parameters\n" ); +return NULL ; + } + +/* Check for valid parameters */ +if ((params->entries >RTE_HASH_ENTRIES_MAX ) || + (params->entries <RTE_HASH_BUCKET_ENTRIES ) || + (params->key_len ==0 )) { + rte_errno =EINVAL ; +RTE_LOG (ERR ,HASH ,"rte_hash_create has invalid parameters\n" );
lib/librte_hash/rte_cuckoo_hash.c rte_hash_create(const struct rte_hash_parameters *params) · line 499
Quoted 10 lines
lib/librte_hash/rte_cuckoo_hash.c +10
-0+return NULL ; + } + +/* Validate correct usage of extra options */ +if ((params->extra_flag &RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF ) && + (params->extra_flag &RTE_HASH_EXTRA_FLAGS_EXT_TABLE )) { + rte_errno =EINVAL ; +RTE_LOG (ERR ,HASH ,"rte_hash_create: extendable bucket " +"feature not supported with rw concurrency " +"lock free\n" );
Please don't split the error text across lines. If you put it on a line by itself, hopefully checkpatch should not complain. If checkpatch does complain about the long line, just ignore it!
[Yes, I know this is copied from original code, but since it appears as new code in this patch, we should fix it]
Quoted 292 lines
lib/librte_hash/rte_cuckoo_hash.c +266
-0+return NULL ; + } + +/* Check extra flags field to check extra options. */ +if (params->extra_flag &RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD ) + use_local_cache =1 ; + +if (params->extra_flag &RTE_HASH_EXTRA_FLAGS_EXT_TABLE ) + ext_table_support =1 ; + +if (params->extra_flag &RTE_HASH_EXTRA_FLAGS_NO_FREE_ON_DEL ) + no_free_on_del =1 ; + +if (params->extra_flag &RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF ) { +/* Do not use lock for RW concurrency */ + readwrite_concur_support =0 ; + readwrite_concur_lf_support =1 ; +/* Enable not freeing internal memory/index on delete */ + no_free_on_del =1 ; + } + +if ((params->extra_flag &RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF ) && + !(params->extra_flag &RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD )) + writer_takes_lock =0 ; + +/* Store all keys and leave the first entry as a dummy entry for lookup_bulk */ +if (use_local_cache) +/* +* Increase number of slots by total number of indices +* that can be stored in the lcore caches +* except for the first cache +*/ + num_key_slots = params->entries + (RTE_MAX_LCORE -1 ) * + (LCORE_CACHE_SIZE -1 ) +1 ; +else + num_key_slots = params->entries +1 ; + +snprintf (ring_name,sizeof (ring_name),"HT_%s" , params->name); +/* Create ring (Dummy slot index is not enqueued) */ + r =rte_ring_create (ring_name,rte_align32pow2 (num_key_slots), + params->socket_id,0 ); +if (r ==NULL ) { +RTE_LOG (ERR ,HASH ,"memory allocation failed\n" ); + goto err; + } + +const uint32_t num_buckets =rte_align32pow2 (params->entries) / +RTE_HASH_BUCKET_ENTRIES ; + +/* Create ring for extendable buckets. */ +if (ext_table_support) { +snprintf (ext_ring_name,sizeof (ext_ring_name),"HT_EXT_%s" , + params->name); + r_ext =rte_ring_create (ext_ring_name, +rte_align32pow2 (num_buckets +1 ), + params->socket_id,0 ); + +if (r_ext ==NULL ) { +RTE_LOG (ERR ,HASH ,"ext buckets memory allocation " +"failed\n" ); + goto err; + } + } + +snprintf (hash_name,sizeof (hash_name),"HT_%s" , params->name); + +rte_rwlock_write_lock (RTE_EAL_TAILQ_RWLOCK ); + +/* guarantee there's no existing: this is normally already checked +* by ring creation above */ + TAILQ_FOREACH(te, hash_list, next) { + h = (struct rte_hash *) te->data; +if (strncmp (params->name, h->name,RTE_HASH_NAMESIZE ) ==0 ) +break ; + } + h =NULL ; +if (te !=NULL ) { + rte_errno =EEXIST ; + te =NULL ; + goto err_unlock; + } + + te =rte_zmalloc ("HASH_TAILQ_ENTRY" ,sizeof (*te),0 ); +if (te ==NULL ) { +RTE_LOG (ERR ,HASH ,"tailq entry allocation failed\n" ); + goto err_unlock; + } + + h = (struct rte_hash *)rte_zmalloc_socket (hash_name,sizeof (struct rte_hash ), +RTE_CACHE_LINE_SIZE , params->socket_id); + +if (h ==NULL ) { +RTE_LOG (ERR ,HASH ,"memory allocation failed\n" ); + goto err_unlock; + } + + buckets =rte_zmalloc_socket (NULL , + num_buckets *sizeof (struct rte_hash_bucket ), +RTE_CACHE_LINE_SIZE , params->socket_id); + +if (buckets ==NULL ) { +RTE_LOG (ERR ,HASH ,"buckets memory allocation failed\n" ); + goto err_unlock; + } + +/* Allocate same number of extendable buckets */ +if (ext_table_support) { + buckets_ext =rte_zmalloc_socket (NULL , + num_buckets *sizeof (struct rte_hash_bucket ), +RTE_CACHE_LINE_SIZE , params->socket_id); +if (buckets_ext ==NULL ) { +RTE_LOG (ERR ,HASH ,"ext buckets memory allocation " +"failed\n" ); + goto err_unlock; + } +/* Populate ext bkt ring. We reserve 0 similar to the +* key-data slot, just in case in future we want to +* use bucket index for the linked list and 0 means NULL +* for next bucket +*/ +for (i =1 ; i <= num_buckets; i++) +rte_ring_sp_enqueue (r_ext, (void *)((uintptr_t ) i)); + } + +const uint32_t key_entry_size = +RTE_ALIGN (sizeof (struct rte_hash_key ) + params->key_len, +KEY_ALIGNMENT ); +const uint64_t key_tbl_size = (uint64_t ) key_entry_size * num_key_slots; + + k =rte_zmalloc_socket (NULL , key_tbl_size, +RTE_CACHE_LINE_SIZE , params->socket_id); + +if (k ==NULL ) { +RTE_LOG (ERR ,HASH ,"memory allocation failed\n" ); + goto err_unlock; + } + + tbl_chng_cnt =rte_zmalloc_socket (NULL ,sizeof (uint32_t ), +RTE_CACHE_LINE_SIZE , params->socket_id); + +if (tbl_chng_cnt ==NULL ) { +RTE_LOG (ERR ,HASH ,"memory allocation failed\n" ); + goto err_unlock; + } + +/* +* If x86 architecture is used, select appropriate compare function, +* which may use x86 intrinsics, otherwise use memcmp +*/ +#if defined(RTE_ARCH_X86 ) || defined(RTE_ARCH_ARM64 ) +/* Select function to compare keys */ +switch (params->key_len) { +case 16 : + h->cmp_jump_table_idx =KEY_16_BYTES ; +break ; +case 32 : + h->cmp_jump_table_idx =KEY_32_BYTES ; +break ; +case 48 : + h->cmp_jump_table_idx =KEY_48_BYTES ; +break ; +case 64 : + h->cmp_jump_table_idx =KEY_64_BYTES ; +break ; +case 80 : + h->cmp_jump_table_idx =KEY_80_BYTES ; +break ; +case 96 : + h->cmp_jump_table_idx =KEY_96_BYTES ; +break ; +case 112 : + h->cmp_jump_table_idx =KEY_112_BYTES ; +break ; +case 128 : + h->cmp_jump_table_idx =KEY_128_BYTES ; +break ; +default : +/* If key is not multiple of 16, use generic memcmp */ + h->cmp_jump_table_idx =KEY_OTHER_BYTES ; + } +#else + h->cmp_jump_table_idx =KEY_OTHER_BYTES ; +#endif + +if (use_local_cache) { + h->local_free_slots =rte_zmalloc_socket (NULL , +sizeof (struct lcore_cache ) *RTE_MAX_LCORE , +RTE_CACHE_LINE_SIZE , params->socket_id); + } + +/* Default hash function */ +#if defined(RTE_ARCH_X86 ) + default_hash_func = (rte_hash_function )rte_hash_crc; +#elif defined(RTE_ARCH_ARM64 ) +if (rte_cpu_get_flag_enabled (RTE_CPUFLAG_CRC32 )) + default_hash_func = (rte_hash_function )rte_hash_crc; +#endif +/* Setup hash context */ +snprintf (h->name,sizeof (h->name),"%s" , params->name); + h->entries = params->entries; + h->key_len = params->key_len; + h->key_entry_size = key_entry_size; + h->hash_func_init_val = params->hash_func_init_val; + + h->num_buckets = num_buckets; + h->bucket_bitmask = h->num_buckets -1 ; + h->buckets = buckets; + h->buckets_ext = buckets_ext; + h->free_ext_bkts = r_ext; + h->hash_func = (params->hash_func ==NULL ) ? + default_hash_func : params->hash_func; + h->key_store = k; + h->free_slots = r; + h->tbl_chng_cnt = tbl_chng_cnt; + *h->tbl_chng_cnt =0 ; + h->hw_trans_mem_support =rte_tm_supported (); + h->use_local_cache = use_local_cache; + h->readwrite_concur_support = readwrite_concur_support; + h->ext_table_support = ext_table_support; + h->writer_takes_lock = writer_takes_lock; + h->no_free_on_del = no_free_on_del; + h->readwrite_concur_lf_support = readwrite_concur_lf_support; + +#if defined(RTE_ARCH_X86 ) +if (rte_cpu_get_flag_enabled (RTE_CPUFLAG_SSE2 )) + h->sig_cmp_fn =RTE_HASH_COMPARE_SSE ; + else +#endif + h->sig_cmp_fn =RTE_HASH_COMPARE_SCALAR ; + +if (h->writer_takes_lock) { + h->readwrite_lock =rte_malloc (NULL ,sizeof (rte_rwlock_t), +RTE_CACHE_LINE_SIZE ); +if (h->readwrite_lock ==NULL ) + goto err_unlock; + +rte_rwlock_init (h->readwrite_lock); + } + +/* Populate free slots ring. Entry zero is reserved for key misses. */ +for (i =1 ; i < num_key_slots; i++) +rte_ring_sp_enqueue (r, (void *)((uintptr_t ) i)); + + te->data = (void *) h; +TAILQ_INSERT_TAIL (hash_list, te, next); +rte_rwlock_write_unlock (RTE_EAL_TAILQ_RWLOCK ); + +return h; +err_unlock: +rte_rwlock_write_unlock (RTE_EAL_TAILQ_RWLOCK ); +err: +rte_ring_free (r); +rte_ring_free (r_ext); +rte_free (te); +rte_free (h); +rte_free (buckets); +rte_free (buckets_ext); +rte_free (k); +rte_free (tbl_chng_cnt); +return NULL ; +} +BIND_DEFAULT_SYMBOL (rte_hash_create, _v1811,18.11 ); +MAP_STATIC_SYMBOL ( + struct rte_hash *rte_hash_create( +const struct rte_hash_parameters *params), + rte_hash_create_v1811);void rte_hash_free (struct rte_hash *h)lib/librte_hash/rte_hash.h +9
-1@@ -30,13 +30,27 @@ extern "C" {#define RTE_HASH_LOOKUP_BULK_MAX 64#define RTE_HASH_LOOKUP_MULTI_MAX RTE_HASH_LOOKUP_BULK_MAX -/** Enable Hardware transactional memory support. */ +/** +* @deprecated +* This define will be removed in the next release. +* If the target platform supports hardware transactional memory +* it will be used without user consent as it provides the best possible +* performance. +* +* Enable Hardware transactional memory support. +*/ #define RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT 0x01/** Default behavior of insertion, single writer/multi writer */ #define RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD 0x02
lib/librte_hash/rte_hash.h extern "C" { · line 55
Quoted 10 lines
lib/librte_hash/rte_hash.h +7
-1-/** Flag to support reader writer concurrency */ +/** +* @deprecated +* This define will be removed in the next release. +* This library should be thread-safe by default. +* +* Flag to support reader writer concurrency +*/ #define RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY 0x04
Do we not need/want to add some new flags to disable these features, in case there are cases where either RW concurrency, or transaction memory is unwanted?
Quoted 33 lines
lib/librte_hash/rte_hash.h +4
-0/** Flag to indicate the extendabe bucket table feature should be used */ @@ -105,6 +119,10 @@ struct rte_hash;*/ struct rte_hash *rte_hash_create (const struct rte_hash_parameters *params); +struct rte_hash * +rte_hash_create_v20 (const struct rte_hash_parameters *params); +struct rte_hash * +rte_hash_create_v1811 (const struct rte_hash_parameters *params);/** * Set a new hash compare function other than the default one. lib/librte_hash/rte_hash_version.map +7
-0@@ -54,6 +54,13 @@ DPDK_18.08 { } DPDK_16.07; +DPDK_18.11 { + global: + + rte_hash_create; + +} DPDK_18.08; + EXPERIMENTAL { global:Signature · 1 line
2.17.1
Re: [PATCH 1/3] hash: deprecate lock ellision and read/write concurreny flags
Quoted 398 lines · Bruce Richardson
Quoted 35 lines · Honnappa Nagarahalli
Hash library should provide read/write concurrency by default as most of the use cases require read/write concurrency. Hence the flag
RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCYis deprecated. The library will decide if locking is required to provide the concurrency based on other configuration flags.If a lock is used to provide the read/write concurrency, best possible locking mechanism available on the platform should be used. Hence, the flag
RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORTis deprecated. The library will use transactional memory if the platform supports it.Signed-off-by Honnappa Nagarahalli <[email protected]>Reviewed-by Dharmik Thakkar <[email protected]>Reviewed-by Gavin Hu <[email protected]>--- lib/librte_hash/rte_cuckoo_hash.c | 319 ++++++++++++++++++++++++++- lib/librte_hash/rte_hash.h | 22 +- lib/librte_hash/rte_hash_version.map | 7 + 3 files changed, 345 insertions(+), 3 deletions(-)lib/librte_hash/rte_cuckoo_hash.c +1
-1@@ -121,7 +121,7 @@ get_alt_bucket_index(const struct rte_hash *h, }struct rte_hash * -rte_hash_create (const struct rte_hash_parameters *params) +rte_hash_create_v20 (const struct rte_hash_parameters *params) {struct rte_hash *h =NULL ;struct rte_tailq_entry *te =NULL ;lib/librte_hash/rte_cuckoo_hash.c rte_hash_create(const struct rte_hash_parameters *params) · line 450
Quoted 5 lines
lib/librte_hash/rte_cuckoo_hash.c +2
-0@@ -446,6 +446,323 @@ rte_hash_create(const struct rte_hash_parameters *params)rte_free (tbl_chng_cnt);return NULL ; } +VERSION_SYMBOL (rte_hash_create, _v20,2.0 ); +To make reviewing this easier, can I ask if in V2 you can put the v18.11 function first, before the existing one. Hopefully that means that the "new" function from git's point of view is the existing one, showing it as a block add that we can pretty much skip reviewing. The benefit of this is that the changes in the v1811 should then show as line-by-line diffs in the patch, so we can easily review the changes made in the new case. It's hard to spot them in the whole function below.
Quoted 39 lines
lib/librte_hash/rte_cuckoo_hash.c +39
-0+struct rte_hash * +rte_hash_create_v1811 (const struct rte_hash_parameters *params) +{ +struct rte_hash *h =NULL ; +struct rte_tailq_entry *te =NULL ; +struct rte_hash_list *hash_list; +struct rte_ring *r =NULL ; +struct rte_ring *r_ext =NULL ; +char hash_name[RTE_HASH_NAMESIZE ]; +void *k =NULL ; +void *buckets =NULL ; +void *buckets_ext =NULL ; +char ring_name[RTE_RING_NAMESIZE ]; +char ext_ring_name[RTE_RING_NAMESIZE ]; +unsigned num_key_slots; +unsigned i; +unsigned int use_local_cache =0 ; +unsigned int ext_table_support =0 ; +unsigned int readwrite_concur_support =1 ; +unsigned int writer_takes_lock =1 ; +unsigned int no_free_on_del =0 ; +uint32_t *tbl_chng_cnt =NULL ; +unsigned int readwrite_concur_lf_support =0 ; + +rte_hash_function default_hash_func = (rte_hash_function )rte_jhash; + + hash_list =RTE_TAILQ_CAST (rte_hash_tailq.head, rte_hash_list); + +if (params ==NULL ) { +RTE_LOG (ERR ,HASH ,"rte_hash_create has no parameters\n" ); +return NULL ; + } + +/* Check for valid parameters */ +if ((params->entries >RTE_HASH_ENTRIES_MAX ) || + (params->entries <RTE_HASH_BUCKET_ENTRIES ) || + (params->key_len ==0 )) { + rte_errno =EINVAL ; +RTE_LOG (ERR ,HASH ,"rte_hash_create has invalid parameters\n" );lib/librte_hash/rte_cuckoo_hash.c rte_hash_create(const struct rte_hash_parameters *params) · line 499
Quoted 10 lines
lib/librte_hash/rte_cuckoo_hash.c +10
-0+return NULL ; + } + +/* Validate correct usage of extra options */ +if ((params->extra_flag &RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF ) && + (params->extra_flag &RTE_HASH_EXTRA_FLAGS_EXT_TABLE )) { + rte_errno =EINVAL ; +RTE_LOG (ERR ,HASH ,"rte_hash_create: extendable bucket " +"feature not supported with rw concurrency " +"lock free\n" );Please don't split the error text across lines. If you put it on a line by itself, hopefully checkpatch should not complain. If checkpatch does complain about the long line, just ignore it!
[Yes, I know this is copied from original code, but since it appears as new code in this patch, we should fix it]Quoted 292 lines
lib/librte_hash/rte_cuckoo_hash.c +266
-0+return NULL ; + } + +/* Check extra flags field to check extra options. */ +if (params->extra_flag &RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD ) + use_local_cache =1 ; + +if (params->extra_flag &RTE_HASH_EXTRA_FLAGS_EXT_TABLE ) + ext_table_support =1 ; + +if (params->extra_flag &RTE_HASH_EXTRA_FLAGS_NO_FREE_ON_DEL ) + no_free_on_del =1 ; + +if (params->extra_flag &RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF ) { +/* Do not use lock for RW concurrency */ + readwrite_concur_support =0 ; + readwrite_concur_lf_support =1 ; +/* Enable not freeing internal memory/index on delete */ + no_free_on_del =1 ; + } + +if ((params->extra_flag &RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF ) && + !(params->extra_flag &RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD )) + writer_takes_lock =0 ; + +/* Store all keys and leave the first entry as a dummy entry for lookup_bulk */ +if (use_local_cache) +/* +* Increase number of slots by total number of indices +* that can be stored in the lcore caches +* except for the first cache +*/ + num_key_slots = params->entries + (RTE_MAX_LCORE -1 ) * + (LCORE_CACHE_SIZE -1 ) +1 ; +else + num_key_slots = params->entries +1 ; + +snprintf (ring_name,sizeof (ring_name),"HT_%s" , params->name); +/* Create ring (Dummy slot index is not enqueued) */ + r =rte_ring_create (ring_name,rte_align32pow2 (num_key_slots), + params->socket_id,0 ); +if (r ==NULL ) { +RTE_LOG (ERR ,HASH ,"memory allocation failed\n" ); + goto err; + } + +const uint32_t num_buckets =rte_align32pow2 (params->entries) / +RTE_HASH_BUCKET_ENTRIES ; + +/* Create ring for extendable buckets. */ +if (ext_table_support) { +snprintf (ext_ring_name,sizeof (ext_ring_name),"HT_EXT_%s" , + params->name); + r_ext =rte_ring_create (ext_ring_name, +rte_align32pow2 (num_buckets +1 ), + params->socket_id,0 ); + +if (r_ext ==NULL ) { +RTE_LOG (ERR ,HASH ,"ext buckets memory allocation " +"failed\n" ); + goto err; + } + } + +snprintf (hash_name,sizeof (hash_name),"HT_%s" , params->name); + +rte_rwlock_write_lock (RTE_EAL_TAILQ_RWLOCK ); + +/* guarantee there's no existing: this is normally already checked +* by ring creation above */ + TAILQ_FOREACH(te, hash_list, next) { + h = (struct rte_hash *) te->data; +if (strncmp (params->name, h->name,RTE_HASH_NAMESIZE ) ==0 ) +break ; + } + h =NULL ; +if (te !=NULL ) { + rte_errno =EEXIST ; + te =NULL ; + goto err_unlock; + } + + te =rte_zmalloc ("HASH_TAILQ_ENTRY" ,sizeof (*te),0 ); +if (te ==NULL ) { +RTE_LOG (ERR ,HASH ,"tailq entry allocation failed\n" ); + goto err_unlock; + } + + h = (struct rte_hash *)rte_zmalloc_socket (hash_name,sizeof (struct rte_hash ), +RTE_CACHE_LINE_SIZE , params->socket_id); + +if (h ==NULL ) { +RTE_LOG (ERR ,HASH ,"memory allocation failed\n" ); + goto err_unlock; + } + + buckets =rte_zmalloc_socket (NULL , + num_buckets *sizeof (struct rte_hash_bucket ), +RTE_CACHE_LINE_SIZE , params->socket_id); + +if (buckets ==NULL ) { +RTE_LOG (ERR ,HASH ,"buckets memory allocation failed\n" ); + goto err_unlock; + } + +/* Allocate same number of extendable buckets */ +if (ext_table_support) { + buckets_ext =rte_zmalloc_socket (NULL , + num_buckets *sizeof (struct rte_hash_bucket ), +RTE_CACHE_LINE_SIZE , params->socket_id); +if (buckets_ext ==NULL ) { +RTE_LOG (ERR ,HASH ,"ext buckets memory allocation " +"failed\n" ); + goto err_unlock; + } +/* Populate ext bkt ring. We reserve 0 similar to the +* key-data slot, just in case in future we want to +* use bucket index for the linked list and 0 means NULL +* for next bucket +*/ +for (i =1 ; i <= num_buckets; i++) +rte_ring_sp_enqueue (r_ext, (void *)((uintptr_t ) i)); + } + +const uint32_t key_entry_size = +RTE_ALIGN (sizeof (struct rte_hash_key ) + params->key_len, +KEY_ALIGNMENT ); +const uint64_t key_tbl_size = (uint64_t ) key_entry_size * num_key_slots; + + k =rte_zmalloc_socket (NULL , key_tbl_size, +RTE_CACHE_LINE_SIZE , params->socket_id); + +if (k ==NULL ) { +RTE_LOG (ERR ,HASH ,"memory allocation failed\n" ); + goto err_unlock; + } + + tbl_chng_cnt =rte_zmalloc_socket (NULL ,sizeof (uint32_t ), +RTE_CACHE_LINE_SIZE , params->socket_id); + +if (tbl_chng_cnt ==NULL ) { +RTE_LOG (ERR ,HASH ,"memory allocation failed\n" ); + goto err_unlock; + } + +/* +* If x86 architecture is used, select appropriate compare function, +* which may use x86 intrinsics, otherwise use memcmp +*/ +#if defined(RTE_ARCH_X86 ) || defined(RTE_ARCH_ARM64 ) +/* Select function to compare keys */ +switch (params->key_len) { +case 16 : + h->cmp_jump_table_idx =KEY_16_BYTES ; +break ; +case 32 : + h->cmp_jump_table_idx =KEY_32_BYTES ; +break ; +case 48 : + h->cmp_jump_table_idx =KEY_48_BYTES ; +break ; +case 64 : + h->cmp_jump_table_idx =KEY_64_BYTES ; +break ; +case 80 : + h->cmp_jump_table_idx =KEY_80_BYTES ; +break ; +case 96 : + h->cmp_jump_table_idx =KEY_96_BYTES ; +break ; +case 112 : + h->cmp_jump_table_idx =KEY_112_BYTES ; +break ; +case 128 : + h->cmp_jump_table_idx =KEY_128_BYTES ; +break ; +default : +/* If key is not multiple of 16, use generic memcmp */ + h->cmp_jump_table_idx =KEY_OTHER_BYTES ; + } +#else + h->cmp_jump_table_idx =KEY_OTHER_BYTES ; +#endif + +if (use_local_cache) { + h->local_free_slots =rte_zmalloc_socket (NULL , +sizeof (struct lcore_cache ) *RTE_MAX_LCORE , +RTE_CACHE_LINE_SIZE , params->socket_id); + } + +/* Default hash function */ +#if defined(RTE_ARCH_X86 ) + default_hash_func = (rte_hash_function )rte_hash_crc; +#elif defined(RTE_ARCH_ARM64 ) +if (rte_cpu_get_flag_enabled (RTE_CPUFLAG_CRC32 )) + default_hash_func = (rte_hash_function )rte_hash_crc; +#endif +/* Setup hash context */ +snprintf (h->name,sizeof (h->name),"%s" , params->name); + h->entries = params->entries; + h->key_len = params->key_len; + h->key_entry_size = key_entry_size; + h->hash_func_init_val = params->hash_func_init_val; + + h->num_buckets = num_buckets; + h->bucket_bitmask = h->num_buckets -1 ; + h->buckets = buckets; + h->buckets_ext = buckets_ext; + h->free_ext_bkts = r_ext; + h->hash_func = (params->hash_func ==NULL ) ? + default_hash_func : params->hash_func; + h->key_store = k; + h->free_slots = r; + h->tbl_chng_cnt = tbl_chng_cnt; + *h->tbl_chng_cnt =0 ; + h->hw_trans_mem_support =rte_tm_supported (); + h->use_local_cache = use_local_cache; + h->readwrite_concur_support = readwrite_concur_support; + h->ext_table_support = ext_table_support; + h->writer_takes_lock = writer_takes_lock; + h->no_free_on_del = no_free_on_del; + h->readwrite_concur_lf_support = readwrite_concur_lf_support; + +#if defined(RTE_ARCH_X86 ) +if (rte_cpu_get_flag_enabled (RTE_CPUFLAG_SSE2 )) + h->sig_cmp_fn =RTE_HASH_COMPARE_SSE ; + else +#endif + h->sig_cmp_fn =RTE_HASH_COMPARE_SCALAR ; + +if (h->writer_takes_lock) { + h->readwrite_lock =rte_malloc (NULL ,sizeof (rte_rwlock_t), +RTE_CACHE_LINE_SIZE ); +if (h->readwrite_lock ==NULL ) + goto err_unlock; + +rte_rwlock_init (h->readwrite_lock); + } + +/* Populate free slots ring. Entry zero is reserved for key misses. */ +for (i =1 ; i < num_key_slots; i++) +rte_ring_sp_enqueue (r, (void *)((uintptr_t ) i)); + + te->data = (void *) h; +TAILQ_INSERT_TAIL (hash_list, te, next); +rte_rwlock_write_unlock (RTE_EAL_TAILQ_RWLOCK ); + +return h; +err_unlock: +rte_rwlock_write_unlock (RTE_EAL_TAILQ_RWLOCK ); +err: +rte_ring_free (r); +rte_ring_free (r_ext); +rte_free (te); +rte_free (h); +rte_free (buckets); +rte_free (buckets_ext); +rte_free (k); +rte_free (tbl_chng_cnt); +return NULL ; +} +BIND_DEFAULT_SYMBOL (rte_hash_create, _v1811,18.11 ); +MAP_STATIC_SYMBOL ( + struct rte_hash *rte_hash_create( +const struct rte_hash_parameters *params), + rte_hash_create_v1811);void rte_hash_free (struct rte_hash *h)lib/librte_hash/rte_hash.h +9
-1@@ -30,13 +30,27 @@ extern "C" {#define RTE_HASH_LOOKUP_BULK_MAX 64#define RTE_HASH_LOOKUP_MULTI_MAX RTE_HASH_LOOKUP_BULK_MAX -/** Enable Hardware transactional memory support. */ +/** +* @deprecated +* This define will be removed in the next release. +* If the target platform supports hardware transactional memory +* it will be used without user consent as it provides the best possible +* performance. +* +* Enable Hardware transactional memory support. +*/ #define RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT 0x01/** Default behavior of insertion, single writer/multi writer */ #define RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD 0x02
Quoted 15 lines
lib/librte_hash/rte_hash.h extern "C" { · line 55
Quoted 10 lines
lib/librte_hash/rte_hash.h +7
-1-/** Flag to support reader writer concurrency */ +/** +* @deprecated +* This define will be removed in the next release. +* This library should be thread-safe by default. +* +* Flag to support reader writer concurrency +*/ #define RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY 0x04Do we not need/want to add some new flags to disable these features, in case there are cases where either RW concurrency, or transaction memory is unwanted?
Commenting more on my own comment - I'm looking for suggestions here from others. Perhaps we should take the YAGNI principle and not add in such flags unless someone comes with a use-case that needs it. Having negative flags where before we had positive could be confusing.
Re: [PATCH 1/3] hash: deprecate lock ellision and read/write concurreny flags
In reply to Bruce RichardsonQuoted 16 lines
lib/librte_hash/rte_cuckoo_hash.c rte_hash_create(const struct
Quoted 15 lines
lib/librte_hash/rte_cuckoo_hash.c +1
-1@@ -121,7 +121,7 @@ get_alt_bucket_index(const struct rte_hash *h, }struct rte_hash * -rte_hash_create (const struct rte_hash_parameters *params) +rte_hash_create_v20 (const struct rte_hash_parameters *params) {struct rte_hash *h =NULL ;struct rte_tailq_entry *te =NULL ;@@ -446,6 +446,323 @@ rte_hash_create(const struct
rte_hash_parameters*params)
Quoted 14 lines
lib/librte_hash/rte_cuckoo_hash.c rte_hash_create(const struct rte_hash_parameters *params) · line 450
Quoted 5 lines
lib/librte_hash/rte_cuckoo_hash.c +2
-0rte_free (tbl_chng_cnt);return NULL ; } +VERSION_SYMBOL (rte_hash_create, _v20,2.0 ); +To make reviewing this easier, can I ask if in V2 you can put the v18.11 function first, before the existing one. Hopefully that means that the "new" function from git's point of view is the existing one, showing it as a block add that we can pretty much skip reviewing. The benefit of this is that the changes in the v1811 should then show as line-by-line diffs in the patch, so we can easily review the changes made in the new case. It's hard to spot them in the whole function below.
I agree it is painful to review. I tried what you suggested here, it still shows v18.11 function as a complete new block of code. I will create another commit in the series. The first commit will have just the exact duplication of the function (but renamed to v18.11). The next commit will have all the required changes for the v18.11 function and deprecation related changes. We can squash both of them once the review completes. Let me know if there is a better solution.
Quoted 19 lines
Quoted 8 lines
lib/librte_hash/rte_cuckoo_hash.c +8
-0+struct rte_hash * +rte_hash_create_v1811 (const struct rte_hash_parameters *params) { +struct rte_hash *h =NULL ; +struct rte_tailq_entry *te =NULL ; +struct rte_hash_list *hash_list; +struct rte_ring *r =NULL ; +struct rte_ring *r_ext =NULL ; +char hash_name[RTE_HASH_NAMESIZE ];lib/librte_hash/rte_cuckoo_hash.c rte_hash_create(const struct rte_hash_parameters *params)
Quoted 10 lines
lib/librte_hash/rte_cuckoo_hash.c +10
-0+void *k =NULL ; +void *buckets =NULL ; +void *buckets_ext =NULL ; +char ring_name[RTE_RING_NAMESIZE ]; +char ext_ring_name[RTE_RING_NAMESIZE ]; +unsigned num_key_slots; +unsigned i; + +/* Validate correct usage of extra options */ + if ((params->extra_flag &
RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF) &&
Quoted 12 lines
lib/librte_hash/rte_cuckoo_hash.c rte_hash_create(const struct rte_hash_parameters *params) · line 499
Quoted 5 lines
lib/librte_hash/rte_cuckoo_hash.c +5
-0+ (params->extra_flag & RTE_HASH_EXTRA_FLAGS_EXT_TABLE)) { + rte_errno =EINVAL ; +RTE_LOG (ERR ,HASH ,"rte_hash_create: extendable bucket " +"feature not supported with rw concurrency " +"lock free\n" );Please don't split the error text across lines. If you put it on a line by itself, hopefully checkpatch should not complain. If checkpatch does complain about the long line, just ignore it!
[Yes, I know this is copied from original code, but since it appears as new code in this patch, we should fix it]
Ok, I can do that. There are other check patch issues which I did not fix (thinking it is old code), will fix those as well.
Quoted 36 lines
lib/librte_hash/rte_cuckoo_hash.c rte_hash_create(const struct rte_hash_parameters *params)
Quoted 5 lines
lib/librte_hash/rte_cuckoo_hash.c +5
-0+return NULL ; + } + +/* Check extra flags field to check extra options. */ + if (params->extra_flag &
RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD)lib/librte_hash/rte_hash.h extern "C" { · line 31
Quoted 12 lines
lib/librte_hash/rte_cuckoo_hash.c +2
-0+ use_local_cache =1 ; +void rte_hash_free (struct rte_hash *h)lib/librte_hash/rte_hash.h +0
-0@@ -30,13 +30,27 @@ extern "C" {#define RTE_HASH_LOOKUP_BULK_MAX 64#define RTE_HASH_LOOKUP_MULTI_MAX
RTE_HASH_LOOKUP_BULK_MAXQuoted 17 lines
lib/librte_hash/rte_hash.h +10
-1-/** Enable Hardware transactional memory support. */ +/** +* @deprecated +* This define will be removed in the next release. +* If the target platform supports hardware transactional memory +* it will be used without user consent as it provides the best +possible +* performance. +* +* Enable Hardware transactional memory support. +*/ #define RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT 0x01/** Default behavior of insertion, single writer/multi writer */ #define RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD 0x02
Quoted 14 lines
lib/librte_hash/rte_hash.h extern "C" { · line 55
Quoted 9 lines
lib/librte_hash/rte_hash.h +6
-1-/** Flag to support reader writer concurrency */ +/** +* @deprecated +* This define will be removed in the next release. +* This library should be thread-safe by default. +* +* Flag to support reader writer concurrency */ #define RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY 0x04Do we not need/want to add some new flags to disable these features, in case there are cases where either RW concurrency, or transaction memory is unwanted?
I cannot think of a case where RW concurrency is not required, except for single thread use case. In the single thread use case, the existing flags provide the most optimal solution. Hopefully, it will be clear from the changes. I am not sure on if there is a case for no wanting transactional memory while using lock based RW concurrency. We have a flag for non-lock based RW concurrency in which case transactional memory will not be used. IMO, I do not see a need for additional flags.
Quoted 34 lines
Quoted 34 lines
lib/librte_hash/rte_hash.h +0
-0/** Flag to indicate the extendabe bucket table feature should be used */ @@ -105,6 +119,10 @@ struct rte_hash;*/
structrte_hash*
rte_hash_create(const struct rte_hash_parameters *params);lib/librte_hash/rte_hash.h +4
-0+struct rte_hash * +rte_hash_create_v20 (const struct rte_hash_parameters *params);struct +rte_hash *rte_hash_create_v1811 (const struct rte_hash_parameters +*params);/** * Set a new hash compare function other than the default one. lib/librte_hash/rte_hash_version.map +7
-1@@ -54,6 +54,13 @@ DPDK_18.08 { } DPDK_16.07; +DPDK_18.11 { + global: + + rte_hash_create; + +} DPDK_18.08; + EXPERIMENTAL { global: --2.17.1
Re: [PATCH 1/3] hash: deprecate lock ellision and read/write concurreny flags
Quoted 30 lines · Honnappa Nagarahalli
Quoted 16 lines
lib/librte_hash/rte_cuckoo_hash.c rte_hash_create(const struct
Quoted 15 lines
lib/librte_hash/rte_cuckoo_hash.c +1
-1@@ -121,7 +121,7 @@ get_alt_bucket_index(const struct rte_hash *h, }struct rte_hash * -rte_hash_create (const struct rte_hash_parameters *params) +rte_hash_create_v20 (const struct rte_hash_parameters *params) {struct rte_hash *h =NULL ;struct rte_tailq_entry *te =NULL ;@@ -446,6 +446,323 @@ rte_hash_create(const struct
rte_hash_parameters*params)Quoted 14 lines
lib/librte_hash/rte_cuckoo_hash.c rte_hash_create(const struct rte_hash_parameters *params) · line 450
Quoted 5 lines
lib/librte_hash/rte_cuckoo_hash.c +2
-0rte_free (tbl_chng_cnt);return NULL ; } +VERSION_SYMBOL (rte_hash_create, _v20,2.0 ); +To make reviewing this easier, can I ask if in V2 you can put the v18.11 function first, before the existing one. Hopefully that means that the "new" function from git's point of view is the existing one, showing it as a block add that we can pretty much skip reviewing. The benefit of this is that the changes in the v1811 should then show as line-by-line diffs in the patch, so we can easily review the changes made in the new case. It's hard to spot them in the whole function below.
Quoted 2 lines
I agree it is painful to review. I tried what you suggested here, it still shows v18.11 function as a complete new block of code. I will create another commit in the series. The first commit will have just the exact duplication of the function (but renamed to v18.11). The next commit will have all the required changes for the v18.11 function and deprecation related changes. We can squash both of them once the review completes. Let me know if there is a better solution.
Thanks. I'll leave the squashing up to Thomas to decide, because even on later review e.g. if we ever need to bisect, having the commits separate could help.
Quoted 84 lines
Quoted 20 lines
Quoted 9 lines
lib/librte_hash/rte_cuckoo_hash.c +8
-0+struct rte_hash * +rte_hash_create_v1811 (const struct rte_hash_parameters *params) { +struct rte_hash *h =NULL ; +struct rte_tailq_entry *te =NULL ; +struct rte_hash_list *hash_list; +struct rte_ring *r =NULL ; +struct rte_ring *r_ext =NULL ; +char hash_name[RTE_HASH_NAMESIZE ];lib/librte_hash/rte_cuckoo_hash.c rte_hash_create(const struct rte_hash_parameters *params)
Quoted 10 lines
lib/librte_hash/rte_cuckoo_hash.c +10
-0+void *k =NULL ; +void *buckets =NULL ; +void *buckets_ext =NULL ; +char ring_name[RTE_RING_NAMESIZE ]; +char ext_ring_name[RTE_RING_NAMESIZE ]; +unsigned num_key_slots; +unsigned i; + +/* Validate correct usage of extra options */ + if ((params->extra_flag &
RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF) &&Quoted 12 lines
lib/librte_hash/rte_cuckoo_hash.c rte_hash_create(const struct rte_hash_parameters *params) · line 499
Quoted 5 lines
lib/librte_hash/rte_cuckoo_hash.c +5
-0+ (params->extra_flag & RTE_HASH_EXTRA_FLAGS_EXT_TABLE)) { + rte_errno =EINVAL ; +RTE_LOG (ERR ,HASH ,"rte_hash_create: extendable bucket " +"feature not supported with rw concurrency " +"lock free\n" );Please don't split the error text across lines. If you put it on a line by itself, hopefully checkpatch should not complain. If checkpatch does complain about the long line, just ignore it!
[Yes, I know this is copied from original code, but since it appears as new code in this patch, we should fix it]Ok, I can do that. There are other check patch issues which I did not fix (thinking it is old code), will fix those as well.
Quoted 36 lines
lib/librte_hash/rte_cuckoo_hash.c rte_hash_create(const struct rte_hash_parameters *params)
Quoted 5 lines
lib/librte_hash/rte_cuckoo_hash.c +5
-0+return NULL ; + } + +/* Check extra flags field to check extra options. */ + if (params->extra_flag &
RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD)lib/librte_hash/rte_hash.h extern "C" { · line 31
Quoted 12 lines
lib/librte_hash/rte_cuckoo_hash.c +2
-0+ use_local_cache =1 ; +void rte_hash_free (struct rte_hash *h)lib/librte_hash/rte_hash.h +0
-0@@ -30,13 +30,27 @@ extern "C" {#define RTE_HASH_LOOKUP_BULK_MAX 64#define RTE_HASH_LOOKUP_MULTI_MAX
RTE_HASH_LOOKUP_BULK_MAXQuoted 17 lines
lib/librte_hash/rte_hash.h +10
-1-/** Enable Hardware transactional memory support. */ +/** +* @deprecated +* This define will be removed in the next release. +* If the target platform supports hardware transactional memory +* it will be used without user consent as it provides the best +possible +* performance. +* +* Enable Hardware transactional memory support. +*/ #define RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT 0x01/** Default behavior of insertion, single writer/multi writer */ #define RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD 0x02Quoted 14 lines
lib/librte_hash/rte_hash.h extern "C" { · line 55
Quoted 9 lines
lib/librte_hash/rte_hash.h +6
-1-/** Flag to support reader writer concurrency */ +/** +* @deprecated +* This define will be removed in the next release. +* This library should be thread-safe by default. +* +* Flag to support reader writer concurrency */ #define RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY 0x04Do we not need/want to add some new flags to disable these features, in case there are cases where either RW concurrency, or transaction memory is unwanted?
Quoted 4 lines
I cannot think of a case where RW concurrency is not required, except for single thread use case. In the single thread use case, the existing flags provide the most optimal solution. Hopefully, it will be clear from the changes. I am not sure on if there is a case for no wanting transactional memory while using lock based RW concurrency. We have a flag for non-lock based RW concurrency in which case transactional memory will not be used. IMO, I do not see a need for additional flags.
I think for testing purposes at least, we need an option to disable TSX. When assessing performance impacting changes to the hash, the developer needs to evaluate the impact in both TSX and non-TSX scenarios.
/Bruce
v2 cover hash: deprecate lock ellision and read/write concurreny flags
In reply to Honnappa NagarahalliVarious configuration flags in rte_hash library result in increase of number of test cases. Configuration flags for enabling transactional memory use and read/write concurrency are not required. These features should be supported by default. Please refer to [1] for more context.
This patch marks these flags for deprecation in 19.02 release and cleans up the test cases.
[1] http://mails.dpdk.org/archives/dev/2018-October/117268.html
Honnappa Nagarahalli (4):
hash: prepare for deprecation of flags
hash: deprecate lock ellision and read/write concurreny flags test/hash: stop using lock ellision and read/write concurreny flags doc/hash: deprecate lock ellision and read/write concurreny flags
doc/guides/rel_notes/deprecation.rst | 5 + lib/librte_hash/rte_cuckoo_hash.c | 321 ++++++++++++++++++++++++++- lib/librte_hash/rte_hash.h | 20 +- lib/librte_hash/rte_hash_version.map | 7 + test/test/test_hash_multiwriter.c | 20 +- test/test/test_hash_perf.c | 40 ++-- test/test/test_hash_readwrite.c | 84 ++----- test/test/test_hash_readwrite_lf.c | 189 ++++------------ 8 files changed, 432 insertions(+), 254 deletions(-)
Signature · 1 line
2.17.1
PATCH v2 1/4 hash: prepare for deprecation of flags
Lock ellision and read/write concurreny flags need to be deprecated. Create the new version of the function and fix checkpatch issues.
--- lib/librte_hash/rte_cuckoo_hash.c | 329 ++++++++++++++++++++++++++++++ lib/librte_hash/rte_hash.h | 2 + 2 files changed, 331 insertions(+)
lib/librte_hash/rte_cuckoo_hash.c +329 -0
@@ -447,6 +447,335 @@ rte_hash_create(const struct rte_hash_parameters *params)return NULL ; } +struct rte_hash * +rte_hash_create_v1811 (const struct rte_hash_parameters *params) +{ +struct rte_hash *h =NULL ; +struct rte_tailq_entry *te =NULL ; +struct rte_hash_list *hash_list; +struct rte_ring *r =NULL ; +struct rte_ring *r_ext =NULL ; +char hash_name[RTE_HASH_NAMESIZE ]; +void *k =NULL ; +void *buckets =NULL ; +void *buckets_ext =NULL ; +char ring_name[RTE_RING_NAMESIZE ]; +char ext_ring_name[RTE_RING_NAMESIZE ]; +unsigned num_key_slots; +unsigned i; +unsigned int hw_trans_mem_support =0 , use_local_cache =0 ; +unsigned int ext_table_support =0 ; +unsigned int readwrite_concur_support =0 ; +unsigned int writer_takes_lock =0 ; +unsigned int no_free_on_del =0 ; +uint32_t *tbl_chng_cnt =NULL ; +unsigned int readwrite_concur_lf_support =0 ; + +rte_hash_function default_hash_func = (rte_hash_function )rte_jhash; + + hash_list =RTE_TAILQ_CAST (rte_hash_tailq.head, rte_hash_list); + +if (params ==NULL ) { +RTE_LOG (ERR ,HASH ,"%s: no parameters\n" , __func__); +return NULL ; + } + +/* Check for valid parameters */ +if ((params->entries >RTE_HASH_ENTRIES_MAX ) || + (params->entries <RTE_HASH_BUCKET_ENTRIES ) || + (params->key_len ==0 )) { + rte_errno =EINVAL ; +RTE_LOG (ERR ,HASH ,"%s: invalid parameters\n" , __func__); +return NULL ; + } + +/* Validate correct usage of extra options */ +if ((params->extra_flag &RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY ) && + (params->extra_flag &RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF )) { + rte_errno =EINVAL ; +RTE_LOG (ERR ,HASH ,"rte_hash_create: choose rw concurrency or " +"rw concurrency lock free\n" ); +return NULL ; + } + +if ((params->extra_flag &RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF ) && + (params->extra_flag &RTE_HASH_EXTRA_FLAGS_EXT_TABLE )) { + rte_errno =EINVAL ; +RTE_LOG (ERR ,HASH ,"%s: extendable bucket feature not supported with rw concurrency lock free\n" , __func__); +return NULL ; + } + +/* Check extra flags field to check extra options. */ +if (params->extra_flag &RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT ) + hw_trans_mem_support =1 ; + +if (params->extra_flag &RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD ) { + use_local_cache =1 ; + writer_takes_lock =1 ; + } + +if (params->extra_flag &RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY ) { + readwrite_concur_support =1 ; + writer_takes_lock =1 ; + } + +if (params->extra_flag &RTE_HASH_EXTRA_FLAGS_EXT_TABLE ) + ext_table_support =1 ; + +if (params->extra_flag &RTE_HASH_EXTRA_FLAGS_NO_FREE_ON_DEL ) + no_free_on_del =1 ; + +if (params->extra_flag &RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF ) { + readwrite_concur_lf_support =1 ; +/* Enable not freeing internal memory/index on delete */ + no_free_on_del =1 ; + } + +/* Store all keys and leave the first entry as a dummy entry +* for lookup_bulk. +*/ +if (use_local_cache) +/* +* Increase number of slots by total number of indices +* that can be stored in the lcore caches +* except for the first cache +*/ + num_key_slots = params->entries + (RTE_MAX_LCORE -1 ) * + (LCORE_CACHE_SIZE -1 ) +1 ; +else + num_key_slots = params->entries +1 ; + +snprintf (ring_name,sizeof (ring_name),"HT_%s" , params->name); +/* Create ring (Dummy slot index is not enqueued) */ + r =rte_ring_create (ring_name,rte_align32pow2 (num_key_slots), + params->socket_id,0 ); +if (r ==NULL ) { +RTE_LOG (ERR ,HASH ,"memory allocation failed\n" ); + goto err; + } + +const uint32_t num_buckets =rte_align32pow2 (params->entries) / +RTE_HASH_BUCKET_ENTRIES ; + +/* Create ring for extendable buckets. */ +if (ext_table_support) { +snprintf (ext_ring_name,sizeof (ext_ring_name),"HT_EXT_%s" , + params->name); + r_ext =rte_ring_create (ext_ring_name, +rte_align32pow2 (num_buckets +1 ), + params->socket_id,0 ); + +if (r_ext ==NULL ) { +RTE_LOG (ERR ,HASH ,"ext buckets memory allocation " +"failed\n" ); + goto err; + } + } + +snprintf (hash_name,sizeof (hash_name),"HT_%s" , params->name); + +rte_rwlock_write_lock (RTE_EAL_TAILQ_RWLOCK ); + +/* guarantee there's no existing: this is normally already checked +* by ring creation above. +*/ + TAILQ_FOREACH(te, hash_list, next) { + h = (struct rte_hash *) te->data; +if (strncmp (params->name, h->name,RTE_HASH_NAMESIZE ) ==0 ) +break ; + } + h =NULL ; +if (te !=NULL ) { + rte_errno =EEXIST ; + te =NULL ; + goto err_unlock; + } + + te =rte_zmalloc ("HASH_TAILQ_ENTRY" ,sizeof (*te),0 ); +if (te ==NULL ) { +RTE_LOG (ERR ,HASH ,"tailq entry allocation failed\n" ); + goto err_unlock; + } + + h = (struct rte_hash *)rte_zmalloc_socket (hash_name, +sizeof (struct rte_hash ), +RTE_CACHE_LINE_SIZE , params->socket_id); + +if (h ==NULL ) { +RTE_LOG (ERR ,HASH ,"memory allocation failed\n" ); + goto err_unlock; + } + + buckets =rte_zmalloc_socket (NULL , + num_buckets *sizeof (struct rte_hash_bucket ), +RTE_CACHE_LINE_SIZE , params->socket_id); + +if (buckets ==NULL ) { +RTE_LOG (ERR ,HASH ,"buckets memory allocation failed\n" ); + goto err_unlock; + } + +/* Allocate same number of extendable buckets */ +if (ext_table_support) { + buckets_ext =rte_zmalloc_socket (NULL , + num_buckets *sizeof (struct rte_hash_bucket ), +RTE_CACHE_LINE_SIZE , params->socket_id); +if (buckets_ext ==NULL ) { +RTE_LOG (ERR ,HASH ,"ext buckets memory allocation " +"failed\n" ); + goto err_unlock; + } +/* Populate ext bkt ring. We reserve 0 similar to the +* key-data slot, just in case in future we want to +* use bucket index for the linked list and 0 means NULL +* for next bucket +*/ +for (i =1 ; i <= num_buckets; i++) +rte_ring_sp_enqueue (r_ext, (void *)((uintptr_t ) i)); + } + +const uint32_t key_entry_size = +RTE_ALIGN (sizeof (struct rte_hash_key ) + params->key_len, +KEY_ALIGNMENT ); +const uint64_t key_tbl_size = (uint64_t ) key_entry_size * num_key_slots; + + k =rte_zmalloc_socket (NULL , key_tbl_size, +RTE_CACHE_LINE_SIZE , params->socket_id); + +if (k ==NULL ) { +RTE_LOG (ERR ,HASH ,"memory allocation failed\n" ); + goto err_unlock; + } + + tbl_chng_cnt =rte_zmalloc_socket (NULL ,sizeof (uint32_t ), +RTE_CACHE_LINE_SIZE , params->socket_id); + +if (tbl_chng_cnt ==NULL ) { +RTE_LOG (ERR ,HASH ,"memory allocation failed\n" ); + goto err_unlock; + } + +/* +* If x86 architecture is used, select appropriate compare function, +* which may use x86 intrinsics, otherwise use memcmp +*/ +#if defined(RTE_ARCH_X86 ) || defined(RTE_ARCH_ARM64 ) +/* Select function to compare keys */ +switch (params->key_len) { +case 16 : + h->cmp_jump_table_idx =KEY_16_BYTES ; +break ; +case 32 : + h->cmp_jump_table_idx =KEY_32_BYTES ; +break ; +case 48 : + h->cmp_jump_table_idx =KEY_48_BYTES ; +break ; +case 64 : + h->cmp_jump_table_idx =KEY_64_BYTES ; +break ; +case 80 : + h->cmp_jump_table_idx =KEY_80_BYTES ; +break ; +case 96 : + h->cmp_jump_table_idx =KEY_96_BYTES ; +break ; +case 112 : + h->cmp_jump_table_idx =KEY_112_BYTES ; +break ; +case 128 : + h->cmp_jump_table_idx =KEY_128_BYTES ; +break ; +default : +/* If key is not multiple of 16, use generic memcmp */ + h->cmp_jump_table_idx =KEY_OTHER_BYTES ; + } +#else + h->cmp_jump_table_idx =KEY_OTHER_BYTES ; +#endif + +if (use_local_cache) { + h->local_free_slots =rte_zmalloc_socket (NULL , +sizeof (struct lcore_cache ) *RTE_MAX_LCORE , +RTE_CACHE_LINE_SIZE , params->socket_id); + } + +/* Default hash function */ +#if defined(RTE_ARCH_X86 ) + default_hash_func = (rte_hash_function )rte_hash_crc; +#elif defined(RTE_ARCH_ARM64 ) +if (rte_cpu_get_flag_enabled (RTE_CPUFLAG_CRC32 )) + default_hash_func = (rte_hash_function )rte_hash_crc; +#endif +/* Setup hash context */ +snprintf (h->name,sizeof (h->name),"%s" , params->name); + h->entries = params->entries; + h->key_len = params->key_len; + h->key_entry_size = key_entry_size; + h->hash_func_init_val = params->hash_func_init_val; + + h->num_buckets = num_buckets; + h->bucket_bitmask = h->num_buckets -1 ; + h->buckets = buckets; + h->buckets_ext = buckets_ext; + h->free_ext_bkts = r_ext; + h->hash_func = (params->hash_func ==NULL ) ? + default_hash_func : params->hash_func; + h->key_store = k; + h->free_slots = r; + h->tbl_chng_cnt = tbl_chng_cnt; + *h->tbl_chng_cnt =0 ; + h->hw_trans_mem_support = hw_trans_mem_support; + h->use_local_cache = use_local_cache; + h->readwrite_concur_support = readwrite_concur_support; + h->ext_table_support = ext_table_support; + h->writer_takes_lock = writer_takes_lock; + h->no_free_on_del = no_free_on_del; + h->readwrite_concur_lf_support = readwrite_concur_lf_support; + +#if defined(RTE_ARCH_X86 ) +if (rte_cpu_get_flag_enabled (RTE_CPUFLAG_SSE2 )) + h->sig_cmp_fn =RTE_HASH_COMPARE_SSE ; + else +#endif + h->sig_cmp_fn =RTE_HASH_COMPARE_SCALAR ; + +/* Writer threads need to take the lock when: +* 1) RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY is enabled OR +* 2) RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD is enabled +*/ +if (h->writer_takes_lock) { + h->readwrite_lock =rte_malloc (NULL ,sizeof (rte_rwlock_t), +RTE_CACHE_LINE_SIZE ); +if (h->readwrite_lock ==NULL ) + goto err_unlock; + +rte_rwlock_init (h->readwrite_lock); + } + +/* Populate free slots ring. Entry zero is reserved for key misses. */ +for (i =1 ; i < num_key_slots; i++) +rte_ring_sp_enqueue (r, (void *)((uintptr_t ) i)); + + te->data = (void *) h; +TAILQ_INSERT_TAIL (hash_list, te, next); +rte_rwlock_write_unlock (RTE_EAL_TAILQ_RWLOCK ); + +return h; +err_unlock: +rte_rwlock_write_unlock (RTE_EAL_TAILQ_RWLOCK ); +err: +rte_ring_free (r); +rte_ring_free (r_ext); +rte_free (te); +rte_free (h); +rte_free (buckets); +rte_free (buckets_ext); +rte_free (k); +rte_free (tbl_chng_cnt); +return NULL ; +} +void rte_hash_free (struct rte_hash *h) {
lib/librte_hash/rte_hash.h +2 -0
@@ -105,6 +105,8 @@ struct rte_hash;*/ struct rte_hash *rte_hash_create (const struct rte_hash_parameters *params); +struct rte_hash * +rte_hash_create_v1811 (const struct rte_hash_parameters *params);/** * Set a new hash compare function other than the default one.
Signature · 1 line
2.17.1
Re: [PATCH v2 1/4] hash: prepare for deprecation of flags
Quoted 1 line · Honnappa Nagarahalli
Lock ellision and read/write concurreny flags need to be deprecated.
typo: concurrency.
Quoted 2 lines
Create the new version of the function and fix checkpatch issues.
Maybe emphasise that the new version is identical to the old, in case this patch does not get squashed into next.
"Create a copy of the hash_create function, identical to the original except for fixing checkpatch issues. Later patches will update this copy"
Quoted 4 lines
Signed-off-by Honnappa Nagarahalli <[email protected]>Reviewed-by Dharmik Thakkar <[email protected]>Reviewed-by Gavin Hu <[email protected]>---
PATCH v2 2/4 hash: deprecate lock ellision and read/write concurreny flags
In reply to Honnappa NagarahalliHash library should provide read/write concurrency by default as most of the use cases require read/write concurrency. Hence the flag RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY is deprecated. The library will decide if locking is required to provide the concurrency based on other configuration flags.
If a lock is used to provide the read/write concurrency, best possible locking mechanism available on the platform should be used. Hence, the flag RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT is deprecated. The library will use transactional memory if the platform supports it.
--- lib/librte_hash/rte_cuckoo_hash.c | 46 +++++++++++----------------- lib/librte_hash/rte_hash.h | 20 ++++++++++-- lib/librte_hash/rte_hash_version.map | 7 +++++ 3 files changed, 43 insertions(+), 30 deletions(-)
lib/librte_hash/rte_cuckoo_hash.c +18 -28
@@ -121,7 +121,7 @@ get_alt_bucket_index(const struct rte_hash *h, }struct rte_hash * -rte_hash_create (const struct rte_hash_parameters *params) +rte_hash_create_v20 (const struct rte_hash_parameters *params) {struct rte_hash *h =NULL ;struct rte_tailq_entry *te =NULL ;
@@ -446,6 +446,7 @@ rte_hash_create(const struct rte_hash_parameters *params)rte_free (tbl_chng_cnt);return NULL ; } +VERSION_SYMBOL (rte_hash_create, _v20,2.0 );struct rte_hash *rte_hash_create_v1811 (const struct rte_hash_parameters *params)
@@ -463,10 +464,10 @@ rte_hash_create_v1811(const struct rte_hash_parameters *params)char ext_ring_name[RTE_RING_NAMESIZE ];unsigned num_key_slots;unsigned i; -unsigned int hw_trans_mem_support =0 , use_local_cache =0 ; +unsigned int use_local_cache =0 ;unsigned int ext_table_support =0 ; -unsigned int readwrite_concur_support =0 ; -unsigned int writer_takes_lock =0 ; +unsigned int readwrite_concur_support =1 ; +unsigned int writer_takes_lock =1 ;unsigned int no_free_on_del =0 ;uint32_t *tbl_chng_cnt =NULL ;unsigned int readwrite_concur_lf_support =0 ;
@@ -490,14 +491,6 @@ rte_hash_create_v1811(const struct rte_hash_parameters *params) }/* Validate correct usage of extra options */ -if ((params->extra_flag &RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY ) && - (params->extra_flag &RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF )) { - rte_errno =EINVAL ; -RTE_LOG (ERR ,HASH ,"rte_hash_create: choose rw concurrency or " -"rw concurrency lock free\n" ); -return NULL ; - } -if ((params->extra_flag &RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF ) && (params->extra_flag &RTE_HASH_EXTRA_FLAGS_EXT_TABLE )) { rte_errno =EINVAL ;
@@ -506,18 +499,8 @@ rte_hash_create_v1811(const struct rte_hash_parameters *params) }/* Check extra flags field to check extra options. */ -if (params->extra_flag &RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT ) - hw_trans_mem_support =1 ; - -if (params->extra_flag &RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD ) { +if (params->extra_flag &RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD ) use_local_cache =1 ; - writer_takes_lock =1 ; - } - -if (params->extra_flag &RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY ) { - readwrite_concur_support =1 ; - writer_takes_lock =1 ; - }if (params->extra_flag &RTE_HASH_EXTRA_FLAGS_EXT_TABLE ) ext_table_support =1 ;
@@ -526,11 +509,17 @@ rte_hash_create_v1811(const struct rte_hash_parameters *params) no_free_on_del =1 ;if (params->extra_flag &RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF ) { +/* Do not use lock for RW concurrency */ + readwrite_concur_support =0 ; readwrite_concur_lf_support =1 ;/* Enable not freeing internal memory/index on delete */ no_free_on_del =1 ; } +if ((params->extra_flag &RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF ) && + !(params->extra_flag &RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD )) + writer_takes_lock =0 ; +/* Store all keys and leave the first entry as a dummy entry * for lookup_bulk. */
@@ -725,7 +714,7 @@ rte_hash_create_v1811(const struct rte_hash_parameters *params) h->free_slots = r; h->tbl_chng_cnt = tbl_chng_cnt; *h->tbl_chng_cnt =0 ; - h->hw_trans_mem_support = hw_trans_mem_support; + h->hw_trans_mem_support =rte_tm_supported (); h->use_local_cache = use_local_cache; h->readwrite_concur_support = readwrite_concur_support; h->ext_table_support = ext_table_support;
@@ -740,10 +729,6 @@ rte_hash_create_v1811(const struct rte_hash_parameters *params)#endif h->sig_cmp_fn =RTE_HASH_COMPARE_SCALAR ; -/* Writer threads need to take the lock when: -* 1) RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY is enabled OR -* 2) RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD is enabled -*/ if (h->writer_takes_lock) { h->readwrite_lock =rte_malloc (NULL ,sizeof (rte_rwlock_t),RTE_CACHE_LINE_SIZE );
@@ -775,6 +760,11 @@ rte_hash_create_v1811(const struct rte_hash_parameters *params)rte_free (tbl_chng_cnt);return NULL ; } +BIND_DEFAULT_SYMBOL (rte_hash_create, _v1811,18.11 ); +MAP_STATIC_SYMBOL ( + struct rte_hash *rte_hash_create( +const struct rte_hash_parameters *params), + rte_hash_create_v1811);void rte_hash_free (struct rte_hash *h)
lib/librte_hash/rte_hash.h +18 -2
@@ -30,13 +30,27 @@ extern "C" {#define RTE_HASH_LOOKUP_BULK_MAX 64#define RTE_HASH_LOOKUP_MULTI_MAX RTE_HASH_LOOKUP_BULK_MAX -/** Enable Hardware transactional memory support. */ +/** +* @deprecated +* This define will be removed in the next release. +* If the target platform supports hardware transactional memory +* it will be used without user consent as it provides the best possible +* performance. +* +* Enable Hardware transactional memory support. +*/ #define RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT 0x01/** Default behavior of insertion, single writer/multi writer */ #define RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD 0x02 -/** Flag to support reader writer concurrency */ +/** +* @deprecated +* This define will be removed in the next release. +* This library should be thread-safe by default. +* +* Flag to support reader writer concurrency +*/ #define RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY 0x04/** Flag to indicate the extendabe bucket table feature should be used */
@@ -106,6 +120,8 @@ struct rte_hash;struct rte_hash *rte_hash_create (const struct rte_hash_parameters *params);struct rte_hash * +rte_hash_create_v20 (const struct rte_hash_parameters *params); +struct rte_hash *rte_hash_create_v1811 (const struct rte_hash_parameters *params);/**
lib/librte_hash/rte_hash_version.map +7 -0
@@ -54,6 +54,13 @@ DPDK_18.08 { } DPDK_16.07; +DPDK_18.11 { + global: + + rte_hash_create; + +} DPDK_18.08; + EXPERIMENTAL { global:
Signature · 1 line
2.17.1
PATCH v2 3/4 test/hash: stop using lock ellision and read/write concurreny flags
In reply to Honnappa NagarahalliWith the deprecation of RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY and RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT flags, the test cases can be simplified. This results in shorter run times.
--- lib/librte_hash/rte_hash.h | 2 - test/test/test_hash_multiwriter.c | 20 +-- test/test/test_hash_perf.c | 40 +++--- test/test/test_hash_readwrite.c | 84 ++++--------- test/test/test_hash_readwrite_lf.c | 189 ++++++----------------------- 5 files changed, 82 insertions(+), 253 deletions(-)
lib/librte_hash/rte_hash.h +0 -2
@@ -32,7 +32,6 @@ extern "C" {/** * @deprecated -* This define will be removed in the next release. * If the target platform supports hardware transactional memory * it will be used without user consent as it provides the best possible * performance.
@@ -46,7 +45,6 @@ extern "C" {/** * @deprecated -* This define will be removed in the next release. * This library should be thread-safe by default. * * Flag to support reader writer concurrency
test/test/test_hash_multiwriter.c +5 -15
@@ -46,8 +46,6 @@ uint32_t rounded_nb_total_tsx_insertion;static rte_atomic64_t gcycles;static rte_atomic64_t ginsertions; -static int use_htm; -static int test_hash_multiwriter_worker (void *arg) {
@@ -113,13 +111,9 @@ test_hash_multiwriter(void) .hash_func_init_val = 0, .socket_id = rte_socket_id(), }; -if (use_htm) - hash_params.extra_flag = -RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT - |RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD ; -else - hash_params.extra_flag = -RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD ; + + hash_params.extra_flag = +RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD ;struct rte_hash *handle;char name[RTE_HASH_NAMESIZE ];
@@ -272,19 +266,15 @@ test_hash_multiwriter_main(void)if (!rte_tm_supported ()) {printf ("Hardware transactional memory (lock elision) " "is NOT supported\n" ); +printf ("Test multi-writer without Hardware transactional " +"memory\n" ); }else {printf ("Hardware transactional memory (lock elision) " "is supported\n" );printf ("Test multi-writer with Hardware transactional memory\n" ); - - use_htm =1 ; -if (test_hash_multiwriter () <0 ) -return -1 ; } -printf ("Test multi-writer without Hardware transactional memory\n" ); - use_htm =0 ;if (test_hash_multiwriter () <0 )return -1 ;
test/test/test_hash_perf.c +14 -26
@@ -79,7 +79,7 @@ static struct rte_hash_parameters ut_params = {static int create_table (unsigned int with_data,unsigned int table_index, -unsigned int with_locks,unsigned int ext) +unsigned int ext) {char name[RTE_HASH_NAMESIZE ];
@@ -89,17 +89,11 @@ create_table(unsigned int with_data, unsigned int table_index,else sprintf (name,"test_hash%d" , hashtest_key_lens[table_index]); - -if (with_locks) - ut_params.extra_flag = -RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT - |RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY ; +if (ext) + ut_params.extra_flag =RTE_HASH_EXTRA_FLAGS_EXT_TABLE ;else ut_params.extra_flag =0 ; -if (ext) - ut_params.extra_flag |=RTE_HASH_EXTRA_FLAGS_EXT_TABLE ; - ut_params.name = name; ut_params.key_len = hashtest_key_lens[table_index]; ut_params.socket_id =rte_socket_id ();
@@ -516,8 +510,7 @@ reset_table(unsigned table_index) }static int -run_all_tbl_perf_tests (unsigned int with_pushes,unsigned int with_locks, -unsigned int ext) +run_all_tbl_perf_tests (unsigned int with_pushes,unsigned int ext) {unsigned i, j, with_data, with_hash;
@@ -526,7 +519,7 @@ run_all_tbl_perf_tests(unsigned int with_pushes, unsigned int with_locks,for (with_data =0 ; with_data <=1 ; with_data++) {for (i =0 ; i <NUM_KEYSIZES ; i++) { -if (create_table (with_data, i, with_locks, ext) <0 ) +if (create_table (with_data, i, ext) <0 )return -1 ;if (get_input_keys (with_pushes, i, ext) <0 )
@@ -669,25 +662,20 @@ fbk_hash_perf_test(void)static int test_hash_perf (void ) { -unsigned int with_pushes, with_locks; -for (with_locks =0 ; with_locks <=1 ; with_locks++) { -if (with_locks) -printf ("\nWith locks in the code\n" ); +unsigned int with_pushes; + +for (with_pushes =0 ; with_pushes <=1 ; with_pushes++) { +if (with_pushes ==0 ) +printf ("\nALL ELEMENTS IN PRIMARY LOCATION\n" );else -printf ("\nWithout locks in the code\n" ); -for (with_pushes =0 ; with_pushes <=1 ; with_pushes++) { -if (with_pushes ==0 ) -printf ("\nALL ELEMENTS IN PRIMARY LOCATION\n" ); -else -printf ("\nELEMENTS IN PRIMARY OR SECONDARY LOCATION\n" ); -if (run_all_tbl_perf_tests (with_pushes, with_locks,0 ) <0 ) -return -1 ; - } +printf ("\nELEMENTS IN PRIMARY OR SECONDARY LOCATION\n" ); +if (run_all_tbl_perf_tests (with_pushes,0 ) <0 ) +return -1 ; }printf ("\n EXTENDABLE BUCKETS PERFORMANCE\n" ); -if (run_all_tbl_perf_tests (1 ,0 ,1 ) <0 ) +if (run_all_tbl_perf_tests (1 ,1 ) <0 )return -1 ;if (fbk_hash_perf_test () <0 )
test/test/test_hash_readwrite.c +23 -61
162 lines not on this page · raw message
test/test/test_hash_readwrite_lf.c +40 -149
342 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v2 4/4 doc/hash: deprecate lock ellision and read/write concurreny flags
In reply to Honnappa NagarahalliRTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY and RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT configuration flags are deprecated. Reader/Writer concurrency is provided by default. Transactional memory will be used if the platform supports it.
--- doc/guides/rel_notes/deprecation.rst | 5 +++++ 1 file changed, 5 insertions(+)
doc/guides/rel_notes/deprecation.rst +5 -0
@@ -55,3 +55,8 @@ Deprecation Notices - ``rte_pdump_set_socket_dir`` will be removed; - The parameter, ``path``, of ``rte_pdump_init`` will be removed; - The enum ``rte_pdump_socktype`` will be removed. + +* hash: The configuration flags RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY and + RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT will be removed in v19.02. + Reader/writer concurrency will be supported by default. The library will + use transactional memory if the platform supports it.
Signature · 1 line
2.17.1
Re: [PATCH v2 4/4] doc/hash: deprecate lock ellision and read/write concurreny flags
Quoted 18 lines · Honnappa Nagarahalli
RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCYandRTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORTconfiguration flags are deprecated. Reader/Writer concurrency is provided by default. Transactional memory will be used if the platform supports it.Signed-off-by Honnappa Nagarahalli <[email protected]>Reviewed-by Dharmik Thakkar <[email protected]>Reviewed-by Gavin Hu <[email protected]>--- doc/guides/rel_notes/deprecation.rst | 5 +++++ 1 file changed, 5 insertions(+)doc/guides/rel_notes/deprecation.rst +0
-0
doc/guides/rel_notes/deprecation.rst Deprecation Notices · line 62
Quoted 8 lines
doc/guides/rel_notes/deprecation.rst +5
-0@@ -55,3 +55,8 @@ Deprecation Notices - ``rte_pdump_set_socket_dir`` will be removed; - The parameter, ``path``, of ``rte_pdump_init`` will be removed; - The enum ``rte_pdump_socktype`` will be removed. + +* hash: The configuration flags RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY and + RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT will be removed in v19.02. + Reader/writer concurrency will be supported by default. The library will + use transactional memory if the platform supports it.
I think we need more documentation than this. The programmers guide also needs an update (probably in patch 2) to record the changes in the flags used on hash create.
/Bruce
Re: [PATCH v2 0/4] hash: deprecate lock ellision and read/write concurreny flags
In reply to Honnappa NagarahalliQuoted 8 lines · Honnappa Nagarahalli
Various configuration flags in
rte_hashlibrary result in increase of number of test cases. Configuration flags for enabling transactional memory use and read/write concurrency are not required. These features should be supported by default. Please refer to [1] for more context.This patch marks these flags for deprecation in 19.02 release and cleans up the test cases.
Quoted 7 lines
[1] http://mails.dpdk.org/archives/dev/2018-October/117268.html
Honnappa Nagarahalli (4): hash: prepare for deprecation of flags hash:
deprecate lock ellision and read/write concurreny flags test/hash: stop using lock ellision and read/write concurreny flags doc/hash: deprecate lock ellision and read/write concurreny flags
While I'd like to reduce the flags and do cleanup, I'm a little concerned about putting this scope of changes in so late in the release. I wonder if less drastic changes could work as well for this release, and do the cleanup later.
For example, rather than deprecating the flags now, how about just change the default for when no flags are set? If user has set flags, follow the existing path - if flags is set to zero, then have the defaults be to use RW concurrency or TSX.
/Bruce
Re: [PATCH v2 0/4] hash: deprecate lock ellision and read/write concurreny flags
Quoted 12 lines · Honnappa Nagarahalli
Quoted 10 lines
Various configuration flags in
rte_hashlibrary result in increase of number of test cases. Configuration flags for enabling transactional memory use and read/write concurrency are not required. These features should be supported by default. Please refer to [1] for more context.This patch marks these flags for deprecation in 19.02 release and cleans up the test cases.
[1] http://mails.dpdk.org/archives/dev/2018-October/117268.html
Quoted 8 lines
Quoted 5 lines
Honnappa Nagarahalli (4): hash: prepare for deprecation of flags hash:
deprecate lock ellision and read/write concurreny flags test/hash:
stop using lock ellision and read/write concurreny flags doc/hash:
deprecate lock ellision and read/write concurreny flagsWhile I'd like to reduce the flags and do cleanup, I'm a little concerned about putting this scope of changes in so late in the release. I wonder if less drastic changes could work as well for this release, and do the cleanup later.
Thank you Bruce for the review. This patch series is not fixing any user related problems, let us skip this for 18.11. It will give us time as well to think through and get this right.
Quoted 4 lines
For example, rather than deprecating the flags now, how about just change the default for when no flags are set? If user has set flags, follow the existing path - if flags is set to zero, then have the defaults be to use RW concurrency or TSX.
This changes the behavior of the library and what the flags mean, still requires ABI change, but does not need deprecation of flags (I guess this is what you meant). However, it will not solve the problem of losing the capability to disable TSX.
Quoted 2 lines
/Bruce
Re: [PATCH v2 0/4] hash: deprecate lock ellision and read/write concurreny flags
Quoted 17 lines · Honnappa Nagarahalli
Quoted 17 lines · Honnappa Nagarahalli
Quoted 15 lines
Various configuration flags in
rte_hashlibrary result in increase of number of test cases. Configuration flags for enabling transactional memory use and read/write concurrency are not required. These features should be supported by default. Please refer to [1] for more context.This patch marks these flags for deprecation in 19.02 release and cleans up the test cases.
[1] http://mails.dpdk.org/archives/dev/2018-October/117268.html
Honnappa Nagarahalli (4): hash: prepare for deprecation of flags hash:
deprecate lock ellision and read/write concurreny flags test/hash:
stop using lock ellision and read/write concurreny flags doc/hash:
deprecate lock ellision and read/write concurreny flags
Quoted 4 lines
Quoted 3 lines
While I'd like to reduce the flags and do cleanup, I'm a little concerned about putting this scope of changes in so late in the release. I wonder if less drastic changes could work as well for this release, and do the cleanup later.
Thank you Bruce for the review. This patch series is not fixing any user related problems, let us skip this for 18.11. It will give us time as well to think through and get this right.
There was no update in the scope of 19.02, I guess it will skip for 19.02 too. Patchset updated as "Change requested" in patchwork.
Quoted 9 lines
Quoted 5 lines
For example, rather than deprecating the flags now, how about just change the default for when no flags are set? If user has set flags, follow the existing path - if flags is set to zero, then have the defaults be to use RW concurrency or TSX.
This changes the behavior of the library and what the flags mean, still requires ABI change, but does not need deprecation of flags (I guess this is what you meant). However, it will not solve the problem of losing the capability to disable TSX.
Quoted 2 lines
/Bruce
PATCH 2/3 test/hash: stop using lock ellision and read/write concurreny flags
In reply to Honnappa NagarahalliWith the deprecation of RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY and RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT flags, the test cases can be simplified. This results in shorter run times.
--- lib/librte_hash/rte_hash.h | 2 - test/test/test_hash_multiwriter.c | 20 +-- test/test/test_hash_perf.c | 40 +++--- test/test/test_hash_readwrite.c | 84 ++++--------- test/test/test_hash_readwrite_lf.c | 189 ++++++----------------------- 5 files changed, 82 insertions(+), 253 deletions(-)
lib/librte_hash/rte_hash.h +0 -2
@@ -32,7 +32,6 @@ extern "C" {/** * @deprecated -* This define will be removed in the next release. * If the target platform supports hardware transactional memory * it will be used without user consent as it provides the best possible * performance.
@@ -46,7 +45,6 @@ extern "C" {/** * @deprecated -* This define will be removed in the next release. * This library should be thread-safe by default. * * Flag to support reader writer concurrency
test/test/test_hash_multiwriter.c +5 -15
@@ -46,8 +46,6 @@ uint32_t rounded_nb_total_tsx_insertion;static rte_atomic64_t gcycles;static rte_atomic64_t ginsertions; -static int use_htm; -static int test_hash_multiwriter_worker (void *arg) {
@@ -113,13 +111,9 @@ test_hash_multiwriter(void) .hash_func_init_val = 0, .socket_id = rte_socket_id(), }; -if (use_htm) - hash_params.extra_flag = -RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT - |RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD ; -else - hash_params.extra_flag = -RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD ; + + hash_params.extra_flag = +RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD ;struct rte_hash *handle;char name[RTE_HASH_NAMESIZE ];
@@ -272,19 +266,15 @@ test_hash_multiwriter_main(void)if (!rte_tm_supported ()) {printf ("Hardware transactional memory (lock elision) " "is NOT supported\n" ); +printf ("Test multi-writer without Hardware transactional " +"memory\n" ); }else {printf ("Hardware transactional memory (lock elision) " "is supported\n" );printf ("Test multi-writer with Hardware transactional memory\n" ); - - use_htm =1 ; -if (test_hash_multiwriter () <0 ) -return -1 ; } -printf ("Test multi-writer without Hardware transactional memory\n" ); - use_htm =0 ;if (test_hash_multiwriter () <0 )return -1 ;
test/test/test_hash_perf.c +14 -26
@@ -79,7 +79,7 @@ static struct rte_hash_parameters ut_params = {static int create_table (unsigned int with_data,unsigned int table_index, -unsigned int with_locks,unsigned int ext) +unsigned int ext) {char name[RTE_HASH_NAMESIZE ];
@@ -89,17 +89,11 @@ create_table(unsigned int with_data, unsigned int table_index,else sprintf (name,"test_hash%d" , hashtest_key_lens[table_index]); - -if (with_locks) - ut_params.extra_flag = -RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT - |RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY ; +if (ext) + ut_params.extra_flag =RTE_HASH_EXTRA_FLAGS_EXT_TABLE ;else ut_params.extra_flag =0 ; -if (ext) - ut_params.extra_flag |=RTE_HASH_EXTRA_FLAGS_EXT_TABLE ; - ut_params.name = name; ut_params.key_len = hashtest_key_lens[table_index]; ut_params.socket_id =rte_socket_id ();
@@ -516,8 +510,7 @@ reset_table(unsigned table_index) }static int -run_all_tbl_perf_tests (unsigned int with_pushes,unsigned int with_locks, -unsigned int ext) +run_all_tbl_perf_tests (unsigned int with_pushes,unsigned int ext) {unsigned i, j, with_data, with_hash;
@@ -526,7 +519,7 @@ run_all_tbl_perf_tests(unsigned int with_pushes, unsigned int with_locks,for (with_data =0 ; with_data <=1 ; with_data++) {for (i =0 ; i <NUM_KEYSIZES ; i++) { -if (create_table (with_data, i, with_locks, ext) <0 ) +if (create_table (with_data, i, ext) <0 )return -1 ;if (get_input_keys (with_pushes, i, ext) <0 )
@@ -669,25 +662,20 @@ fbk_hash_perf_test(void)static int test_hash_perf (void ) { -unsigned int with_pushes, with_locks; -for (with_locks =0 ; with_locks <=1 ; with_locks++) { -if (with_locks) -printf ("\nWith locks in the code\n" ); +unsigned int with_pushes; + +for (with_pushes =0 ; with_pushes <=1 ; with_pushes++) { +if (with_pushes ==0 ) +printf ("\nALL ELEMENTS IN PRIMARY LOCATION\n" );else -printf ("\nWithout locks in the code\n" ); -for (with_pushes =0 ; with_pushes <=1 ; with_pushes++) { -if (with_pushes ==0 ) -printf ("\nALL ELEMENTS IN PRIMARY LOCATION\n" ); -else -printf ("\nELEMENTS IN PRIMARY OR SECONDARY LOCATION\n" ); -if (run_all_tbl_perf_tests (with_pushes, with_locks,0 ) <0 ) -return -1 ; - } +printf ("\nELEMENTS IN PRIMARY OR SECONDARY LOCATION\n" ); +if (run_all_tbl_perf_tests (with_pushes,0 ) <0 ) +return -1 ; }printf ("\n EXTENDABLE BUCKETS PERFORMANCE\n" ); -if (run_all_tbl_perf_tests (1 ,0 ,1 ) <0 ) +if (run_all_tbl_perf_tests (1 ,1 ) <0 )return -1 ;if (fbk_hash_perf_test () <0 )
test/test/test_hash_readwrite.c +23 -61
162 lines not on this page · raw message
test/test/test_hash_readwrite_lf.c +40 -149
342 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 3/3 doc/hash: deprecate lock ellision and read/write concurreny flags
In reply to Honnappa NagarahalliRTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY and RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT configuration flags are deprecated. Reader/Writer concurrency is provided by default. Transactional memory will be used if the platform supports it.
--- doc/guides/rel_notes/deprecation.rst | 5 +++++ 1 file changed, 5 insertions(+)
doc/guides/rel_notes/deprecation.rst +5 -0
@@ -55,3 +55,8 @@ Deprecation Notices - ``rte_pdump_set_socket_dir`` will be removed; - The parameter, ``path``, of ``rte_pdump_init`` will be removed; - The enum ``rte_pdump_socktype`` will be removed. + +* hash: The configuration flags RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY and + RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT will be removed in v19.02. + Reader/writer concurrency will be supported by default. The library will + use transactional memory if the platform supports it.
Signature · 1 line
2.17.1