Set NIC to specific CPU Core

Set NIC to specific CPU Core

To make the IRQ affinity setting permanent across reboots, you can create a systemd service that automatically sets the IRQ affinity when the system starts.

Follow these steps to create a systemd service for this purpose:

  1. Create a new script that sets the IRQ affinity:
sudo nano /usr/local/bin/set_irq_affinity.sh
  1. In the script, add the following content (replace <interface_name> with your NIC's interface name, and replace <cpu_hex> with the hexadecimal value of the CPU core you want to isolate the NIC to):
#!/bin/bash

# Get the network interface name
INTERFACE_NAME=eth0

# Get the IRQ number for the network interface
IRQ=$(grep $INTERFACE_NAME /proc/interrupts | awk '{print $1}' | tr -d ':')

# Set IRQ affinity to core 1
echo 2 > /proc/irq/$IRQ/smp_affinity

Save the file and exit the text editor.

Make the script executable:

sudo chmod +x /usr/local/bin/set_irq_affinity.sh
  1. Create a new systemd service file:
sudo nano /etc/systemd/system/set_irq_affinity.service
  1. Add the following content to the service file:
[Unit]
Description=Set IRQ affinity for the network interface
After=network.target

[Service]
Type=oneshot
ExecStart=/usr/local/bin/set_irq_affinity.sh

[Install]
WantedBy=multi-user.target

Save the file and exit the text editor.

Reload the systemd configuration:

sudo systemctl daemon-reload
  1. Enable the newly created service, so it starts automatically at boot:
sudo systemctl enable set_irq_affinity.service
  1. Start the service to apply the settings immediately:
sudo systemctl start set_irq_affinity.service

Now, the IRQ affinity setting should be applied automatically at each system startup, making it permanent across reboots.

How to check?

After running the set_irq_affinity.sh script, you can check if the IRQ affinity has been set correctly by examining the /proc/irq directory. Here's how:

  1. Run the set_irq_affinity.sh script:
sudo ./set_irq_affinity.sh
  1. Check the current IRQ affinity for the network interface:
cat /proc/irq/<IRQ_number>/smp_affinity

Replace <IRQ_number> with the IRQ number you found earlier (in your case, it was 22).

If the IRQ affinity has been set correctly, this command should return the hexadecimal value 2, which corresponds to core 1. If the value is different, there might be an issue with the script, and you should double-check the script and the network interface name.

Additionally, you can check the output of the dmesg command for any related messages:

dmesg | grep -i "irq"

This command filters the kernel messages for IRQ-related information, which can help you verify if the IRQ affinity has been changed.

Remember that the changes made by the script will not persist across reboots unless you also create and enable the systemd service as described in the previous instructions.