大家好,欢迎来到IT知识分享网。
随笔记录
目录
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: 0 Firmware date: 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: S2NX8 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: 0 Firmware date: 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: 0 Firmware date: 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: S2NX8 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 -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 -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 -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
2.2.3 绑定CPU 中断核
# 绑定CPU 中断核 # service irqbalance stop echo <CPU ID Number>>/proc/irq/165/smp_affinity_list # 绑定CPU 中断核为 5 # 如果不绑定CPU 中断核,很可能出现中断核即为 隔离核 第一步:关闭中断 # service irqbalance stop 第二步:强制指定 CPU 中断核 echo 5 >/proc/irq/165/smp_affinity_list # 绑核前 [root@localhost magx]# cat /proc/interrupts |grep swiftn* 165: 23 0 0 0 0 0 1 0 0 0 0 2 0 0 0 0 PCI-MSI -edge swiftn0 [root@localhost magx]# [root@localhost magx]# cat /proc/irq/165/smp_affinity_list 6 [root@localhost magx]# [root@localhost magx]# # 关闭中断 [root@localhost magx]# [root@localhost magx]# service irqbalance stop Redirecting to /bin/systemctl stop irqbalance.service [root@localhost magx]# [root@localhost magx]# service irqbalance stop Redirecting to /bin/systemctl stop irqbalance.service [root@localhost magx]# # 中断核指定 5 [root@localhost magx]# [root@localhost magx]# echo 5 >/proc/irq/165/smp_affinity_list [root@localhost magx]# [root@localhost magx]# cat /proc/irq/165/smp_affinity_list 5 [root@localhost magx]# 注意: 4.3修改中断亲和CPU 某些情况下,中断亲和的核心会出现在隔离核里。建议在测试性能时,手动绑定中断核 心到非隔离核,避免这种情况出现。配置方法如下: service irgbalance stop∥停止中断亲和自动分配CPU核心(该功能开启的话,系统会自动选择较为空 闲的核心作为中断核心】 echo xxx(CPU号)P/proc/irq/xx(中断号)/smp.affinity list echo xx(CPU号)>proc/irqx(中断号)/smp affinity list
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 # 以CentOS 为例 [root@localhost test]# grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg Generating grub configuration file ... Adding boot menu entry for EFI firmware configuration done [root@localhost test]#
注意:执行完生成命令后,最好重启系统以查看新的引导项是否正常工作
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 绑核操作。
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/119378.html
