gpt4 book ai didi

c - 用于多线程环境的 PMU

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

我计划测量 L1、L2、L3 未命中分支预测未命中的 PMU 计数器,我已阅读相关的英特尔文档,但我不确定以下情况。有人可以澄清一下吗?

//assume PMU reset and PERFEVTSELx configurtion done above 
ioctl(fd, IOCTL_MSR_CMDS, (long long)msr_start) //PMU start counters
my_program();
ioctl(fd, IOCTL_MSR_CMDS, (long long)msr_stop) ///PMU stop
//now reading PMU counters

1.如果我的进程在 my_program() 运行时被调度到另一个核心,会发生什么情况?

2.如果进程调度出去并再次调度回同一个核心,同时一些其他进程重置 PMU 计数器,会发生什么?

如何确保我们从 PMU 计数器读取正确的值。?

Machine details:CentOS with Linux kernel 3.10.0-327.22.2.el7.x86_64 , which is powered up with Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz

谢谢

最佳答案

摘要the Intel forum thread由 OP 启动:

  • Linux perf 子系统虚拟化了性能计数器,但这意味着您必须通过系统调用而不是 rdpmc 来读取它们,以获得完整的虚拟化的 64 位值,而不是架构性能计数器寄存器中当前的任何值。

  • 如果您想在自己的代码中使用 rdpmc 以便它可以 self 测量,请将每个线程固定到一个核心,因为上下文切换不会保存/恢复 PMC。没有简单的方法可以避免测量核心上发生的一切,包括中断处理程序和其他获得时间片的进程。这可能是一件好事,因为您需要考虑内核开销的影响。


更多有用的引用来自 John D. McCalpin 博士(“带宽博士”):

For inline code instrumentation you should be able to use the "perf events" API, but the documentation is minimal. Some resources are available at http://web.eece.maine.edu/~vweaver/projects/perf_events/faq.html

You can use "pread()" on the /dev/cpu/*/msr device files to read theMSRs -- this may be a bit easier to read than IOCTL-based code. Thecodes "rdmsr.c" and "wrmsr.c" from "msr-tools-1.3" provide excellentexamples.

There have been a number of approaches to reserving and sharingperformance counters, including both software-only and combinedhardware+software approaches, but at this point there is not a"standard" approach. (It looks like Intel has a hardware-basedapproach using MSR 0x392 IA32_PERF_GLOBAL_INUSE, but I don't know whatplatforms support it.)


您的问题

what will happen if my process is scheduled out when my_program() is running, and scheduled to another core?

您会看到随机垃圾,如果另一个进程在您进程的时间片之间重置 PMC,情况也是如此。

关于c - 用于多线程环境的 PMU,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38848914/

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