首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >理解perf报告

理解perf报告
EN

Stack Overflow用户
提问于 2018-08-29 00:39:05
回答 1查看 2.2K关注 0票数 4

我一直在做一些时间敏感的项目。由于时间上的一些不理想的尖峰,我不得不走得更深一点。

场景

我有一个内核模块,它被固定在一个CPU核心上。这个CPU核心也在内核引导参数中的isolcpus中列出。下面是我在cmdline中对内核引导参数所做的工作

代码语言:javascript
复制
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)

代码语言:javascript
复制
sudo ./perf record -e context-switches -a -g --cpu=8 taskset -c 9 ./test.sh

**编辑1-补充资料**

内核版本: 4.15.12

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

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

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

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

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

这是输入perf report后的输出

代码语言:javascript
复制
# 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分析结果

代码语言:javascript
复制
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脚本的输出

代码语言:javascript
复制
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显示

代码语言:javascript
复制
# 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

谢谢,

库沙尔。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-29 12:12:26

祖兰非常亲密,他的所有建议都应该贯彻到底。

来自perf report的手册页

命令列在perf report输出中引用了从其中收集样本的过程。在每线程/每个进程模式中,这始终是受监视命令的名称。但是在cpu范围内,命令可能会有所不同.

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

每cpu上下文切换记录pid/tid

现在,值-1指的是一个已死的过程,也就是说,这个过程已经超越了僵尸进程的状态。这意味着task_struct成员现在指向已经释放的内存,不应该取消引用应该是allowed.The,do_task_dead方法应该清楚地反映这一点。是进程pid作为-1返回的地方,并同时在perf report中报告。

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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52067936

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档