Skip to content

Instantly share code, notes, and snippets.

@stedolan
Created July 18, 2011 16:09
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save stedolan/1089968 to your computer and use it in GitHub Desktop.
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
#!/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