Binding NIC Interrupts to Cores
Purpose
- Each CPU corresponds to a network interface card (NIC). Bind the cores of the CPU to the corresponding NIC by node.
- The number of interrupts is as small as possible and all service cores run when the client is fully loaded and the CPU is fully occupied.
- Use the same core binding script and execute the script on physical machines for the container in host network sharing mode and IP VLAN mode.
Procedure
- Disable irqbalance.
1 2 3
systemctl stop irqbalance.service systemctl disable irqbalance.service systemctl status irqbalance.service
- Bind NIC interrupts to cores. The bound cores are used to process NIC interrupts.
In the following example, bind the HTTP processes to four CPU cores to process short connections. To modify the core binding script, you only need to change the name of the network port to be bound (eth1) and the NIC queue depth (cnt).
- Create a script.
1vim irq_http_4core.sh - Press i to enter the insert mode and add the following content to the file:
#!/bin/bash # filename: irq_http_4core.sh cnt=2 eth1=enp3s0 ethtool -L $eth1 combined $cnt irq1=`cat /proc/interrupts| grep -E ${eth1} | head -1 | awk -F ':' '{print $1}'` irq1=`echo $irq1` i=0 while(( $i < 1)) do for cpunum in 2 3 do echo $cpunum "->" $irq1 echo $cpunum > /proc/irq/$irq1/smp_affinity_list let "irq1++" done let "i++" doneTable 1 describes the parameters and commands.
Table 1 Parameter and command description Parameter and Command
Description
cnt
Specifies the number of network port queues. cnt is a variable, and 2 is the number of queues.
eth1
Specifies the name of the network port used for communication. eth1 is a variable, and enp3s0 is the network port name.
irq1
Specifies the interrupt number of the network port eth1. irq1 is a variable.
cpunum
Specifies the core assigned to the network port eth1 for processing NIC interrupts. cpunum is a variable.
ethtool -L $eth1 combined $cnt
Specifies the number of queues to the number of cores.
cat /proc/interrupts | grep $eth1 | awk -F ':' '{print $1}'
Queries the network port interrupt number.
echo $cpunum > /proc/irq/$irq1/smp_affinity_list
Binds each interrupt to a core based on the interrupt number.
- Press Esc, type :wq!, and press Enter to save the file and exit.
- Execute the script.
1sh irq_http_4core.sh
- Create a script.