linux查看CPU快取(cache)資訊

來源:互聯網
上載者:User

標籤:style   blog   http   color   strong   檔案   

一、Linux下查看CPU Cache級數,每級大小

dmesg | grep cache

執行個體結果如下:

 

二、查看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 資訊,在編寫高效程式時將所有協助。

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.