DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] hash: validate hash bucket entries while compiling
@ 2018-05-31 15:30 Honnappa Nagarahalli
  2018-07-12  7:42 ` Thomas Monjalon
  0 siblings, 1 reply; 6+ messages in thread
From: Honnappa Nagarahalli @ 2018-05-31 15:30 UTC (permalink / raw)
  To: bruce.richardson, pablo.de.lara.guarch; +Cc: dev, Honnappa Nagarahalli

Validate RTE_HASH_BUCKET_ENTRIES during compilation instead of
run time.

Signed-off-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
Reviewed-by: Gavin Hu <gavin.hu@arm.com>
---
 lib/librte_eal/common/include/rte_common.h | 5 +++++
 lib/librte_hash/rte_cuckoo_hash.c          | 1 -
 lib/librte_hash/rte_cuckoo_hash.h          | 4 ++++
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index 434adfd45..a9df7c161 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -293,6 +293,11 @@ rte_combine64ms1b(register uint64_t v)
 
 /*********** Macros to work with powers of 2 ********/
 
+/**
+ * Macro to return 1 if n is a power of 2, 0 otherwise
+ */
+#define RTE_IS_POWER_OF_2(n) ((n) && !(((n) - 1) & (n)))
+
 /**
  * Returns true if n is a power of 2
  * @param n
diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c
index a07543a29..375e7d208 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -107,7 +107,6 @@ rte_hash_create(const struct rte_hash_parameters *params)
 	/* Check for valid parameters */
 	if ((params->entries > RTE_HASH_ENTRIES_MAX) ||
 			(params->entries < RTE_HASH_BUCKET_ENTRIES) ||
-			!rte_is_power_of_2(RTE_HASH_BUCKET_ENTRIES) ||
 			(params->key_len == 0)) {
 		rte_errno = EINVAL;
 		RTE_LOG(ERR, HASH, "rte_hash_create has invalid parameters\n");
diff --git a/lib/librte_hash/rte_cuckoo_hash.h b/lib/librte_hash/rte_cuckoo_hash.h
index 7a54e5557..bd6ad1bd6 100644
--- a/lib/librte_hash/rte_cuckoo_hash.h
+++ b/lib/librte_hash/rte_cuckoo_hash.h
@@ -97,6 +97,10 @@ enum add_key_case {
 /** Number of items per bucket. */
 #define RTE_HASH_BUCKET_ENTRIES		8
 
+#if !RTE_IS_POWER_OF_2(RTE_HASH_BUCKET_ENTRIES)
+#error RTE_HASH_BUCKET_ENTRIES must be a power of 2
+#endif
+
 #define NULL_SIGNATURE			0
 
 #define EMPTY_SLOT			0
-- 
2.14.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [dpdk-dev] [PATCH] hash: validate hash bucket entries while compiling
  2018-05-31 15:30 [dpdk-dev] [PATCH] hash: validate hash bucket entries while compiling Honnappa Nagarahalli
@ 2018-07-12  7:42 ` Thomas Monjalon
  2018-07-12  8:05   ` De Lara Guarch, Pablo
  0 siblings, 1 reply; 6+ messages in thread
From: Thomas Monjalon @ 2018-07-12  7:42 UTC (permalink / raw)
  To: bruce.richardson, pablo.de.lara.guarch; +Cc: dev, Honnappa Nagarahalli

Review please?

31/05/2018 17:30, Honnappa Nagarahalli:
> Validate RTE_HASH_BUCKET_ENTRIES during compilation instead of
> run time.
> 
> Signed-off-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
> Reviewed-by: Gavin Hu <gavin.hu@arm.com>
> ---
>  lib/librte_eal/common/include/rte_common.h | 5 +++++
>  lib/librte_hash/rte_cuckoo_hash.c          | 1 -
>  lib/librte_hash/rte_cuckoo_hash.h          | 4 ++++
>  3 files changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
> index 434adfd45..a9df7c161 100644
> --- a/lib/librte_eal/common/include/rte_common.h
> +++ b/lib/librte_eal/common/include/rte_common.h
> @@ -293,6 +293,11 @@ rte_combine64ms1b(register uint64_t v)
>  
>  /*********** Macros to work with powers of 2 ********/
>  
> +/**
> + * Macro to return 1 if n is a power of 2, 0 otherwise
> + */
> +#define RTE_IS_POWER_OF_2(n) ((n) && !(((n) - 1) & (n)))
> +
>  /**
>   * Returns true if n is a power of 2
>   * @param n
> diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c
> index a07543a29..375e7d208 100644
> --- a/lib/librte_hash/rte_cuckoo_hash.c
> +++ b/lib/librte_hash/rte_cuckoo_hash.c
> @@ -107,7 +107,6 @@ rte_hash_create(const struct rte_hash_parameters *params)
>  	/* Check for valid parameters */
>  	if ((params->entries > RTE_HASH_ENTRIES_MAX) ||
>  			(params->entries < RTE_HASH_BUCKET_ENTRIES) ||
> -			!rte_is_power_of_2(RTE_HASH_BUCKET_ENTRIES) ||
>  			(params->key_len == 0)) {
>  		rte_errno = EINVAL;
>  		RTE_LOG(ERR, HASH, "rte_hash_create has invalid parameters\n");
> diff --git a/lib/librte_hash/rte_cuckoo_hash.h b/lib/librte_hash/rte_cuckoo_hash.h
> index 7a54e5557..bd6ad1bd6 100644
> --- a/lib/librte_hash/rte_cuckoo_hash.h
> +++ b/lib/librte_hash/rte_cuckoo_hash.h
> @@ -97,6 +97,10 @@ enum add_key_case {
>  /** Number of items per bucket. */
>  #define RTE_HASH_BUCKET_ENTRIES		8
>  
> +#if !RTE_IS_POWER_OF_2(RTE_HASH_BUCKET_ENTRIES)
> +#error RTE_HASH_BUCKET_ENTRIES must be a power of 2
> +#endif
> +
>  #define NULL_SIGNATURE			0
>  
>  #define EMPTY_SLOT			0
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [dpdk-dev] [PATCH] hash: validate hash bucket entries while compiling
  2018-07-12  7:42 ` Thomas Monjalon
@ 2018-07-12  8:05   ` De Lara Guarch, Pablo
  2018-07-12 10:43     ` Thomas Monjalon
  2018-07-13 20:20     ` Honnappa Nagarahalli
  0 siblings, 2 replies; 6+ messages in thread
From: De Lara Guarch, Pablo @ 2018-07-12  8:05 UTC (permalink / raw)
  To: Thomas Monjalon, Richardson, Bruce; +Cc: dev, Honnappa Nagarahalli



> -----Original Message-----
> From: Thomas Monjalon [mailto:thomas@monjalon.net]
> Sent: Thursday, July 12, 2018 8:42 AM
> To: Richardson, Bruce <bruce.richardson@intel.com>; De Lara Guarch, Pablo
> <pablo.de.lara.guarch@intel.com>
> Cc: dev@dpdk.org; Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
> Subject: Re: [dpdk-dev] [PATCH] hash: validate hash bucket entries while
> compiling
> 
> Review please?
> 
> 31/05/2018 17:30, Honnappa Nagarahalli:
> > Validate RTE_HASH_BUCKET_ENTRIES during compilation instead of run
> > time.
> >
> > Signed-off-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
> > Reviewed-by: Gavin Hu <gavin.hu@arm.com>
> > ---

Acked-by: Pablo de Lara <Pablo.de.lara.guarch@intel.com>
 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [dpdk-dev] [PATCH] hash: validate hash bucket entries while compiling
  2018-07-12  8:05   ` De Lara Guarch, Pablo
@ 2018-07-12 10:43     ` Thomas Monjalon
  2018-07-13 20:20     ` Honnappa Nagarahalli
  1 sibling, 0 replies; 6+ messages in thread
From: Thomas Monjalon @ 2018-07-12 10:43 UTC (permalink / raw)
  To: Honnappa Nagarahalli
  Cc: dev, De Lara Guarch, Pablo, Richardson, Bruce, Gavin Hu

12/07/2018 10:05, De Lara Guarch, Pablo:
> From: Thomas Monjalon [mailto:thomas@monjalon.net]
> > 
> > Review please?
> > 
> > 31/05/2018 17:30, Honnappa Nagarahalli:
> > > Validate RTE_HASH_BUCKET_ENTRIES during compilation instead of run
> > > time.
> > >
> > > Signed-off-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
> > > Reviewed-by: Gavin Hu <gavin.hu@arm.com>
> > > ---
> 
> Acked-by: Pablo de Lara <Pablo.de.lara.guarch@intel.com>

Applied, thanks

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [dpdk-dev] [PATCH] hash: validate hash bucket entries while compiling
  2018-07-12  8:05   ` De Lara Guarch, Pablo
  2018-07-12 10:43     ` Thomas Monjalon
@ 2018-07-13 20:20     ` Honnappa Nagarahalli
  2018-07-13 21:40       ` Thomas Monjalon
  1 sibling, 1 reply; 6+ messages in thread
From: Honnappa Nagarahalli @ 2018-07-13 20:20 UTC (permalink / raw)
  To: De Lara Guarch, Pablo, Thomas Monjalon, Richardson, Bruce; +Cc: dev

Hi Pablo,
Thank you for your response. I recently noticed this macro 'RTE_BUILD_BUG_ON'. Does it make sense to use this macro instead (though the error message will be more cryptic)?

Thank you,
Honnappa

-----Original Message-----
From: De Lara Guarch, Pablo <pablo.de.lara.guarch@intel.com>
Sent: Thursday, July 12, 2018 3:05 AM
To: Thomas Monjalon <thomas@monjalon.net>; Richardson, Bruce <bruce.richardson@intel.com>
Cc: dev@dpdk.org; Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>
Subject: RE: [dpdk-dev] [PATCH] hash: validate hash bucket entries while compiling



> -----Original Message-----
> From: Thomas Monjalon [mailto:thomas@monjalon.net]
> Sent: Thursday, July 12, 2018 8:42 AM
> To: Richardson, Bruce <bruce.richardson@intel.com>; De Lara Guarch,
> Pablo <pablo.de.lara.guarch@intel.com>
> Cc: dev@dpdk.org; Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
> Subject: Re: [dpdk-dev] [PATCH] hash: validate hash bucket entries
> while compiling
>
> Review please?
>
> 31/05/2018 17:30, Honnappa Nagarahalli:
> > Validate RTE_HASH_BUCKET_ENTRIES during compilation instead of run
> > time.
> >
> > Signed-off-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
> > Reviewed-by: Gavin Hu <gavin.hu@arm.com>
> > ---

Acked-by: Pablo de Lara <Pablo.de.lara.guarch@intel.com>


IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [dpdk-dev] [PATCH] hash: validate hash bucket entries while compiling
  2018-07-13 20:20     ` Honnappa Nagarahalli
@ 2018-07-13 21:40       ` Thomas Monjalon
  0 siblings, 0 replies; 6+ messages in thread
From: Thomas Monjalon @ 2018-07-13 21:40 UTC (permalink / raw)
  To: Honnappa Nagarahalli; +Cc: dev, De Lara Guarch, Pablo, Richardson, Bruce

13/07/2018 22:20, Honnappa Nagarahalli:
> Hi Pablo,
> Thank you for your response. I recently noticed this macro 'RTE_BUILD_BUG_ON'. Does it make sense to use this macro instead (though the error message will be more cryptic)?

Yes, I've hesitated to suggest RTE_BUILD_BUG_ON,
but decided to push your #error solution which should be fine.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-07-13 21:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-31 15:30 [dpdk-dev] [PATCH] hash: validate hash bucket entries while compiling Honnappa Nagarahalli
2018-07-12  7:42 ` Thomas Monjalon
2018-07-12  8:05   ` De Lara Guarch, Pablo
2018-07-12 10:43     ` Thomas Monjalon
2018-07-13 20:20     ` Honnappa Nagarahalli
2018-07-13 21:40       ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).