gpt4 book ai didi

linux-kernel - 了解性能报告

转载 作者:行者123 更新时间:2023-12-03 23:54:09 25 4
gpt4 key购买 nike

我一直在做一些时间敏感的项目。由于时间安排中出现了一些不希望的尖峰,我不得不走得更深一些。

场景 :

我有一个内核模块,它固定在 CPU 内核上。这个 CPU 内核也在内核启动参数中的 isolcpus 中列出。这是我在 cmdline 中对内核启动参数所做的

intel_iommu=on iommu=pt default_hugepagesz=1G hugepagesz=1G hugepages=1 intel_idle.max_cstate=0 processor.max_cstate=0 nohz_full=7-11 isolcpus=7-11 mce=off rcu_nocbs=7-11 nosoftlockup idle=poll cpuidle.off=1 powersave=off nonmi_ipi nowatchdog

我运行了以下命令(此时我正在尝试仅分析 CPU 8)
sudo ./perf record -e context-switches -a -g --cpu=8 taskset -c 9 ./test.sh

**编辑 1 - 附加信息 **

内核版本:4.15.12

我的内核模块每 X 个时间单位发送同步数据包。目前,我已将其配置为每 50 毫秒发送一次。

在这种情况下,我简化了 test.sh。它需要几个参数,但是,关于这个脚本的重要一点是它调用了内核模块。

例如,
我的 KM 有一个 proc fs。
当此 proc fs 上触发写入事件时,它会创建一个新的 Kthread,将其绑定(bind)到 CPU (8),并开始每 50 毫秒生成一次数据包。

为了避免冲突和上下文切换,我把这个东西移到了内核空间。此外,我已将脚本的亲和性设置为与内核模块不同的 CPU。

因此,我观察到的是,发送时间有一点抖动,可能是因为这些上下文切换。

这是我输入 perf report 后的输出
# To display the perf.data header info, please use --header/--header-only options.
#
#
# Total Lost Samples: 0
#
# Samples: 8 of event 'context-switches'
# Event count (approx.): 39
#
# Children Self Command Shared Object Symbol
# ........ ........ ........... ................ .................
#
69.23% 69.23% :-1 [kernel.vmlinux] [k] do_task_dead
|
---do_task_dead

25.64% 25.64% swapper [kernel.vmlinux] [k] schedule_idle
|
---schedule_idle

2.56% 2.56% :2100 [kernel.vmlinux] [k] _cond_resched
|
---_cond_resched

2.56% 2.56% kworker/8:1 [kernel.vmlinux] [k] schedule
|
---schedule

它说有 8 个上下文切换。另外,我不明白 :-1 在第一个 Command 行的 do_task_dead() 列中的实际含义。如果有人能为我提供一些深入研究这个问题的方向,那就太好了。

编辑 2 - perf 脚本报告和 cpu_idle 分析结果
swapper     0 [008] 64409.434193:          1 context-switches:
aceea8 schedule_idle (/lib/modules/4.15.12/build/vmlinux)

:-1 -1 [008] 64410.434267: 1 context-switches:
2ac066 do_task_dead (/lib/modules/4.15.12/build/vmlinux)

swapper 0 [008] 64410.442240: 1 context-switches:
aceea8 schedule_idle (/lib/modules/4.15.12/build/vmlinux)

:29026 29026 [008] 64411.442313: 1 context-switches:
acee0d _cond_resched (/lib/modules/4.15.12/build/vmlinux)

kworker/8:1 181 [008] 64411.442318: 1 context-switches:
acebf2 schedule (/lib/modules/4.15.12/build/vmlinux)

:-1 -1 [008] 64411.442327: 1 context-switches:
2ac066 do_task_dead (/lib/modules/4.15.12/build/vmlinux)

swapper 0 [008] 64411.466238: 8 context-switches:
aceea8 schedule_idle (/lib/modules/4.15.12/build/vmlinux)

swapper 0 [008] 64414.538207: 31 context-switches:
aceea8 schedule_idle (/lib/modules/4.15.12/build/vmlinux)

使用 power:cpu_idle 事件运行,这是 perf 脚本的输出
swapper     0 [008] 65787.514565: power:cpu_idle: state=4294967295 cpu_id=8
ad3a2f cpu_idle_poll (/lib/modules/4.15.12/build/vmlinux)

swapper 0 [008] 65788.514653: power:cpu_idle: state=0 cpu_id=8
ad39d0 cpu_idle_poll (/lib/modules/4.15.12/build/vmlinux)

swapper 0 [008] 65788.522618: power:cpu_idle: state=4294967295 cpu_id=8
ad3a2f cpu_idle_poll (/lib/modules/4.15.12/build/vmlinux)

swapper 0 [008] 65789.522693: power:cpu_idle: state=0 cpu_id=8
ad39d0 cpu_idle_poll (/lib/modules/4.15.12/build/vmlinux)

swapper 0 [008] 65789.546577: power:cpu_idle: state=4294967295 cpu_id=8
ad3a2f cpu_idle_poll (/lib/modules/4.15.12/build/vmlinux)

swapper 0 [008] 65790.546648: power:cpu_idle: state=0 cpu_id=8
ad39d0 cpu_idle_poll (/lib/modules/4.15.12/build/vmlinux)

swapper 0 [008] 65790.570574: power:cpu_idle: state=4294967295 cpu_id=8
ad3a2f cpu_idle_poll (/lib/modules/4.15.12/build/vmlinux)
....

perf report 显示
# Samples: 22  of event 'power:cpu_idle'
# Event count (approx.): 22
#
# Children Self Trace output
# ........ ........ .........................
#
50.00% 50.00% state=0 cpu_id=8
|
---cpu_idle_poll

50.00% 50.00% state=4294967295 cpu_id=8
|
---cpu_idle_poll

谢谢你,

库沙尔。

最佳答案

祖蓝很亲近,他的所有建议都应该被采纳。

来自 perf report 的手册页:

命令 perf report 中的列输出是指收集样本的过程。在每线程/每进程模式下,这始终是被监视命令的名称。但在 cpu-wide 模式下,命令可能会有所不同。

因为您正在测量 per-cpu从您的 perf record ... -cpu=8... 中可以看到上下文切换事件命令,perf report 命令将开始报告下一个/上一个任务的 PID/TID。你可以在这里看到 -

per-cpu context switch records pid/tid

现在值 -1 指的是一个已死的进程,即该进程已经超出了作为僵尸进程的状态。这意味着 task_struct成员现在指向已释放的内存,不应允许取消引用。do_task_dead方法应该清楚地反射(reflect)这一点。
This是进程的 pid 作为 -1 返回并同时在 perf report 中报告的位置.

有一个广泛的discussion关于这个问题。最初的值 0 用于在 perf report 中引用此类进程状态。输出,但您可能已经猜到了,pid=0 指的是 空闲线程 因此使用 -1 的值。

关于linux-kernel - 了解性能报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52067936/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com