[PATCH 1/2] tuna: Print warning if setting affinity results in EPERM and continue

John Kacur <[email protected]> Thu, 7 May 2026 15:28:57 -0400
Newsgroups org.kernel.vger.linux-rt-users
Message-ID <[email protected]>
When trying to isolate a CPU, if setting the affinity on a process fails
with EPERM (Operation not permitted), this can occur due to security
restrictions, namespace isolation, or lack of capabilities.

This is commonly seen with PID 1 (systemd/init) even when running as root,
particularly when using 'su -c' which may not grant full capabilities, or
when SELinux/AppArmor policies restrict the operation.

tuna should print a warning that this pid could not be moved, and continue
processing other processes, similar to how EBUSY errors are handled.

Assisted-by: Claude Sonnet 4.5 <[email protected]>
Signed-off-by: John Kacur <[email protected]>
---
 tuna/tuna.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tuna/tuna.py b/tuna/tuna.py
index ef60c033362d..8e57cddd0c13 100755
--- a/tuna/tuna.py
+++ b/tuna/tuna.py
@@ -370,6 +370,10 @@ def isolate_cpus(cpus, nr_cpus):
                     comm = ps[pid].stat["comm"]
                     print(f'Warning: Unable to isolate pid {pid} [{comm}]')
                     continue
+                if err.args[0] == errno.EPERM:
+                    comm = ps[pid].stat["comm"]
+                    print(f'Warning: Unable to isolate pid {pid} [{comm}]')
+                    continue
                 raise err
 
         if "threads" not in ps[pid]:
-- 
2.54.0