[dpdk-dev,v4,3/3] efd: run-time dispatch over x86 EFD functions

Message ID 1506960796-71620-4-git-send-email-xiaoyun.li@intel.com (mailing list archive)
State Superseded, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail Compilation issues

Commit Message

Li, Xiaoyun Oct. 2, 2017, 4:13 p.m. UTC
  This patch dynamically selects x86 EFD functions at run-time.
This patch uses function pointer and binds it to the relative
function based on CPU flags at constructor time.

Signed-off-by: Xiaoyun Li <xiaoyun.li@intel.com>
---
 lib/librte_efd/rte_efd_x86.h | 41 ++++++++++++++++++++++++++++++++++++++---
 1 file changed, 38 insertions(+), 3 deletions(-)
  

Comments

Ananyev, Konstantin Oct. 2, 2017, 4:52 p.m. UTC | #1
> -----Original Message-----
> From: Li, Xiaoyun
> Sent: Monday, October 2, 2017 5:13 PM
> To: Ananyev, Konstantin <konstantin.ananyev@intel.com>; Richardson, Bruce <bruce.richardson@intel.com>
> Cc: Lu, Wenzhuo <wenzhuo.lu@intel.com>; Zhang, Helin <helin.zhang@intel.com>; dev@dpdk.org; Li, Xiaoyun <xiaoyun.li@intel.com>
> Subject: [PATCH v4 3/3] efd: run-time dispatch over x86 EFD functions
> 
> This patch dynamically selects x86 EFD functions at run-time.
> This patch uses function pointer and binds it to the relative
> function based on CPU flags at constructor time.
> 
> Signed-off-by: Xiaoyun Li <xiaoyun.li@intel.com>
> ---
>  lib/librte_efd/rte_efd_x86.h | 41 ++++++++++++++++++++++++++++++++++++++---
>  1 file changed, 38 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/librte_efd/rte_efd_x86.h b/lib/librte_efd/rte_efd_x86.h
> index 34f37d7..93b6743 100644
> --- a/lib/librte_efd/rte_efd_x86.h
> +++ b/lib/librte_efd/rte_efd_x86.h
> @@ -43,12 +43,29 @@
>  #define EFD_LOAD_SI128(val) _mm_lddqu_si128(val)
>  #endif
> 
> +typedef efd_value_t
> +(*efd_lookup_internal_avx2_t)(const efd_hashfunc_t *group_hash_idx,
> +		const efd_lookuptbl_t *group_lookup_table,
> +		const uint32_t hash_val_a, const uint32_t hash_val_b);
> +
> +static efd_lookup_internal_avx2_t efd_lookup_internal_avx2_ptr;
> +
>  static inline efd_value_t
>  efd_lookup_internal_avx2(const efd_hashfunc_t *group_hash_idx,
>  		const efd_lookuptbl_t *group_lookup_table,
>  		const uint32_t hash_val_a, const uint32_t hash_val_b)
>  {
> -#ifdef RTE_MACHINE_CPUFLAG_AVX2
> +	return (*efd_lookup_internal_avx2_ptr)(group_hash_idx,
> +					       group_lookup_table,
> +					       hash_val_a, hash_val_b);

I don't think you need all that.
All you need - build proper avx2 function even if current HW doesn't support it.
The existing runtime selection here seems ok already.
Konstantin

> +}
> +
> +#ifdef CC_SUPPORT_AVX2
> +static inline efd_value_t
> +efd_lookup_internal_avx2_AVX2(const efd_hashfunc_t *group_hash_idx,
> +		const efd_lookuptbl_t *group_lookup_table,
> +		const uint32_t hash_val_a, const uint32_t hash_val_b)
> +{
>  	efd_value_t value = 0;
>  	uint32_t i = 0;
>  	__m256i vhash_val_a = _mm256_set1_epi32(hash_val_a);
> @@ -74,13 +91,31 @@ efd_lookup_internal_avx2(const efd_hashfunc_t *group_hash_idx,
>  	}
> 
>  	return value;
> -#else
> +}
> +#endif
> +
> +static inline efd_value_t
> +efd_lookup_internal_avx2_DEFAULT(const efd_hashfunc_t *group_hash_idx,
> +		const efd_lookuptbl_t *group_lookup_table,
> +		const uint32_t hash_val_a, const uint32_t hash_val_b)
> +{
>  	RTE_SET_USED(group_hash_idx);
>  	RTE_SET_USED(group_lookup_table);
>  	RTE_SET_USED(hash_val_a);
>  	RTE_SET_USED(hash_val_b);
>  	/* Return dummy value, only to avoid compilation breakage */
>  	return 0;
> -#endif
> +}
> 
> +static void __attribute__((constructor))
> +rte_efd_x86_init(void)
> +{
> +#ifdef CC_SUPPORT_AVX2
> +	if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2))
> +		efd_lookup_internal_avx2_ptr = efd_lookup_internal_avx2_AVX2;
> +	else
> +		efd_lookup_internal_avx2_ptr = efd_lookup_internal_avx2_DEFAULT;
> +#else
> +	efd_lookup_internal_avx2_ptr = efd_lookup_internal_avx2_DEFAULT;
> +#endif
>  }
> --
> 2.7.4
  
Li, Xiaoyun Oct. 3, 2017, 8:15 a.m. UTC | #2
Hi

> -----Original Message-----
> From: Ananyev, Konstantin
> Sent: Tuesday, October 3, 2017 00:52
> To: Li, Xiaoyun <xiaoyun.li@intel.com>; Richardson, Bruce
> <bruce.richardson@intel.com>
> Cc: Lu, Wenzhuo <wenzhuo.lu@intel.com>; Zhang, Helin
> <helin.zhang@intel.com>; dev@dpdk.org
> Subject: RE: [PATCH v4 3/3] efd: run-time dispatch over x86 EFD functions
> 
> 
> 
> > -----Original Message-----
> > From: Li, Xiaoyun
> > Sent: Monday, October 2, 2017 5:13 PM
> > To: Ananyev, Konstantin <konstantin.ananyev@intel.com>; Richardson,
> > Bruce <bruce.richardson@intel.com>
> > Cc: Lu, Wenzhuo <wenzhuo.lu@intel.com>; Zhang, Helin
> > <helin.zhang@intel.com>; dev@dpdk.org; Li, Xiaoyun
> > <xiaoyun.li@intel.com>
> > Subject: [PATCH v4 3/3] efd: run-time dispatch over x86 EFD functions
> >
> > This patch dynamically selects x86 EFD functions at run-time.
> > This patch uses function pointer and binds it to the relative function
> > based on CPU flags at constructor time.
> >
> > Signed-off-by: Xiaoyun Li <xiaoyun.li@intel.com>
> > ---
> >  lib/librte_efd/rte_efd_x86.h | 41
> > ++++++++++++++++++++++++++++++++++++++---
> >  1 file changed, 38 insertions(+), 3 deletions(-)
> >
> > diff --git a/lib/librte_efd/rte_efd_x86.h
> > b/lib/librte_efd/rte_efd_x86.h index 34f37d7..93b6743 100644
> > --- a/lib/librte_efd/rte_efd_x86.h
> > +++ b/lib/librte_efd/rte_efd_x86.h
> > @@ -43,12 +43,29 @@
> >  #define EFD_LOAD_SI128(val) _mm_lddqu_si128(val)  #endif
> >
> > +typedef efd_value_t
> > +(*efd_lookup_internal_avx2_t)(const efd_hashfunc_t *group_hash_idx,
> > +		const efd_lookuptbl_t *group_lookup_table,
> > +		const uint32_t hash_val_a, const uint32_t hash_val_b);
> > +
> > +static efd_lookup_internal_avx2_t efd_lookup_internal_avx2_ptr;
> > +
> >  static inline efd_value_t
> >  efd_lookup_internal_avx2(const efd_hashfunc_t *group_hash_idx,
> >  		const efd_lookuptbl_t *group_lookup_table,
> >  		const uint32_t hash_val_a, const uint32_t hash_val_b)  { -
> #ifdef
> > RTE_MACHINE_CPUFLAG_AVX2
> > +	return (*efd_lookup_internal_avx2_ptr)(group_hash_idx,
> > +					       group_lookup_table,
> > +					       hash_val_a, hash_val_b);
> 
> I don't think you need all that.
> All you need - build proper avx2 function even if current HW doesn't support
> it.
> The existing runtime selection here seems ok already.
> Konstantin
> 

Sorry, not quite understand here. So don't need to change codes of efd here?
I didn't care about the HW. CC_SUPPORT_AVX2 only means the compiler supports AVX2 since would runtime selection.
The existing codes RTE_MACHINE_CPUFLAG_AVX2 means both the compiler and HW supports AVX2.


Best Regards,
Xiaoyun Li


> > +}
> > +
> > +#ifdef CC_SUPPORT_AVX2
> > +static inline efd_value_t
> > +efd_lookup_internal_avx2_AVX2(const efd_hashfunc_t *group_hash_idx,
> > +		const efd_lookuptbl_t *group_lookup_table,
> > +		const uint32_t hash_val_a, const uint32_t hash_val_b) {
> >  	efd_value_t value = 0;
> >  	uint32_t i = 0;
> >  	__m256i vhash_val_a = _mm256_set1_epi32(hash_val_a); @@ -
> 74,13
> > +91,31 @@ efd_lookup_internal_avx2(const efd_hashfunc_t
> *group_hash_idx,
> >  	}
> >
> >  	return value;
> > -#else
> > +}
> > +#endif
> > +
> > +static inline efd_value_t
> > +efd_lookup_internal_avx2_DEFAULT(const efd_hashfunc_t
> *group_hash_idx,
> > +		const efd_lookuptbl_t *group_lookup_table,
> > +		const uint32_t hash_val_a, const uint32_t hash_val_b) {
> >  	RTE_SET_USED(group_hash_idx);
> >  	RTE_SET_USED(group_lookup_table);
> >  	RTE_SET_USED(hash_val_a);
> >  	RTE_SET_USED(hash_val_b);
> >  	/* Return dummy value, only to avoid compilation breakage */
> >  	return 0;
> > -#endif
> > +}
> >
> > +static void __attribute__((constructor))
> > +rte_efd_x86_init(void)
> > +{
> > +#ifdef CC_SUPPORT_AVX2
> > +	if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2))
> > +		efd_lookup_internal_avx2_ptr =
> efd_lookup_internal_avx2_AVX2;
> > +	else
> > +		efd_lookup_internal_avx2_ptr =
> efd_lookup_internal_avx2_DEFAULT;
> > +#else
> > +	efd_lookup_internal_avx2_ptr = efd_lookup_internal_avx2_DEFAULT;
> > +#endif
> >  }
> > --
> > 2.7.4
  
Ananyev, Konstantin Oct. 3, 2017, 11:23 a.m. UTC | #3
> -----Original Message-----
> From: Li, Xiaoyun
> Sent: Tuesday, October 3, 2017 9:15 AM
> To: Ananyev, Konstantin <konstantin.ananyev@intel.com>; Richardson, Bruce <bruce.richardson@intel.com>
> Cc: Lu, Wenzhuo <wenzhuo.lu@intel.com>; Zhang, Helin <helin.zhang@intel.com>; dev@dpdk.org
> Subject: RE: [PATCH v4 3/3] efd: run-time dispatch over x86 EFD functions
> 
> Hi
> 
> > -----Original Message-----
> > From: Ananyev, Konstantin
> > Sent: Tuesday, October 3, 2017 00:52
> > To: Li, Xiaoyun <xiaoyun.li@intel.com>; Richardson, Bruce
> > <bruce.richardson@intel.com>
> > Cc: Lu, Wenzhuo <wenzhuo.lu@intel.com>; Zhang, Helin
> > <helin.zhang@intel.com>; dev@dpdk.org
> > Subject: RE: [PATCH v4 3/3] efd: run-time dispatch over x86 EFD functions
> >
> >
> >
> > > -----Original Message-----
> > > From: Li, Xiaoyun
> > > Sent: Monday, October 2, 2017 5:13 PM
> > > To: Ananyev, Konstantin <konstantin.ananyev@intel.com>; Richardson,
> > > Bruce <bruce.richardson@intel.com>
> > > Cc: Lu, Wenzhuo <wenzhuo.lu@intel.com>; Zhang, Helin
> > > <helin.zhang@intel.com>; dev@dpdk.org; Li, Xiaoyun
> > > <xiaoyun.li@intel.com>
> > > Subject: [PATCH v4 3/3] efd: run-time dispatch over x86 EFD functions
> > >
> > > This patch dynamically selects x86 EFD functions at run-time.
> > > This patch uses function pointer and binds it to the relative function
> > > based on CPU flags at constructor time.
> > >
> > > Signed-off-by: Xiaoyun Li <xiaoyun.li@intel.com>
> > > ---
> > >  lib/librte_efd/rte_efd_x86.h | 41
> > > ++++++++++++++++++++++++++++++++++++++---
> > >  1 file changed, 38 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/lib/librte_efd/rte_efd_x86.h
> > > b/lib/librte_efd/rte_efd_x86.h index 34f37d7..93b6743 100644
> > > --- a/lib/librte_efd/rte_efd_x86.h
> > > +++ b/lib/librte_efd/rte_efd_x86.h
> > > @@ -43,12 +43,29 @@
> > >  #define EFD_LOAD_SI128(val) _mm_lddqu_si128(val)  #endif
> > >
> > > +typedef efd_value_t
> > > +(*efd_lookup_internal_avx2_t)(const efd_hashfunc_t *group_hash_idx,
> > > +		const efd_lookuptbl_t *group_lookup_table,
> > > +		const uint32_t hash_val_a, const uint32_t hash_val_b);
> > > +
> > > +static efd_lookup_internal_avx2_t efd_lookup_internal_avx2_ptr;
> > > +
> > >  static inline efd_value_t
> > >  efd_lookup_internal_avx2(const efd_hashfunc_t *group_hash_idx,
> > >  		const efd_lookuptbl_t *group_lookup_table,
> > >  		const uint32_t hash_val_a, const uint32_t hash_val_b)  { -
> > #ifdef
> > > RTE_MACHINE_CPUFLAG_AVX2
> > > +	return (*efd_lookup_internal_avx2_ptr)(group_hash_idx,
> > > +					       group_lookup_table,
> > > +					       hash_val_a, hash_val_b);
> >
> > I don't think you need all that.
> > All you need - build proper avx2 function even if current HW doesn't support
> > it.
> > The existing runtime selection here seems ok already.
> > Konstantin
> >
> 
> Sorry, not quite understand here. So don't need to change codes of efd here?
> I didn't care about the HW. CC_SUPPORT_AVX2 only means the compiler supports AVX2 since would runtime selection.
> The existing codes RTE_MACHINE_CPUFLAG_AVX2 means both the compiler and HW supports AVX2.

What I am saying - you don't need all these dances with extra function pointer.
All you need - move efd_lookup_internal_avx2() into a .c file and make sure it get compiled with -mavx2 flag.
Then at rte_efd_create() select AVX2 only when both HW and compiler supports AVX2:

...
#ifdef CC_SUPPORT_AVX2
  if (RTE_EFD_VALUE_NUM_BITS > 3 && rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2))
                table->lookup_fn = EFD_LOOKUP_AVX2;
        else
#endif
...

Konstantin

> 
> 
> Best Regards,
> Xiaoyun Li
> 
> 
> > > +}
> > > +
> > > +#ifdef CC_SUPPORT_AVX2
> > > +static inline efd_value_t
> > > +efd_lookup_internal_avx2_AVX2(const efd_hashfunc_t *group_hash_idx,
> > > +		const efd_lookuptbl_t *group_lookup_table,
> > > +		const uint32_t hash_val_a, const uint32_t hash_val_b) {
> > >  	efd_value_t value = 0;
> > >  	uint32_t i = 0;
> > >  	__m256i vhash_val_a = _mm256_set1_epi32(hash_val_a); @@ -
> > 74,13
> > > +91,31 @@ efd_lookup_internal_avx2(const efd_hashfunc_t
> > *group_hash_idx,
> > >  	}
> > >
> > >  	return value;
> > > -#else
> > > +}
> > > +#endif
> > > +
> > > +static inline efd_value_t
> > > +efd_lookup_internal_avx2_DEFAULT(const efd_hashfunc_t
> > *group_hash_idx,
> > > +		const efd_lookuptbl_t *group_lookup_table,
> > > +		const uint32_t hash_val_a, const uint32_t hash_val_b) {
> > >  	RTE_SET_USED(group_hash_idx);
> > >  	RTE_SET_USED(group_lookup_table);
> > >  	RTE_SET_USED(hash_val_a);
> > >  	RTE_SET_USED(hash_val_b);
> > >  	/* Return dummy value, only to avoid compilation breakage */
> > >  	return 0;
> > > -#endif
> > > +}
> > >
> > > +static void __attribute__((constructor))
> > > +rte_efd_x86_init(void)
> > > +{
> > > +#ifdef CC_SUPPORT_AVX2
> > > +	if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2))
> > > +		efd_lookup_internal_avx2_ptr =
> > efd_lookup_internal_avx2_AVX2;
> > > +	else
> > > +		efd_lookup_internal_avx2_ptr =
> > efd_lookup_internal_avx2_DEFAULT;
> > > +#else
> > > +	efd_lookup_internal_avx2_ptr = efd_lookup_internal_avx2_DEFAULT;
> > > +#endif
> > >  }
> > > --
> > > 2.7.4
  
Li, Xiaoyun Oct. 3, 2017, 11:27 a.m. UTC | #4
OK.

> -----Original Message-----
> From: Ananyev, Konstantin
> Sent: Tuesday, October 3, 2017 19:23
> To: Li, Xiaoyun <xiaoyun.li@intel.com>; Richardson, Bruce
> <bruce.richardson@intel.com>
> Cc: Lu, Wenzhuo <wenzhuo.lu@intel.com>; Zhang, Helin
> <helin.zhang@intel.com>; dev@dpdk.org
> Subject: RE: [PATCH v4 3/3] efd: run-time dispatch over x86 EFD functions
> 
> 
> 
> > -----Original Message-----
> > From: Li, Xiaoyun
> > Sent: Tuesday, October 3, 2017 9:15 AM
> > To: Ananyev, Konstantin <konstantin.ananyev@intel.com>; Richardson,
> > Bruce <bruce.richardson@intel.com>
> > Cc: Lu, Wenzhuo <wenzhuo.lu@intel.com>; Zhang, Helin
> > <helin.zhang@intel.com>; dev@dpdk.org
> > Subject: RE: [PATCH v4 3/3] efd: run-time dispatch over x86 EFD
> > functions
> >
> > Hi
> >
> > > -----Original Message-----
> > > From: Ananyev, Konstantin
> > > Sent: Tuesday, October 3, 2017 00:52
> > > To: Li, Xiaoyun <xiaoyun.li@intel.com>; Richardson, Bruce
> > > <bruce.richardson@intel.com>
> > > Cc: Lu, Wenzhuo <wenzhuo.lu@intel.com>; Zhang, Helin
> > > <helin.zhang@intel.com>; dev@dpdk.org
> > > Subject: RE: [PATCH v4 3/3] efd: run-time dispatch over x86 EFD
> > > functions
> > >
> > >
> > >
> > > > -----Original Message-----
> > > > From: Li, Xiaoyun
> > > > Sent: Monday, October 2, 2017 5:13 PM
> > > > To: Ananyev, Konstantin <konstantin.ananyev@intel.com>;
> > > > Richardson, Bruce <bruce.richardson@intel.com>
> > > > Cc: Lu, Wenzhuo <wenzhuo.lu@intel.com>; Zhang, Helin
> > > > <helin.zhang@intel.com>; dev@dpdk.org; Li, Xiaoyun
> > > > <xiaoyun.li@intel.com>
> > > > Subject: [PATCH v4 3/3] efd: run-time dispatch over x86 EFD
> > > > functions
> > > >
> > > > This patch dynamically selects x86 EFD functions at run-time.
> > > > This patch uses function pointer and binds it to the relative
> > > > function based on CPU flags at constructor time.
> > > >
> > > > Signed-off-by: Xiaoyun Li <xiaoyun.li@intel.com>
> > > > ---
> > > >  lib/librte_efd/rte_efd_x86.h | 41
> > > > ++++++++++++++++++++++++++++++++++++++---
> > > >  1 file changed, 38 insertions(+), 3 deletions(-)
> > > >
> > > > diff --git a/lib/librte_efd/rte_efd_x86.h
> > > > b/lib/librte_efd/rte_efd_x86.h index 34f37d7..93b6743 100644
> > > > --- a/lib/librte_efd/rte_efd_x86.h
> > > > +++ b/lib/librte_efd/rte_efd_x86.h
> > > > @@ -43,12 +43,29 @@
> > > >  #define EFD_LOAD_SI128(val) _mm_lddqu_si128(val)  #endif
> > > >
> > > > +typedef efd_value_t
> > > > +(*efd_lookup_internal_avx2_t)(const efd_hashfunc_t
> *group_hash_idx,
> > > > +		const efd_lookuptbl_t *group_lookup_table,
> > > > +		const uint32_t hash_val_a, const uint32_t hash_val_b);
> > > > +
> > > > +static efd_lookup_internal_avx2_t efd_lookup_internal_avx2_ptr;
> > > > +
> > > >  static inline efd_value_t
> > > >  efd_lookup_internal_avx2(const efd_hashfunc_t *group_hash_idx,
> > > >  		const efd_lookuptbl_t *group_lookup_table,
> > > >  		const uint32_t hash_val_a, const uint32_t hash_val_b)  { -
> > > #ifdef
> > > > RTE_MACHINE_CPUFLAG_AVX2
> > > > +	return (*efd_lookup_internal_avx2_ptr)(group_hash_idx,
> > > > +					       group_lookup_table,
> > > > +					       hash_val_a, hash_val_b);
> > >
> > > I don't think you need all that.
> > > All you need - build proper avx2 function even if current HW doesn't
> > > support it.
> > > The existing runtime selection here seems ok already.
> > > Konstantin
> > >
> >
> > Sorry, not quite understand here. So don't need to change codes of efd
> here?
> > I didn't care about the HW. CC_SUPPORT_AVX2 only means the compiler
> supports AVX2 since would runtime selection.
> > The existing codes RTE_MACHINE_CPUFLAG_AVX2 means both the
> compiler and HW supports AVX2.
> 
> What I am saying - you don't need all these dances with extra function
> pointer.
> All you need - move efd_lookup_internal_avx2() into a .c file and make sure
> it get compiled with -mavx2 flag.
> Then at rte_efd_create() select AVX2 only when both HW and compiler
> supports AVX2:
> 
> ...
> #ifdef CC_SUPPORT_AVX2
>   if (RTE_EFD_VALUE_NUM_BITS > 3 &&
> rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2))
>                 table->lookup_fn = EFD_LOOKUP_AVX2;
>         else
> #endif
> ...
> 
> Konstantin
> 
> >
> >
> > Best Regards,
> > Xiaoyun Li
> >
> >
> > > > +}
> > > > +
> > > > +#ifdef CC_SUPPORT_AVX2
> > > > +static inline efd_value_t
> > > > +efd_lookup_internal_avx2_AVX2(const efd_hashfunc_t
> *group_hash_idx,
> > > > +		const efd_lookuptbl_t *group_lookup_table,
> > > > +		const uint32_t hash_val_a, const uint32_t hash_val_b) {
> > > >  	efd_value_t value = 0;
> > > >  	uint32_t i = 0;
> > > >  	__m256i vhash_val_a = _mm256_set1_epi32(hash_val_a); @@ -
> > > 74,13
> > > > +91,31 @@ efd_lookup_internal_avx2(const efd_hashfunc_t
> > > *group_hash_idx,
> > > >  	}
> > > >
> > > >  	return value;
> > > > -#else
> > > > +}
> > > > +#endif
> > > > +
> > > > +static inline efd_value_t
> > > > +efd_lookup_internal_avx2_DEFAULT(const efd_hashfunc_t
> > > *group_hash_idx,
> > > > +		const efd_lookuptbl_t *group_lookup_table,
> > > > +		const uint32_t hash_val_a, const uint32_t hash_val_b) {
> > > >  	RTE_SET_USED(group_hash_idx);
> > > >  	RTE_SET_USED(group_lookup_table);
> > > >  	RTE_SET_USED(hash_val_a);
> > > >  	RTE_SET_USED(hash_val_b);
> > > >  	/* Return dummy value, only to avoid compilation breakage */
> > > >  	return 0;
> > > > -#endif
> > > > +}
> > > >
> > > > +static void __attribute__((constructor))
> > > > +rte_efd_x86_init(void)
> > > > +{
> > > > +#ifdef CC_SUPPORT_AVX2
> > > > +	if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2))
> > > > +		efd_lookup_internal_avx2_ptr =
> > > efd_lookup_internal_avx2_AVX2;
> > > > +	else
> > > > +		efd_lookup_internal_avx2_ptr =
> > > efd_lookup_internal_avx2_DEFAULT;
> > > > +#else
> > > > +	efd_lookup_internal_avx2_ptr = efd_lookup_internal_avx2_DEFAULT;
> > > > +#endif
> > > >  }
> > > > --
> > > > 2.7.4
  

Patch

diff --git a/lib/librte_efd/rte_efd_x86.h b/lib/librte_efd/rte_efd_x86.h
index 34f37d7..93b6743 100644
--- a/lib/librte_efd/rte_efd_x86.h
+++ b/lib/librte_efd/rte_efd_x86.h
@@ -43,12 +43,29 @@ 
 #define EFD_LOAD_SI128(val) _mm_lddqu_si128(val)
 #endif
 
+typedef efd_value_t
+(*efd_lookup_internal_avx2_t)(const efd_hashfunc_t *group_hash_idx,
+		const efd_lookuptbl_t *group_lookup_table,
+		const uint32_t hash_val_a, const uint32_t hash_val_b);
+
+static efd_lookup_internal_avx2_t efd_lookup_internal_avx2_ptr;
+
 static inline efd_value_t
 efd_lookup_internal_avx2(const efd_hashfunc_t *group_hash_idx,
 		const efd_lookuptbl_t *group_lookup_table,
 		const uint32_t hash_val_a, const uint32_t hash_val_b)
 {
-#ifdef RTE_MACHINE_CPUFLAG_AVX2
+	return (*efd_lookup_internal_avx2_ptr)(group_hash_idx,
+					       group_lookup_table,
+					       hash_val_a, hash_val_b);
+}
+
+#ifdef CC_SUPPORT_AVX2
+static inline efd_value_t
+efd_lookup_internal_avx2_AVX2(const efd_hashfunc_t *group_hash_idx,
+		const efd_lookuptbl_t *group_lookup_table,
+		const uint32_t hash_val_a, const uint32_t hash_val_b)
+{
 	efd_value_t value = 0;
 	uint32_t i = 0;
 	__m256i vhash_val_a = _mm256_set1_epi32(hash_val_a);
@@ -74,13 +91,31 @@  efd_lookup_internal_avx2(const efd_hashfunc_t *group_hash_idx,
 	}
 
 	return value;
-#else
+}
+#endif
+
+static inline efd_value_t
+efd_lookup_internal_avx2_DEFAULT(const efd_hashfunc_t *group_hash_idx,
+		const efd_lookuptbl_t *group_lookup_table,
+		const uint32_t hash_val_a, const uint32_t hash_val_b)
+{
 	RTE_SET_USED(group_hash_idx);
 	RTE_SET_USED(group_lookup_table);
 	RTE_SET_USED(hash_val_a);
 	RTE_SET_USED(hash_val_b);
 	/* Return dummy value, only to avoid compilation breakage */
 	return 0;
-#endif
+}
 
+static void __attribute__((constructor))
+rte_efd_x86_init(void)
+{
+#ifdef CC_SUPPORT_AVX2
+	if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2))
+		efd_lookup_internal_avx2_ptr = efd_lookup_internal_avx2_AVX2;
+	else
+		efd_lookup_internal_avx2_ptr = efd_lookup_internal_avx2_DEFAULT;
+#else
+	efd_lookup_internal_avx2_ptr = efd_lookup_internal_avx2_DEFAULT;
+#endif
 }