gpt4 book ai didi

linux - 使用 Linux 读取 ARMv8 中的 PMU 计数器

转载 作者:太空宇宙 更新时间:2023-11-04 10:11:19 30 4
gpt4 key购买 nike

我有一个运行 Linux 的 Raspberry Pi 3。 RPi3 具有四核 cortex-A53,带有性能监控单元 (PMU) v3。我执行 cyclictest 程序来做一些实时测试。 Cyclcitest 是一个应用程序,您可以在其中设置周期和迭代次数并计算延迟。因此,它会执行一些操作,然后进入休眠状态直到下一个周期,系统将其唤醒。

我想在每次 cyclictest 执行时读取缓存内存值,以查看它在执行时有多少缓存未命中(我不希望任务处于 sleep 状态时发生未命中)。

我已经尝试使用 perf stat 执行:

perf stat -o result1.txt -r 10 -i -e armv8_pmuv3/l1d_cache/ 
-e armv8_pmuv3/l1d_cache_refill/
-e armv8_pmuv3/l1d_cache_wb/
-e armv8_pmuv3/l1d_tlb_refill/
-e armv8_pmuv3/l1i_cache/
-e armv8_pmuv3/l1i_cache_refill/
-e armv8_pmuv3/l1i_tlb_refill/
-e armv8_pmuv3/l2d_cache/
-e armv8_pmuv3/l2d_cache_refill/
-e armv8_pmuv3/l2d_cache_wb/
-e armv8_pmuv3/mem_access/
cyclictest -l57600 -m -n -t1 -p80 -i50000 -h300 -q --histfile=666_data_50

但是,它确实提供了大约 50% 执行的信息:

Performance counter stats for 'cyclictest -l57600 -m -n -t1 -p80 -i50000 -h300 -q --histfile=666_data_50' (10 runs):

937729229 armv8_pmuv3/l1d_cache/ ( +- 2.41% ) (54.50%)
44736600 armv8_pmuv3/l1d_cache_refill/ ( +- 2.33% ) (54.39%)
44784430 armv8_pmuv3/l1d_cache_wb/ ( +- 2.11% ) (54.33%)
294033 armv8_pmuv3/l1d_tlb_refill/ ( +- 13.82% ) (54.21%)
1924752301 armv8_pmuv3/l1i_cache/ ( +- 2.37% ) (54.41%)
120581610 armv8_pmuv3/l1i_cache_refill/ ( +- 2.41% ) (54.46%)
761651 armv8_pmuv3/l1i_tlb_refill/ ( +- 4.87% ) (54.70%)
215103404 armv8_pmuv3/l2d_cache/ ( +- 2.28% ) (54.69%)
30884575 armv8_pmuv3/l2d_cache_refill/ ( +- 1.44% ) (54.83%)
11424917 armv8_pmuv3/l2d_cache_wb/ ( +- 2.03% ) (54.76%)
943041718 armv8_pmuv3/mem_access/ ( +- 2.41% ) (54.74%)

2904.940283006 seconds time elapsed ( +- 0.07% )

不知道这个计数器是只在运行时统计这个任务的缓存信息,还是在休眠时也统计。有人知道吗?我还有其他应用程序在运行,它们能否按照我在 perf stat 中指定的那样修改这些计数器的值?

如果无法读取任务运行时计数器的准确值?使用模块或自定义用户空间应用程序?

谢谢!!

最佳答案

每个性能监视器硬件都受到 channel 数量的限制:每时每刻可以同时计算多少个事件。例如,许多现代 x86/x86_64 可能为每个 cpu 内核提供 4 个灵活 channel 和 3 个固定 channel 。当您向探查器询问更多事件时,它会进行多路复用(如 VTunePAPI 所做的那样)。当多路复用处于事件状态时,某些事件 e1 被测量为运行时间的 55%,并且 perf stat(但不是 perf record?)will extrapolate counts into full running time (“C. 多路复用”)。这种推断可能有一些错误。

带有 PMU v3 的 cortex-A53 只有六个 channel :http://infocenter.arm.com/help/topic/com.arm.doc.ddi0500d/BIIDADBH.htmlPMEVCNTR0_EL0 - PMEVCNTR5_EL0 和 PMEVTYPER0_EL0 - PMEVTYPER5_EL0。尝试使用不超过 6 个事件的单次运行测试启动 perf stat 以关闭事件多路复用:

perf stat -o result1.txt -r 10 -i \
-e armv8_pmuv3/l1d_cache/ \
-e armv8_pmuv3/l1d_cache_refill/ \
-e armv8_pmuv3/l1d_cache_wb/ \
-e armv8_pmuv3/l1d_tlb_refill/ \
-e armv8_pmuv3/l1i_cache/ \
-e armv8_pmuv3/l1i_cache_refill/ \
cyclictest -l57600 -m -n -t1 -p80 -i50000 -h300 -q --histfile=666_data_50

perf stat -o result2.txt -r 10 -i \
-e armv8_pmuv3/l1i_tlb_refill/ \
-e armv8_pmuv3/l2d_cache/ \
-e armv8_pmuv3/l2d_cache_refill/ \
-e armv8_pmuv3/l2d_cache_wb/ \
-e armv8_pmuv3/mem_access/ \
cyclictest -l57600 -m -n -t1 -p80 -i50000 -h300 -q --histfile=666_data_50

您也可以尝试将事件分组到集合中:-e\{event1,event2...,event6\} ( https://stackoverflow.com/a/48448876 ) 并且集合将与其他集合多路复用。

关于linux - 使用 Linux 读取 ARMv8 中的 PMU 计数器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48926250/

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