Best Phoronix-test-suite code snippet using phodevi_cpu.get_core_name
phodevi_cpu.php
Source:phodevi_cpu.php
...34 'thread-count' => new phodevi_device_property('cpu_thread_count', phodevi::std_caching),35 'node-count' => new phodevi_device_property('cpu_node_count', phodevi::smart_caching),36 'scaling-governor' => new phodevi_device_property('cpu_scaling_governor', phodevi::std_caching),37 'microcode-version' => new phodevi_device_property('cpu_microcode_version', phodevi::std_caching),38 'core-family-name' => new phodevi_device_property('get_core_name', phodevi::smart_caching),39 'cache-size' => new phodevi_device_property('cpu_cache_size', phodevi::smart_caching),40 'cache-size-string' => new phodevi_device_property('cpu_cache_size_string', phodevi::smart_caching),41 'smt' => new phodevi_device_property('cpu_smt', phodevi::std_caching),42 'cpu-family' => new phodevi_device_property('get_cpu_family', phodevi::smart_caching),43 'cpu-model' => new phodevi_device_property('get_cpu_model', phodevi::smart_caching),44 );45 }46 public static function cpu_string()47 {48 $model = phodevi::read_property('cpu', 'model');49 // Append the processor frequency to string50 if(($freq = phodevi::read_property('cpu', 'default-frequency')) > 0)51 {52 $model = str_replace($freq . 'GHz', null, $model); // we'll replace it if it's already in the string53 $model .= ' @ ' . $freq . 'GHz';54 }55 $core_count = phodevi::read_property('cpu', 'physical-core-count');56 $thread_count = phodevi::read_property('cpu', 'thread-count');57 if($core_count > 0 && $thread_count > $core_count)58 {59 $count_msg = pts_strings::plural_handler($core_count, 'Core') . ' / ' . $thread_count . ' Threads';60 }61 else62 {63 $count_msg = pts_strings::plural_handler($core_count, 'Core');64 }65 return $model . ' (' . $count_msg . ')';66 }67 public static function cpu_model_and_speed()68 {69 $model = phodevi::read_property('cpu', 'model');70 // Append the processor frequency to string71 if(($freq = phodevi::read_property('cpu', 'default-frequency')) > 0)72 {73 $model = str_replace($freq . 'GHz', null, $model); // we'll replace it if it's already in the string74 $model .= ' @ ' . $freq . 'GHz';75 }76 return $model;77 }78 public static function cpu_core_count()79 {80 $info = null;81 if(($n = getenv('NUM_CPU_CORES')) && is_numeric($n) && $n > 0)82 {83 // NUM_CPU_CORES can be used for overriding the number of exposed cores/threads to tests, matches the name of the env var set by PTS to test scripts84 $info = $n;85 }86 else if(($n = getenv('PTS_NPROC')) && is_numeric($n) && $n > 0)87 {88 // PTS_NPROC can be used for overriding the number of exposed cores/threads to tests89 $info = $n;90 }91 else if(($n = getenv('NUMBER_OF_PROCESSORS')) && is_numeric($n) && $n > 0)92 {93 // Should be used by Windows they have NUMBER_OF_PROCESSORS set and use this as an easy way to override CPUs exposed94 $info = $n;95 }96 else if(phodevi::is_linux())97 {98 if(is_file('/sys/devices/system/cpu/online') && stripos(phodevi::read_property('system', 'system-layer'), 'lxc') === false)99 {100 $present = pts_file_io::file_get_contents('/sys/devices/system/cpu/online');101 if(isset($present[2]) && substr($present, 0, 2) == '0-')102 {103 $present = substr($present, 2);104 if(is_numeric($present))105 {106 $info = $present + 1;107 }108 }109 }110 }111 else if(phodevi::is_solaris())112 {113 $info = count(explode(PHP_EOL, trim(shell_exec('psrinfo'))));114 }115 else if(phodevi::is_bsd())116 {117 $info = intval(phodevi_bsd_parser::read_sysctl(array('hw.ncpufound', 'hw.ncpu')));118 }119 else if(phodevi::is_macosx())120 {121 $info = intval(phodevi_bsd_parser::read_sysctl(array('hw.ncpu')));122 if(empty($info))123 {124 $info = phodevi_osx_parser::read_osx_system_profiler('SPHardwareDataType', 'TotalNumberOfCores');125 }126 }127 if(phodevi::is_windows())128 {129 // Should be hit by the first NUMBER_OF_PROCESSORS env check...130 $logical_cores = array_sum(phodevi_windows_parser::get_wmi_object('Win32_Processor', 'NumberOfLogicalProcessors', true));131 if($logical_cores > $info || !is_numeric($info))132 {133 $info = $logical_cores;134 }135 }136 if($info == null && isset(phodevi::$vfs->cpuinfo))137 {138 $info = self::cpuinfo_thread_count();139 }140 return (is_numeric($info) && $info > 0 ? $info : 1);141 }142 public static function cpu_physical_core_count()143 {144 $physical_cores = null;145 if(phodevi::is_linux())146 {147 $physical_cores = phodevi_cpu::cpuinfo_core_count();148 if(empty($physical_cores) || $physical_cores == phodevi::read_property('cpu', 'thread-count'))149 {150 // Needed for POWER9 at least151 if(isset(phodevi::$vfs->lscpu) && ($t = strpos(phodevi::$vfs->lscpu, 'Core(s) per socket:')))152 {153 $lscpu = substr(phodevi::$vfs->lscpu, $t + strlen('Core(s) per socket:') + 1);154 $lscpu = substr($lscpu, 0, strpos($lscpu, PHP_EOL));155 $cores_per_socket = trim($lscpu);156 if($cores_per_socket > 1 && ($t = strpos(phodevi::$vfs->lscpu, 'Socket(s):')))157 {158 $lscpu = substr(phodevi::$vfs->lscpu, $t + strlen('Socket(s):') + 1);159 $lscpu = substr($lscpu, 0, strpos($lscpu, PHP_EOL));160 $sockets = trim($lscpu);161 if(is_numeric($sockets) && $sockets >= 1)162 {163 $physical_cores = $cores_per_socket * $sockets;164 }165 }166 }167 }168 }169 else if(phodevi::is_bsd())170 {171 // hw.cpu_topology_core_ids works at least on DragonFly BSD172 $ht_ids = intval(phodevi_bsd_parser::read_sysctl(array('hw.cpu_topology_ht_ids')));173 if($ht_ids == 2)174 {175 $info = intval(phodevi_bsd_parser::read_sysctl(array('hw.ncpu')));176 if($info > 1)177 {178 $physical_cores = $info / 2;179 }180 }181 else182 {183 $phys_ids = intval(phodevi_bsd_parser::read_sysctl(array('hw.cpu_topology_phys_ids')));184 $physical_cores = intval(phodevi_bsd_parser::read_sysctl(array('hw.cpu_topology_core_ids')));185 if($phys_ids > 0 && ($phys_ids * $physical_cores) <= phodevi::read_property('cpu', 'thread-count') && $physical_cores % 2 == 0)186 {187 $physical_cores = $phys_ids * $physical_cores;188 }189 }190 }191 else if(phodevi::is_macosx())192 {193 $physical_cores = intval(phodevi_bsd_parser::read_sysctl(array('hw.physicalcpu')));194 }195 else if(phodevi::is_windows())196 {197 $physical_cores = array_sum(phodevi_windows_parser::get_wmi_object('Win32_Processor', 'NumberOfCores', true));198 }199 if(empty($physical_cores) || !is_numeric($physical_cores))200 {201 $physical_cores = phodevi::read_property('cpu', 'core-count');202 }203 return $physical_cores;204 }205 public static function cpu_thread_count()206 {207 $threads = null;208 if(phodevi::is_linux())209 {210 $threads = phodevi_cpu::cpuinfo_thread_count();211 }212 else213 {214 $threads = phodevi::read_property('cpu', 'core-count');215 }216 return $threads;217 }218 public static function cpu_node_count()219 {220 $node_count = 1;221 if(isset(phodevi::$vfs->lscpu) && ($t = strpos(phodevi::$vfs->lscpu, 'NUMA node(s):')))222 {223 $lscpu = substr(phodevi::$vfs->lscpu, $t + strlen('NUMA node(s):') + 1);224 $lscpu = substr($lscpu, 0, strpos($lscpu, PHP_EOL));225 $node_count = trim($lscpu);226 }227 return (is_numeric($node_count) && $node_count > 0 ? $node_count : 1);228 }229 public static function cpu_cache_size()230 {231 $cache_size = 0; // in KB232 if(phodevi::is_linux())233 {234 if(isset(phodevi::$vfs->lscpu) && ($t = strpos(phodevi::$vfs->lscpu, 'L3 cache:')))235 {236 $lscpu = substr(phodevi::$vfs->lscpu, $t + strlen('L3 cache:') + 1);237 $lscpu = substr($lscpu, 0, strpos($lscpu, PHP_EOL));238 $lscpu = trim($lscpu);239 $cache_size = pts_math::number_with_unit_to_mb($lscpu);240 }241 if(empty($cache_size) || !is_numeric($cache_size))242 {243 $cache_size = self::cpuinfo_cache_size();244 }245 }246 else if(phodevi::is_macosx())247 {248 $cache_size = pts_math::number_with_unit_to_mb(phodevi_osx_parser::read_osx_system_profiler('SPHardwareDataType', 'L3Cache'));249 }250 else if(phodevi::is_windows())251 {252 $cache_size = phodevi_windows_parser::get_wmi_object('Win32_Processor', 'L2CacheSize');253 }254 return $cache_size;255 }256 public static function cpu_default_frequency_mhz()257 {258 return self::cpu_default_frequency() * 1000;259 }260 public static function cpu_scaling_governor()261 {262 $scaling_governor = false;263 if(is_file('/sys/devices/system/cpu/cpu0/cpufreq/scaling_driver'))264 {265 $scaling_governor = pts_file_io::file_get_contents('/sys/devices/system/cpu/cpu0/cpufreq/scaling_driver') . ' ';266 }267 if(is_file('/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor'))268 {269 $scaling_governor .= pts_file_io::file_get_contents('/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor');270 }271 return trim($scaling_governor);272 }273 public static function cpu_smt()274 {275 $smt = false;276 if(pts_client::executable_in_path('ppc64_cpu')) {277 $ppc64 = trim(shell_exec('ppc64_cpu --smt -n | grep SMT= | cut -d= -f2'));278 if(is_numeric($ppc64) && $ppc64 >= 1)279 $smt = $ppc64;280 }281 return trim($smt);282 }283 public static function is_genuine($cpu)284 {285 /*286 Real/Genuine CPUs should have:287 1. Contain more than one word in string288 2. Check vendor (to avoid QEMU, Virtual CPU, etc): Intel, VIA, AMD, ARM, SPARC289 */290 return strpos($cpu, ' ') !== false && strpos($cpu, ' ') != strrpos($cpu, ' ') && pts_strings::has_in_istring($cpu, array('Intel', 'VIA', 'AMD', 'ARM', 'SPARC', 'Transmeta')) && stripos($cpu, 'unknown') === false;291 }292 public static function cpu_microcode_version()293 {294 $ucode_version = null;295 if(is_readable('/sys/devices/system/cpu/cpu0/microcode/version'))296 {297 $ucode_version = pts_file_io::file_get_contents('/sys/devices/system/cpu/cpu0/microcode/version');298 }299 if(empty($ucode_version) && isset(phodevi::$vfs->cpuinfo))300 {301 $ucode_version = self::read_cpuinfo_line('microcode');302 }303 if(empty($ucode_version) && phodevi::is_macosx())304 {305 $ucode_version = phodevi_bsd_parser::read_sysctl(array('machdep.cpu.microcode_version'));306 }307 return $ucode_version;308 }309 public static function cpu_default_frequency($cpu_core = 0)310 {311 // Find out the processor frequency312 $info = null;313 // First, the ideal way, with modern CPUs using CnQ or EIST and cpuinfo reporting the current314 if(phodevi::is_linux())315 {316 if(is_file('/sys/devices/system/cpu/cpu' . $cpu_core . '/cpufreq/scaling_max_freq'))317 {318 $info = pts_file_io::file_get_contents('/sys/devices/system/cpu/cpu' . $cpu_core . '/cpufreq/scaling_max_freq');319 $info = intval($info) / 1000000;320 if($info > 9)321 {322 // For some reason on Linux 3.10 the scaling_max_freq is reported as 25GHz...323 $info = null;324 }325 }326 if($info == null && isset(phodevi::$vfs->cpuinfo) && phodevi::read_property('system', 'kernel-architecture') != 'x86_64') // fall back for those without cpufreq327 {328 // Don't use this code path for x86_64 since for those systems the /sys reporting should work329 // and when that isn't the case, CPUFreq not loaded and thus reported here is usually dynamic frequency330 $cpu_mhz = self::read_cpuinfo_line('cpu MHz');331 $info = $cpu_mhz / 1000;332 if(empty($info))333 {334 $cpu_mhz = str_replace('MHz', '', self::read_cpuinfo_line('clock'));335 if(is_numeric($cpu_mhz))336 {337 $info = $cpu_mhz / 1000;338 }339 }340 }341 }342 else if($info == null && phodevi::is_bsd())343 {344 $info = phodevi_bsd_parser::read_sysctl(array('dev.cpu.0.freq_levels'));345 if($info != null)346 {347 // Popping the top speed off of dev.cpu.0.freq_levels should be the default/highest supported frequency348 $info = pts_arrays::first_element(explode(' ', str_replace('/', ' ', $info)));349 if(!is_numeric($info))350 {351 $info = null;352 }353 }354 if($info == null)355 {356 $info = phodevi_bsd_parser::read_sysctl(array('hw.acpi.cpu.px_global', 'machdep.est.frequency.target', 'hw.cpuspeed'));357 }358 if($info == null)359 {360 // dev.cpu.0.freq seems to be the real/current frequency, affected by power management, etc so only use as last fallback361 $info = phodevi_bsd_parser::read_sysctl(array('dev.cpu.0.freq'));362 }363 if(is_numeric($info))364 {365 $info = $info / 1000;366 }367 else368 {369 $info = null;370 }371 }372 else if($info == null && phodevi::is_windows())373 {374 $info = phodevi_windows_parser::get_wmi_object('win32_processor', 'MaxClockSpeed');375 if($info != null && is_numeric($info))376 {377 $info = $info / 1000;378 }379 else380 {381 $info = null;382 }383 }384 else if($info == null)385 {386 $freq_sensor = new cpu_freq(0, NULL);387 $info = phodevi::read_sensor($freq_sensor);388 unset($freq_sensor);389 if($info > 1000)390 {391 // Convert from MHz to GHz392 $info = $info / 1000;393 }394 }395 return pts_math::set_precision($info, 2);396 }397 public static function cpu_model()398 {399 // Returns the processor name / frequency information400 $info = null;401 if(isset(phodevi::$vfs->cpuinfo))402 {403 $physical_cpu_ids = phodevi_linux_parser::read_cpuinfo('physical id');404 $physical_cpu_count = count(array_unique($physical_cpu_ids));405 $cpu_strings = phodevi_linux_parser::read_cpuinfo(array('model name', 'Processor', 'cpu', 'cpu model'));406 $cpu_strings_unique = array_unique($cpu_strings);407 if($physical_cpu_count == 1 || empty($physical_cpu_count))408 {409 // Just one processor410 if(isset($cpu_strings[0]) && ($cut = strpos($cpu_strings[0], ' (')) !== false)411 {412 $cpu_strings[0] = substr($cpu_strings[0], 0, $cut);413 }414 $info = isset($cpu_strings[0]) ? $cpu_strings[0] : null;415 // Fallback CPU detection416 switch($info)417 {418 case 'AMD Eng Sample: 100-000000163_43/29_Y':419 if(count($physical_cpu_ids) == 128)420 {421 $info = 'AMD Ryzen Threadripper 3990X 64-Core';422 }423 break;424 default:425 $info = str_replace(': ', ' ', $info);426 break;427 }428 if(strpos($info, 'ARM') !== false)429 {430 if(is_dir('/sys/devices/system/exynos-core/') && stripos($info, 'Exynos') === false)431 {432 $info = 'Exynos ' . $info;433 }434 }435 }436 else if($physical_cpu_count > 1 && count($cpu_strings_unique) == 1)437 {438 // Multiple processors, same model439 $info = $physical_cpu_count . ' x ' . $cpu_strings[0];440 }441 else if($physical_cpu_count > 1 && count($cpu_strings_unique) > 1)442 {443 // Multiple processors, different models444 $current_id = -1;445 $current_string = $cpu_strings[0];446 $current_count = 0;447 $cpus = array();448 for($i = 0; $i < count($physical_cpu_ids); $i++)449 {450 if($current_string != $cpu_strings[$i] || $i == (count($physical_cpu_ids) - 1))451 {452 array_push($cpus, $current_count . ' x ' . $current_string);453 $current_string = $cpu_strings[$i];454 $current_count = 0;455 }456 if($physical_cpu_ids[$i] != $current_id)457 {458 $current_count++;459 $current_id = $physical_cpu_ids[$i];460 }461 }462 $info = implode(', ', $cpus);463 }464 }465 else if(phodevi::is_solaris())466 {467 $dmi_cpu = phodevi_solaris_parser::read_sun_ddu_dmi_info('CPUType', '-C');468 if(count($dmi_cpu) == 0)469 {470 $dmi_cpu = phodevi_solaris_parser::read_sun_ddu_dmi_info('ProcessorName');471 }472 if(count($dmi_cpu) > 0)473 {474 $info = $dmi_cpu[0];475 }476 else477 {478 $info = trim(shell_exec('dmesg 2>&1 | grep cpu0'));479 $info = trim(substr($info, strrpos($info, 'cpu0:') + 6));480 if(empty($info))481 {482 $info = array_pop(phodevi_solaris_parser::read_sun_ddu_dmi_info('ProcessorManufacturer'));483 }484 }485 //TODO: Add in proper support for reading multiple CPUs, similar to the code from above486 $physical_cpu_count = count(phodevi_solaris_parser::read_sun_ddu_dmi_info('ProcessorSocketType'));487 if($physical_cpu_count > 1 && !empty($info))488 {489 // TODO: For now assuming when multiple CPUs are installed, that they are of the same type490 $info = $physical_cpu_count . ' x ' . $info;491 }492 }493 else if(phodevi::is_bsd())494 {495 $info = phodevi_bsd_parser::read_sysctl('hw.model');496 }497 else if(phodevi::is_macosx())498 {499 $info = phodevi_bsd_parser::read_sysctl('machdep.cpu.brand_string');500 if(empty($info))501 {502 $info = phodevi_osx_parser::read_osx_system_profiler('SPHardwareDataType', 'ProcessorName');503 }504 }505 else if(phodevi::is_windows())506 {507 $info = phodevi_windows_parser::get_wmi_object('win32_processor', 'Name');508 $cpu_count = count(phodevi_windows_parser::get_wmi_object('Win32_Processor', 'DeviceID', true));509 if($cpu_count > 1)510 {511 $info = $cpu_count . ' x ' . $info;512 }513 if(!$info)514 {515 $info = getenv('PROCESSOR_IDENTIFIER');516 }517 }518 if(empty($info) || strpos($info, 'rev ') !== false)519 {520 if(phodevi::is_linux())521 {522 $new_info = null;523 $implementer = phodevi_linux_parser::read_cpuinfo_single('CPU implementer');524 if($implementer == '0x41' || $implementer == '0x50')525 {526 $architecture = phodevi_linux_parser::read_cpuinfo_single('CPU architecture');527 switch($architecture)528 {529 case '7':530 $new_info = 'ARMv7';531 break;532 case '8':533 case 'AArch64':534 $new_info = 'ARMv8';535 break;536 }537 $part = phodevi_linux_parser::read_cpuinfo_single('CPU part');538 // parts listed @ https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/config/arm/arm-cpus.in539 switch($part)540 {541 case '0xc07':542 $new_info .= ' Cortex-A7';543 break;544 case '0xc20':545 $new_info .= ' Cortex-M7';546 break;547 case '0xc09':548 $new_info .= ' Cortex-A9';549 break;550 case '0xc0f':551 $new_info .= ' Cortex-A15';552 break;553 case '0xc0e':554 $new_info .= ' Cortex-A12';555 break;556 case '0xd01':557 $new_info .= ' Cortex-A32';558 break;559 case '0xd03':560 $new_info .= ' Cortex-A53';561 break;562 case '0xd05':563 $new_info .= ' Cortex-A55';564 break;565 case '0xd07':566 $new_info .= ' Cortex-A57';567 break;568 case '0xd06':569 $new_info .= ' Cortex-A65';570 break;571 case '0xd43':572 $new_info .= ' Cortex-A65AE';573 break;574 case '0xd08':575 $new_info .= ' Cortex-A72';576 break;577 case '0xd09':578 $new_info .= ' Cortex-A73';579 break;580 case '0xd0a':581 $new_info .= ' Cortex-A75';582 break;583 case '0xd0b':584 $new_info .= ' Cortex-A76';585 break;586 case '0xd0e':587 $new_info .= ' Cortex-A76AE';588 break;589 case '0xd0d':590 $new_info .= ' Cortex-A77';591 break;592 case '0xd0c':593 $new_info .= ' Neoverse-N1';594 break;595 case '0xd44':596 $new_info .= ' Cortex-X1';597 break;598 case '0xd49':599 $new_info .= ' Neoverse-N2';600 break;601 case '0xd4a':602 $new_info .= ' Neoverse-E1';603 break;604 case '0xd13':605 $new_info .= ' Cortex-R52';606 break;607 case '0xd20':608 $new_info .= ' Cortex-M23';609 break;610 case '0xd21':611 $new_info .= ' Cortex-M33';612 break;613 }614 }615 if(strpos(phodevi::$vfs->dmesg, 'Ampere eMAG') !== false || stripos(pts_file_io::file_get_contents_if_exists('/sys/devices/virtual/dmi/id/sys_vendor'), 'Ampere') !== false)616 {617 $product_family = pts_file_io::file_get_contents_if_exists('/sys/devices/virtual/dmi/id/product_family');618 $sys_vendor = pts_file_io::file_get_contents_if_exists('/sys/devices/virtual/dmi/id/sys_vendor');619 if(stripos($product_family, 'Quicksilver') !== false)620 {621 $new_info = 'Ampere Altra ' . $new_info;622 }623 else if(stripos($sys_vendor, 'Lenovo') !== false || stripos($product_family, 'eMAG') !== false)624 {625 $new_info = 'Ampere eMAG ' . $new_info;626 }627 else628 {629 $new_info = 'Ampere ' . $new_info;630 }631 }632 else if(strpos(phodevi::$vfs->dmesg, 'thunderx') !== false || strpos(phodevi::$vfs->dmesg, 'Cavium erratum') !== false)633 {634 // Haven't found a better way to detect ThunderX as not exposed via cpuinfo, etc635 $new_info = 'Cavium ThunderX ' . $new_info;636 }637 else if(strpos(phodevi::$vfs->dmesg, 'rockchip-cpuinfo') !== false)638 {639 // Haven't found a better way to detect Rockchip as not exposed via cpuinfo, etc640 $new_info = 'Rockchip ' . $new_info;641 }642 else if(is_file('/sys/devices/system/cpu/cpu0/cpufreq/scaling_driver'))643 {644 $scaling_driver = file_get_contents('/sys/devices/system/cpu/cpu0/cpufreq/scaling_driver');645 if(strpos($scaling_driver, 'meson_') !== false)646 {647 $new_info = 'Amlogic ' . $new_info;648 }649 }650 if(!empty($new_info))651 {652 $info = trim($new_info);653 }654 if(empty($info))655 {656 $isa = phodevi_linux_parser::read_cpuinfo_single('isa');657 $uarch = phodevi_linux_parser::read_cpuinfo_single('uarch');658 if(!empty($uarch) && stripos($isa, 'rv') !== false && strpos($uarch, 'sifive') !== false)659 {660 $info = 'SiFive RISC-V';661 }662 else if(!empty($isa))663 {664 $info = $isa;665 }666 }667 }668 if(empty($info))669 {670 $info = 'Unknown';671 }672 }673 else674 {675 if(($strip_point = strpos($info, '@')) > 0)676 {677 $info = trim(substr($info, 0, $strip_point)); // stripping out the reported freq, since the CPU could be overclocked, etc678 }679 $info = pts_strings::strip_string($info);680 // It seems Intel doesn't report its name when reporting Pentium hardware681 if(strpos($info, 'Pentium') !== false && strpos($info, 'Intel') === false)682 {683 $info = 'Intel ' . $info;684 }685 if(substr($info, 0, 5) == 'Intel')686 {687 $cpu_words = explode(' ', $info);688 $cpu_words_count = count($cpu_words);689 // Convert strings like 'Intel Core i7 M 620' -> 'Intel Core i7 620M' and 'Intel Core i7 X 990' -> 'Intel Core i7 990X' to better reflect Intel product marketing names690 if($cpu_words_count > 4 && is_numeric($cpu_words[($cpu_words_count - 1)]) && strlen($cpu_words[($cpu_words_count - 2)]) == 1 && strlen($cpu_words[($cpu_words_count - 3)]) == 2)691 {692 $cpu_words[($cpu_words_count - 1)] .= $cpu_words[($cpu_words_count - 2)];693 unset($cpu_words[($cpu_words_count - 2)]);694 $info = implode(' ', $cpu_words);695 }696 }697 else if(($gen = strpos($info, ' Gen')) !== false && ($intel = strpos($info, 'Intel ')) !== false && $gen < $intel)698 {699 // Tiger Lake reports "11th Gen Intel" as CPU string700 $info = substr($info, $intel);701 }702 }703 if(($c = strpos($info, '-Core ')) !== false && $c < strpos($info, ' '))704 {705 // At least on newer macOS, they append strings like 6-Core prior to Intel706 $info = substr($info, ($c + 6));707 }708 return $info;709 }710 public static function get_cpu_feature_constants()711 {712 return array(713 'sse2' => (1 << 1), // SSE 2714 'sse3' => (1 << 2), // SSE 3715 'sse4a' => (1 << 3), // SSE 4a716 'sse4_1' => (1 << 4), // SSE 4.1717 'sse4_2' => (1 << 5), // SSE 4.2718 //'sse5' => (1 << 6), // SSE 5719 'avx' => (1 << 7), // AVX720 'avx2' => (1 << 8), // AVX2721 'aes' => (1 << 9), // AES722 'epb' => (1 << 10), // EPB723 'svm' => (1 << 11), // AMD SVM (Virtualization)724 'vmx' => (1 << 12), // Intel Virtualization725 'xop' => (1 << 13), // AMD XOP Instruction Set726 'fma3' => (1 << 14), // FMA3 Instruction Set727 'fma4' => (1 << 15), // FMA4 Instruction Set728 'rdrand' => (1 << 16), // Intel Bull Mountain RDRAND - Ivy Bridge729 'fsgsbase' => (1 << 17), // FSGSBASE - Ivy Bridge AVX730 'bmi2' => (1 << 18), // Intel Haswell has BMI2731 'avx512cd' => (1 << 19), // AVX-512732 'avx512_vnni' => (1 << 20), // AVX-512 VNNI (DL BOOST)733 'avx512_bf16' => (1 << 21), // AVX-512 BFloat16734 'amx_tile' => (1 << 22), // AMX735 );736 }737 public static function prominent_cpu_features()738 {739 return array(740 'sse4_2' => 'SSE 4.2', // SSE 4.2741 'avx' => 'AVX', // AVX742 'avx2' => 'AVX2', // AVX2743 'aes' => 'AES', // AES744 'svm' => 'AMD SVM', // AMD SVM (Virtualization)745 'vmx' => 'Intel VT-d', // Intel Virtualization746 'fma3' => 'FMA3', // FMA3 Instruction Set747 'fma4' => 'FMA4', // FMA4 Instruction Set748 'rdrand' => 'RdRand', // Intel Bull Mountain RDRAND - Ivy Bridge749 'fsgsbase' => 'FSGSBASE', // FSGSBASE - Ivy Bridge AVX750 'bmi2' => 'BMI2', // Intel Haswell has BMI2751 'avx512cd' => 'AVX-512', // AVX-512752 'avx512_vnni' => 'AVX-512 VNNI / DL-BOOST', // AVX-512 VNNI (DL BOOST)753 'avx512_bf16' => 'AVX-512 BFloat16', // AVX-512 BFloat16754 'amx_tile' => 'AMX', // Advanced Matrix Extensions755 );756 }757 public static function prominent_cpu_bugs()758 {759 return array(760 'cpu_meltdown' => 'Meltdown',761 'spectre_v1' => 'Spectre V1',762 'spectre_v2' => 'Spectre V2',763 'spec_store_bypass' => 'Spectre V4 / SSBD',764 'l1tf' => 'L1 Terminal Fault / Foreshadow',765 'mds' => 'Microarchitectural Data Sampling',766 'swapgs' => 'SWAPGS',767 'itlb_multihit' => 'iTLB Multihit',768 'taa' => 'TSX Asynchronous Abort',769 );770 }771 public static function get_cpu_family()772 {773 $family = null;774 if(phodevi::is_linux())775 {776 $cpuinfo = phodevi_linux_parser::cpuinfo_to_array();777 $family = isset($cpuinfo['cpu family']) ? $cpuinfo['cpu family'] : $family;778 }779 else if(phodevi::is_windows())780 {781 $processor_identifier = explode(' ', getenv('PROCESSOR_IDENTIFIER'));782 if(($x = array_search('Family', $processor_identifier)) !== false)783 {784 $family = $processor_identifier[($x + 1)];785 }786 }787 else if(phodevi::is_macosx())788 {789 $family = phodevi_bsd_parser::read_sysctl(array('machdep.cpu.family'));790 }791 return $family;792 }793 public static function get_cpu_model()794 {795 $model = null;796 if(phodevi::is_linux())797 {798 $cpuinfo = phodevi_linux_parser::cpuinfo_to_array();799 $model = isset($cpuinfo['model']) ? $cpuinfo['model'] : $model;800 }801 else if(phodevi::is_windows())802 {803 $processor_identifier = explode(' ', getenv('PROCESSOR_IDENTIFIER'));804 if(($x = array_search('Model', $processor_identifier)) !== false)805 {806 $model = $processor_identifier[($x + 1)];807 }808 }809 else if(phodevi::is_macosx())810 {811 $model = phodevi_bsd_parser::read_sysctl(array('machdep.cpu.model'));812 }813 return $model;814 }815 public static function get_core_name($family = false, $model = false, $cpu_string = null)816 {817 if($family === false && $model === false && PTS_IS_CLIENT)818 {819 $family = phodevi::read_property('cpu', 'cpu-family');820 $model = phodevi::read_property('cpu', 'cpu-model');821 $cpu_string = phodevi::read_property('cpu', 'model');822 }823 // Useful: https://en.wikichip.org/wiki/amd/cpuid / https://en.wikichip.org/wiki/intel/cpuid824 // https://github.com/torvalds/linux/blob/master/arch/x86/include/asm/intel-family.h825 $amd_map = array(826 14 => array(827 1 => 'Bobcat',828 2 => 'Bobcat',829 ),...
get_core_name
Using AI Code Generation
1$cpu = new phodevi_cpu();2echo $cpu->get_core_name(0);3$cpu = new phodevi_cpu();4echo $cpu->get_core_name(1);5$cpu = new phodevi_cpu();6echo $cpu->get_core_name(2);7$cpu = new phodevi_cpu();8echo $cpu->get_core_name(3);9$cpu = new phodevi_cpu();10echo $cpu->get_core_name(4);11$cpu = new phodevi_cpu();12echo $cpu->get_core_name(5);13$cpu = new phodevi_cpu();14echo $cpu->get_core_name(6);15$cpu = new phodevi_cpu();16echo $cpu->get_core_name(7);17$cpu = new phodevi_cpu();18echo $cpu->get_core_name(8);19$cpu = new phodevi_cpu();20echo $cpu->get_core_name(9);21$cpu = new phodevi_cpu();22echo $cpu->get_core_name(10);23$cpu = new phodevi_cpu();24echo $cpu->get_core_name(11);
get_core_name
Using AI Code Generation
1$cpu = new phodevi_cpu();2echo $cpu->get_core_name();3$cpu = new phodevi_cpu();4echo $cpu->get_core_name();5$cpu = new phodevi_cpu();6echo $cpu->get_core_name();7$cpu = new phodevi_cpu();8echo $cpu->get_core_name();9$cpu = new phodevi_cpu();10echo $cpu->get_core_name();11$cpu = new phodevi_cpu();12echo $cpu->get_core_name();13$cpu = new phodevi_cpu();14echo $cpu->get_core_name();15$cpu = new phodevi_cpu();16echo $cpu->get_core_name();17$cpu = new phodevi_cpu();18echo $cpu->get_core_name();19$cpu = new phodevi_cpu();20echo $cpu->get_core_name();21$cpu = new phodevi_cpu();22echo $cpu->get_core_name();23$cpu = new phodevi_cpu();24echo $cpu->get_core_name();25$cpu = new phodevi_cpu();26echo $cpu->get_core_name();
get_core_name
Using AI Code Generation
1$cpu = new phodevi_cpu();2$cpu->get_core_name();3$cpu = new phodevi_cpu();4$cpu->get_core_name();5$cpu = new phodevi_cpu();6$cpu->get_core_name();7$cpu = new phodevi_cpu();8$cpu->get_core_name();9$cpu = new phodevi_cpu();10$cpu->get_core_name();11$cpu = new phodevi_cpu();12$cpu->get_core_name();13$cpu = new phodevi_cpu();14$cpu->get_core_name();15$cpu = new phodevi_cpu();16$cpu->get_core_name();17$cpu = new phodevi_cpu();18$cpu->get_core_name();19$cpu = new phodevi_cpu();20$cpu->get_core_name();21$cpu = new phodevi_cpu();22$cpu->get_core_name();23$cpu = new phodevi_cpu();24$cpu->get_core_name();25$cpu = new phodevi_cpu();26$cpu->get_core_name();
get_core_name
Using AI Code Generation
1require_once 'phodevi.php';2echo phodevi::read_property('cpu', 'get_core_name', 0);3require_once 'phodevi.php';4echo phodevi::read_property('cpu', 'get_core_name', 1);5require_once 'phodevi.php';6echo phodevi::read_property('cpu', 'get_core_name', 0);7require_once 'phodevi.php';8echo phodevi::read_property('cpu', 'get_core_name', 0);9require_once 'phodevi.php';10echo phodevi::read_property('cpu', 'get_core_name', 0);11require_once 'phodevi.php';12echo phodevi::read_property('cpu', 'get_core_name', 0);13require_once 'phodevi.php';14echo phodevi::read_property('cpu', 'get_core_name', 0);15require_once 'phodevi.php';16echo phodevi::read_property('cpu', 'get_core_name', 0);17require_once 'phodevi.php';18echo phodevi::read_property('cpu', 'get_core_name', 0);19require_once 'phodevi.php';20echo phodevi::read_property('cpu', 'get_core_name', 0);
get_core_name
Using AI Code Generation
1require_once 'phodevi.php';2$cpu = new phodevi_cpu();3$cpu->get_core_name();4require_once 'phodevi.php';5$cpu = new phodevi_cpu();6$cpu->get_core_name();7require_once 'phodevi.php';8$cpu = new phodevi_cpu();9$cpu->get_core_name();10require_once 'phodevi.php';11$cpu = new phodevi_cpu();12$cpu->get_core_name();13require_once 'phodevi.php';14$cpu = new phodevi_cpu();15$cpu->get_core_name();16require_once 'phodevi.php';17$cpu = new phodevi_cpu();18$cpu->get_core_name();19require_once 'phodevi.php';20$cpu = new phodevi_cpu();21$cpu->get_core_name();22require_once 'phodevi.php';23$cpu = new phodevi_cpu();24$cpu->get_core_name();25require_once 'phodevi.php';26$cpu = new phodevi_cpu();27$cpu->get_core_name();28require_once 'phodevi.php';29$cpu = new phodevi_cpu();30$cpu->get_core_name();31require_once 'phodevi.php';32$cpu = new phodevi_cpu();33$cpu->get_core_name();
get_core_name
Using AI Code Generation
1require_once('/usr/share/php/phodevi/cpu.php');2echo phodevi_cpu::get_core_name(0);3require_once('/usr/share/php/phodevi/cpu.php');4echo phodevi_cpu::get_core_name(1);5require_once('/usr/share/php/phodevi/cpu.php');6echo phodevi_cpu::get_core_name(2);7require_once('/usr/share/php/phodevi/cpu.php');8echo phodevi_cpu::get_core_name(3);9require_once('/usr/share/php/phodevi/cpu.php');10echo phodevi_cpu::get_core_name(4);11require_once('/usr/share/php/phodevi/cpu.php');12echo phodevi_cpu::get_core_name(5);13require_once('/usr/share/php/phodevi/cpu.php');14echo phodevi_cpu::get_core_name(6);15require_once('/usr/share/php/phodevi/cpu.php');16echo phodevi_cpu::get_core_name(
get_core_name
Using AI Code Generation
1include_once('phodevi.php');2$cpu_core_name = phodevi_cpu::get_core_name();3echo $cpu_core_name;4include_once('phodevi.php');5$cpu_core_name = phodevi_cpu::get_core_name();6echo $cpu_core_name;7include_once('phodevi.php');8$cpu_core_name = phodevi_cpu::get_core_name();9echo $cpu_core_name;10include_once('phodevi.php');11$cpu_core_name = phodevi_cpu::get_core_name();12echo $cpu_core_name;13include_once('phodevi.php');14$cpu_core_name = phodevi_cpu::get_core_name();15echo $cpu_core_name;16include_once('phodevi.php');17$cpu_core_name = phodevi_cpu::get_core_name();18echo $cpu_core_name;19include_once('phodevi.php');20$cpu_core_name = phodevi_cpu::get_core_name();21echo $cpu_core_name;22include_once('phodevi.php');23$cpu_core_name = phodevi_cpu::get_core_name();24echo $cpu_core_name;25include_once('phodevi.php');26$cpu_core_name = phodevi_cpu::get_core_name();27echo $cpu_core_name;
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with get_core_name on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!