Created
January 27, 2011 01:18
-
-
Save jesstess/797876 to your computer and use it in GitHub Desktop.
CPU cache level, type, size, cache line size, associativity.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for path in /sys/devices/system/cpu/cpu*/cache/index*/ | |
do | |
echo $path; | |
echo -n "Level: "; cat $path/level; | |
echo -n "Type: "; cat $path/type; | |
echo -n "Size: "; cat $path/size; | |
echo -n "Cache line size: "; cat $path/coherency_line_size; | |
echo -n "Associativity: "; cat $path/ways_of_associativity; | |
done | |
=== | |
#include <unistd.h> | |
#include <stdio.h> | |
#include <math.h> | |
int main() { | |
long size = sysconf(_SC_LEVEL1_ICACHE_SIZE) / pow(2, 10); | |
long assoc = sysconf(_SC_LEVEL1_ICACHE_ASSOC); | |
long line = sysconf(_SC_LEVEL1_ICACHE_LINESIZE); | |
printf("level 1 icache size = %ldK, assoc = %ld, line size = %ld\n", size, assoc, line); | |
size = sysconf(_SC_LEVEL1_DCACHE_SIZE) / pow(2, 10); | |
assoc = sysconf(_SC_LEVEL1_DCACHE_ASSOC); | |
line = sysconf(_SC_LEVEL1_DCACHE_LINESIZE); | |
printf("level 1 dcache size = %ldK, assoc = %ld, line size = %ld\n", size, assoc, line); | |
size = sysconf(_SC_LEVEL2_CACHE_SIZE) / pow(2, 10); | |
assoc = sysconf(_SC_LEVEL2_CACHE_ASSOC); | |
line = sysconf(_SC_LEVEL2_CACHE_LINESIZE); | |
printf("level 2 cache size = %ldK, assoc = %ld, line size = %ld\n", size, assoc, line); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment