diff --git a/setup-multiqueue.py b/setup-multiqueue.py new file mode 100644 index 0000000..7ca3b44 --- /dev/null +++ b/setup-multiqueue.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python3 + +import os +import shutil +import subprocess +import sys + +# Domyślne wartości +iface = "ens19" +queues = "1" + +# Sprawdzenie parametrów +if len(sys.argv) >= 2: + iface = sys.argv[1] +if len(sys.argv) >= 3: + queues = sys.argv[2] + +bash_script_path = "/usr/local/bin/setup-multiqueue.sh" +service_path = "/etc/systemd/system/setup-multiqueue.service" + +# Sprawdzenie ethtool +if shutil.which("ethtool") is None: + print("❗ Brak ethtool w systemie. Zainstaluj: pacman -S ethtool (Arch Linux)") + sys.exit(1) + +# Treść skryptu bash +bash_script = """#!/bin/bash + +IFACE="$1" +QUEUES="$2" + +if [ -z "$IFACE" ] || [ -z "$QUEUES" ]; then + echo "Użycie: $0 " + exit 1 +fi + +ethtool -L "$IFACE" combined "$QUEUES" + +for irq in $(grep "$IFACE-TxRx" /proc/interrupts | awk '{print $1}' | tr -d ':'); do + echo f > /proc/irq/$irq/smp_affinity +done +""" + +# Zapis skryptu bash +with open(bash_script_path, "w") as f: + f.write(bash_script) +os.chmod(bash_script_path, 0o755) +print(f"✅ Utworzono {bash_script_path}") + +# Treść usługi systemd +service_file = f"""[Unit] +Description=Configure multiqueue for virtio-net +After=network-online.target +Wants=network-online.target + +[Service] +Type=oneshot +ExecStart={bash_script_path} {iface} {queues} + +[Install] +WantedBy=multi-user.target +""" + +# Zapis usługi +with open(service_path, "w") as f: + f.write(service_file) +print(f"✅ Utworzono {service_path}") + +# Reload systemd, enable, start +subprocess.run(["systemctl", "daemon-reload"], check=True) +subprocess.run(["systemctl", "enable", "--now", "setup-multiqueue.service"], check=True) + +print(f"✅ Usługa włączona i uruchomiona dla interfejsu: {iface}, kolejek: {queues}.")