[v2,1/6] lib/eal: add a common wrapper for restricted pointers
diff mbox series

Message ID 20200706074930.54299-2-joyce.kong@arm.com
State Superseded
Delegated to: David Marchand
Headers show
Series
  • Restrict pointer aliasing with a common wrapper
Related show

Checks

Context Check Description
ci/iol-mellanox-Performance success Performance Testing PASS
ci/Intel-compilation fail Compilation issues
ci/iol-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/checkpatch success coding style OK

Commit Message

Joyce Kong July 6, 2020, 7:49 a.m. UTC
The 'restrict' keyword is recognized in C99, while type qulifier
'__restrict' compiles ok in C with all language levels. This patch
is to add a wrapper defining '__rte_restrict' with 'restrict' and
'__restrict' to be supported by all compilers.

Signed-off-by: Joyce Kong <joyce.kong@arm.com>
---
 lib/librte_eal/include/rte_common.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Jerin Jacob July 7, 2020, 2:15 a.m. UTC | #1
On Mon, Jul 6, 2020 at 1:19 PM Joyce Kong <joyce.kong@arm.com> wrote:
>
> The 'restrict' keyword is recognized in C99, while type qulifier
> '__restrict' compiles ok in C with all language levels. This patch
> is to add a wrapper defining '__rte_restrict' with 'restrict' and
> '__restrict' to be supported by all compilers.
>
> Signed-off-by: Joyce Kong <joyce.kong@arm.com>

Acked-by: Jerin Jacob <jerinj@marvell.com>


> ---
>  lib/librte_eal/include/rte_common.h | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/lib/librte_eal/include/rte_common.h b/lib/librte_eal/include/rte_common.h
> index 0843ce69e..cda32c056 100644
> --- a/lib/librte_eal/include/rte_common.h
> +++ b/lib/librte_eal/include/rte_common.h
> @@ -103,6 +103,16 @@ typedef uint16_t unaligned_uint16_t;
>   */
>  #define __rte_unused __attribute__((__unused__))
>
> +/**
> + * Define a wrapper for restricted pointers which can be supported
> + * by all compilers.
> + */
> +#if __STDC_VERSION__ >= 199901
> +#define __rte_restrict restrict
> +#else
> +#define __rte_restrict __restrict
> +#endif
> +
>  /**
>   * definition to mark a variable or function parameter as used so
>   * as to avoid a compiler warning
> --
> 2.27.0
>
Phil Yang July 7, 2020, 2:24 a.m. UTC | #2
> -----Original Message-----
> From: Joyce Kong <joyce.kong@arm.com>
> Sent: Monday, July 6, 2020 3:49 PM
> To: maxime.coquelin@redhat.com; jerinj@marvell.com;
> zhihong.wang@intel.com; xiaolong.ye@intel.com; beilei.xing@intel.com;
> jia.guo@intel.com; john.mcnamara@intel.com; matan@mellanox.com;
> shahafs@mellanox.com; viacheslavo@mellanox.com; Honnappa Nagarahalli
> <Honnappa.Nagarahalli@arm.com>; Phil Yang <Phil.Yang@arm.com>;
> Ruifeng Wang <Ruifeng.Wang@arm.com>
> Cc: dev@dpdk.org; nd <nd@arm.com>
> Subject: [PATCH v2 1/6] lib/eal: add a common wrapper for restricted
> pointers
> 
> The 'restrict' keyword is recognized in C99, while type qulifier
> '__restrict' compiles ok in C with all language levels. This patch
> is to add a wrapper defining '__rte_restrict' with 'restrict' and
> '__restrict' to be supported by all compilers.
> 
> Signed-off-by: Joyce Kong <joyce.kong@arm.com>
> ---

Reviewed-by: Phil Yang <phil.yang@arm.com>
Ruifeng Wang July 7, 2020, 2:40 a.m. UTC | #3
> -----Original Message-----
> From: Joyce Kong <joyce.kong@arm.com>
> Sent: Monday, July 6, 2020 3:49 PM
> To: maxime.coquelin@redhat.com; jerinj@marvell.com;
> zhihong.wang@intel.com; xiaolong.ye@intel.com; beilei.xing@intel.com;
> jia.guo@intel.com; john.mcnamara@intel.com; matan@mellanox.com;
> shahafs@mellanox.com; viacheslavo@mellanox.com; Honnappa Nagarahalli
> <Honnappa.Nagarahalli@arm.com>; Phil Yang <Phil.Yang@arm.com>;
> Ruifeng Wang <Ruifeng.Wang@arm.com>
> Cc: dev@dpdk.org; nd <nd@arm.com>
> Subject: [PATCH v2 1/6] lib/eal: add a common wrapper for restricted
> pointers
> 
> The 'restrict' keyword is recognized in C99, while type qulifier '__restrict'
> compiles ok in C with all language levels. This patch is to add a wrapper
> defining '__rte_restrict' with 'restrict' and '__restrict' to be supported by all
> compilers.
> 
> Signed-off-by: Joyce Kong <joyce.kong@arm.com>
> ---
>  lib/librte_eal/include/rte_common.h | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/lib/librte_eal/include/rte_common.h
> b/lib/librte_eal/include/rte_common.h
> index 0843ce69e..cda32c056 100644
> --- a/lib/librte_eal/include/rte_common.h
> +++ b/lib/librte_eal/include/rte_common.h
> @@ -103,6 +103,16 @@ typedef uint16_t unaligned_uint16_t;
>   */
>  #define __rte_unused __attribute__((__unused__))
> 
> +/**
> + * Define a wrapper for restricted pointers which can be supported
> + * by all compilers.
> + */
> +#if __STDC_VERSION__ >= 199901
> +#define __rte_restrict restrict
> +#else
> +#define __rte_restrict __restrict
> +#endif
> +
>  /**
>   * definition to mark a variable or function parameter as used so
>   * as to avoid a compiler warning
> --
> 2.27.0
Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
David Marchand July 7, 2020, 1:57 p.m. UTC | #4
On Mon, Jul 6, 2020 at 9:50 AM Joyce Kong <joyce.kong@arm.com> wrote:
>
> The 'restrict' keyword is recognized in C99, while type qulifier
> '__restrict' compiles ok in C with all language levels. This patch
> is to add a wrapper defining '__rte_restrict' with 'restrict' and
> '__restrict' to be supported by all compilers.
>
> Signed-off-by: Joyce Kong <joyce.kong@arm.com>
> ---
>  lib/librte_eal/include/rte_common.h | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/lib/librte_eal/include/rte_common.h b/lib/librte_eal/include/rte_common.h
> index 0843ce69e..cda32c056 100644
> --- a/lib/librte_eal/include/rte_common.h
> +++ b/lib/librte_eal/include/rte_common.h
> @@ -103,6 +103,16 @@ typedef uint16_t unaligned_uint16_t;
>   */
>  #define __rte_unused __attribute__((__unused__))
>
> +/**
> + * Define a wrapper for restricted pointers which can be supported
> + * by all compilers.
> + */
> +#if __STDC_VERSION__ >= 199901
> +#define __rte_restrict restrict
> +#else
> +#define __rte_restrict __restrict
> +#endif
> +
>  /**
>   * definition to mark a variable or function parameter as used so
>   * as to avoid a compiler warning
> --
> 2.27.0
>

This triggers a build error on Centos 7 as reported by the CI.
I suppose the following would do the trick, though it is untested:

/**
 * Define a wrapper for restricted pointers which can be supported
 * by all compilers.
 */
#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
#define __rte_restrict __restrict
#else
#define __rte_restrict restrict
#endif
Joyce Kong July 8, 2020, 2:46 a.m. UTC | #5
> -----Original Message-----
> From: David Marchand <david.marchand@redhat.com>
> Sent: Tuesday, July 7, 2020 9:57 PM
> To: Joyce Kong <Joyce.Kong@arm.com>
> Cc: Maxime Coquelin <maxime.coquelin@redhat.com>; jerinj@marvell.com;
> Zhihong Wang <zhihong.wang@intel.com>; Xiaolong Ye
> <xiaolong.ye@intel.com>; Beilei Xing <beilei.xing@intel.com>; Jeff Guo
> <jia.guo@intel.com>; Mcnamara, John <john.mcnamara@intel.com>; Matan
> Azrad <matan@mellanox.com>; Shahaf Shuler <shahafs@mellanox.com>;
> Viacheslav Ovsiienko <viacheslavo@mellanox.com>; Honnappa Nagarahalli
> <Honnappa.Nagarahalli@arm.com>; Phil Yang <Phil.Yang@arm.com>;
> Ruifeng Wang <Ruifeng.Wang@arm.com>; dev <dev@dpdk.org>; nd
> <nd@arm.com>
> Subject: Re: [dpdk-dev] [PATCH v2 1/6] lib/eal: add a common wrapper for
> restricted pointers
> 
> On Mon, Jul 6, 2020 at 9:50 AM Joyce Kong <joyce.kong@arm.com> wrote:
> >
> > The 'restrict' keyword is recognized in C99, while type qulifier
> > '__restrict' compiles ok in C with all language levels. This patch is
> > to add a wrapper defining '__rte_restrict' with 'restrict' and
> > '__restrict' to be supported by all compilers.
> >
> > Signed-off-by: Joyce Kong <joyce.kong@arm.com>
> > ---
> >  lib/librte_eal/include/rte_common.h | 10 ++++++++++
> >  1 file changed, 10 insertions(+)
> >
> > diff --git a/lib/librte_eal/include/rte_common.h
> > b/lib/librte_eal/include/rte_common.h
> > index 0843ce69e..cda32c056 100644
> > --- a/lib/librte_eal/include/rte_common.h
> > +++ b/lib/librte_eal/include/rte_common.h
> > @@ -103,6 +103,16 @@ typedef uint16_t unaligned_uint16_t;
> >   */
> >  #define __rte_unused __attribute__((__unused__))
> >
> > +/**
> > + * Define a wrapper for restricted pointers which can be supported
> > + * by all compilers.
> > + */
> > +#if __STDC_VERSION__ >= 199901
> > +#define __rte_restrict restrict
> > +#else
> > +#define __rte_restrict __restrict
> > +#endif
> > +
> >  /**
> >   * definition to mark a variable or function parameter as used so
> >   * as to avoid a compiler warning
> > --
> > 2.27.0
> >
> 
> This triggers a build error on Centos 7 as reported by the CI.
> I suppose the following would do the trick, though it is untested:
> 
> /**
>  * Define a wrapper for restricted pointers which can be supported
>  * by all compilers.
>  */
> #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L #define
> __rte_restrict __restrict #else #define __rte_restrict restrict #endif
> 

Will add this judgement in next version.

> 
> --
> David Marchand

Patch
diff mbox series

diff --git a/lib/librte_eal/include/rte_common.h b/lib/librte_eal/include/rte_common.h
index 0843ce69e..cda32c056 100644
--- a/lib/librte_eal/include/rte_common.h
+++ b/lib/librte_eal/include/rte_common.h
@@ -103,6 +103,16 @@  typedef uint16_t unaligned_uint16_t;
  */
 #define __rte_unused __attribute__((__unused__))
 
+/**
+ * Define a wrapper for restricted pointers which can be supported
+ * by all compilers.
+ */
+#if __STDC_VERSION__ >= 199901
+#define __rte_restrict restrict
+#else
+#define __rte_restrict __restrict
+#endif
+
 /**
  * definition to mark a variable or function parameter as used so
  * as to avoid a compiler warning