编写一个C程序来衡量缓存性能和内存层次结构。 [英] Write a C program that measures your cache performance and memory hierarchy.

查看:94
本文介绍了编写一个C程序来衡量缓存性能和内存层次结构。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们希望得到以下CPU的参数

实验:

•缓存数量

•所有缓存的大小

•所有缓存和主存储器的访问延迟

•缓存行大小



我尝试过:



sizes = [1k,4k,256K,...]

foreach尺寸大小

创建'size`数组



启动计时器

for i = 0到n //只是继续访问数组

arr [(i * 16)%arr.length] ++ // i * 16应该修改每个缓存行...请参阅链接

记录/打印时间

We want to derive the following parameters of our CPU
experimentally:
• The number of caches
• The sizes of all caches
• The access latencies of all caches and main memory
• The cache line size

What I have tried:

sizes = [1k, 4k, 256K, ...]
foreach size in sizes
create array of `size`

start timer
for i = 0 to n // just keep accessing array
arr[(i * 16) % arr.length]++ // i * 16 supposed to modify every cache line ... see link
record/print time

推荐答案

实际上无法通过实验进行测量。这是因为所有这些对应用程序都是透明的,因为它们应该是。如果它们不是那么芯片设计不正确。



有几个应用程序会为你显示这些信息,比如CPU-Z,但它们确实如此不通过实验确定信息。他们通过查询芯片和BIOS来获取信息。
This is virtually impossible to measure experimentally. That is because all of these things are transparent to an application, as they should be. If they aren't then the chip was not designed properly.

There are a few apps that will display this information for you, like CPU-Z, but they do not determine the info experimentally. They get the info by querying the chip and BIOS.


这篇关于编写一个C程序来衡量缓存性能和内存层次结构。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆