summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2010-11-05 20:23:31 +0000
committerPaul Buetow <paul@buetow.org>2010-11-05 20:23:31 +0000
commit9be1b7ea764a138705c73645f7159afef82448fd (patch)
tree7aad0ad909ebbc54c95577c651be01f8f39a13c6
initial cpuinfo in utils
-rwxr-xr-xcpuinfo66
-rw-r--r--examples/laptop.txt15
-rw-r--r--examples/server.txt15
-rw-r--r--examples/server2.txt13
4 files changed, 109 insertions, 0 deletions
diff --git a/cpuinfo b/cpuinfo
new file mode 100755
index 0000000..64e616f
--- /dev/null
+++ b/cpuinfo
@@ -0,0 +1,66 @@
+#!/bin/sh
+
+# (c) Paul Buetow
+
+gawk -F: '
+ function say ( str ) {
+ gsub(/ +/, " ", str)
+ printf "%s\n", str
+ }
+
+ # Newer versions of GAWK can use the built in length function instead
+ function alength ( arr ) {
+ len = 0
+ for (var in arr)
+ len++
+ return len
+ }
+
+ function alength_min_1 ( arr ) {
+ len = alength(arr)
+ return len ? len : 1
+ }
+
+ BEGIN {
+ say( "cpuinfo (c) 2010 Paul Buetow" )
+ say()
+ }
+
+ $1 ~ /^core id/ { core_id[$2]++ }
+ $1 ~ /^physical id/ { physical_id[$2]++ }
+ $1 ~ /^processor/ { count["processor"]++ }
+
+ {
+ key = $1
+ gsub(/[ \t]+/, "", key)
+ info[key] = $2
+ }
+
+ END {
+ ht = info["siblings"] != alength(core_id)
+ physical_cpus = alength(physical_id) ? alength(physical_id) : 1
+
+
+ say( info["modelname"] " " info["vendor_id"] " " info["cachesize"] " cache")
+ say()
+
+ say( sprintf("%s = %.3d %s", "p", physical_cpus, "Physical processors") )
+ say( sprintf("%s = %.3d %s", "c", alength(core_id), "Cores @ each physical processor" ) )
+ say( sprintf("%s = %.3d %s", "s", info["siblings"], "Siblings (Hyper-Threading enabled if s != c)") )
+ say( sprintf("%s = %.3d [v = p*c*(s != c ? 2 : 1)] %s", "v", count["processor"], "Total processors (including virtual)") )
+ say( " Hyper-Threading is " ( ht ? "enabled" : "disabled" ) )
+ say()
+
+ if ( alength(core_id) )
+ say( sprintf("%.7d %s", info["cpuMHz"], "MHz each core") )
+
+ say( sprintf("%.7d %s", info["cpuMHz"] * alength_min_1(core_id) * physical_cpus, "MHz total") )
+
+ if ( count["processor"] > 1 )
+ say( sprintf("%.7d %s", info["bogomips"], "Bogomips each processor (including virtual)") )
+
+ say( sprintf("%.7d %s", info["bogomips"] * alength_min_1(core_id) * physical_cpus, "Bogomips total") )
+ say()
+ }
+
+' /proc/cpuinfo
diff --git a/examples/laptop.txt b/examples/laptop.txt
new file mode 100644
index 0000000..43eee6a
--- /dev/null
+++ b/examples/laptop.txt
@@ -0,0 +1,15 @@
+cpuinfo (c) 2010 Paul Buetow
+
+ Intel(R) Core(TM)2 Duo CPU P8400 @ 2.26GHz GenuineIntel 3072 KB cache
+
+p = 001 Physical processors
+c = 002 Cores @ each physical processor
+s = 002 Siblings (Hyper-Threading enabled if s != c)
+v = 002 [v = p*c*(s != c ? 2 : 1)] Total processors (including virtual)
+ Hyper-Threading is disabled
+
+0001600 MHz each core
+0003200 MHz total
+0004522 Bogomips each processor (including virtual)
+0009044 Bogomips total
+
diff --git a/examples/server.txt b/examples/server.txt
new file mode 100644
index 0000000..191a696
--- /dev/null
+++ b/examples/server.txt
@@ -0,0 +1,15 @@
+cpuinfo (c) 2010 Paul Buetow
+
+ Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz GenuineIntel 8192 KB cache
+
+p = 001 Physical processors
+c = 004 Cores @ each physical processor
+s = 001 Siblings (Hyper-Threading enabled if s != c)
+v = 008 [v = p*c*(s != c ? 2 : 1)] Total processors (including virtual)
+ Hyper-Threading is enabled
+
+0002673 MHz each core
+0010693 MHz total
+0005348 Bogomips each processor (including virtual)
+0042787 Bogomips total
+
diff --git a/examples/server2.txt b/examples/server2.txt
new file mode 100644
index 0000000..1a15025
--- /dev/null
+++ b/examples/server2.txt
@@ -0,0 +1,13 @@
+ Intel(R) Xeon(R) CPU E5530 @ 2.40GHz GenuineIntel 8192 KB cache
+
+p = 002 Physical processors
+c = 004 Cores @ each physical processor
+s = 008 Siblings (Hyper-Threading enabled if s != c)
+v = 016 [v = p*c*(s != c ? 2 : 1)] Total processors (including virtual)
+ Hyper-Threading is enabled
+
+0002400 MHz each core
+0019200 MHz total
+0004799 Bogomips each processor (including virtual)
+0076789 Bogomips total
+