Generate pmu-events.c using jevents.py rather than the binary built from
jevents.c. Add a new config variable NO_JEVENTS that is set when there
is no architecture json or an appropriate python interpreter isn't present.
When NO_JEVENTS is defined the file pmu-events/empty-pmu-events.c is copied
and used as the pmu-events.c file.
Signed-off-by: Ian Rogers <[email protected]>
---
tools/perf/Makefile.config | 19 +++++++++++++++++++
tools/perf/Makefile.perf | 1 +
tools/perf/pmu-events/Build | 11 +++++++++--
tools/perf/pmu-events/empty-pmu-events.c | 21 +++++++++++++++++++++
4 files changed, 50 insertions(+), 2 deletions(-)
create mode 100644 tools/perf/pmu-events/empty-pmu-events.c
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index d9b699ad402c..5a19469f0048 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -854,6 +854,25 @@ else
endif
endif
+ifneq ($(NO_JEVENTS),1)
+ ifeq ($(wildcard pmu-events/arch/$(SRCARCH)/mapfile.csv),)
+ NO_JEVENTS := 1
+ endif
+endif
+ifneq ($(NO_JEVENTS),1)
+ NO_JEVENTS := 0
+ ifndef PYTHON
+ $(warning No python interpreter disabling jevent generation)
+ NO_JEVENTS := 1
+ else
+ # jevents.py uses os.scandir and type hints present in Python 3.5 released in Sept. 2015.
+ JEVENTS_PYTHON_GOOD := $(shell $(PYTHON) -c 'import sys;print("1" if(sys.version_info.major >= 3 and sys.version_info.minor >= 5) else "0")')
+ ifneq ($(JEVENTS_PYTHON_GOOD), 1)
+ $(warning Python interpreter too old (older than 3.5) disabling jevent generation)
+ NO_JEVENTS := 1
+ endif
+ endif
+endif
ifndef NO_LIBBFD
ifeq ($(feature-libbfd), 1)
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 078f0b06f08a..db416a13dca7 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -655,6 +655,7 @@ JEVENTS := $(OUTPUT)pmu-events/jevents
JEVENTS_IN := $(OUTPUT)pmu-events/jevents-in.o
PMU_EVENTS_IN := $(OUTPUT)pmu-events/pmu-events-in.o
+export NO_JEVENTS
export JEVENTS
diff --git a/tools/perf/pmu-events/Build b/tools/perf/pmu-events/Build
index a055dee6a46a..5e459e1c7a85 100644
--- a/tools/perf/pmu-events/Build
+++ b/tools/perf/pmu-events/Build
@@ -9,10 +9,17 @@ JSON = $(shell [ -d $(JDIR) ] && \
JDIR_TEST = pmu-events/arch/test
JSON_TEST = $(shell [ -d $(JDIR_TEST) ] && \
find $(JDIR_TEST) -name '*.json')
+JEVENTS_PY = pmu-events/jevents.py
#
# Locate/process JSON files in pmu-events/arch/
# directory and create tables in pmu-events.c.
#
-$(OUTPUT)pmu-events/pmu-events.c: $(JSON) $(JSON_TEST) $(JEVENTS)
- $(Q)$(call echo-cmd,gen)$(JEVENTS) $(SRCARCH) pmu-events/arch $(OUTPUT)pmu-events/pmu-events.c $(V)
+
+ifeq ($(NO_JEVENTS),1)
+$(OUTPUT)pmu-events/pmu-events.c: pmu-events/empty-pmu-events.c
+ $(Q)cp $< $@
+else
+$(OUTPUT)pmu-events/pmu-events.c: $(JSON) $(JSON_TEST) $(JEVENTS_PY)
+ $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(SRCARCH) pmu-events/arch $@
+endif
diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-events/empty-pmu-events.c
new file mode 100644
index 000000000000..08fee615e015
--- /dev/null
+++ b/tools/perf/pmu-events/empty-pmu-events.c
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * An empty pmu-events.c file used when there is no architecture json files in
+ * arch or when the jevents.py script cannot be run.
+ */
+#include "pmu-events/pmu-events.h"
+
+const struct pmu_events_map pmu_events_map[] = {
+ {
+ .cpuid = 0,
+ .version = 0,
+ .type = 0,
+ .table = 0,
+ },
+};
+
+const struct pmu_sys_events pmu_sys_event_tables[] = {
+ {
+ .table = 0
+ },
+};
--
2.36.0.512.ge40c2bad7a-goog
On Fri, May 13, 2022 at 8:38 AM John Garry <[email protected]> wrote:
>
> On 11/05/2022 22:15, Ian Rogers wrote:
> > # jevents.py uses os.scandir and type hints present in Python 3.5 released in Sept. 2015.
> > + JEVENTS_PYTHON_GOOD := $(shell $(PYTHON) -c 'import sys;print("1" if(sys.version_info.major >= 3 and sys.version_info.minor >= 5) else "0")')
>
> I think that many - like me - will have python 2.7, so now will find no
> pmu-events generated any longer after missing this message in the build :(
>
> Maybe many will have python >= 3.5 - but I don't know...
So Python 2 has been end-of-life for over 2 years now:
https://www.python.org/doc/sunset-python-2/
There have been a number of LKML patches upgrading python to version 3.
Python 3.5 has some very nice features of os.scandir and type hints,
so if I set the bar lower than this it hurts the code quality. It is
also at least 6 years old at this point, and so hopefully not
unreasonable for a distribution to have picked it up :-) Looking at
the change to C11 thread:
https://lore.kernel.org/lkml/[email protected]/
It seems the motivation for picking a language version is the features
it provides and compatibility. If we choose pre-Python 3.5 we get more
compatibility but we lose language features.
My feeling is that we shouldn't need to support things that are no
longer maintained (like Python 2) but I'm less clear if Python 3.5 is
sufficiently compatible for everyone's needs. I kind of hope so, hence
making the patches this way.
> > + ifneq ($(JEVENTS_PYTHON_GOOD), 1)
> > + $(warning Python interpreter too old (older than 3.5) disabling
> jevent generation)
> > + NO_JEVENTS := 1
>
> It is possible to flip NO_JEVENTS to be JEVENTS, i.e. no
> double-negatives, like NO_JEVENTS := 0
Agreed that double negatives are bad. The NO_... pattern is kind of
throughout the make files and build files. I preferred the NO_... for
consistency but if there's a consensus I'm happy to change.
Thanks,
Ian
> > + endif
>
> Thanks,
> John
On 11/05/2022 22:15, Ian Rogers wrote:
> # jevents.py uses os.scandir and type hints present in Python 3.5 released in Sept. 2015.
> + JEVENTS_PYTHON_GOOD := $(shell $(PYTHON) -c 'import sys;print("1" if(sys.version_info.major >= 3 and sys.version_info.minor >= 5) else "0")')
I think that many - like me - will have python 2.7, so now will find no
pmu-events generated any longer after missing this message in the build :(
Maybe many will have python >= 3.5 - but I don't know...
> + ifneq ($(JEVENTS_PYTHON_GOOD), 1)
> + $(warning Python interpreter too old (older than 3.5) disabling
jevent generation)
> + NO_JEVENTS := 1
It is possible to flip NO_JEVENTS to be JEVENTS, i.e. no
double-negatives, like NO_JEVENTS := 0
> + endif
Thanks,
John
On Tue, May 17, 2022 at 3:32 AM John Garry <[email protected]> wrote:
>
> On 13/05/2022 16:58, Ian Rogers wrote:
> > On Fri, May 13, 2022 at 8:38 AM John Garry <[email protected]> wrote:
> >>
> >> On 11/05/2022 22:15, Ian Rogers wrote:
> >>> # jevents.py uses os.scandir and type hints present in Python 3.5 released in Sept. 2015.
> >>> + JEVENTS_PYTHON_GOOD := $(shell $(PYTHON) -c 'import sys;print("1" if(sys.version_info.major >= 3 and sys.version_info.minor >= 5) else "0")')
> >>
> >> I think that many - like me - will have python 2.7, so now will find no
> >> pmu-events generated any longer after missing this message in the build :(
> >>
> >> Maybe many will have python >= 3.5 - but I don't know...
> >
> > So Python 2 has been end-of-life for over 2 years now:
> > https://www.python.org/doc/sunset-python-2/
> > There have been a number of LKML patches upgrading python to version 3.
> >
> > Python 3.5 has some very nice features of os.scandir and type hints,
> > so if I set the bar lower than this it hurts the code quality. It is
> > also at least 6 years old at this point, and so hopefully not
> > unreasonable for a distribution to have picked it up :-) Looking at
> > the change to C11 thread:
> > https://lore.kernel.org/lkml/[email protected]/
> > It seems the motivation for picking a language version is the features
> > it provides and compatibility. If we choose pre-Python 3.5 we get more
> > compatibility but we lose language features.
> >
> > My feeling is that we shouldn't need to support things that are no
> > longer maintained (like Python 2) but I'm less clear if Python 3.5 is
> > sufficiently compatible for everyone's needs. I kind of hope so, hence
> > making the patches this way.
>
> Fine, I just think that you need to make this transition as seamless as
> possible, otherwise it can be judged as a regression.
Agreed.
> For example, I have now python 3.6 (default) and 2.7 but it still
> doesn't seem to work:
>
> john@localhost:~/acme/tools/perf> make
> BUILD: Doing 'make -j4' parallel build
> Warning: Kernel ABI header at 'tools/include/linux/coresight-pmu.h'
> differs from latest version at 'include/linux/coresight-pmu.h'
> diff -u tools/include/linux/coresight-pmu.h include/linux/coresight-pmu.h
> Makefile.config:593: No sys/sdt.h found, no SDT events are defined,
> please install systemtap-sdt-devel or systemtap-sdt-dev
> Makefile.config:871: Python interpreter too old (older than 3.5)
> disabling jevent generation
> Makefile.config:904: Old version of libbfd/binutils things like PE
> executable profiling will not be available
> Makefile.config:1092: No openjdk development package found, please
> install JDK package, e.g. openjdk-8-jdk, java-1.8.0-openjdk-devel
>
> Auto-detecting system features:
> ... dwarf: [ on ]
> ... dwarf_getlocations: [ on ]
> ... glibc: [ on ]
> ... libbfd: [ OFF ]
> ... libbfd-buildid: [ OFF ]
> ... libcap: [ on ]
> ... libelf: [ on ]
> ... libnuma: [ on ]
> ... numa_num_possible_cpus: [ on ]
> ... libperl: [ on ]
> ... libpython: [ on ]
> ... libcrypto: [ on ]
> ... libunwind: [ on ]
> ... libdw-dwarf-unwind: [ on ]
> ... zlib: [ on ]
> ... lzma: [ on ]
> ... get_cpuid: [ on ]
> ... bpf: [ on ]
> ... libaio: [ on ]
> ... libzstd: [ on ]
> ... disassembler-four-args: [ on ]
>
>
> make[3]: Nothing to be done for 'install_headers'.
> john@localhost:~/acme/tools/perf> python --version
> Python 3.6.12
> john@localhost:~/acme/tools/perf>
>
> which I need to figure out...
Yep, I can't explain that :-) You could try something like adding a
$(warning ... or similar to the build and running:
python3 -c 'import sys; print(sys.version_info)'
the jevents.py uses f-strings and so I'll need to bump the version
from 3.5 to 3.6 in v2. Python 3.6 was released in December 2016.
Thanks,
Ian
> >
> >> > + ifneq ($(JEVENTS_PYTHON_GOOD), 1)
> >> > + $(warning Python interpreter too old (older than 3.5) disabling
> >> jevent generation)
> >> > + NO_JEVENTS := 1
> >>
> >> It is possible to flip NO_JEVENTS to be JEVENTS, i.e. no
> >> double-negatives, like NO_JEVENTS := 0
> >
> > Agreed that double negatives are bad. The NO_... pattern is kind of
> > throughout the make files and build files. I preferred the NO_... for
> > consistency but if there's a consensus I'm happy to change.
> >
>
> I have no strong preference. I just find that double negatives boggle
> the mind.
>
> Thanks,
> john