Skip to content

Instantly share code, notes, and snippets.

@jesstess
Created January 27, 2011 01:18
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jesstess/797876 to your computer and use it in GitHub Desktop.
Save jesstess/797876 to your computer and use it in GitHub Desktop.
CPU cache level, type, size, cache line size, associativity.
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