2023年12月11日 星期一

smp_affinity, taskset and isolcpus 指定CPU方法

  • smp_affinity
    MV31是走USB介面,用lsusb查看,是用xhci_hcd
    $ lsusb
    Bus 004 Device 002: ID 1e2d:00b3 Gemalto M2M GmbH Cinterion PID 0x00B3 USB Mobile Broadband
    Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
    
    $ lsusb -t
    /:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/8p, 20000M/x2
        |__ Port 2: Dev 2, If 0, Class=Communications, Driver=cdc_mbim, 5000M
        |__ Port 2: Dev 2, If 1, Class=CDC Data, Driver=cdc_mbim, 5000M
        |__ Port 2: Dev 2, If 2, Class=Vendor Specific Class, Driver=option, 5000M
        |__ Port 2: Dev 2, If 3, Class=Vendor Specific Class, Driver=, 5000M
        |__ Port 2: Dev 2, If 4, Class=Vendor Specific Class, Driver=option, 5000M
        |__ Port 2: Dev 2, If 5, Class=Vendor Specific Class, Driver=option, 5000M
    
    

    查下中斷表是否有xhci_hcd
    $ cat /proc/interrupts | grep -i xhci_hcd
     130:          0          0          0          0          0          0          0          0          0          0          0          0          0          0          0          0  IR-PCI-MSI-0000:00:0d.0    0-edge      xhci_hcd
     132:          0        537          0          0          0          0          0          0          0          0          0          0          0      19774          0          0  IR-PCI-MSI-0000:00:14.0    0-edge      xhci_hcd
    

    中斷號碼132看起來在CPU13用得比較多(19774)
    用ping再度確認下
    CPU13變高到25209
    $ ping -I wwan0 8.8.8.8
    PING 8.8.8.8 (8.8.8.8) from 10.238.24.92 wwan0: 56(84) bytes of data.
    64 bytes from 8.8.8.8: icmp_seq=1 ttl=55 time=41.2 ms
    64 bytes from 8.8.8.8: icmp_seq=2 ttl=55 time=23.8 ms
    64 bytes from 8.8.8.8: icmp_seq=3 ttl=55 time=37.3 ms
    ^C
    --- 8.8.8.8 ping statistics ---
    3 packets transmitted, 3 received, 0% packet loss, time 2003ms
    rtt min/avg/max/mdev = 23.798/34.110/41.199/7.460 ms
    
    $ cat /proc/interrupts | grep -i xhci_hcd
     130:          0          0          0          0          0          0          0          0          0          0          0          0          0          0          0          0  IR-PCI-MSI-0000:00:0d.0    0-edge      xhci_hcd
     132:          0        537          0          0          0          0          0          0          0          0          0          0          0      25209          0          0  IR-PCI-MSI-0000:00:14.0    0-edge      xhci_hcd
    

    系統用哪顆CPU來處理這個中斷
    $ cat /proc/irq/132/smp_affinity
    2020
    

    試著改變到CPU14和CPU15,並用PING再測試
    # echo "c000" > /proc/irq/132/smp_affinity
    
    # cat /proc/irq/132/smp_affinity
    c000
    
    $ cat /proc/interrupts | grep -i xhci_hcd
     130:          0          0          0          0          0          0          0          0          0          0          0          0          0          0          0          0  IR-PCI-MSI-0000:00:0d.0    0-edge      xhci_hcd
     132:          0        537          0          0          0          0          0          0          0          0          0          0          0      35409       1373          0  IR-PCI-MSI-0000:00:14.0    0-edge      xhci_hcd
    

    queues
    $ cd /sys/class/net/wwan0/queues
    $ tree -L 1
    .
    ├── rx-0
    └── tx-0
    
    $ cat rx-0/rps_cpus
    0000  //這個值也能調整來提高效率
    

  • taskset
    Install:
    $ sudo apt-get install util-linux
    

    查訊程式用哪顆CPU處理
    $ taskset -p PID
    $ taskset -p 6151
    pid 6151's current affinity mask: ffff
    

    指定程式用哪顆CPU處理
    $ taskset 8 /usr/local/bin/my_programer
    or
    $ taskset -p CPU_number PID
    
    $ taskset -p c000 6195
    pid 6195's current affinity mask: ffff
    pid 6195's new affinity mask: c000
    


  • isolcpus尚末使用


ref:
1. [转]再转载一篇关于SMP IRQ affinity的好文章(包含RPS/RFS)
2. CPU Affinity taskset (cpuset)
3. 在 Linux 中以特定的 CPU 核心執行程式

沒有留言:

張貼留言