[dpdk-dev] [PATCH] hash: fix to support multi process

Bruce Richardson bruce.richardson at intel.com
Fri Mar 25 15:41:04 CET 2016


On Thu, Mar 24, 2016 at 01:56:44PM +0000, Pablo de Lara wrote:
> Hash library used a function pointer to choose a different
> key compare function, depending on the key size.
> As a result, multiple processes could not use the same hash table,
> as the function addresses vary from one process to another.
> 
> Instead, a jump table is used, so each process has its own
> function addresses, accessing this table with an index stored
> in the hash table (note that using a custom key compare function
> is not supported in multi-process mode).
> 
> Fixes: 48a399119619 ("hash: replace with cuckoo hash implementation")
> 
> Signed-off-by: Pablo de Lara <pablo.de.lara.guarch at intel.com>

This is a hard problem to solve, but this probably looks the least-worst solution
to it. Pablo, I assume the performance hit for lookups is pretty small here?

One small nit in the code below, and a comment on the doc change. Otherwise,

Acked-by: Bruce Richardson <bruce.richardson at intel.com>

> ---
>  doc/guides/rel_notes/release_16_04.rst |  5 ++
>  lib/librte_hash/rte_cuckoo_hash.c      | 85 ++++++++++++++++++++++++++--------
>  2 files changed, 71 insertions(+), 19 deletions(-)
> 
> diff --git a/doc/guides/rel_notes/release_16_04.rst b/doc/guides/rel_notes/release_16_04.rst
> index 2785b29..c4359dd 100644
> --- a/doc/guides/rel_notes/release_16_04.rst
> +++ b/doc/guides/rel_notes/release_16_04.rst
> @@ -351,6 +351,11 @@ Libraries
>    Fix crc32c hash functions to return a valid crc32c value for data lengths
>    not multiple of 4 bytes.
>  
> +* **hash: Fixed hash library to support multi-process mode.**
> +
> +  Fix hash library to support multi-process mode, using a jump table,
> +  instead of storing a function pointer to the key compare function.
> +
You probably need to clarify here and in the other docs (e.g. API doc) that:
* multi-process mode only works with the built-in functions and key sizes.
* a custom function not in the jump table can be used but only in single-process
mode.

>  * **librte_port: Fixed segmentation fault for ring and ethdev writer nodrop.**
>  
>    Fixed core dump issue on txq and swq when dropless is set to yes.
> diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c
> index 71b5b76..38c19ab 100644
> --- a/lib/librte_hash/rte_cuckoo_hash.c
> +++ b/lib/librte_hash/rte_cuckoo_hash.c
> @@ -102,6 +102,41 @@ EAL_REGISTER_TAILQ(rte_hash_tailq)
>  
>  #define LCORE_CACHE_SIZE		8
>  
> +/*
> + * All different options to select a key compare function,
> + * based on the key size and custom function.
> + */
> +enum cmp_jump_table_case {
> +	KEY_CUSTOM = 0,
> +	KEY_16_BYTES,
> +	KEY_32_BYTES,
> +	KEY_48_BYTES,
> +	KEY_64_BYTES,
> +	KEY_80_BYTES,
> +	KEY_96_BYTES,
> +	KEY_112_BYTES,
> +	KEY_128_BYTES,
> +	KEY_OTHER_BYTES,
> +	NUM_KEY_CMP_CASES,
> +};
> +
> +/*
> + * Table storing all different key compare functions
> + * (multi-process supported)
> + */
> +rte_hash_cmp_eq_t cmp_jump_table[NUM_KEY_CMP_CASES] = {
> +	NULL,
> +	rte_hash_k16_cmp_eq,
> +	rte_hash_k32_cmp_eq,
> +	rte_hash_k48_cmp_eq,
> +	rte_hash_k64_cmp_eq,
> +	rte_hash_k80_cmp_eq,
> +	rte_hash_k96_cmp_eq,
> +	rte_hash_k112_cmp_eq,
> +	rte_hash_k128_cmp_eq,
> +	memcmp
> +};

Array should be const.

/Bruce



More information about the dev mailing list