tuna: Improve process migration messaging clarity
PATCH 1/3 tuna: Improve process migration messaging clarity
Change the migration report from 'failed: N' to 'N kernel threads skipped' to clarify that these are expected kernel thread rejections, not errors.
Kernel threads (cpuhp, ksoftirqd, migration, kworker, IRQ handlers, etc.) cannot be migrated to user cpusets and are correctly rejected by the kernel with EINVAL. The previous wording made this normal behavior appear as failures, which was confusing to users.
--- tuna-cmd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tuna-cmd.py +1 -1
@@ -1704,7 +1704,7 @@ def main(): print(f"Migrating processes to housekeeping cpuset...") tm = cpuset.TaskMigrate(cpusets_init, hk_cpuset) migrated, failed = tm.migrate() - print(f"Migrated {migrated} processes to '{housekeeping_name}' (failed: {failed})") + print(f"Migrated {migrated} processes to '{housekeeping_name}' ({failed} kernel threads skipped)") except Exception as e: print(f"Error creating cpusets: {e}", file=sys.stderr)
Signature · 1 line
2.55.0
PATCH 2/3 tuna: Allow cpuset destroy to accept multiple names
Changed 'tuna cpuset destroy' to accept multiple cpuset names in a single command, improving usability and consistency with other commands.
Previous behavior:
tuna cpuset destroy NAME # Single cpuset only
tuna cpuset destroy --pattern '*' # Multiple via pattern
New behavior:
tuna cpuset destroy NAME1 NAME2 NAME3 # Multiple by name
tuna cpuset destroy --pattern '*' # Multiple via pattern (unchanged)
This change makes the command more flexible and allows users to destroy specific cpusets without needing to use pattern matching. The implementation changed the 'name' argument from nargs='?' to 'names' with nargs='*', and updated the handler function to iterate over the list.
Also added parser_class=HelpMessageParser to subparsers to improve error message context (though argparse still shows top-level help for some unrecognized argument errors due to internal behavior).
--- tuna-cmd.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-)
tuna-cmd.py +17 -16
@@ -149,7 +149,7 @@ def gen_parser(): parser.add_argument('-D', '--debug', **MODS['debug']) parser.add_argument('-w', '--warn', **MODS['warn']) - subparser = parser.add_subparsers(dest='command') + subparser = parser.add_subparsers(dest='command', parser_class=HelpMessageParser) idle_set = subparser.add_parser('cpu_power', description='Manage CPU idle state disabling (requires libcpupower and it\'s Python bindings)',
@@ -265,7 +265,7 @@ def gen_parser(): gui.add_argument('-K', '--no_kthreads', **MODS['no_kthreads']) # Cpuset nested subcommands - cpuset_subparser = cpuset.add_subparsers(dest='cpuset_command', required=True) + cpuset_subparser = cpuset.add_subparsers(dest='cpuset_command', required=True, parser_class=HelpMessageParser) # cpuset create cpuset_create = cpuset_subparser.add_parser('create', description='Create a new cpuset', help='Create a new cpuset')
@@ -285,7 +285,7 @@ def gen_parser(): # cpuset destroy cpuset_destroy = cpuset_subparser.add_parser('destroy', description='Destroy cpuset(s)', help='Destroy cpuset(s)') - cpuset_destroy.add_argument('name', nargs='?', type=str, metavar='NAME', help='Cpuset name to destroy (use this OR --pattern)') + cpuset_destroy.add_argument('names', nargs='*', type=str, metavar='NAME', help='Cpuset name(s) to destroy (one or more, OR use --pattern)') cpuset_destroy.add_argument('-p', '--pattern', type=str, metavar='PATTERN', help='Glob pattern to destroy multiple cpusets (e.g., tuna*)') cpuset_destroy.add_argument('-f', '--force', action='store_true', help='Migrate tasks to root cgroup before destroying') cpuset_destroy.add_argument('--include-empty', action='store_true', help='When using --pattern, include cpusets with no CPUs assigned (default: skip empty)')
@@ -1140,12 +1140,12 @@ def cpuset_list(pattern, verbose, show_empty, show_system, recursive): print("This may indicate a problem with blocklist protection.", file=sys.stderr) -def cpuset_destroy(name, pattern, force, include_empty, recursive): +def cpuset_destroy(names, pattern, force, include_empty, recursive): """Handler for 'tuna cpuset destroy' command. Args: - name: Cpuset name to destroy (single cpuset, mutually exclusive with pattern) - pattern: Glob pattern for cpusets to destroy (mutually exclusive with name) + names: List of cpuset names to destroy (mutually exclusive with pattern) + pattern: Glob pattern for cpusets to destroy (mutually exclusive with names) force: If True, migrate tasks to root before destroying include_empty: If True, include cpusets with no CPUs assigned (default: skip empty, only used with pattern) recursive: If True, find and clean nested cpusets (only used with pattern)
@@ -1156,19 +1156,20 @@ def cpuset_destroy(name, pattern, force, include_empty, recursive): print("Error: cgroup v2 cpusets not supported on this system", file=sys.stderr) sys.exit(1) - # Validate: must have either name OR pattern, not both, not neither - if name and pattern: - print("Error: specify either NAME or --pattern, not both", file=sys.stderr) + # Validate: must have either names OR pattern, not both, not neither + if names and pattern: + print("Error: specify either NAME(s) or --pattern, not both", file=sys.stderr) sys.exit(2) - if not name and not pattern: - print("Error: must specify either NAME or --pattern", file=sys.stderr) + if not names and not pattern: + print("Error: must specify either NAME(s) or --pattern", file=sys.stderr) sys.exit(2) try: - if name: - # Single cpuset destroy (include_empty not applicable) - cpuset.destroy_cpuset(name, force=force) - print(f"Destroyed cpuset '{name}'") + if names: + # Destroy specified cpusets by name (one or more) + for name in names: + cpuset.destroy_cpuset(name, force=force) + print(f"Destroyed cpuset '{name}'") else: # Pattern-based cleanup if not include_empty:
@@ -1879,7 +1880,7 @@ def main(): cpuset_list(args.pattern, args.verbose, args.show_empty, args.show_system, args.recursive) elif args.cpuset_command == 'destroy': - cpuset_destroy(args.name, args.pattern, args.force, args.include_empty, args.recursive) + cpuset_destroy(args.names, args.pattern, args.force, args.include_empty, args.recursive) elif args.cpuset_command == 'move': cpuset_move(args.name, args.thread_list, args.pid_list)
Signature · 1 line
2.55.0
PATCH 3/3 tests: Update cpuset_destroy test calls for new parameter name
In reply to John KacurUpdate test calls to use 'names=' parameter instead of 'name=' to match the function signature change in cpuset_destroy(). The function was changed to accept a list of names (names=[...]) instead of a single optional name (name='...') to support destroying multiple cpusets in one command.
Changed three test functions:
- test_destroy_single_cpuset: name='...' -> names=['...']
- test_destroy_by_pattern: name=None -> names=None
- test_destroy_default_skips_empty: name=None -> names=None
--- tests/test_cpuset_cli.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tests/test_cpuset_cli.py +3 -3
@@ -300,7 +300,7 @@ class TestCpusetDestroyCLI(unittest.TestCase): self.assertTrue(os.path.exists(path)) # Destroy it (without force, no tasks) - cpuset_destroy(name='test_destroy_single', pattern=None, force=False, + cpuset_destroy(names=['test_destroy_single'], pattern=None, force=False, include_empty=True, recursive=True) # Should be gone
@@ -317,7 +317,7 @@ class TestCpusetDestroyCLI(unittest.TestCase): self.created_cpusets.extend(['test_destroy_bulk_1', 'test_destroy_bulk_2']) # Destroy by pattern - cpuset_destroy(name=None, pattern='test_destroy_bulk_*', force=True, + cpuset_destroy(names=None, pattern='test_destroy_bulk_*', force=True, include_empty=True, recursive=False) # Should be gone
@@ -339,7 +339,7 @@ class TestCpusetDestroyCLI(unittest.TestCase): self.created_cpusets.append('test_destroy_empty') # Destroy with default (include_empty=False, which skips empty) - cpuset_destroy(name=None, pattern='test_destroy_*', force=True, + cpuset_destroy(names=None, pattern='test_destroy_*', force=True, include_empty=False, recursive=False) # Non-empty should be destroyed
Signature · 1 line
2.55.0