Created
June 2, 2021 04:36
-
-
Save ms1995/59721f3b214825fd2d04610dc96177a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import psutil | |
import random | |
CPUSET = [int(x) for x in sys.argv[1].split(',')] | |
PID = int(sys.argv[2]) | |
threads = [] | |
for p in psutil.Process(PID).children(recursive=True): | |
if 'qemu-system' in p.name(): | |
threads += p.threads() | |
# random.shuffle(threads) | |
threads.sort(key=lambda thread: thread.user_time + thread.system_time, reverse=True) | |
random.shuffle(CPUSET) | |
for i, thread in enumerate(threads): | |
cpu = CPUSET[i % len(CPUSET)] | |
psutil.Process(thread.id).cpu_affinity([cpu]) | |
# print("Thread %d bound to CPU #%d" % (thread.id, cpu)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment