Check which CPU core handles network card interrupts

By default, Linux defaults that the interrupt operation of a network card is processed in one CPU core. When the large amount of data or the PPS of the network card's sending and receiving performance is tested, the IO operation of the network card becomes the most CPU-consuming. bottleneck. If we have multiple network cards to send and receive packets at the same time, we can artificially modify the CPU core used for processing network card interrupts to achieve better performance.

1. Check the CPU usage

As shown in the figure below, we can see that 9.6% of the CPU occupied by si has the second CPU core, while other CPU cores do not come to help with processing.
insert image description here

2. View the distribution of system interrupt processing among each CPU core

As shown in the figure below, we can see that a large number of interrupts of the network card device enp2s0 numbered 128 are processed by CPU1

sudo cat /proc/interrupts

insert image description here

3. View the CPU core used to handle network card interrupts

cat /proc/irq/128/smp_affinity

We will see that the returned result is 2, which is 0x0010 when converted into binary system, indicating that it is on the second CPU, which is CPU1 (Note: the bit mask is used here, if it is 0x0001 means the first CPU, 0x0010 means the second CPU, 0x0100 means the third CPU, 0x1000 means the fourth CPU)

4. Modify the CPU core used to handle network card interrupts

After entering the root mode, use the following command to set the system to use the fourth CPU (8 = 0x1000) to handle the interrupt of the network card

echo "8">/proc/irq/128/smp_affinity

Using the following command again, we can see that the number of interrupts on the second CPU no longer increases, while the number of interrupts on the fourth CPU keeps increasing, indicating that the interrupts of the network card have been transferred to the fourth CPU for processing

sudo cat /proc/interrupts

insert image description here

Guess you like

Origin blog.csdn.net/meihualing/article/details/131183814