Skip to content

Commit 2a1bb41

Browse files
authored
Merge pull request #717 from zacikpa/affinity-error-logs
scheduler: Log process info when its affinity cannot be changed and re-check blacklisted cgroups
2 parents 13dfc68 + 7113c91 commit 2a1bb41

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

tuned/plugins/plugin_scheduler.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -657,15 +657,24 @@ def _set_rt(self, pid, sched, prio):
657657
def _is_kthread(self, process):
658658
return process["stat"]["flags"] & procfs.pidstat.PF_KTHREAD != 0
659659

660+
def _process_in_blacklisted_cgroup(self, process):
661+
if self._cgroup_ps_blacklist_re == "":
662+
return False
663+
return re.search(self._cgroup_ps_blacklist_re, self._get_stat_cgroup(process)) is not None
664+
660665
# Returns True if we can ignore a failed affinity change of
661666
# a process with the given PID and therefore not report it as an error.
662-
def _ignore_set_affinity_error(self, pid):
667+
def _ignore_set_affinity_error(self, process):
668+
pid = process.pid
663669
try:
664-
process = procfs.process(pid)
665670
if process["stat"]["state"] == "Z":
666671
log.debug("Affinity of zombie task with PID %d could not be changed."
667672
% pid)
668673
return True
674+
if self._process_in_blacklisted_cgroup(process):
675+
log.debug("Affinity of task with PID %d could not be changed, the task was moved into a blacklisted cgroup."
676+
% pid)
677+
return True
669678
if process["stat"].is_bound_to_cpu():
670679
if self._is_kthread(process):
671680
log.debug("Affinity of kernel thread with PID %d cannot be changed, the task's affinity mask is fixed."
@@ -674,6 +683,9 @@ def _ignore_set_affinity_error(self, pid):
674683
log.warning("Affinity of task with PID %d cannot be changed, the task's affinity mask is fixed."
675684
% pid)
676685
return True
686+
log.info("Task %d cmdline: %s" % (pid, self._get_cmdline(process)))
687+
log.info("Task %d cgroup: %s" % (pid, self._get_stat_cgroup(process)))
688+
log.info("Task %d affinity: %s" % (pid, list(self._scheduler_utils.get_affinity(pid))))
677689
except (OSError, IOError) as e:
678690
if e.errno == errno.ENOENT or e.errno == errno.ESRCH:
679691
log.debug("Failed to get task info for PID %d, the task vanished."
@@ -1181,13 +1193,17 @@ def _get_affinity(self, pid):
11811193
return res
11821194

11831195
def _set_affinity(self, pid, affinity):
1196+
process = procfs.process(pid)
1197+
if self._process_in_blacklisted_cgroup(process):
1198+
log.debug("Not setting CPU affinity of PID %d, the task belongs to a blacklisted cgroup." % pid)
1199+
return
11841200
log.debug("Setting CPU affinity of PID %d to '%s'." % (pid, affinity))
11851201
try:
11861202
self._scheduler_utils.set_affinity(pid, affinity)
11871203
# Workaround for old python-schedutils (pre-0.4) which
11881204
# incorrectly raised SystemError instead of OSError
11891205
except (SystemError, OSError) as e:
1190-
if not self._ignore_set_affinity_error(pid):
1206+
if not self._ignore_set_affinity_error(process):
11911207
log.error("Failed to set affinity of PID %d to '%s': %s"
11921208
% (pid, affinity, e))
11931209

@@ -1204,9 +1220,6 @@ def _set_all_obj_affinity(self, objs, affinity, threads = False):
12041220
if self._ps_blacklist != "":
12051221
psl = [v for v in psl if re.search(self._ps_blacklist,
12061222
self._get_stat_comm(v)) is None]
1207-
if self._cgroup_ps_blacklist_re != "":
1208-
psl = [v for v in psl if re.search(self._cgroup_ps_blacklist_re,
1209-
self._get_stat_cgroup(v)) is None]
12101223
psd = dict([(v.pid, v) for v in psl])
12111224
for pid in psd:
12121225
try:

0 commit comments

Comments
 (0)