linux查看cpu缓存大小,linux查看CPU高速缓存(cache)信息

一、Linux下查看CPU Cache级数,每级大小

dmesg | grep cache

实例结果如下:

20180924224126250366.png

二、查看Cache的关联方式

在/sys/devices/system/cpu/中查看相应的文件夹

如查看cpu0 的一级缓存中的有多少组,

$ cat /sys/devices/system/cpu/cpu0/cache/index0/number_of_sets

$64

如查看cpu0的一级缓存中一组中的行数

$cat /sys/devices/system/cpu/cpu0/cache/index0/ways_of_associativity

$8

三、查看cache_line的大小

上面以本人电脑的cpu一级缓存为例知道了cpu0的一级缓存的大小:32k,其包含64个(sets)组,每组有8(ways),则可以算出每一个way(cache_line)的大小 cache_line = 32*1024/(64*8)=64 bytes。当然我们也可以通过以下命令查出cache_line的大小

$ cat /sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size

或者

$ cat /proc/cpuinfo

processor : 0

vendor_id : GenuineIntel

cpu family : 6

model : 60

model name : Intel(R) Core(TM) i7-4770K CPU @ 3.50GHz

stepping : 3

cpu MHz : 3497.664

cache size : 8192 KB

physical id : 0

siblings : 8

core id : 0

cpu cores : 4

apicid : 0

initial apicid : 0

fpu : yes

fpu_exception : yes

cpuid level : 13

wp : yes

flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology tsc_reliable nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 fma cx16 xtpr pdcm sse4_1 sse4_2 movbe popcnt aes xsave avx lahf_lm abm ida arat tpr_shadow vnmi flexpriority ept vpid

bogomips : 6995.32

clflush size : 64

cache_alignment : 64

address sizes : 39 bits physical, 48 bits virtual

知道了cpu的cache 信息,在编写高效程序时将所有帮助。

原文:http://www.cnblogs.com/kekukele/p/3829369.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值