Skip to contentSkip to conversation

perf: reproducibility fixes for pmu-events.c

PATCH New Bruce Ashfield 1 participant 1 message Mar 11, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf: reproducibility fixes for pmu-events.c

From: Bruce Ashfield <[email protected]>

perf generates pmu-events.c as part of the build process. The code that generates the events is doing tree walks and potentially other non-determinstic things.

We'd rather not mess with that implementation, so we add a script that knows how to read the pmu-events.c, sort the entries and then copy it over the generated one.

With this, we should always have events in the same order, improving reproducibility.

---
 meta/recipes-kernel/perf/perf.bb              | 16 ++++
 .../perf/perf/sort-pmuevents.py               | 93 +++++++++++++++++++
 2 files changed, 109 insertions(+)
 create mode 100755 meta/recipes-kernel/perf/perf/sort-pmuevents.py
meta/recipes-kernel/perf/perf.bb +16 -0
index 2beb404c03..c7653e523c 100644
@@ -250,6 +250,14 @@ do_configure_prepend () {
         # all the calls have YFLAGS, which contains prefix mapping information.
         sed -i -e 's,$(YACC),$(YACC) $(YFLAGS),g' ${S}/scripts/Makefile.host
     fi
+    if [ -e "${S}/tools/perf/pmu-events/Build" ]; then
+        target='$(OUTPUT)pmu-events/pmu-events.c $(V)'
+        replacement1='$(OUTPUT)pmu-events/pmu-events.c $(V)\n'
+        replacement2='\t$(srctree)/sort-pmuevents.py $(OUTPUT)pmu-events/pmu-events.c $(OUTPUT)pmu-events/pmu-events.c.new\n'
+        replacement3='\tcp $(OUTPUT)pmu-events/pmu-events.c.new $(OUTPUT)pmu-events/pmu-events.c'
+        sed -i -e "s,$target,$replacement1$replacement2$replacement3,g" \
+                       "${S}/tools/perf/pmu-events/Build"
+    fi
     # end reproducibility substitutions
 
     # We need to ensure the --sysroot option in CC is preserved
@@ -292,6 +300,14 @@ do_configure_prepend () {
     # so we copy it from the sysroot unistd.h to the perf unistd.h
     install -D -m0644 ${STAGING_INCDIR}/asm-generic/unistd.h ${S}/tools/include/uapi/asm-generic/unistd.h
     install -D -m0644 ${STAGING_INCDIR}/asm-generic/unistd.h ${S}/include/uapi/asm-generic/unistd.h
+
+    # the fetcher is inhibited by the 'inherit kernelsrc', so we do a quick check and
+    # copy for a helper script we need
+    for p in $(echo ${FILESPATH} | tr ':' '\n'); do
+	if [ -e $p/sort-pmuevents.py ]; then
+	    cp $p/sort-pmuevents.py ${S}
+	fi
+    done
 }
 
 python do_package_prepend() {
meta/recipes-kernel/perf/perf/sort-pmuevents.py new file +93 -0

93 lines not on this page · raw message

Signature · 1 line
2.19.1