50 lines
1.2 KiB
Python
50 lines
1.2 KiB
Python
import os
|
|
import sys
|
|
import getopt
|
|
import subprocess
|
|
|
|
options = getopt.getopt(sys.argv[1:], 'b:s:d:p:')[0]
|
|
|
|
base=0
|
|
stride=2
|
|
num = 0
|
|
port = 0
|
|
|
|
for opt, arg in options:
|
|
if opt == '-b':
|
|
base = int(arg)
|
|
elif opt == '-s':
|
|
stride = int(arg)
|
|
elif opt == '-d':
|
|
num = int(arg)
|
|
elif opt == '-p':
|
|
port = int(arg)
|
|
result = subprocess.run("sysctl -a", shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
lines = result.stdout.decode().split('\n')
|
|
cclines : list[str] = []
|
|
for line in lines:
|
|
if ("irq" in line) and (f"t6nex{num}" in line) and (f"{port}a" in line):
|
|
cclines.append(line)
|
|
|
|
if len(cclines) == 0:
|
|
print(f"No t6nex {num}a lines from sysctl.\n")
|
|
exit(1)
|
|
|
|
irqs = []
|
|
for line in cclines:
|
|
eles = line.split(' ')
|
|
irq = eles[0]
|
|
if (irq.startswith("irq") and irq.endswith(":")):
|
|
irq = irq[3:-1]
|
|
irqs.append(int(irq))
|
|
else:
|
|
print(f"Unknown line format: f{line}")
|
|
|
|
print(f"Detected {len(irqs)} irqs:\n{str(irqs)}")
|
|
|
|
for irq in irqs:
|
|
print(f"Setting irq{irq}'s affinity to core {base}...")
|
|
subprocess.run(f"cpuset -l {base} -x {irq}", check=True, shell=True)
|
|
base = base + stride
|
|
|
|
exit(0) |