本文介绍了以编程方式计算缓存故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在一系列有关内存层次结构效率的假设中评估C ++函数所花费的时间(例如:读取数组的一部分时发生高速缓存未命中,高速缓存命中或页面错误所花费的时间),因此,我想拥有一些可以让我计算缓存未命中/页面错误的库,以便能够自动生成性能摘要.

我知道有一些诸如cachegrind之类的工具可以提供有关给定应用程序执行情况的一些相关统计信息,但是正如我已经说过的,我想要一个库.

编辑哦,我忘记了:我正在使用Linux,并且对可移植性不感兴趣,这是一门学术性的事情.

欢迎任何建议!

解决方案

看起来现在正是我要搜索的内容: perf_event_open .

它使您能够执行一些有趣的事情,例如初始化/启用/禁用某些性能计数器,以便随后通过统一而直观的API来获取其值(它为您提供了一个特殊的文件描述符,其中包含了包含先前请求的信息的结构).

这是仅适用于Linux的解决方案,其功能因内核版本而异,因此请小心:)

I need to evaluate the time taken by a C++ function in a bunch of hypothesis about memory hierarchy efficiency (e.g: time taken when we have a cache miss, a cache hit or page fault when reading a portion of an array), so I'd like to have some libraries that let me count the cache miss / page faults in order to be capable of auto-generating a performance summary.

I know there are some tools like cachegrind that gives some related statistics on a given application execution, but I'd like a library, as I've already said.

edit Oh, I forgot: I'm using Linux and I'm not interested in portability, it's an academic thing.

Any suggestion is welcome!

解决方案

It looks like now there is exactly what I was searching for: perf_event_open.

It lets you do interesting things like initializing/enabling/disabling some performance counters for subsequently fetching their values through an uniform and intuitive API (it gives you a special file descriptor which hosts a struct containing the previously requested informations).

It is a linux-only solution and the functionalities varies depending on the kernel version, so be careful :)

这篇关于以编程方式计算缓存故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 21:44