我要评分
获取效率
正确性
完整性
易理解

Binding NIC Interrupts to Cores

Purpose

  1. Each CPU corresponds to a network interface card (NIC). Bind the cores of the CPU to the corresponding NIC by node.
  2. 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.
  3. Use the same core binding script and execute the script on physical machines for the container in host network sharing mode and IPVLAN mode.

Procedure

  1. Disable irqbalance.

    Before binding cores to NICs, disable irqbalance.

    1. Stop the irqbalance service.
      1
      systemctl stop irqbalance.service
      

      The preceding operation of stopping the irqbalance service will become invalid after the system is restarted. To permanently disable the irqbalance service, run the following command:

      1
      systemctl disable irqbalance.service
      
    2. Check whether the irqbalance service is disabled.
      1
      systemctl status irqbalance.service
      
  2. 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 number of network port queues to be bound (cnt), the name of the network port to be bound (eth1), and the cores to be bound.

    The core binding script is as follows:

    #!/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++"
    done

    Table 1 describes the parameters and commands.

    Table 1 Parameter and command description

    Parameter and Command

    Description

    cnt

    Sets the number of network port queues. cnt is a variable, and 2 is the number of queues.

    eth1

    Sets 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

    Sets 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/$irq/smp_affinity_list

    Binds each interrupt to a core based on the interrupt number.