[dpdk-dev] [PATCH] test-pmd: Fix pointer aliasing error

2014-12-04 Thread Qiu, Michael
On 12/3/2014 11:36 PM, Richardson, Bruce wrote:
> On Wed, Dec 03, 2014 at 03:19:34PM +, Qiu, Michael wrote:
>> On 2014/12/3 22:51, Richardson, Bruce wrote:
>>> On Wed, Dec 03, 2014 at 01:59:58PM +, Qiu, Michael wrote:
 On 2014/12/3 19:43, Richardson, Bruce wrote:
> On Wed, Dec 03, 2014 at 07:28:19PM +0800, Michael Qiu wrote:
>> app/test-pmd/csumonly.c: In function ?get_psd_sum?:
>> build/include/rte_ip.h:161: error: dereferencing pointer ?u16?
>>  does break strict-aliasing rules
>> build/include/rte_ip.h:157: note: initialized from here
>>  ...
>>
>> The root cause is that, compile enable strict aliasing by default,
>> while in function rte_raw_cksum() try to convert 'const char *'
>> to 'const uint16_t *'.
>>
> What compiler version is this with? Is there any other way to fix this
> other than disabling the compiler warnings. Turning off strict aliasing 
> may
> affect performance as it reduces the number of optimizations that the 
> compiler
> can perform.
 The compile version is:

 $ gcc -v
 Using built-in specs.
 Target: x86_64-redhat-linux
 ...
 gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)


 The OS is centos6.5 x86_64


 Actually, another possible solution is, as gcc manual shows, use union.
 In function rte_raw_cksum() of lib/librte_net/rte_ip.h:

 static inline uint16_t
 rte_raw_cksum(const char *buf, size_t len){
 union {
 const char *ubuf;
 const uint16_t *uu16;
 } convert;

 convert.ubuf = buf;
 const uint16_t *u16 = convert.uu16;
 ...
 }

 This may be work, but not test yet.

 Any comments about this solution?
>>> what happens if you make rte_raw_cksum take a void * (or const void *) 
>>> parameter
>>> instead of "const char *"?
>> "size_t len" is for type char, it is the the array size(for char array
>> is byte numbers), if we use void *, the meaning maybe confuse I think.
> That shouldn't be a big issue. We can rename it to "size" instead of "len" if
> needed.

As I tested in my env just, void * is still not work, the same errors
post when compile.

Then the solution for DPDK should be:
-  As Olivier suggest, add the -Wno-strict-aliasing only for gcc 4.4 in
the Makefile
- As gcc manual suggest, use "union" to work around this issue.

Thanks,
Michael
>> But it should work with other code change.
>>
>> Thanks,
>> Michael
>>> /Bruce
>>>



[dpdk-dev] [PATCH] test-pmd: Fix pointer aliasing error

2014-12-04 Thread Dayu Qiu
Hi Olivier,

You can check gcc manual.

-fstrict-aliasing
   Allow the compiler to assume the strictest aliasing rules
applicable to the language being
   compiled.  For C (and C++), this activates optimizations based
on the type of expressions.  In
   particular, an object of one type is assumed never to reside at
the same address as an object of a
   different type, unless the types are almost the same.  For
example, an "unsigned int" can alias an
   "int", but not a "void*" or a "double".  A character type may
alias any other type.

So it should not be a bug, but I have no idea about why other version does
not reproduce.

Thanks,
Michael

On Wed, Dec 3, 2014 at 11:24 PM, Olivier MATZ 
wrote:

> Hi Bruce,
>
> On 12/03/2014 12:42 PM, Bruce Richardson wrote:
>
>> On Wed, Dec 03, 2014 at 07:28:19PM +0800, Michael Qiu wrote:
>>
>>> app/test-pmd/csumonly.c: In function ?get_psd_sum?:
>>> build/include/rte_ip.h:161: error: dereferencing pointer ?u16?
>>> does break strict-aliasing rules
>>> build/include/rte_ip.h:157: note: initialized from here
>>> ...
>>>
>>> The root cause is that, compile enable strict aliasing by default,
>>> while in function rte_raw_cksum() try to convert 'const char *'
>>> to 'const uint16_t *'.
>>>
>>>
>> What compiler version is this with? Is there any other way to fix this
>> other than disabling the compiler warnings. Turning off strict aliasing
>> may
>> affect performance as it reduces the number of optimizations that the
>> compiler
>> can perform.
>>
>
> I can reproduce the issue with a gcc-4.4.6 toolchain. But I think it's
> a toolchain bug as the warning does not occur with other versions I've
> tested.
>
> If it's the case, we could either:
>
> - do nothing: in this case the user need to upgrade its toolchain, or
>   pass the -Wno-strict-aliasing manually in EXTRA_CFLAGS
>
> - add the -Wno-strict-aliasing only for gcc 4.4 in the Makefile
>
> What do you think?
>
> Regards,
> Olivier
>
>


-- 
Thanks & Best Regards
Mike


[dpdk-dev] [PATCH] test-pmd: Fix pointer aliasing error

2014-12-03 Thread Dayu Qiu
Just re-post this mail as Thomas said it missed in mail list.

On Wed, Dec 3, 2014 at 7:42 PM, Bruce Richardson  wrote:

> On Wed, Dec 03, 2014 at 07:28:19PM +0800, Michael Qiu wrote:
> > app/test-pmd/csumonly.c: In function ?get_psd_sum?:
> > build/include/rte_ip.h:161: error: dereferencing pointer ?u16?
> >   does break strict-aliasing rules
> > build/include/rte_ip.h:157: note: initialized from here
> >   ...
> >
> > The root cause is that, compile enable strict aliasing by default,
> > while in function rte_raw_cksum() try to convert 'const char *'
> > to 'const uint16_t *'.
> >
>
> What compiler version is this with? Is there any other way to fix this
> other than disabling the compiler warnings. Turning off strict aliasing may
> affect performance as it reduces the number of optimizations that the
> compiler
> can perform.
>
>

The compile version is:

$ gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
...
gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)


The OS is centos6.5 x86_64


Actually, another possible solution is, as gcc manual shows, use union.
In function rte_raw_cksum() of lib/librte_net/rte_ip.h:

static inline uint16_t
rte_raw_cksum(const char *buf, size_t len){
union {
const char *ubuf;
const uint16_t *uu16;
} convert;

convert.ubuf = buf;
const uint16_t *u16 = convert.uu16;
...
}

This may be work, but not test yet.


Thanks,
Michael

> /Bruce
>
> > Need to add CFLAG '-Wno-strict-aliasing' to avoid this issue.
> >
> > Signed-off-by: Michael Qiu 
> > ---
> >  app/test-pmd/Makefile | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/app/test-pmd/Makefile b/app/test-pmd/Makefile
> > index 97dc2e6..995c874 100644
> > --- a/app/test-pmd/Makefile
> > +++ b/app/test-pmd/Makefile
> > @@ -38,7 +38,7 @@ ifeq ($(CONFIG_RTE_TEST_PMD),y)
> >  #
> >  APP = testpmd
> >
> > -CFLAGS += -O3
> > +CFLAGS += -O3 -Wno-strict-aliasing
> >  CFLAGS += $(WERROR_FLAGS)
> >
> >  ifeq ($(CONFIG_RTE_LIBRTE_PMD_PCAP),y)
> > --
> > 1.9.3
> >
>



-- 
Thanks & Best Regards
Mike


[dpdk-dev] [PATCH] test-pmd: Fix pointer aliasing error

2014-12-03 Thread Olivier MATZ
Hi Bruce,

On 12/03/2014 12:42 PM, Bruce Richardson wrote:
> On Wed, Dec 03, 2014 at 07:28:19PM +0800, Michael Qiu wrote:
>> app/test-pmd/csumonly.c: In function ?get_psd_sum?:
>> build/include/rte_ip.h:161: error: dereferencing pointer ?u16?
>>  does break strict-aliasing rules
>> build/include/rte_ip.h:157: note: initialized from here
>>  ...
>>
>> The root cause is that, compile enable strict aliasing by default,
>> while in function rte_raw_cksum() try to convert 'const char *'
>> to 'const uint16_t *'.
>>
>
> What compiler version is this with? Is there any other way to fix this
> other than disabling the compiler warnings. Turning off strict aliasing may
> affect performance as it reduces the number of optimizations that the compiler
> can perform.

I can reproduce the issue with a gcc-4.4.6 toolchain. But I think it's
a toolchain bug as the warning does not occur with other versions I've
tested.

If it's the case, we could either:

- do nothing: in this case the user need to upgrade its toolchain, or
   pass the -Wno-strict-aliasing manually in EXTRA_CFLAGS

- add the -Wno-strict-aliasing only for gcc 4.4 in the Makefile

What do you think?

Regards,
Olivier



[dpdk-dev] [PATCH] test-pmd: Fix pointer aliasing error

2014-12-03 Thread Bruce Richardson
On Wed, Dec 03, 2014 at 03:19:34PM +, Qiu, Michael wrote:
> On 2014/12/3 22:51, Richardson, Bruce wrote:
> > On Wed, Dec 03, 2014 at 01:59:58PM +, Qiu, Michael wrote:
> >> On 2014/12/3 19:43, Richardson, Bruce wrote:
> >>> On Wed, Dec 03, 2014 at 07:28:19PM +0800, Michael Qiu wrote:
>  app/test-pmd/csumonly.c: In function ?get_psd_sum?:
>  build/include/rte_ip.h:161: error: dereferencing pointer ?u16?
>   does break strict-aliasing rules
>  build/include/rte_ip.h:157: note: initialized from here
>   ...
> 
>  The root cause is that, compile enable strict aliasing by default,
>  while in function rte_raw_cksum() try to convert 'const char *'
>  to 'const uint16_t *'.
> 
> >>> What compiler version is this with? Is there any other way to fix this
> >>> other than disabling the compiler warnings. Turning off strict aliasing 
> >>> may
> >>> affect performance as it reduces the number of optimizations that the 
> >>> compiler
> >>> can perform.
> >> The compile version is:
> >>
> >> $ gcc -v
> >> Using built-in specs.
> >> Target: x86_64-redhat-linux
> >> ...
> >> gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)
> >>
> >>
> >> The OS is centos6.5 x86_64
> >>
> >>
> >> Actually, another possible solution is, as gcc manual shows, use union.
> >> In function rte_raw_cksum() of lib/librte_net/rte_ip.h:
> >>
> >> static inline uint16_t
> >> rte_raw_cksum(const char *buf, size_t len){
> >> union {
> >> const char *ubuf;
> >> const uint16_t *uu16;
> >> } convert;
> >>
> >> convert.ubuf = buf;
> >> const uint16_t *u16 = convert.uu16;
> >> ...
> >> }
> >>
> >> This may be work, but not test yet.
> >>
> >> Any comments about this solution?
> > what happens if you make rte_raw_cksum take a void * (or const void *) 
> > parameter
> > instead of "const char *"?
> 
> "size_t len" is for type char, it is the the array size(for char array
> is byte numbers), if we use void *, the meaning maybe confuse I think.
That shouldn't be a big issue. We can rename it to "size" instead of "len" if
needed.

> But it should work with other code change.
> 
> Thanks,
> Michael
> >
> > /Bruce
> >
> 


[dpdk-dev] [PATCH] test-pmd: Fix pointer aliasing error

2014-12-03 Thread Bruce Richardson
On Wed, Dec 03, 2014 at 01:59:58PM +, Qiu, Michael wrote:
> On 2014/12/3 19:43, Richardson, Bruce wrote:
> > On Wed, Dec 03, 2014 at 07:28:19PM +0800, Michael Qiu wrote:
> >> app/test-pmd/csumonly.c: In function ?get_psd_sum?:
> >> build/include/rte_ip.h:161: error: dereferencing pointer ?u16?
> >>does break strict-aliasing rules
> >> build/include/rte_ip.h:157: note: initialized from here
> >>...
> >>
> >> The root cause is that, compile enable strict aliasing by default,
> >> while in function rte_raw_cksum() try to convert 'const char *'
> >> to 'const uint16_t *'.
> >>
> > What compiler version is this with? Is there any other way to fix this
> > other than disabling the compiler warnings. Turning off strict aliasing may
> > affect performance as it reduces the number of optimizations that the 
> > compiler
> > can perform.
> 
> The compile version is:
> 
> $ gcc -v
> Using built-in specs.
> Target: x86_64-redhat-linux
> ...
> gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)
> 
> 
> The OS is centos6.5 x86_64
> 
> 
> Actually, another possible solution is, as gcc manual shows, use union.
> In function rte_raw_cksum() of lib/librte_net/rte_ip.h:
> 
> static inline uint16_t
> rte_raw_cksum(const char *buf, size_t len){
> union {
> const char *ubuf;
> const uint16_t *uu16;
> } convert;
> 
> convert.ubuf = buf;
> const uint16_t *u16 = convert.uu16;
> ...
> }
> 
> This may be work, but not test yet.
> 
> Any comments about this solution?

what happens if you make rte_raw_cksum take a void * (or const void *) parameter
instead of "const char *"?

/Bruce


[dpdk-dev] [PATCH] test-pmd: Fix pointer aliasing error

2014-12-03 Thread Qiu, Michael
On 2014/12/3 19:43, Richardson, Bruce wrote:
> On Wed, Dec 03, 2014 at 07:28:19PM +0800, Michael Qiu wrote:
>> app/test-pmd/csumonly.c: In function ?get_psd_sum?:
>> build/include/rte_ip.h:161: error: dereferencing pointer ?u16?
>>  does break strict-aliasing rules
>> build/include/rte_ip.h:157: note: initialized from here
>>  ...
>>
>> The root cause is that, compile enable strict aliasing by default,
>> while in function rte_raw_cksum() try to convert 'const char *'
>> to 'const uint16_t *'.
>>
> What compiler version is this with? Is there any other way to fix this
> other than disabling the compiler warnings. Turning off strict aliasing may
> affect performance as it reduces the number of optimizations that the compiler
> can perform.

The compile version is:

$ gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
...
gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)


The OS is centos6.5 x86_64


Actually, another possible solution is, as gcc manual shows, use union.
In function rte_raw_cksum() of lib/librte_net/rte_ip.h:

static inline uint16_t
rte_raw_cksum(const char *buf, size_t len){
union {
const char *ubuf;
const uint16_t *uu16;
} convert;

convert.ubuf = buf;
const uint16_t *u16 = convert.uu16;
...
}

This may be work, but not test yet.

Any comments about this solution?

Thanks,
Michael
>
> /Bruce
>
>> Need to add CFLAG '-Wno-strict-aliasing' to avoid this issue.
>>
>> Signed-off-by: Michael Qiu 
>> ---
>>  app/test-pmd/Makefile | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/app/test-pmd/Makefile b/app/test-pmd/Makefile
>> index 97dc2e6..995c874 100644
>> --- a/app/test-pmd/Makefile
>> +++ b/app/test-pmd/Makefile
>> @@ -38,7 +38,7 @@ ifeq ($(CONFIG_RTE_TEST_PMD),y)
>>  #
>>  APP = testpmd
>>  
>> -CFLAGS += -O3
>> +CFLAGS += -O3 -Wno-strict-aliasing
>>  CFLAGS += $(WERROR_FLAGS)
>>  
>>  ifeq ($(CONFIG_RTE_LIBRTE_PMD_PCAP),y)
>> -- 
>> 1.9.3
>>



[dpdk-dev] [PATCH] test-pmd: Fix pointer aliasing error

2014-12-03 Thread Bruce Richardson
On Wed, Dec 03, 2014 at 07:28:19PM +0800, Michael Qiu wrote:
> app/test-pmd/csumonly.c: In function ?get_psd_sum?:
> build/include/rte_ip.h:161: error: dereferencing pointer ?u16?
>   does break strict-aliasing rules
> build/include/rte_ip.h:157: note: initialized from here
>   ...
> 
> The root cause is that, compile enable strict aliasing by default,
> while in function rte_raw_cksum() try to convert 'const char *'
> to 'const uint16_t *'.
>

What compiler version is this with? Is there any other way to fix this
other than disabling the compiler warnings. Turning off strict aliasing may
affect performance as it reduces the number of optimizations that the compiler
can perform.

/Bruce

> Need to add CFLAG '-Wno-strict-aliasing' to avoid this issue.
> 
> Signed-off-by: Michael Qiu 
> ---
>  app/test-pmd/Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/app/test-pmd/Makefile b/app/test-pmd/Makefile
> index 97dc2e6..995c874 100644
> --- a/app/test-pmd/Makefile
> +++ b/app/test-pmd/Makefile
> @@ -38,7 +38,7 @@ ifeq ($(CONFIG_RTE_TEST_PMD),y)
>  #
>  APP = testpmd
>  
> -CFLAGS += -O3
> +CFLAGS += -O3 -Wno-strict-aliasing
>  CFLAGS += $(WERROR_FLAGS)
>  
>  ifeq ($(CONFIG_RTE_LIBRTE_PMD_PCAP),y)
> -- 
> 1.9.3
>