Re: [cfe-users] RFC v2: Re: cacheflush.2

2020-12-11 Thread Alejandro Colomar (man-pages) via cfe-users
Hi Michael,

On 12/11/20 9:15 AM, Michael Kerrisk (man-pages) wrote:
> i Alex,
> 
> On 12/10/20 9:56 PM, Alejandro Colomar (man-pages) wrote:
>> Hi all,
>>
>> v2:
>>
>> [
>> NOTES
>>Unless  you  need  the finer grained control that this system
>>call provides, you probably want  to  use  the  GCC  built-in
>>function  __builtin___clear_cache(),  which  provides  a more
>>portable interface:
>>
>>void __builtin___clear_cache(void *begin, void *end);
>> ]
> 
> This seems a reasonable text to me, but I think it would be helpful
> to say a little more precisely what kind of portability we are
> talking about here.
Sure.

> 
> Greater ortability across Linux architectures? Greater portability
> across platforms supported by GCC (including non-Linux) platforms?
> Something else?

'... which provides a portable interface across platforms supported by
GCC:' sounds good.

Maybe GCC devs have something more to add.

Thanks,

Alex

> 
> Thanks,
> 
> Michael
> 
> 

-- 
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es
___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


[cfe-users] RFC v2: Re: cacheflush.2

2020-12-11 Thread Alejandro Colomar (man-pages) via cfe-users
Hi all,

v2:

[
NOTES
   Unless  you  need  the finer grained control that this system
   call provides, you probably want  to  use  the  GCC  built-in
   function  __builtin___clear_cache(),  which  provides  a more
   portable interface:

   void __builtin___clear_cache(void *begin, void *end);
]

If you like it, I'll send the patch.

BTW, I'll also have a look and document the different prototypes for
cacheflush(2).

Thanks,

Alex

On 12/10/20 8:20 PM, Heinrich Schuchardt wrote:
> On 12/10/20 7:17 PM, Dave Martin wrote:
>> On Wed, Dec 09, 2020 at 07:34:09PM +0100, Alejandro Colomar
>> (man-pages) wrote:
>>> Hi Heinrich & Michael,
>>>
>>> What about the following?:
>>>
>>> [
>>> NOTES
>>>     GCC provides a similar function, which may be useful on  archi‐
>>>     tectures that lack this system call:
>>>
>>>     void __builtin___clear_cache(void *begin, void *end);
>>> ]
>>>
>>> Cheers,
>>>
>>> Alex
>>
>> Maybe we should discourage people from calling the cacheflush syscall?
>>
>> I think that people shouldn't be using the syscall unless they really
>> need the finer grained control it provides, and are prepared to take a
>> hit to portability.
>>
>> (On arches where userspace is allowed to do cache flushing directly,
>> __builtin___clear_cache() should transparently do the right thing, with
>> no syscall overhead -- if not, that's probably a bug in the toolchain or
>> compiler support library.)
> 
> What the compiler builtin does depends on the architecture (e.g. nothing
> for x86, cacheflush() for MIPS, a private syscall (0xf0002) on ARM,
> assembly code on ARM64, ...) and on the the operating system (Linux,
> BSD, OS X). For portable code the builtin is really the best choice.
> 
> Best regards
> 
> Heinrich
> 
>>
>> [...]
>>
>> Cheers
>> ---Dave
>>
> 

-- 
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es
___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] cacheflush.2

2020-12-11 Thread Alejandro Colomar (man-pages) via cfe-users
Hi Heinrich,

It looks like a bug (or at least an undocumented divergence from GCC) in
Clang/LLVM.  Or I couldn't find the documentation for it.

Clang uses 'char *':
https://github.com/llvm/llvm-project/blob/7faf62a80bfc3a9dfe34133681fcc31f8e8d658b/clang/include/clang/Basic/Builtins.def#L583

GCC uses 'void *':
https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html

I CCd Clang and GCC lists; maybe they know about that divergence.

Cheers,

Alex

On 12/9/20 7:48 PM, Heinrich Schuchardt wrote:
> On 12/9/20 7:34 PM, Alejandro Colomar (man-pages) wrote:
>> Hi Heinrich & Michael,
>>
>> What about the following?:
>>
>> [
>> NOTES
>>     GCC provides a similar function, which may be useful on  archi‐
>>     tectures that lack this system call:
>>
>>     void __builtin___clear_cache(void *begin, void *end);
>> ]
> 
> I just checked building with Clang/LLVM. There the arguments are of type
> (char *). See the following error output:
> 
> +arch/sandbox/cpu/cache.c:19:26: error: passing 'uint8_t *' (aka
> 'unsigned char *') to parameter of type 'char *' converts between
> pointers to integer types with different sign [-Werror,-Wpointer-sign]
> +    __builtin___clear_cache(state->ram_buf,
> +    ^~
> +arch/sandbox/cpu/cache.c:20:12: error: passing 'uint8_t *' (aka
> 'unsigned char *') to parameter of type 'char *' converts between
> pointers to integer types with different sign [-Werror,-Wpointer-sign]
> +    state->ram_buf + state->ram_size);
> +    ^~~~
> 
> Best regards
> 
> Heinrich
> 
>>
>> Cheers,
>>
>> Alex
>>
>> On 12/9/20 7:04 PM, Heinrich Schuchardt wrote:
>>> Hello Michael,
>>>
>>> function cacheflush() does not exist on many architectures.
>>>
>>> It would have saved me a lot of time if the man-page had referenced
>>> GCC's
>>>
>>> void __builtin___clear_cache(void *begin, void *end)
>>>
>>> Maybe you can add it to NOTES.
>>>
>>> Best regards
>>>
>>> heirnich
>>
> 

-- 
Alejandro Colomar
Linux man-pages comaintainer; http://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es
___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] cacheflush.2

2020-12-11 Thread Alejandro Colomar (man-pages) via cfe-users
It looks like GCC recently moved from 'char *' to 'void *'.
This SO question[1] (4 years ago) quotes the GCC docs
and they had 'char *'.
Maybe Clang hasn't noticed the change.
I'll report a bug.

[1]: https://stackoverflow.com/q/35741814/6872717

On 12/9/20 8:15 PM, Alejandro Colomar (man-pages) wrote:
> Hi Heinrich,
> 
> It looks like a bug (or at least an undocumented divergence from GCC) in
> Clang/LLVM.  Or I couldn't find the documentation for it.
> 
> Clang uses 'char *':
> https://github.com/llvm/llvm-project/blob/7faf62a80bfc3a9dfe34133681fcc31f8e8d658b/clang/include/clang/Basic/Builtins.def#L583
> 
> GCC uses 'void *':
> https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
> 
> I CCd Clang and GCC lists; maybe they know about that divergence.
> 
> Cheers,
> 
> Alex
> 
> On 12/9/20 7:48 PM, Heinrich Schuchardt wrote:
>> On 12/9/20 7:34 PM, Alejandro Colomar (man-pages) wrote:
>>> Hi Heinrich & Michael,
>>>
>>> What about the following?:
>>>
>>> [
>>> NOTES
>>>     GCC provides a similar function, which may be useful on  archi‐
>>>     tectures that lack this system call:
>>>
>>>     void __builtin___clear_cache(void *begin, void *end);
>>> ]
>>
>> I just checked building with Clang/LLVM. There the arguments are of type
>> (char *). See the following error output:
>>
>> +arch/sandbox/cpu/cache.c:19:26: error: passing 'uint8_t *' (aka
>> 'unsigned char *') to parameter of type 'char *' converts between
>> pointers to integer types with different sign [-Werror,-Wpointer-sign]
>> +    __builtin___clear_cache(state->ram_buf,
>> +    ^~
>> +arch/sandbox/cpu/cache.c:20:12: error: passing 'uint8_t *' (aka
>> 'unsigned char *') to parameter of type 'char *' converts between
>> pointers to integer types with different sign [-Werror,-Wpointer-sign]
>> +    state->ram_buf + state->ram_size);
>> +    ^~~~
>>
>> Best regards
>>
>> Heinrich
>>
>>>
>>> Cheers,
>>>
>>> Alex
>>>
>>> On 12/9/20 7:04 PM, Heinrich Schuchardt wrote:
 Hello Michael,

 function cacheflush() does not exist on many architectures.

 It would have saved me a lot of time if the man-page had referenced
 GCC's

 void __builtin___clear_cache(void *begin, void *end)

 Maybe you can add it to NOTES.

 Best regards

 heirnich
>>>
>>
> 

-- 
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es
___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


[cfe-users] RFC v3: Re: cacheflush.2

2020-12-11 Thread Alejandro Colomar (man-pages) via cfe-users
Hi all,

Please review this text:

[
NOTES
   Unless  you  need  the finer grained control that this system
   call provides, you probably want  to  use  the  GCC  built-in
   function  __builtin___clear_cache(),  which  provides  a more
   portable interface:

   void __builtin___clear_cache(void *begin, void *end);

   On platforms that don't require  instruction  cache  flushes,
   __builtin___clear_cache() has no effect.

   Note:  On  some  GCC-compatible compilers, such as clang, the
   prototype for this function uses char * instead of void *.
]

Thanks,

Alex

On 12/11/20 7:02 PM, Alejandro Colomar (man-pages) wrote:
> Hi Michael,
> 
> On 12/11/20 9:15 AM, Michael Kerrisk (man-pages) wrote:
>> i Alex,
>>
>> On 12/10/20 9:56 PM, Alejandro Colomar (man-pages) wrote:
>>> Hi all,
>>>
>>> v2:
>>>
>>> [
>>> NOTES
>>>Unless  you  need  the finer grained control that this system
>>>call provides, you probably want  to  use  the  GCC  built-in
>>>function  __builtin___clear_cache(),  which  provides  a more
>>>portable interface:
>>>
>>>void __builtin___clear_cache(void *begin, void *end);
>>> ]
>>
>> This seems a reasonable text to me, but I think it would be helpful
>> to say a little more precisely what kind of portability we are
>> talking about here.
> Sure.
> 
>>
>> Greater ortability across Linux architectures? Greater portability
>> across platforms supported by GCC (including non-Linux) platforms?
>> Something else?
> 
> '... which provides a portable interface across platforms supported by
> GCC:' sounds good.
> 
> Maybe GCC devs have something more to add.

> 
> Thanks,
> 
> Alex
> 
>>
>> Thanks,
>>
>> Michael
>>
>>
> 

-- 
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es
___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


[cfe-users] RFC v4: Re: cacheflush.2

2020-12-11 Thread Alejandro Colomar (man-pages) via cfe-users
I forgot to add a junk to the text.

v4:

NOTES
   Unless  you  need  the finer grained control that this system
   call provides, you probably want  to  use  the  GCC  built-in
   function __builtin___clear_cache(), which provides a portable
   interface across platforms supported by  GCC  and  compatible
   compilers:

//Maybe 'and compatible compilers' is redundant and I should remove it?

   void __builtin___clear_cache(void *begin, void *end);

   On  platforms  that  don't require instruction cache flushes,
   __builtin___clear_cache() has no effect.

   Note: On some GCC-compatible compilers, such  as  clang,  the
   prototype for this function uses char * instead of void *.


On 12/11/20 7:22 PM, Alejandro Colomar (man-pages) wrote:
> Hi all,
> 
> Please review this text:
> 
> [
> NOTES
>Unless  you  need  the finer grained control that this system
>call provides, you probably want  to  use  the  GCC  built-in
>function  __builtin___clear_cache(),  which  provides  a more
>portable interface:
> 
>void __builtin___clear_cache(void *begin, void *end);
> 
>On platforms that don't require  instruction  cache  flushes,
>__builtin___clear_cache() has no effect.
> 
>Note:  On  some  GCC-compatible compilers, such as clang, the
>prototype for this function uses char * instead of void *.
> ]
> 
> Thanks,
> 
> Alex
> 
> On 12/11/20 7:02 PM, Alejandro Colomar (man-pages) wrote:
>> Hi Michael,
>>
>> On 12/11/20 9:15 AM, Michael Kerrisk (man-pages) wrote:
>>> i Alex,
>>>
>>> On 12/10/20 9:56 PM, Alejandro Colomar (man-pages) wrote:
 Hi all,

 v2:

 [
 NOTES
Unless  you  need  the finer grained control that this system
call provides, you probably want  to  use  the  GCC  built-in
function  __builtin___clear_cache(),  which  provides  a more
portable interface:

void __builtin___clear_cache(void *begin, void *end);
 ]
>>>
>>> This seems a reasonable text to me, but I think it would be helpful
>>> to say a little more precisely what kind of portability we are
>>> talking about here.
>> Sure.
>>
>>>
>>> Greater ortability across Linux architectures? Greater portability
>>> across platforms supported by GCC (including non-Linux) platforms?
>>> Something else?
>>
>> '... which provides a portable interface across platforms supported by
>> GCC:' sounds good.
>>
>> Maybe GCC devs have something more to add.
> 
>>
>> Thanks,
>>
>> Alex
>>
>>>
>>> Thanks,
>>>
>>> Michael
>>>
>>>
>>
> 

-- 
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es
___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] RFC v2: Re: cacheflush.2

2020-12-11 Thread Michael Kerrisk (man-pages) via cfe-users
i Alex,

On 12/10/20 9:56 PM, Alejandro Colomar (man-pages) wrote:
> Hi all,
> 
> v2:
> 
> [
> NOTES
>Unless  you  need  the finer grained control that this system
>call provides, you probably want  to  use  the  GCC  built-in
>function  __builtin___clear_cache(),  which  provides  a more
>portable interface:
> 
>void __builtin___clear_cache(void *begin, void *end);
> ]

This seems a reasonable text to me, but I think it would be helpful
to say a little more precisely what kind of portability we are
talking about here.

Greater ortability across Linux architectures? Greater portability
across platforms supported by GCC (including non-Linux) platforms?
Something else?

Thanks,

Michael


-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users