From e511d70d40679f27aac84fe0b1574d039ebe9f35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= Date: Fri, 1 Jun 2018 23:49:34 +0200 Subject: [PATCH] scheduler: Fix reverting CPU affinity in process groups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously CPU affinity of tasks created while Tuned was running was not correctly reverted on Tuned shutdown. Reproducer (on a 4 core machine): $ mkdir /etc/tuned/test $ cat > /etc/tuned/test/tuned.conf << EOF [scheduler] group.foo=0:o:0:1:a.out EOF $ cat > a.c << EOF #include int main(void) { pause(); return 0; } EOF $ gcc a.c $ systemctl start tuned $ ./a.out & $ systemctl stop tuned $ taskset -p $(pgrep a.out) pid 9950's current affinity mask: 1 <<< should be "f" Known issue: if you run the above reproducer with the config below after this commit is applied, the affinity of the task after stopping tuned will be 0xd, not 0xf. This is because after starting tuned, first the affinity of the shell session is set to the non-isolated cores (0xd). Then when ./a.out starts, it inherits that affinity. Then when tuned tunes the affinity of the ./a.out process, it remembers 0xd as its old affinity rather than 0xf. It is unclear to me at this point whether we should do anything about this issue. Properly fixing it would require tracing where processes get their affinity from. [scheduler] group.foo=0:o:0:1:a.out ps_blacklist=.*a.out.* isolated_cores=1 Signed-off-by: Ondřej Lysoněk --- tuned/plugins/plugin_scheduler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tuned/plugins/plugin_scheduler.py b/tuned/plugins/plugin_scheduler.py index babe108..890c2b3 100644 --- a/tuned/plugins/plugin_scheduler.py +++ b/tuned/plugins/plugin_scheduler.py @@ -284,7 +284,7 @@ class SchedulerPlugin(base.Plugin): for pid, vals in list(instance._scheduler_original.items()): # if command line for the pid didn't change, it's very probably the same process try: - if ps[pid] == vals[0]: + if ps[int(pid)] == vals[0]: self._set_rt(pid, self._sched2param(vals[1]), vals[2]) self._set_affinity(pid, vals[3]) except KeyError as e: