From 3e2ea53472f31a8bf52abace2395bb2c9c3d0bd0 Mon Sep 17 00:00:00 2001 From: John Kacur Date: Tue, 14 Dec 2021 19:57:51 -0500 Subject: [PATCH] tuna: Display correct cpu-affinity when a cpu is disabled - Patch uses the number of cpus on a system, including disabled cpus in order to create the correct affinity mask Resolves: rhbz#2032460 Signed-off-by: John Kacur --- ...splays-incorrect-cpu-affinity-when-c.patch | 61 +++++++++++++++++++ tuna.spec | 8 ++- 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 tuna-Fix-tuna-displays-incorrect-cpu-affinity-when-c.patch diff --git a/tuna-Fix-tuna-displays-incorrect-cpu-affinity-when-c.patch b/tuna-Fix-tuna-displays-incorrect-cpu-affinity-when-c.patch new file mode 100644 index 0000000..d2a04eb --- /dev/null +++ b/tuna-Fix-tuna-displays-incorrect-cpu-affinity-when-c.patch @@ -0,0 +1,61 @@ +From 6e43ce523e7b403cc4f5e94c988d8811d2053e0f Mon Sep 17 00:00:00 2001 +From: John Kacur +Date: Tue, 14 Dec 2021 14:59:50 -0500 +Subject: [PATCH] tuna: Fix tuna displays incorrect cpu affinity when cpu is + offlined + +If we create a process and query it's affinity, both taskset and tuna +display the same result, but if we then disable a processor, tuna +displays the wrong affinity, as below. + +[jkacur@fionn tuna]$ sha1sum /dev/zero & +[1] 10640 +[jkacur@fionn tuna]$ taskset -p 10640 +pid 10640's current affinity mask: fff +[jkacur@fionn tuna]$ su -c './tuna-cmd.py -t sha1sum -P' +Password: + thread ctxt_switches + pid SCHED_ rtpri affinity voluntary nonvoluntary cmd + 10640 OTHER 0 0xfff 0 423 sha1sum +[jkacur@fionn tuna]$ su -c 'chcpu -d 5' +Password: +CPU 5 disabled +[jkacur@fionn tuna]$ taskset -p 10640 +pid 10640's current affinity mask: fdf +[jkacur@fionn tuna]$ su -c './tuna-cmd.py -t sha1sum -P' +Password: + thread ctxt_switches + pid SCHED_ rtpri affinity voluntary nonvoluntary cmd + 10640 OTHER 0 0x7df 0 919 sha1sum + +The reason for this is that after tuna gets the affinity for the +process, when it converts this to a hex value, it passes the number of +enabled processors to hexbitmask in procfs, when what we really need is +the number of processors including disabled ones. + +Fix this by querrying SC_NPROCESSORS_CONF and passing that value to +hexbitmask. + +Signed-off-by: John Kacur +--- + tuna-cmd.py | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/tuna-cmd.py b/tuna-cmd.py +index d209a2e89493..7e33a128d676 100755 +--- a/tuna-cmd.py ++++ b/tuna-cmd.py +@@ -199,7 +199,9 @@ def format_affinity(affinity): + if len(affinity) <= 4: + return ",".join(str(a) for a in affinity) + +- return ",".join(str(hex(a)) for a in procfs.hexbitmask(affinity, get_nr_cpus())) ++ # We need the number of cpus on a system, including disabled ones ++ ncpus = os.sysconf('SC_NPROCESSORS_CONF') ++ return ",".join(str(hex(a)) for a in procfs.hexbitmask(affinity, ncpus)) + + + def ps_show_thread(pid, affect_children, ps, has_ctxt_switch_info, sock_inodes, +-- +2.31.1 + diff --git a/tuna.spec b/tuna.spec index fc8bd0c..9e1ad4e 100644 --- a/tuna.spec +++ b/tuna.spec @@ -1,6 +1,6 @@ Name: tuna Version: 0.16 -Release: 5%{?dist} +Release: 6%{?dist} License: GPLv2 Summary: Application tuning GUI & command line utility URL: https://git.kernel.org/pub/scm/utils/tuna/tuna.git @@ -17,6 +17,7 @@ Requires: python3-linux-procfs >= 0.6 Patch1: tuna-Print-warning-if-setting-affinity-results-in-EBUSY.patch Patch2: tuna-Add-distinction-between-spread-and-move-to-erro.patch Patch3: tuna-Make-it-clear-that-include-and-isolate-affects-IRQs.patch +Patch4: tuna-Fix-tuna-displays-incorrect-cpu-affinity-when-c.patch %description Provides interface for changing scheduler and IRQ tunables, at whole CPU and at @@ -32,6 +33,7 @@ installed. %patch1 -p1 %patch2 -p1 %patch3 -p1 +%patch4 -p1 %build %py3_build @@ -73,6 +75,10 @@ done %{_datadir}/polkit-1/actions/org.tuna.policy %changelog +* Tue Dec 14 2021 John Kacur - 0.16-6 +- Display correct cpu-affinity when a cpu is disabled +Resolves: rhbz#2032460 + * Thu Nov 11 2021 John Kacur - 0.16-5 - Make it clear in online help and man pages that --include and --isolate affect IRQs as well as threads