summaryrefslogtreecommitdiffstats
path: root/pts-core/functions/pts-functions_system_cpu.php
diff options
context:
space:
mode:
authorMichael Larabel <michael@phx-laptop.(none)>2008-04-26 15:01:49 -0400
committerMichael Larabel <michael@phx-laptop.(none)>2008-04-26 15:01:49 -0400
commita5b489b596dfc2e517a54539635df3e0128d5118 (patch)
treee8ea0c6d04725c877dfdd43e1c5a883baa32e8bd /pts-core/functions/pts-functions_system_cpu.php
parent8d82e4af67a02fa3f18d5ca027b1d3812c501ec7 (diff)
downloadphoronix-test-suite-upstream-a5b489b596dfc2e517a54539635df3e0128d5118.tar.gz
phoronix-test-suite-upstream-a5b489b596dfc2e517a54539635df3e0128d5118.tar.xz
phoronix-test-suite-upstream-a5b489b596dfc2e517a54539635df3e0128d5118.zip
Split out CPU and graphics parts of pts-functions_system into
pts-functions_system_cpu and pts-functions_system_graphics, respectively.
Diffstat (limited to 'pts-core/functions/pts-functions_system_cpu.php')
-rw-r--r--pts-core/functions/pts-functions_system_cpu.php125
1 files changed, 125 insertions, 0 deletions
diff --git a/pts-core/functions/pts-functions_system_cpu.php b/pts-core/functions/pts-functions_system_cpu.php
new file mode 100644
index 0000000..efb1b47
--- /dev/null
+++ b/pts-core/functions/pts-functions_system_cpu.php
@@ -0,0 +1,125 @@
+<?php
+
+function read_cpuinfo_values($attribute)
+{
+ $cpuinfo_matches = array();
+
+ if(is_file("/proc/cpuinfo"))
+ {
+ $cpuinfo_lines = explode("\n", file_get_contents("/proc/cpuinfo"));
+
+ foreach($cpuinfo_lines as $line)
+ {
+ $line = explode(": ", $line);
+ $this_attribute = trim($line[0]);
+ $this_value = trim($line[1]);
+
+ if($this_attribute == $attribute)
+ array_push($cpuinfo_matches, $this_value);
+ }
+ }
+
+ return $cpuinfo_matches;
+}
+function cpu_core_count()
+{
+ $processors = read_cpuinfo_values("processor");
+ $info = count($processors); // or could do array_pop($processors) + 1
+
+ return $info;
+}
+function cpu_job_count()
+{
+ return cpu_core_count() + 1;
+}
+function processor_string()
+{
+ $info = "";
+
+ if(is_file("/proc/cpuinfo"))
+ {
+ $physical_cpu_ids = read_cpuinfo_values("physical id");
+ $physical_cpu_count = array_pop($physical_cpu_ids) + 1;
+
+ $cpu_strings = read_cpuinfo_values("model name");
+ $cpu_strings_unique = array_unique($cpu_strings);
+
+ if($physical_cpu_count == 1)
+ {
+ // Just one processor
+ $info = append_processor_frequency(pts_clean_information_string($cpu_strings[0]));
+ }
+ else if($physical_cpu_count > 1 && count($cpu_strings_unique) == 1)
+ {
+ // Multiple processors, same model
+ $info = $physical_cpu_count . " x " . append_processor_frequency(pts_clean_information_string($cpu_strings[0]));
+ }
+ else if($physical_cpu_count > 1 && count($cpu_strings_unique) > 1)
+ {
+ // Multiple processors, different models
+ $current_id = -1;
+ $current_string = $cpu_strings[0];
+ $current_count = 0;
+
+ for($i = 0; $i < count($physical_cpu_ids); $i++)
+ {
+ if($current_string != $cpu_strings[$i] || $i == (count($physical_cpu_ids) - 1))
+ {
+ $info .= $current_count . " x " . append_processor_frequency(pts_clean_information_string($current_string), $i);
+
+ $current_string = $cpu_strings[$i];
+ $current_count = 0;
+ }
+
+ if($physical_cpu_ids[$i] != $current_id)
+ {
+ $current_count++;
+ $current_id = $physical_cpu_ids[$i];
+ }
+ }
+ }
+ }
+
+ if(empty($info))
+ $info = "Unknown";
+
+ return $info;
+}
+function append_processor_frequency($cpu_string, $cpu_core = 0)
+{
+ if(($freq = processor_frequency($cpu_core)) > 0)
+ {
+ if(($strip_point = strpos($cpu_string, '@')) > 0)
+ $cpu_string = trim(substr($cpu_string, 0, $strip_point)); // stripping out the reported freq, since the CPU could be overclocked, etc
+
+ $cpu_string .= " @ " . $freq . "GHz";
+ }
+
+ return $cpu_string;
+}
+function processor_frequency($cpu_core = 0)
+{
+
+ if(is_file("/sys/devices/system/cpu/cpu" . $cpu_core . "/cpufreq/scaling_max_freq")) // The ideal way, with modern CPUs using CnQ or EIST and cpuinfo reporting the current
+ {
+ $info = trim(file_get_contents("/sys/devices/system/cpu/cpu" . $cpu_core . "/cpufreq/scaling_max_freq"));
+ $info = pts_trim_double(intval($info) / 1000000, 2);
+ }
+ else if(is_file("/proc/cpuinfo")) // fall back for those without cpufreq
+ {
+ $cpu_speeds = read_cpuinfo_values("cpu MHz");
+
+ if(count($cpu_speeds) > $cpu_core)
+ $info = $cpu_speeds[$cpu_core];
+ else
+ $info = $cpu_speeds[0];
+
+ $info = pts_trim_double(intval($info) / 1000, 2);
+ }
+ else
+ $info = 0;
+
+ return $info;
+}
+
+?>