Skip to contentSkip to conversation

perf build: Update build rule for generated files

PATCH In review Namhyung Kim 2 participants 6 messages Jul 28, 2023 – Aug 10, 2023

Subsystems (2)
lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

PATCH v2 1/2 perf build: Update build rule for generated files

The bison and flex generate C files from the source (.y and .l) files. When O= option is used, they are saved in a separate directory but the default build rule assumes the .C files are in the source directory. So it might read invalid file if there are generated files from an old version. The same is true for the pmu-events files.

For example, the following command would cause a build failure:

  $ git checkout v6.3
  $ make -C tools/perf  # build in the same directory
  $ git checkout v6.5-rc2
  $ mkdir build  # create a build directory
  $ make -C tools/perf O=build  # build in a different directory but it
                                # refers files in the source directory

Let's update the build rule to specify those cases explicitly to depend on the files in the output directory.

Note that it's not a complete fix and it needs the next patch for the include path too.

Fixes 80eeb67fe577 ("perf jevents: Program to convert JSON file")
---
 tools/build/Makefile.build  | 10 ++++++++++
 tools/perf/pmu-events/Build |  6 ++++++
 2 files changed, 16 insertions(+)
tools/build/Makefile.build +10 -0
index 89430338a3d9..fac42486a8cf 100644
@@ -117,6 +117,16 @@ $(OUTPUT)%.s: %.c FORCE
 	$(call rule_mkdir)
 	$(call if_changed_dep,cc_s_c)
 
+# bison and flex files are generated in the OUTPUT directory
+# so it needs a separate rule to depend on them properly
+$(OUTPUT)%-bison.o: $(OUTPUT)%-bison.c FORCE
+	$(call rule_mkdir)
+	$(call if_changed_dep,$(host)cc_o_c)
+
+$(OUTPUT)%-flex.o: $(OUTPUT)%-flex.c FORCE
+	$(call rule_mkdir)
+	$(call if_changed_dep,$(host)cc_o_c)
+
 # Gather build data:
 #   obj-y        - list of build objects
 #   subdir-y     - list of directories to nest
tools/perf/pmu-events/Build +6 -0
index 150765f2baee..1d18bb89402e 100644
@@ -35,3 +35,9 @@ $(PMU_EVENTS_C): $(JSON) $(JSON_TEST) $(JEVENTS_PY) $(METRIC_PY) $(METRIC_TEST_L
 	$(call rule_mkdir)
 	$(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) $(JEVENTS_MODEL) pmu-events/arch $@
 endif
+
+# pmu-events.c file is generated in the OUTPUT directory so it needs a
+# separate rule to depend on it properly
+$(OUTPUT)pmu-events/pmu-events.o: $(PMU_EVENTS_C)
+	$(call rule_mkdir)
+	$(call if_changed_dep,cc_o_c)
Signature · 1 line
2.41.0.487.g6d72f3e995-goog
author maintainer
#1 lore raw

PATCH v2 2/2 perf build: Include generated header files properly

The flex and bison generate header files from the source. When user specified a build directory with O= option, it'd generate files under the directory. The build command has -I option to specify the header include directory.

But the -I option only affects the files included like <...>. Let's change the flex and bison headers to use it instead of "...".

Fixes 80eeb67fe577 ("perf jevents: Program to convert JSON file")
---
 tools/perf/pmu-events/jevents.py | 2 +-
 tools/perf/util/bpf-filter.c     | 4 ++--
 tools/perf/util/expr.c           | 4 ++--
 tools/perf/util/parse-events.c   | 4 ++--
 tools/perf/util/pmu.c            | 4 ++--
 5 files changed, 9 insertions(+), 9 deletions(-)
tools/perf/pmu-events/jevents.py +1 -1
index 12e80bb7939b..82c42c46d886 100755
@@ -999,7 +999,7 @@ such as "arm/cortex-a34".''',
   _args = ap.parse_args()
 
   _args.output_file.write("""
-#include "pmu-events/pmu-events.h"
+#include <pmu-events/pmu-events.h>
 #include "util/header.h"
 #include "util/pmu.h"
 #include <string.h>
tools/perf/util/bpf-filter.c +2 -2
index 0b30688d78a7..47f01df658d9 100644
@@ -9,8 +9,8 @@
 #include "util/evsel.h"
 
 #include "util/bpf-filter.h"
-#include "util/bpf-filter-flex.h"
-#include "util/bpf-filter-bison.h"
+#include <util/bpf-filter-flex.h>
+#include <util/bpf-filter-bison.h>
 
 #include "bpf_skel/sample-filter.h"
 #include "bpf_skel/sample_filter.skel.h"
tools/perf/util/expr.c +2 -2
index 4814262e3805..7410a165f68b 100644
@@ -10,8 +10,8 @@
 #include "debug.h"
 #include "evlist.h"
 #include "expr.h"
-#include "expr-bison.h"
-#include "expr-flex.h"
+#include <util/expr-bison.h>
+#include <util/expr-flex.h>
 #include "util/hashmap.h"
 #include "smt.h"
 #include "tsc.h"
tools/perf/util/parse-events.c +2 -2
index acde097e327c..f3773467c103 100644
@@ -18,8 +18,8 @@
 #include "debug.h"
 #include <api/fs/tracing_path.h>
 #include <perf/cpumap.h>
-#include "parse-events-bison.h"
-#include "parse-events-flex.h"
+#include <util/parse-events-bison.h>
+#include <util/parse-events-flex.h>
 #include "pmu.h"
 #include "pmus.h"
 #include "asm/bug.h"
tools/perf/util/pmu.c +2 -2
index 7f984a7f16ca..b6654b9f55d2 100644
@@ -19,8 +19,8 @@
 #include "evsel.h"
 #include "pmu.h"
 #include "pmus.h"
-#include "pmu-bison.h"
-#include "pmu-flex.h"
+#include <util/pmu-bison.h>
+#include <util/pmu-flex.h>
 #include "parse-events.h"
 #include "print-events.h"
 #include "header.h"
Signature · 1 line
2.41.0.487.g6d72f3e995-goog
#2 lore raw
In reply to Namhyung Kim

Em Thu, Jul 27, 2023 at 07:24:46PM -0700, Namhyung Kim escreveu:

Quoted 16 lines

The bison and flex generate C files from the source (.y and .l) files. When O= option is used, they are saved in a separate directory but the default build rule assumes the .C files are in the source directory. So it might read invalid file if there are generated files from an old version. The same is true for the pmu-events files.

For example, the following command would cause a build failure:

  $ git checkout v6.3
  $ make -C tools/perf  # build in the same directory
  $ git checkout v6.5-rc2
  $ mkdir build  # create a build directory
  $ make -C tools/perf O=build  # build in a different directory but it
                                # refers files in the source directory
Quoted 5 lines

Let's update the build rule to specify those cases explicitly to depend on the files in the output directory.

Note that it's not a complete fix and it needs the next patch for the include path too.

Applied, testing it on the container builds.

- Arnaldo

Quoted 46 lines
Fixes 80eeb67fe577 ("perf jevents: Program to convert JSON file")
---
 tools/build/Makefile.build  | 10 ++++++++++
 tools/perf/pmu-events/Build |  6 ++++++
 2 files changed, 16 insertions(+)
tools/build/Makefile.build +10 -0
index 89430338a3d9..fac42486a8cf 100644
@@ -117,6 +117,16 @@ $(OUTPUT)%.s: %.c FORCE
 	$(call rule_mkdir)
 	$(call if_changed_dep,cc_s_c)
 
+# bison and flex files are generated in the OUTPUT directory
+# so it needs a separate rule to depend on them properly
+$(OUTPUT)%-bison.o: $(OUTPUT)%-bison.c FORCE
+	$(call rule_mkdir)
+	$(call if_changed_dep,$(host)cc_o_c)
+
+$(OUTPUT)%-flex.o: $(OUTPUT)%-flex.c FORCE
+	$(call rule_mkdir)
+	$(call if_changed_dep,$(host)cc_o_c)
+
 # Gather build data:
 #   obj-y        - list of build objects
 #   subdir-y     - list of directories to nest
tools/perf/pmu-events/Build +6 -0
index 150765f2baee..1d18bb89402e 100644
@@ -35,3 +35,9 @@ $(PMU_EVENTS_C): $(JSON) $(JSON_TEST) $(JEVENTS_PY) $(METRIC_PY) $(METRIC_TEST_L
 	$(call rule_mkdir)
 	$(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) $(JEVENTS_MODEL) pmu-events/arch $@
 endif
+
+# pmu-events.c file is generated in the OUTPUT directory so it needs a
+# separate rule to depend on it properly
+$(OUTPUT)pmu-events/pmu-events.o: $(PMU_EVENTS_C)
+	$(call rule_mkdir)
+	$(call if_changed_dep,cc_o_c)
Signature · 1 line
2.41.0.487.g6d72f3e995-goog
Signature · 1 line
- Arnaldo
author maintainer
#3 lore raw

Hi Arnaldo,

Quoted 18 lines · Arnaldo Carvalho de Melo

Em Thu, Jul 27, 2023 at 07:24:46PM -0700, Namhyung Kim escreveu:

Quoted 16 lines

The bison and flex generate C files from the source (.y and .l) files. When O= option is used, they are saved in a separate directory but the default build rule assumes the .C files are in the source directory. So it might read invalid file if there are generated files from an old version. The same is true for the pmu-events files.

For example, the following command would cause a build failure:

  $ git checkout v6.3
  $ make -C tools/perf  # build in the same directory
  $ git checkout v6.5-rc2
  $ mkdir build  # create a build directory
  $ make -C tools/perf O=build  # build in a different directory but it
                                # refers files in the source directory
Quoted 7 lines
Quoted 5 lines

Let's update the build rule to specify those cases explicitly to depend on the files in the output directory.

Note that it's not a complete fix and it needs the next patch for the include path too.

Applied, testing it on the container builds.

I don't see these commits in the perf-tools{,-next} yet.

Thanks,
Namhyung

#4 lore raw

Em Wed, Aug 09, 2023 at 03:56:17PM +0900, Namhyung Kim escreveu:

Quoted 11 lines · Arnaldo Carvalho de Melo
Quoted 8 lines

Em Thu, Jul 27, 2023 at 07:24:46PM -0700, Namhyung Kim escreveu:

Quoted 5 lines

Let's update the build rule to specify those cases explicitly to depend on the files in the output directory.

Note that it's not a complete fix and it needs the next patch for the include path too.

Applied, testing it on the container builds.

I don't see these commits in the perf-tools{,-next} yet.

6 days perf build: Include generated header files properly Namhyung Kim 5 -9/+9
6 days perf build: Update build rule for generated files Namhyung Kim 2 -0/+16

https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/commit/?h=perf-tools-next&id=7822a8913f4c51c7d1aff793b525d60c3384fb5b
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/commit/?h=perf-tools-next&id=c7e97f215a4ad634b746804679f5937d25f77e29

Did I miss something?

- Arnaldo

author maintainer
#5 lore raw
Quoted 14 lines · Arnaldo Carvalho de Melo

Em Wed, Aug 09, 2023 at 03:56:17PM +0900, Namhyung Kim escreveu:

Quoted 11 lines · Arnaldo Carvalho de Melo
Quoted 8 lines

Em Thu, Jul 27, 2023 at 07:24:46PM -0700, Namhyung Kim escreveu:

Quoted 5 lines

Let's update the build rule to specify those cases explicitly to depend on the files in the output directory.

Note that it's not a complete fix and it needs the next patch for the include path too.

Applied, testing it on the container builds.

I don't see these commits in the perf-tools{,-next} yet.

Quoted 7 lines
6 days  perf build: Include generated header files properly     Namhyung Kim    5       -9/+9
6 days  perf build: Update build rule for generated files       Namhyung Kim    2       -0/+16

https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/commit/?h=perf-tools-next&id=7822a8913f4c51c7d1aff793b525d60c3384fb5b
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/commit/?h=perf-tools-next&id=c7e97f215a4ad634b746804679f5937d25f77e29

Did I miss something?

Oops, my bad. I somehow overlooked the commits. Now I can see it in the perf-tools-next, sorry for the noise.

Thanks,
Namhyung