简体   繁体   English

微基准测试 C++ Linux

[英]Micro benchmarking C++ Linux

I am benchmarking a function of my c++ program using inline rdtsc(1st and last instruction in the function) My setup has isolated cores and hyper threading is off and the frequency is 3.5Mhz.我正在使用内联 rdtsc(函数中的第一条和最后一条指令)对我的 C++ 程序的一个函数进行基准测试我的设置有独立的内核,超线程关闭,频率为 3.5Mhz。

I cannot afford more than 1000 cpu cycles so i count the percentage of calls taking more than 1000 cpu cycles and that is approximately 2-3%.我负担不起超过 1000 个 CPU 周期,所以我计算了调用超过 1000 个 CPU 周期的百分比,大约是 2-3%。 The structure being accessed in the code is huge and can certainly result in cache miss.代码中访问的结构非常庞大,肯定会导致缓存未命中。 But a cache miss is 300-400 cpu cycles.但是高速缓存未命中是 300-400 个 cpu 周期。

Is there a problem with rdtsc benchmarking? rdtsc 基准测试有问题吗? If not, what else can cause a 2-3% of my cases going through the same set of instructions abruptly high number of cycles如果不是,还有什么会导致我的 2-3% 的案例突然通过同一组指令执行大量循环

I want help to understand what i should look for to understand this 2-3% of my WC(worst cases)我需要帮助来理解我应该寻找什么来理解这 2-3% 的 WC(最坏情况)

Often rare "performance noise" like you describe is caused by context switches in the timed region, where your process happened to exceed its scheduler quanta during your interval and some other process was scheduled to run on the core.通常像您描述的那样罕见的“性能噪声”是由定时区域中的上下文切换引起的,在该区域中,您的进程在您的时间间隔内恰好超过其调度程序量子,而其他一些进程被安排在核心上运行。 Another possibility is a core migration by the kernel.另一种可能性是内核进行核心迁移。

When you say "My setup has isolated cores", are you actually pinning your process to specific cores using a tool (eg hwloc )?当您说“我的设置有独立的核心”时,您实际上是在使用工具(例如hwloc )将您的进程固定到特定的核心吗? This can greatly help to get reproducible results.这可以极大地帮助获得可重现的结果。 Have you checked for other daemon processes that might also be eligible to run on your core?您是否检查过其他可能也有资格在您的核心上运行的守护进程?

Have you tried measuring your code using a sampling profiler like gprof or HPCToolkit ?您是否尝试过使用像gprofHPCToolkit这样的采样分析器来测量您的代码? These tools provide alot more context and behavioral information that can be difficult to discover from manual instrumentation.这些工具提供了更多的上下文和行为信息,这些信息很难从手动检测中发现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM