[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#990165: perf: allow using other versions than the running kernel



Package: linux-base
Version: 4.6
Severity: normal
Tags: patch

Hi,

The perf wrapper script in Debian requires the perf binary of the running
kernel. However, there's not really a good reason for this; perf has a stable
ABI, and even though it's distributed and built with the kernel, you can freely
mix and match versions (I've done so, a lot).

There may still be reasons why people prefer to keep the versions matched,
but perf shouldn't just give up and die if it can't find the right version.
I've made a patch that makes this a bit more flexible; it first tries to
find a matching version, and if it doesn't exist, it simply picks the newest
one it can find. (If that's older than the kernel, it gives a warning,
since there may be new features the user would want to upgrade for, but it
doesn't die.)

Hopefully this should be safe, while being a lot less annoying when running
a newer or self-compiled kernel. :-)

--- linux-base-4.6.orig/bin/perf	2018-07-20 03:35:21.000000000 +0200
+++ linux-base-4.6/bin/perf	2021-06-22 00:15:59.618443368 +0200
@@ -10,9 +10,11 @@
 	;;
 esac
 shopt -s execfail
-exec "perf_$version" "$@"
+if [ -x "/usr/bin/perf_$version" ]; then
+    exec "perf_$version" "$@"
+fi
 
-# Not found? Tell the user which package to install.
+# Not found? Find out which version to install.
 case "$version" in
     3.* | 4.0 | 4.0.*)
 	package=linux-tools-$version
@@ -21,5 +23,16 @@
 	package=linux-perf-$version
 	;;
 esac
+
+# See if we have a usable alternative available.
+perfversion="$( linux-version sort --reverse $( echo /usr/bin/perf_* | sed "s,/usr/bin/perf_,,g" ) | head -n 1 )"
+if [ -x "/usr/bin/perf_$perfversion" ]; then
+    if linux-version compare "$perfversion" lt "$version"; then
+        echo >&2 "W: perf_$perfversion is older than the running kernel, consider installing $package."
+    fi
+    exec "perf_$perfversion" "$@"
+fi
+
+# Still nothing? Tell the user.
 echo >&2 "E: $package is not installed."
 exit 1

-- System Information:
Debian Release: 11.0
  APT prefers stable-debug
  APT policy: (500, 'stable-debug'), (500, 'testing'), (500, 'oldstable'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 5.12.8 (SMP w/40 CPU threads)
Locale: LANG=en_DK.UTF-8, LC_CTYPE=en_DK.UTF-8 (charmap=UTF-8), LANGUAGE=en_NO:en_US:en_GB:en
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages linux-base depends on:
ii  debconf [debconf-2.0]  1.5.75

linux-base recommends no packages.

linux-base suggests no packages.

-- debconf-show failed


Reply to: