Blame SOURCES/tuna-fix-the-check-of-PF_NO_SETAFFINITY-flag-for-thr.patch

16280a
From 92aa193749be6d1e531e05abef22b9092c577bb3 Mon Sep 17 00:00:00 2001
16280a
From: Daniel Bristot de Oliveira <bristot@redhat.com>
16280a
Date: Fri, 27 Nov 2015 16:36:54 -0200
16280a
Subject: [PATCH] tuna: fix the check of PF_NO_SETAFFINITY flag for threads
16280a
16280a
commit 95c4e2ad2603cd29af1357c0ceb780da8dc161cc upstream
16280a
16280a
The following is the commit that caused the regression
16280a
commit 29fbb6e82357c87be652c6717ef52d808ec0af78
16280a
tuna: Decide whether to isolate a thread based on PF_NO_SETAFFINITY
16280a
16280a
Tuna checks if PF_NO_SETAFFINITY is set on /proc/PID/stat's 'flag' field
16280a
to verify if it is possible to migrate a process/thread.  This is
16280a
working fine for process, but not for threads.
16280a
16280a
For threads, the file /proc/TID/stat is being checked, but this file
16280a
does not exist as the stat file of a thread is at
16280a
/proc/PID/task/TID/stat.  Hence, the check was failing and threads were
16280a
not being migrated.
16280a
16280a
This patch adds a function to check thread's stat file, and this
16280a
function is called to verify the PF_NO_SETAFFINITY flag for threads.
16280a
16280a
Committer note:
16280a
16280a
Before, doing:
16280a
16280a
  # tuna --cpu 3 --isolate
16280a
  # tuna -t firefox -CP
16280a
                      thread       ctxt_switches
16280a
      pid SCHED_ rtpri affinity voluntary nonvoluntary             cmd
16280a
   14838   OTHER     0    0,1,2    873954        27498         firefox
16280a
    14857  OTHER     0  0,1,2,3         3            1  Gecko_IOThread
16280a
    14858  OTHER     0  0,1,2,3         1            0    Link Monitor
16280a
    14859  OTHER     0  0,1,2,3    126717        12214   Socket Thread
16280a
  <SNIP>
16280a
16280a
So it affected just the main thread, all the children remained with
16280a
their existing affinity mask.
16280a
16280a
After the patch:
16280a
16280a
  # tuna --cpu 3 --isolate
16280a
  # tuna -t firefox -CP
16280a
                        thread       ctxt_switches
16280a
      pid SCHED_ rtpri affinity voluntary nonvoluntary             cmd
16280a
   14838   OTHER     0    0,1,2    877488        27583         firefox
16280a
    14857  OTHER     0    0,1,2         3            1  Gecko_IOThread
16280a
    14858  OTHER     0    0,1,2         1            0    Link Monitor
16280a
    14859  OTHER     0    0,1,2    126933        12235   Socket Thread
16280a
  <SNIP>
16280a
16280a
Signed-off-by: Daniel Bristot de Oliveira <bristot@redhat.com>
16280a
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
16280a
Cc: Jiri Kastner <jkastner@redhat.com>
16280a
Cc: John Kacur <jkacur@redhat.com>
16280a
Cc: Luiz Capitulino <lcapitulino@redhat.com>
16280a
Cc: Tuna <tuna-devel@lists.fedorahosted.org>
16280a
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1286221
16280a
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
16280a
Resolves: rhbz#1286221
16280a
Signed-off-by: John Kacur <jkacur@redhat.com>
16280a
---
16280a
 tuna/tuna.py | 13 +++++++++++--
16280a
 1 file changed, 11 insertions(+), 2 deletions(-)
16280a
16280a
diff --git a/tuna/tuna.py b/tuna/tuna.py
16280a
index 3c30f03ea134..1de63b07a5ee 100755
16280a
--- a/tuna/tuna.py
16280a
+++ b/tuna/tuna.py
16280a
@@ -181,6 +181,15 @@ def cannot_set_affinity(self, pid):
16280a
 		except:
16280a
 			return True
16280a
 
16280a
+# FIXME: move to python-linux-procfs
16280a
+def cannot_set_thread_affinity(self, pid, tid):
16280a
+		PF_NO_SETAFFINITY = 0x04000000
16280a
+		try:
16280a
+			return int(self.processes[pid].threads[tid]["stat"]["flags"]) & \
16280a
+				PF_NO_SETAFFINITY and True or False
16280a
+		except:
16280a
+			return True
16280a
+
16280a
 def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None,
16280a
 			spread = False):
16280a
 	changed = False
16280a
@@ -357,7 +366,7 @@ def isolate_cpus(cpus, nr_cpus):
16280a
 			continue
16280a
 		threads = ps[pid]["threads"]
16280a
 		for tid in threads.keys():
16280a
-			if cannot_set_affinity(ps, tid):
16280a
+			if cannot_set_thread_affinity(ps, pid, tid):
16280a
 				continue
16280a
 			try:
16280a
 				affinity = schedutils.get_affinity(tid)
16280a
@@ -425,7 +434,7 @@ def include_cpus(cpus, nr_cpus):
16280a
 			continue
16280a
 		threads = ps[pid]["threads"]
16280a
 		for tid in threads.keys():
16280a
-			if cannot_set_affinity(ps, tid):
16280a
+			if cannot_set_thread_affinity(ps, pid, tid):
16280a
 				continue
16280a
 			try:
16280a
 				affinity = schedutils.get_affinity(tid)
16280a
-- 
16280a
2.4.3
16280a