编程方式获得高速缓存行大小? [英] Programmatically get the cache line size?

查看:332
本文介绍了编程方式获得高速缓存行大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有平台欢迎,请注明你的答案的平台。

All platforms welcome, please specify the platform for your answer.

有一个类似的问题:如何以编程方式获取CPU高速缓存页面大小在C ++

推荐答案

在Linux操作系统(有一个合理的最近的内核),你可以得到这个信息输出/ SYS的:

On Linux (with a reasonably recent kernel), you can get this information out of /sys:

/sys/devices/system/cpu/cpu0/cache/

该目录对缓存中的每一级子目录。每个这些目录包含以下文件:

This directory has a subdirectory for each level of cache. Each of those directories contains the following files:

coherency_line_size
level
number_of_sets
physical_line_partition
shared_cpu_list
shared_cpu_map
size
type
ways_of_associativity

此为您介绍有关缓存,那么你会永远希望知道,包括超高速缓存行大小以及什么CPU共享这个缓存的详细信息。这是非常有用的,如果你是做多线程编程共享数据(你会得到更好的结果,如果线程共享数据也共享一个缓存)。

This gives you more information about the cache then you'd ever hope to know, including the cacheline size as well as what CPUs share this cache. This is very useful if you are doing multithreaded programming with shared data (you'll get better results if the threads sharing data are also sharing a cache).

这篇关于编程方式获得高速缓存行大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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