Created
July 18, 2011 16:09
-
-
Save stedolan/1089968 to your computer and use it in GitHub Desktop.
Prints number of cores, CPU topology and cache topology/size on Linux machines
This file contains 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
#!/bin/bash | |
unshared () { | |
grep '^[0-9]\+$' "$1" > /dev/null | |
} | |
for cpu in $(ls -d /sys/devices/system/cpu/cpu[0-9]* | sort -t u -k 3 -n); do | |
echo "${cpu##*/}: [Package #$(cat $cpu/topology/physical_package_id), Core #$(cat $cpu/topology/core_id)]" | |
if ! unshared $cpu/topology/core_siblings_list; then | |
echo " same package as $(cat $cpu/topology/core_siblings_list)" | |
fi | |
if ! unshared $cpu/topology/thread_siblings_list; then | |
echo " same core as $(cat $cpu/topology/thread_siblings_list)" | |
fi | |
for cache in $cpu/cache/index*; do | |
printf " %-15s " "L$(cat $cache/level) $(cat $cache/type):" | |
echo "$(cat $cache/size) $(cat $cache/ways_of_associativity)-way with $(cat $cache/coherency_line_size) byte lines" | |
if ! unshared $cache/shared_cpu_list; then | |
printf " %-15s [%s]\n" "" "shared with $(cat $cache/shared_cpu_list)" | |
fi | |
done | |
echo | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment