diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2008-10-16 16:20:36 -0200 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2008-10-16 16:20:36 -0200 |
commit | 9eaa9bafa0d6d22083077b1c383762fd1abe6969 (patch) | |
tree | 7739956f84db02b62897409e5cb572aebbce421b | |
parent | c5930661a727ef48e25f0e8e0985d6373472f540 (diff) | |
download | tuna-9eaa9bafa0d6d22083077b1c383762fd1abe6969.tar.gz |
tuna: Add a "spread" parameter to move_threads_to_cpu
[root@emilia tuna]# tuna --threads 7926,7927,7928,7929 --sockets 1 --spread --show_threads
thread ctxt_switches
pid SCHED_ rtpri affinity voluntary nonvoluntary cmd
7926 OTHER 0 1 14 2 mingetty
7927 OTHER 0 3 23 3 mingetty
7928 OTHER 0 5 21 4 mingetty
7929 OTHER 0 7 24 5 mingetty
[root@emilia tuna]#
This is on a machine with two CPU sockets where the second socket (1) has 4
cores (1, 3, 5, 7).
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rwxr-xr-x | tuna-cmd.py | 13 | ||||
-rwxr-xr-x | tuna/tuna.py | 12 |
2 files changed, 22 insertions, 3 deletions
diff --git a/tuna-cmd.py b/tuna-cmd.py index 07ba81d..eee2909 100755 --- a/tuna-cmd.py +++ b/tuna-cmd.py @@ -174,14 +174,15 @@ def do_ps(threads, cpus, show_uthreads, show_kthreads, affect_children): def main(): try: opts, args = getopt.getopt(sys.argv[1:], - "c:CfghiIKmp:Ps:S:t:UW", + "c:CfghiIKmp:Ps:S:t:UWx", ("cpus=", "affect_children", "filter", "gui", "help", "isolate", "include", "no_kthreads", "move", "priority=", "show_threads", "save=", "sockets=", "threads=", - "no_uthreads", "what_is")) + "no_uthreads", "what_is", + "spread")) except getopt.GetoptError, err: usage() print str(err) @@ -256,6 +257,14 @@ def main(): sys.exit(2) for tid in threads: thread_help(tid) + elif o in ("-x", "--spread"): + if not cpus: + print "tuna: --spread requires a cpu list!" + sys.exit(2) + if not threads: + print "tuna: --spread requires a thread list!" + sys.exit(2) + tuna.move_threads_to_cpu(cpus, threads, spread = True) if run_gui: try: diff --git a/tuna/tuna.py b/tuna/tuna.py index 5cad29e..c2be7bd 100755 --- a/tuna/tuna.py +++ b/tuna/tuna.py @@ -142,11 +142,21 @@ def list_to_cpustring(l): prev = i return ",".join(strings) -def move_threads_to_cpu(new_affinity, pid_list, set_affinity_warning = None): +def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None, + spread = False): changed = False ps = procfs.pidstats() + cpu_idx = 0 + nr_cpus = len(cpus) + new_affinity = cpus for pid in pid_list: + if spread: + new_affinity = [cpus[cpu_idx]] + cpu_idx += 1 + if cpu_idx == nr_cpus: + cpu_idx = 0 + try: try: curr_affinity = schedutils.get_affinity(pid) |