Re: [gentoo-user] Re: Multilib ABI specific CPU use flags?

2020-10-08 Thread Walter Dnes
On Fri, Oct 09, 2020 at 12:26:17AM +, Jonathan Yong wrote
> 
> I have a skylake system:
> CPU_FLAGS_X86: aes avx avx2 f16c fma3 mmx mmxext pclmul popcnt rdrand 
> sse sse2 sse3 sse4_1 sse4_2 ssse3

  A heavy-handed 2-part solution
1) remove "avx2" from CPU_FLAGS_X86
2) assuming you have "-march=native" or "-march=skylake" in your CFLAGS
and CXXFLAGS, follow that with "-march=no-avx2".  e.g...
"-march=skylake -march=no-avx2"

  This tells gcc "I don't have avx2, so don't compile any avx2 code".
I think the performance loss will be minimal.

-- 
Walter Dnes 
I don't run "desktop environments"; I run useful applications



Re: [gentoo-user] Re: Multilib ABI specific CPU use flags?

2020-10-08 Thread Jonathan Yong

On 10/8/20 3:40 PM, Ashley Dixon wrote:

On Thu, Oct 08, 2020 at 11:57:52AM +, Jonathan Yong wrote:

I am getting AVX2 related compile errors in 32bit media-libs/opencv-4.4.0,
there are some internet text mentioning not all AVX2 instructions are
supported on 32bit x86.

For now, I have set -abi_x86_32 since I don't need it now.

Any plans to support ABI specific USE masking/setting?


Do you mean that you want to install the 32-bit and 64-bit version of a package,
enabling one set of flags on one, and another set on the other?



Yes exactly, but more to CPU, I understand perfectly other USE flags 
will make dependency calculation much more complicated.



The problem you will face is that the CPU_FLAGS_X86 option, which allows you  to
disable AVX(2)  instructions,  amongst  many  other  processor  extensions  [1],
applies to both x86 and amd64 architectures, and from reading the according wiki
page [2], I don't think it's possible to discriminate between those two;  it  is
the responsibility of the package to test  whether  a  particular  AVX  function
should be employed or not.

Can you post the output of `cpuid2cpuflags`  (from  app-portage/cpuid2cpuflags)?
If this list includes "avx2", and the compilation is still failing,  this  is  a
BUG and should be reported as such.  I think it's known to the Gentoo  community
already, although it seems to be an issue with upstream [3].   Analogous  issues
exist in other packages [4].



I have a skylake system:
CPU_FLAGS_X86: aes avx avx2 f16c fma3 mmx mmxext pclmul popcnt rdrand 
sse sse2 sse3 sse4_1 sse4_2 ssse3



The problem in upstream is probably caused by this call to  _mm256_extract_epi64
[5], introduced quite a while ago (the nature of this function, being  exclusive
to 64-bit processors, was even noted in the commit message [6]).



Yes this was the same error I had, albeit through some C++ error message 
mangling.



It will probably be fixed soon. No need to worry since you don't need the 32-bit
binary interface anyway.



This time, I can avoid it, since OpenCV is not a dependency of 32bit 
Wine, which I do use.



[1] 
https://gitweb.gentoo.org/repo/gentoo.git/plain/profiles/desc/cpu_flags_x86.desc
[2] https://wiki.gentoo.org/wiki/CPU_FLAGS_X86#Configuration
[3] https://bugs.gentoo.org/747163
[4] https://github.com/pytorch/pytorch/issues/17901
[5] 
https://github.com/opencv/opencv/blame/152e6476d9a270e6ce35d3f1b200a303654e576e/modules/core/include/opencv2/core/hal/intrin_avx.hpp#L130
[6] 
https://github.com/opencv/opencv/commit/75315fb297a010153d3acab8111ebb87d909cdcf



I'm open to fixing ebuild packages by myself in my own overlay, though I 
prefer not to due to eventual bit rot. Any hints on how to mask CPU USE 
flags based on multilib arch in the .ebuild file itself?


My previous attempt was through portage bashrc, but it was too late in 
the emerge processing.


OpenPGP_0x713B5FE29C145D45_and_old_rev.asc
Description: application/pgp-keys


OpenPGP_signature
Description: OpenPGP digital signature


Re: [gentoo-user] preparing for make menuconfig

2020-10-08 Thread John Covici
On Thu, 08 Oct 2020 16:26:19 -0400,
Ashley Dixon wrote:
> 
> [1  ]
> On Thu, Oct 08, 2020 at 01:55:04PM -0400, John Covici wrote:
> > modules.alias  modules.builtin
> > modules.builtin.binmodules.dep.binmodules.order
> > modules.symbols
> > modules.alias.bin  modules.builtin.alias.bin  modules.dep
> > modules.devnamemodules.softdep
> > modules.symbols.bin
> 
> That's fine.
> 
> > and the error message is
> > 
> > lspci: Unable to load libkmod resources: error -12
> 
> That error message is printed by lspci [1], although it is  the  result  of  
> the
> libkmod `kmod_load_resources` function returning less than zero [2].  With a 
> -12
> error, this suggests a failing with the `index_mm_open` function [3]. It's 
> quite
> a beast of a function; the failure could be due to a multitude of reasons.
> 
> Considering the nature of the error (memory allocation  failure),  I  reckon  
> it
> must be either the following call to mmap(2), or the preceding call to  
> open(2):
> (paraphrasing for formatting):
> 
> 
>   if ((fd = open(filename, O_RDONLY|O_CLOEXEC)) < 0) {
>   DBG(ctx, "open(%s, O_RDONLY|O_CLOEXEC): %m\n", filename);
>   err = -errno;
>   goto fail_open;
>   }
> 
> /* [...] */
> 
>   if ( ( idx->mm = mmap ( NULL, st.st_size, PROT_READ,
> MAP_PRIVATE, fd, 0 ) ) == MAP_FAILED) 
> {
>   ERR(ctx, "mmap (NULL, %"PRIu64", PROT_READ, %d, " \
> "MAP_PRIVATE, 0 ): %m\n", st.st_size, fd);
>   err = -errno;
>   goto fail_nommap;
>   }
> 
> I might you need to debug this on your machine, as I can't reproduce it  
> myself.
> You'll need to clone, recompile,  and  relink  libkmod  and  pciutils  with  
> the
> maximum debugging settings, to keep all symbols in  the  executable.   I  
> assume
> you're using GCC, although I suspect the same should work with Clang.
> 
> git clone both repos: [4] and [5].
> 
> libkmod:
> - Save the old symlink, by renaming /lib64/libkmod. to
>   something temporary, like libkmod.old.
> - Execute ./autogen.sh to create a configure script.
> - Run the configure script to enable maximum debugging:
> ./configure CFLAGS='-ggdb3' --prefix=/usr --sysconfdir=/etc \
> --libdir=/usr/lib64 --with-rootprefix= 
> --with-rootlibdir=/lib64
> - Compile and install the shared objects (you need to be root):
> make && make install
> - Ensure the `make install` has recreated the major version symlink in
>   /lib64 to the new shared object file.
> 
> pciutils:
> - Compile; there is no need to install:
> make CFLAGS="-ggdb3"
> 
> Now you have an lspci executable which is linked with the new libkmod, just 
> need
> to attach a debugger, such as gdb, and break on the troublesome function:
> 
> $ gdb ./lspci
> Reading symbols from ./lspci...
> (gdb) b index_mm_open
> Function "index_mm_open" not defined.
> Make breakpoint pending on future shared library load? (y or [n]) y
> Breakpoint 1 (index_mm_open) pending.
> (gdb) run -k
> 
> ... after a while, you'll encounter the first invocation of the troublemaker:
> 
> Breakpoint 1, index_mm_open (ctx=0x55583340, 
> filename=0x7fffc920
> "/lib/modules/5.4.60-gentoo/modules.dep.bin", 
> stamp=0x555833a0,
> pidx=0x55583378) at libkmod/libkmod-index.c:744
> 
> Before going any further, I want to confirm that  `filename`  does  point  to 
>  a
> correct file?  I doubt the open(2) call would fail with ENOMEM if the  file  
> was
> invalid, although you never know.  Assuming `filename` is valid,  we  can  
> start
> stepping through the function to determine which inner function is failing.   
> My
> bets are on mmap.
> 
> Hope to hear from you soon.
> 
> [1] 
> https://git.kernel.org/pub/scm/utils/pciutils/pciutils.git/tree/ls-kernel.c#n42
> [2] 
> https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git/tree/libkmod/libkmod.c#n842
> [3] 
> https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git/tree/libkmod/libkmod-index.c#n742
> [4] git://git.kernel.org/pub/scm/utils/pciutils/pciutils.git
> [5] git://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git
> 


Since I compile most packages with split-debug and my default flags
contain -gdb, could I use  the existing packages?

-- 
Your life is like a penny.  You're going to lose it.  The question is:
How do
you spend it?

 John Covici wb2una
 cov...@ccs.covici.com



Re: [gentoo-user] preparing for make menuconfig

2020-10-08 Thread Ashley Dixon
On Thu, Oct 08, 2020 at 01:55:04PM -0400, John Covici wrote:
> modules.alias  modules.builtin
> modules.builtin.binmodules.dep.binmodules.order
> modules.symbols
> modules.alias.bin  modules.builtin.alias.bin  modules.dep
> modules.devnamemodules.softdep
> modules.symbols.bin

That's fine.

> and the error message is
> 
> lspci: Unable to load libkmod resources: error -12

That error message is printed by lspci [1], although it is  the  result  of  the
libkmod `kmod_load_resources` function returning less than zero [2].  With a -12
error, this suggests a failing with the `index_mm_open` function [3]. It's quite
a beast of a function; the failure could be due to a multitude of reasons.

Considering the nature of the error (memory allocation  failure),  I  reckon  it
must be either the following call to mmap(2), or the preceding call to  open(2):
(paraphrasing for formatting):


if ((fd = open(filename, O_RDONLY|O_CLOEXEC)) < 0) {
DBG(ctx, "open(%s, O_RDONLY|O_CLOEXEC): %m\n", filename);
err = -errno;
goto fail_open;
}

/* [...] */

if ( ( idx->mm = mmap ( NULL, st.st_size, PROT_READ,
MAP_PRIVATE, fd, 0 ) ) == MAP_FAILED) {
ERR(ctx, "mmap (NULL, %"PRIu64", PROT_READ, %d, " \
"MAP_PRIVATE, 0 ): %m\n", st.st_size, fd);
err = -errno;
goto fail_nommap;
}

I might you need to debug this on your machine, as I can't reproduce it  myself.
You'll need to clone, recompile,  and  relink  libkmod  and  pciutils  with  the
maximum debugging settings, to keep all symbols in  the  executable.   I  assume
you're using GCC, although I suspect the same should work with Clang.

git clone both repos: [4] and [5].

libkmod:
- Save the old symlink, by renaming /lib64/libkmod. to
  something temporary, like libkmod.old.
- Execute ./autogen.sh to create a configure script.
- Run the configure script to enable maximum debugging:
./configure CFLAGS='-ggdb3' --prefix=/usr --sysconfdir=/etc \
--libdir=/usr/lib64 --with-rootprefix= --with-rootlibdir=/lib64
- Compile and install the shared objects (you need to be root):
make && make install
- Ensure the `make install` has recreated the major version symlink in
  /lib64 to the new shared object file.

pciutils:
- Compile; there is no need to install:
make CFLAGS="-ggdb3"

Now you have an lspci executable which is linked with the new libkmod, just need
to attach a debugger, such as gdb, and break on the troublesome function:

$ gdb ./lspci
Reading symbols from ./lspci...
(gdb) b index_mm_open
Function "index_mm_open" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (index_mm_open) pending.
(gdb) run -k

... after a while, you'll encounter the first invocation of the troublemaker:

Breakpoint 1, index_mm_open (ctx=0x55583340, filename=0x7fffc920
"/lib/modules/5.4.60-gentoo/modules.dep.bin", stamp=0x555833a0,
pidx=0x55583378) at libkmod/libkmod-index.c:744

Before going any further, I want to confirm that  `filename`  does  point  to  a
correct file?  I doubt the open(2) call would fail with ENOMEM if the  file  was
invalid, although you never know.  Assuming `filename` is valid,  we  can  start
stepping through the function to determine which inner function is failing.   My
bets are on mmap.

Hope to hear from you soon.

[1] 
https://git.kernel.org/pub/scm/utils/pciutils/pciutils.git/tree/ls-kernel.c#n42
[2] 
https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git/tree/libkmod/libkmod.c#n842
[3] 
https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git/tree/libkmod/libkmod-index.c#n742
[4] git://git.kernel.org/pub/scm/utils/pciutils/pciutils.git
[5] git://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git

-- 

Ashley Dixon
suugaku.co.uk

2A9A 4117
DA96 D18A
8A7B B0D2
A30E BF25
F290 A8AA



signature.asc
Description: PGP signature


Re: [gentoo-user] preparing for make menuconfig

2020-10-08 Thread John Covici
On Thu, 08 Oct 2020 11:07:44 -0400,
Ashley Dixon wrote:
> 
> [1  ]
> On Thu, Oct 08, 2020 at 07:04:46AM -0400, John Covici wrote:
> > I always get this error, but the flag indicating which driver is being
> > used still works, so I have not paid too much attention to this one.
> > I do have a running system with /lib/modules and the error still
> > occurrs.
> 
> What is the exact error?  Is it accompanied by an error code?  libkmod looks 
> for
> the following files, typically  located  in  `/lib/modules/$(uname  -r)/`,  
> when
> client applications request a context [1]; most of these can be  generated  
> with
> depmod(8):
> 
>  - modules.dep
>  - modules.alias
>  - modules.symbols
>  - modules.builtin.alias
>  - modules.builtin
> 
> struct _index_files {
> const char *fn;
> const char *prefix;
> }
> 
> The most interesting for kernel modules is `modules.alias`, which  is  the  
> more
> modern representation of `modules.{pci,usb}map` [2].  Are all these files 
> intact
> on your system? What happens when you run `lsmod`?
> 
> [1] 
> https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git/tree/libkmod/libkmod.c#n53
> [2] https://stackoverflow.com/a/25644147/

I have the following in my running kernel:

modules.alias  modules.builtin
modules.builtin.binmodules.dep.binmodules.order
modules.symbols
modules.alias.bin  modules.builtin.alias.bin  modules.dep
modules.devnamemodules.softdep
modules.symbols.bin

and the error message is

lspci: Unable to load libkmod resources: error -12


-- 
Your life is like a penny.  You're going to lose it.  The question is:
How do
you spend it?

 John Covici wb2una
 cov...@ccs.covici.com



[gentoo-user] Re: Multilib ABI specific CPU use flags?

2020-10-08 Thread Ashley Dixon
On Thu, Oct 08, 2020 at 11:57:52AM +, Jonathan Yong wrote:
> I am getting AVX2 related compile errors in 32bit media-libs/opencv-4.4.0,
> there are some internet text mentioning not all AVX2 instructions are
> supported on 32bit x86.
> 
> For now, I have set -abi_x86_32 since I don't need it now.
> 
> Any plans to support ABI specific USE masking/setting?

Do you mean that you want to install the 32-bit and 64-bit version of a package,
enabling one set of flags on one, and another set on the other?

The problem you will face is that the CPU_FLAGS_X86 option, which allows you  to
disable AVX(2)  instructions,  amongst  many  other  processor  extensions  [1],
applies to both x86 and amd64 architectures, and from reading the according wiki
page [2], I don't think it's possible to discriminate between those two;  it  is
the responsibility of the package to test  whether  a  particular  AVX  function
should be employed or not.

Can you post the output of `cpuid2cpuflags`  (from  app-portage/cpuid2cpuflags)?
If this list includes "avx2", and the compilation is still failing,  this  is  a
BUG and should be reported as such.  I think it's known to the Gentoo  community
already, although it seems to be an issue with upstream [3].   Analogous  issues
exist in other packages [4].

The problem in upstream is probably caused by this call to  _mm256_extract_epi64
[5], introduced quite a while ago (the nature of this function, being  exclusive
to 64-bit processors, was even noted in the commit message [6]).

It will probably be fixed soon. No need to worry since you don't need the 32-bit
binary interface anyway.

[1] 
https://gitweb.gentoo.org/repo/gentoo.git/plain/profiles/desc/cpu_flags_x86.desc
[2] https://wiki.gentoo.org/wiki/CPU_FLAGS_X86#Configuration
[3] https://bugs.gentoo.org/747163
[4] https://github.com/pytorch/pytorch/issues/17901
[5] 
https://github.com/opencv/opencv/blame/152e6476d9a270e6ce35d3f1b200a303654e576e/modules/core/include/opencv2/core/hal/intrin_avx.hpp#L130
[6] 
https://github.com/opencv/opencv/commit/75315fb297a010153d3acab8111ebb87d909cdcf

-- 

Ashley Dixon
suugaku.co.uk

2A9A 4117
DA96 D18A
8A7B B0D2
A30E BF25
F290 A8AA



signature.asc
Description: PGP signature


Re: [gentoo-user] preparing for make menuconfig

2020-10-08 Thread Ashley Dixon
On Thu, Oct 08, 2020 at 07:04:46AM -0400, John Covici wrote:
> I always get this error, but the flag indicating which driver is being
> used still works, so I have not paid too much attention to this one.
> I do have a running system with /lib/modules and the error still
> occurrs.

What is the exact error?  Is it accompanied by an error code?  libkmod looks for
the following files, typically  located  in  `/lib/modules/$(uname  -r)/`,  when
client applications request a context [1]; most of these can be  generated  with
depmod(8):

 - modules.dep
 - modules.alias
 - modules.symbols
 - modules.builtin.alias
 - modules.builtin

struct _index_files {
const char *fn;
const char *prefix;
}

The most interesting for kernel modules is `modules.alias`, which  is  the  more
modern representation of `modules.{pci,usb}map` [2].  Are all these files intact
on your system? What happens when you run `lsmod`?

[1] 
https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git/tree/libkmod/libkmod.c#n53
[2] https://stackoverflow.com/a/25644147/

-- 

Ashley Dixon
suugaku.co.uk

2A9A 4117
DA96 D18A
8A7B B0D2
A30E BF25
F290 A8AA



signature.asc
Description: PGP signature


[gentoo-user] Multilib ABI specific CPU use flags?

2020-10-08 Thread Jonathan Yong

Hello,

I am getting AVX2 related compile errors in 32bit 
media-libs/opencv-4.4.0, there are some internet text mentioning not all 
AVX2 instructions are supported on 32bit x86.


For now, I have set -abi_x86_32 since I don't need it now.

Any plans to support ABI specific USE masking/setting?


OpenPGP_0x713B5FE29C145D45_and_old_rev.asc
Description: application/pgp-keys


OpenPGP_signature
Description: OpenPGP digital signature


[gentoo-user] Multilib ABI specific CPU use flags?

2020-10-08 Thread Jonathan Yong

Hello,

I am getting AVX2 related compile errors in 32bit 
media-libs/opencv-4.4.0, there are some internet text mentioning not all 
AVX2 instructions are supported on 32bit x86.


For now, I have set -abi_x86_32 since I don't need it now.

Any plans to support ABI specific USE masking/setting?



Re: [gentoo-user] preparing for make menuconfig

2020-10-08 Thread John Covici
On Thu, 08 Oct 2020 02:51:49 -0400,
Ashley Dixon wrote:
> 
> [1  ]
> On Thu, Oct 08, 2020 at 07:30:45AM +0100, Ashley Dixon wrote:
> > This is just a total guess, but I can suppose that lspci uses it to convey
> > which kernel modules are being used by each PCI device.
> 
> Clarification: kmod is used specifically with the `-k` switch of lspci:
> 
> $ ash-euses -o pciutils:kmod
> sys-apps/pciutils:kmod - Enable sys-apps/kmod support for the -k 
> switch
> in lspci command
> 
> This causes the LIBKMOD variable to be passed to the Makefile [1, 2]:
> 
> pemake() {
> emake \
> [...]
> LIBKMOD=$(multilib_native_usex kmod) \
> [...]
> "$@"
> }
> 
> Anyway, with regards to your problem: if you're just installing your system 
> now,
> then you're probably getting this error  because  `/lib/modules`  doesn't  
> exist
> inside your chroot.  This path is hardcoded into pciutils  [3];  this  has  
> been
> modified by some vendors of the package, but not Gentoo [4].  You needn't  
> worry
> unless you're still getting this error  outside  of  your  chroot,  once  
> you've
> completed the installation. Just focus on building a kernel for now.
> 
> [1] 
> https://gitweb.gentoo.org/repo/gentoo.git/tree/sys-apps/pciutils/pciutils-3.7.0.ebuild#n81
> [2] https://devmanual.gentoo.org/eclass-reference/multilib-build.eclass/#lbAE
> [3] 
> https://git.kernel.org/pub/scm/utils/pciutils/pciutils.git/tree/ls-kernel.c#n134
> [4] 
> https://github.com/NixOS/nixpkgs/commit/286c836b3f1421553c103758537929e596256e65#diff-0a685886728285db8aa0594d87cb29b4

I always get this error, but the flag indicating which driver is being
used still works, so I have not paid too much attention to this one.
I do have a running system with /lib/modules and the error still
occurrs.

-- 
Your life is like a penny.  You're going to lose it.  The question is:
How do
you spend it?

 John Covici wb2una
 cov...@ccs.covici.com