Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add some initial Mac OS X support

  • Loading branch information...
commit 0dbaeda8a0438a4e7e473f736aa8590a3b10bda2 1 parent 98d3e2e
Greg Smith authored
Showing with 38 additions and 1 deletion.
  1. +38 −1 stream-scaling
View
39 stream-scaling
@@ -34,6 +34,9 @@ if [ -n "$1" ] ; then
MAX_CORES="$1"
elif [ -f "/proc/cpuinfo" ] ; then
MAX_CORES=`grep -c processor /proc/cpuinfo`
+elif [ -x "/usr/sbin/sysctl" ] ; then
+ # This should work on Mac OS X
+ MAX_CORES=`sysctl -n hw.ncpu`
fi
if [ -z "$MAX_CORES" ] ; then
@@ -130,6 +133,23 @@ function simple_cache_size {
eval $__resultvar="'$TOTAL_CACHE'"
}
+# Guess the cache size based on sysctl info, which will work on some
+# Apple Mac hardware. Returns it into the variable name passed.
+# Currently this just looks at L3 cache size and assumes that is
+# close enough, given the margin factor build into the rest of the
+# program. It really should consider the other caches too.
+function total_mac_cache_size {
+ local __resultvar=$1
+ TOTAL_CACHE=`sysctl -n hw.l3cachesize`
+
+ if [ -z "$TOTAL_CACHE" ] ; then
+ echo Error: can\'t interpret CPU cache information from sysctl
+ return
+ fi
+
+ eval $__resultvar="'$TOTAL_CACHE'"
+}
+
#
# stream_array_elements determines how large the array stream
# runs against needs to be to avoid caching effects.
@@ -146,6 +166,10 @@ function stream_array_elements {
total_cache_size TOTAL_CACHE
+ if [ "$TOTAL_CACHE" -eq 0 ] ; then
+ total_mac_cache_size TOTAL_CACHE
+ fi
+
if [ -z "$TOTAL_CACHE" ] ; then
echo Unable to guess cache size on this system. Using default.
NEEDED_SIZE = 2000000
@@ -249,7 +273,20 @@ fi
echo
echo === CPU Core Summary ===
-cat /proc/cpuinfo | egrep "processor|model name|cpu MHz|siblings" | tail -n 4
+
+if [ -f /proc/cpuinfo ] ; then
+ # Linux
+ cat /proc/cpuinfo | egrep "processor|model name|cpu MHz|siblings" | tail -n 4
+elif [ -x /usr/sbin/sysctl ] ; then
+ # Mac OS X (maybe)
+ sysctl machdep.cpu.brand_string
+ sysctl hw.cpufrequency
+ sysctl hw.physicalcpu
+ sysctl hw.logicalcpu
+ sysctl -A hw 2>&1 | grep cache
+else
+ echo Cannot figure out the CPU info on this system
+fi
#
# Download and compile stream
Please sign in to comment.
Something went wrong with that request. Please try again.