随笔记录
目录
2.2.1 查询本服务上所有设备 CPU 中断核Number
1. 背景介绍
需要单独cpu 核执行抓包程序。
目标:绑定CPU 中断核之外CPU 核
2. 查询设备CPU 中断核
2.1 查询设备名
# yusur_ctl 查看设备名
[root@LAPTOP-BJ-0216 ~]#
[root@LAPTOP-BJ-0216 ~]# yusur_ctl
Device swiftn0:
Firmware version: 03110808
Firmware date: 23080301
Product type: KPU SWIFT-2200N Pro 2x10G
swiftn.ko version: 1.9.3.13
instanta.ko version: 1.9.3.13
libinstanta.so version: 1.9.3.13
SN: S2NX223010034828
VCCaux: 1.80 V Temperature: 41.6 C VCCint: 0.94 V
Device type: network interface
swift23f0:
Port flags=<UP, no SFP, no signal, no link>
Port speed: 10000 Mbps
ether: 74:3e:39:00:08:f6
RX packets 0
RX fcs errors 0
TX packets 0
swift23f1:
Port flags=<UP, no SFP, no signal, no link>
Port speed: 10000 Mbps
ether: 74:3e:39:00:08:f7
RX packets 0
RX fcs errors 0
TX packets 0
Device swiftn1: # 目标设备
Firmware version: 04210007
Firmware date: 24070301
Product type: KPU SWIFT-2200N Pro 2x10G
swiftn.ko version: 1.9.3.13
instanta.ko version: 1.9.3.13
libinstanta.so version: 1.9.3.13
SN: 00155D3CA26F
VCCaux: 1.78 V Temperature: 48.0 C VCCint: 0.85 V
Device type: customer application
Customer version: 0 (0)
swift49f0:
Port flags=<UP, SFP present, signal detected, link active>
Port speed: 10000 Mbps
ether: 00:15:5d:3c:a2:6f
RX packets 0
RX fcs errors 0
TX packets 0
swift49f1:
Port flags=<UP, SFP present, signal detected, link active>
Port speed: 10000 Mbps
ether: 00:15:5d:3c:a2:70
RX packets 2144
RX fcs errors 0
TX packets 2144
Device swiftn2:
Firmware version: 03110903
Firmware date: 24032401
Product type: KPU SWIFT-2200N Pro 2x10G
swiftn.ko version: 1.9.3.13
instanta.ko version: 1.9.3.13
libinstanta.so version: 1.9.3.13
SN: S2NX223350000178
VCCaux: 1.80 V Temperature: 46.3 C VCCint: 0.94 V
Device type: network interface
swift177f0:
Port flags=<UP, SFP present, signal detected, link active>
Port speed: 10000 Mbps
ether: 74:3e:39:00:0a:28
RX packets 0
RX fcs errors 0
TX packets 0
swift177f1:
Port flags=<UP, SFP present, signal detected, link active>
Port speed: 10000 Mbps
ether: 74:3e:39:00:0a:29
RX packets 0
RX fcs errors 0
TX packets 0
[root@LAPTOP-BJ-0216 ~]#
2.2 查询设备CPU 中断核
2.2.1 查询本服务上所有设备 CPU 中断核Number
第一步:查询本服务上所有设备 CPU 中断核Number
# cat /proc/interrupts | grep <设备名称>
[root@LAPTOP-BJ-0216 ~]#
[root@LAPTOP-BJ-0216 ~]# cat /proc/interrupts | grep swiftn*
280: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 IR-PCI-MSI 12058624-edge swiftn0
281: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 IR-PCI-MSI 25690112-edge swiftn1
282: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 IR-PCI-MSI 92798976-edge swiftn2
[root@LAPTOP-BJ-0216 ~]#
###########
注意:
运行命令 cat /proc/irq/280/smp_affinity_list,看到输出 74 时,
这表示中断号 280 的 CPU 亲和性设置为 CPU 核心 74。
这意味着该中断仅被分配给 CPU 核心 74 来处理。
2.2.2 查询 每个设备cpu 中断核的
第二步:查询 每个设备cpu 中断核的
# cat /proc/irq/<设备cpu 中断核Number>/smp_affinity_list
# 解释 中断核 <设备cpu 中断核Number> 的中断又被分配给 <其他CPU 核>处理
[root@LAPTOP-BJ-0216 ~]# cat /proc/irq/280/smp_affinity_list
74
[root@LAPTOP-BJ-0216 ~]#
[root@LAPTOP-BJ-0216 ~]# cat /proc/irq/281/smp_affinity_list
67
[root@LAPTOP-BJ-0216 ~]#
[root@LAPTOP-BJ-0216 ~]# cat /proc/irq/282/smp_affinity_list
93
[root@LAPTOP-BJ-0216 ~]#
[root@LAPTOP-BJ-0216 ~]#
################################################
注意:
解释说明:设备 Swiftn1 的CPU 中断核是 281, 中断又被分配给 67
3. 确定可绑定CPU 核
3.1 查询cpu 信息
# 查询 CPU 信息
# lscpu -e
[root@LAPTOP-BJ-0216 ~]#
[root@LAPTOP-BJ-0216 ~]# lscpu -e
CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE MAXMHZ MINMHZ
0 0 0 0 0:0:0:0 yes 3400.0000 800.0000
1 0 0 1 1:1:1:0 yes 3400.0000 800.0000
2 0 0 2 2:2:2:0 yes 3400.0000 800.0000
3 0 0 3 3:3:3:0 yes 3400.0000 800.0000
......
......
......
......
63 0 0 11 11:11:11:0 yes 3400.0000 800.0000
64 0 0 12 12:12:12:0 yes 3400.0000 800.0000
65 0 0 13 13:13:13:0 yes 3400.0000 800.0000 # cpu 核 66 的L3
66 0 0 14 14:14:14:0 yes 3400.0000 800.0000
67 0 0 15 15:15:15:0 yes 3400.0000 800.0000
68 0 0 16 16:16:16:0 yes 3400.0000 800.0000
69 0 0 17 17:17:17:0 yes 3400.0000 800.0000
70 0 0 18 18:18:18:0 yes 3400.0000 800.0000
......
......
81 1 1 29 29:29:29:1 yes 3400.0000 800.0000
82 1 1 30 30:30:30:1 yes 3400.0000 800.0000
83 1 1 31 31:31:31:1 yes 3400.0000 800.0000
84 1 1 32 32:32:32:1 yes 3400.0000 800.0000
85 1 1 33 33:33:33:1 yes 3400.0000 800.0000
86 1 1 34 34:34:34:1 yes 3400.0000 800.0000
87 1 1 35 35:35:35:1 yes 3400.0000 800.0000
88 1 1 36 36:36:36:1 yes 3400.0000 800.0000
[root@LAPTOP-BJ-0216 ~]#
####################
注意:
背景:设备 Swiftn1 的CPU 中断核是 281, 终端又被分配给 67
目标: 为 设备 Swiftn1 绑定CPU 中断核之外的隔离核。
可绑定隔离核目标是: L1d:L1i:L2:L3 中L3 相同的 CPU 核
比如:63 ~70 都可以(只要不是其他cpu 中断核即可)
CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE MAXMHZ MINMHZ
63 0 0 11 11:11:11:0 yes 3400.0000 800.0000
64 0 0 12 12:12:12:0 yes 3400.0000 800.0000
65 0 0 13 13:13:13:0 yes 3400.0000 800.0000
66 0 0 14 14:14:14:0 yes 3400.0000 800.0000
67 0 0 15 15:15:15:0 yes 3400.0000 800.0000
68 0 0 16 16:16:16:0 yes 3400.0000 800.0000
69 0 0 17 17:17:17:0 yes 3400.0000 800.0000
70 0 0 18 18:18:18:0 yes 3400.0000 800.0000
3.2 绑核
1. 打开配置文件
# vi /etc/default/grub
2. 绑核:将 以下命令:
"isolcpus=<隔离核CPU-1,隔离核CPU-2> nohz_full=<隔离核CPU-1,隔离核CPU-2> rcu_nocbs=<隔离核CPU-1,隔离核CPU-2> iommu=pt processor.max_cstate=0 idle=poll"
添加到 GRUB_CMDLINE_LINUX 配置型末端即可。
# 此时欲将 CPU:65,66 设置为隔离核
# isolcpus=65,66 nohz_full=65,66 rcu_nocbs=65,66 iommu=pt processor.max_cstate=0 idle=poll
[root@LAPTOP-BJ-0216 ~]# vi /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
#GRUB_CMDLINE_LINUX="crashkernel=auto resume=/dev/mapper/cs-swap rd.lvm.lv=cs/root rd.lvm.lv=cs/swap rhgb quiet"
GRUB_CMDLINE_LINUX="crashkernel=auto resume=/dev/mapper/cs-swap rd.lvm.lv=cs/root rd.lvm.lv=cs/swap rhgb quiet isolcpus=65,66 nohz_full=65,66 rcu_nocbs=65,66 iommu=pt processor.max_cstate=0 idle=poll"
GRUB_DISABLE_RECOVERY="true"
GRUB_ENABLE_BLSCFG=true
[root@LAPTOP-BJ-0216 ~]#
3.3 更新group
# CentOs 系统
# grub2-mkconfig –o /boot/efi/EFI/centos/grub.cfg
# kylin (鲲鹏)
#grub2-mkconfig –o /boot/efi/EFI/kylin/grub.cfg
注意:执行完生成命令后,最好重启系统以查看新的引导项是否正常工作
3.4 重启后查看
查看 comline
# cat /proc/cmdline
[root@LAPTOP-BJ-0216 ~]#
[root@LAPTOP-BJ-0216 ~]# cat /proc/cmdline
BOOT_IMAGE=(hd0,gpt2)/vmlinuz-4.18.0-536.el8.x86_64 root=/dev/mapper/cs-root ro crashkernel=auto resume=/dev/mapper/cs-swap rd.lvm.lv=cs/root rd.lvm.lv=cs/swap rhgb quiet isolcpus=65,66 nohz_full=65,66 rcu_nocbs=65,66 iommu=pt processor.max_cstate=0 idle=poll
[root@LAPTOP-BJ-0216 ~]#
# 隔离核 65,66 已设置为隔离核
4. 绑核执行程序
# 绑核执行程序命令:
taskset -c <绑定CPU 核Number> *****
# taskset -c 65 python3 a.py
到此已完成CPU 绑核操作。