Re: [GIT PULL] perf tools changes for v6.2: 1st batch

From: Arnaldo Carvalho de Melo
Date: Tue Dec 20 2022 - 08:08:13 EST


tldr;: if you do:

$ make -C tools clean
$ sudo dnf remove python2 python2-devel
$ sudo dnf install python-devel

It should build cleanly, below I looked at the various places these
feature detections are made and found places for improving messages,
etc.

Ian, that "jevent generation" gets confused when python2 _and_ python3
is installed, please take a look at that.

- Arnaldo

Em Sat, Dec 17, 2022 at 01:55:25PM -0600, Linus Torvalds escreveu:
> On Sat, Dec 17, 2022 at 8:50 AM Arnaldo Carvalho de Melo <acme@xxxxxxxxxx> wrote:
> > The python3-setuptools package is needed to build the python binding, so
> > that one can use things like:
>
> So this fixes the error, but there's some other reason for it.
>
> I have
>
> Package python3-setuptools-59.6.0-3.fc36.noarch is already installed.
>
> and with that patch the 'perf' build now works for me, but it says:
>
> Makefile.config:898: Missing python setuptools, the python binding
> won't be built, please install python3-setuptools or equivalent
>
> and then (pre-existing)
>
> Makefile.config:921: Python interpreter too old (older than 3.6)
> disabling jevent generation
>
> but I have
>
> python3-3.10.8-3.fc36.x86_64
>
> Now, for some reason I *also* have python2 installed, but that one is
> called "python2".

> [ Me trying to figure things out ]
>
> Ok, so if I uninstall my old python2 install, I now get
>
> Makefile.config:880: No python interpreter was found: disables
> Python support - please install python-devel/python-dev

> Makefile.config:915: No python interpreter disabling jevent generation
>
> ok, so I didn't have 'python3-devel' installed. Installing that fixes
> some things, but then I get
>
> Makefile.config:889: No 'Python.h' (for Python 2.x support) was
> found: disables Python support - please install
> python-devel/python-dev

Humm, I couldn't reproduce this one, as I have:

⬢[acme@toolbox perf]$ grep libpython /tmp/build/perf/FEATURE-DUMP
feature-libpython=1
⬢[acme@toolbox perf]$

And that message only happens when that feature-libpython != 1

That is set by this feature query snippet:

⬢[acme@toolbox perf]$ cat tools/build/feature/test-libpython.c
// SPDX-License-Identifier: GPL-2.0
#include <Python.h>

int main(void)
{
Py_Initialize();

return 0;
}
#undef _GNU_SOURCE
⬢[acme@toolbox perf]$

One can see the output of building it at (if you build it without O=,
please look at tools/build/feature/test-libpython.make.output instead):
):

⬢[acme@toolbox perf]$ cat /tmp/build/perf/feature/test-libpython.make.output
⬢[acme@toolbox perf]$

In my case, it is working, so empty make.output file and the test binary
works and links with python3 (tools/build/feature/test-libpython.bin
when building without O=):

⬢[acme@toolbox perf]$ file /tmp/build/perf/feature/test-libpython.bin
/tmp/build/perf/feature/test-libpython.bin: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=601e3a065cc8e045e7a46199234c0bbf80707981, for GNU/Linux 3.2.0, not stripped
⬢[acme@toolbox perf]$ ldd /tmp/build/perf/feature/test-libpython.bin
linux-vdso.so.1 (0x00007ffc371fe000)
libpython3.10.so.1.0 => /lib64/libpython3.10.so.1.0 (0x00007fddb0200000)
libcrypt.so.2 => /lib64/libcrypt.so.2 (0x00007fddb05f9000)
libm.so.6 => /lib64/libm.so.6 (0x00007fddb0122000)
libc.so.6 => /lib64/libc.so.6 (0x00007fddafe00000)
/lib64/ld-linux-x86-64.so.2 (0x00007fddb063f000)
⬢[acme@toolbox perf]$

The needed file is available and is part of the python3-devel file:

⬢[acme@toolbox perf]$ ls -la /usr/include/python3.10/Python.h
-rw-r--r--. 1 root root 3224 Oct 11 08:21 /usr/include/python3.10/Python.h
⬢[acme@toolbox perf]$ rpm -qf /usr/include/python3.10/Python.h
python3-devel-3.10.8-3.fc36.x86_64
⬢[acme@toolbox perf]$

That message needs updating, its from a long time ago:

9734163b6ee1425c6 tools/perf/config/Makefile (Ingo Molnar 2013-09-30 15:18:37 +0200 888) ifneq ($(feature-libpython), 1)
6c5aa23704e2786eb tools/perf/config/Makefile (Ingo Molnar 2015-02-28 09:33:45 +0100 889) $(call disable-python,No 'Python.h' (for Python 2.x support) was found: disables Python support - please install python-devel/python-dev)
6e533cf12de06368a tools/perf/config/Makefile (Jiri Olsa 2013-03-18 00:35:32 +0100 890) else

> so apparently perf really wants *both* python2 and python3 installed.
> Isn't that a bit excessive?

I'll update that message, its one or the other, and we will work to make
it support only python3 as python2 is deprecated.

> Anyway, it's clearly something about the install on this laptop, but
> the error messages and the "this package is missing" things are
> clearly not entirely right.

Right, perhaps a 'make -C tools clean' may clean some previous feature
detection that stuck somehow? I'll do continue tinkering here to see if
I get this in a better shape.

> Whatever. It does build cleanly now for me, and I'll ignore that "No
> 'Python.h' (for Python 2.x support)" thing.

The only time I got this message was now that I uninstalled
python3-devel:

Makefile.config:889: No 'Python.h' (for Python 2.x support) was found: disables Python support - please install python-devel/python-dev

The next one I got because I have python2 installed:

⬢[acme@toolbox perf]$ rpm -qa | grep python2
python2.7-2.7.18-22.fc36.x86_64

Makefile.config:921: Python interpreter too old (older than 3.6) disabling jevent generation

Removing python2 I get:

Makefile.config:880: No python interpreter was found: disables Python support - please install python-devel/python-dev
Makefile.config:915: No python interpreter disabling jevent generation

So you get this message:

> Makefile.config:889: No 'Python.h' (for Python 2.x support) was
> found: disables Python support - please install
> python-devel/python-dev

When you have python2 and python3 but no python3-devel nor
python2-devel:

⬢[acme@toolbox perf]$ rpm -q python3
python3-3.10.8-3.fc36.x86_64
⬢[acme@toolbox perf]$ rpm -qa | grep python2
python2.7-2.7.18-22.fc36.x86_64
⬢[acme@toolbox perf]$ rpm -q python2-devel
package python2-devel is not installed
⬢[acme@toolbox perf]$ rpm -q python3-devel
package python3-devel is not installed
⬢[acme@toolbox perf]$ m
make: Entering directory '/var/home/acme/git/perf/tools/perf'
BUILD: Doing 'make -j32' parallel build
<SNIP>
Makefile.config:889: No 'Python.h' (for Python 2.x support) was found: disables Python support - please install python-devel/python-dev
Makefile.config:921: Python interpreter too old (older than 3.6) disabling jevent generation

Auto-detecting system features:
<SNIP>
... libpython: [ OFF ]
⬢[acme@toolbox perf]$

If I then uninstall python2:

⬢[acme@toolbox perf]$ sudo dnf remove python2

It changes to:

Makefile.config:880: No python interpreter was found: disables Python support - please install python-devel/python-dev
Makefile.config:915: No python interpreter disabling jevent generation

Which is more sensible, then if I install python-devel:

⬢[acme@toolbox perf]$ sudo dnf install python-devel

$ sudo dnf install python-devel

I see no warnings, clean build and libpython detected:

... libpython: [ on ]


⬢[acme@toolbox perf]$ ldd /tmp/build/perf/perf | grep python
libpython3.10.so.1.0 => /lib64/libpython3.10.so.1.0 (0x00007f1eea200000)
⬢[acme@toolbox perf]$

- Arnaldo