From cfdd4c487d92eb02750b69b1adb79c5c982b0904 Mon Sep 17 00:00:00 2001 From: SimonFair <39065407+SimonFair@users.noreply.github.com> Date: Fri, 4 Apr 2025 10:20:26 +0100 Subject: [PATCH] Initial commit --- .../dynamix.vm.manager/VMMachines.page | 11 ++-- .../templates/Custom.form.php | 9 ++- emhttp/plugins/dynamix/CPUvms.page | 15 ++++- emhttp/plugins/dynamix/DashStats.page | 24 +++----- emhttp/plugins/dynamix/include/CPUset.php | 13 +++-- emhttp/plugins/dynamix/include/Helpers.php | 58 +++++++++++++++++++ emhttp/plugins/dynamix/include/SysDevs.php | 11 +++- 7 files changed, 111 insertions(+), 30 deletions(-) diff --git a/emhttp/plugins/dynamix.vm.manager/VMMachines.page b/emhttp/plugins/dynamix.vm.manager/VMMachines.page index 19b64eee3..713cf4198 100644 --- a/emhttp/plugins/dynamix.vm.manager/VMMachines.page +++ b/emhttp/plugins/dynamix.vm.manager/VMMachines.page @@ -20,6 +20,8 @@ Markdown="false" 0) $core_type = "$core_types[$cpu1]"; else $core_type = ""; if (!$cpu2) { - echo ""; + echo ""; } else { - echo ""; + echo ""; $check = ($vcpu && in_array($cpu2, $vcpu)) ? 'fa-circle orange-text':'fa-circle-o'; - echo ""; + echo ""; } } echo "
vCPUs: {$vm['domain']['vcpus']} $nopining"; diff --git a/emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php b/emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php index ef782b506..fa8e5118e 100644 --- a/emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php +++ b/emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php @@ -555,16 +555,19 @@ if ($snapshots!=null && count($snapshots) && !$boolNew) {
1 ? 'checked' : 'checked disabled') : ''; + if ($is_intel_cpu && count($core_types) > 0) $core_type = "{$core_types[$cpu1]}"; else $core_type = ""; if (!$cpu2) { - echo ""; + echo ""; } else { - echo ""; + echo ""; $extra = ($arrConfig['domain']['vcpu'] && in_array($cpu2, $arrConfig['domain']['vcpu'])) ? ($arrConfig['domain']['vcpus'] > 1 ? 'checked' : 'checked disabled') : ''; - echo ""; + echo ""; } } ?> diff --git a/emhttp/plugins/dynamix/CPUvms.page b/emhttp/plugins/dynamix/CPUvms.page index 89e6e6f25..297ab883c 100644 --- a/emhttp/plugins/dynamix/CPUvms.page +++ b/emhttp/plugins/dynamix/CPUvms.page @@ -22,10 +22,12 @@ $cpus = cpu_list(); $total = count($cpus); $spinner = "
"; $cpuset = implode(';',$cpus); +$is_intel_cpu = is_intel_cpu(); +$core_types = $is_intel_cpu ? get_intel_core_types() : []; function create($type = "") { // create the table header. Make multiple rows when CPU cores are many ;) - global $total, $cpus; + global $total, $cpus, $is_intel_cpu, $core_types; $loop = floor(($total-1)/32) + 1; $text = []; for ($c = 0; $c < $loop; $c++) { @@ -39,8 +41,12 @@ function create($type = "") { } $label = implode('
', array_fill(0, $loop, 'CORES:' . ($cpu2 ? '
CORES:' : ''))); if ($type == "vm") echo "VCPUS"; + echo "$label" . implode(array_map(function($t) { - return "$t"; + global $is_intel_cpu, $core_types; + [$cpu1, $cpu2] = my_preg_split('/[,
]/',$t); + if ($is_intel_cpu && count($core_types) > 0) $core_type = "$core_types[$cpu1]"; else $core_type = ""; + return "$t"; }, $text)); } ?> @@ -175,7 +181,10 @@ function ct() { /* Inject thread to containers toggles */ if ($('a[onclick^="thread2containers"]').length === 0) { $('form[name=ct]').find('thead tr th:gt(1)').each((i, elem) => { - elem.innerHTML = elem.innerHTML.replace(/(\d+)/g, '$1'); + // Preserve the existing title if available + let existingTitle = elem.title || ""; + let newTitle = existingTitle ? existingTitle + " _(Toggle thread to containers)_" : "_(Toggle thread to containers)_"; + elem.innerHTML = elem.innerHTML.replace(/(\d+)/g, '$1'); }); } }); diff --git a/emhttp/plugins/dynamix/DashStats.page b/emhttp/plugins/dynamix/DashStats.page index 5f2e59ad0..1e418c080 100644 --- a/emhttp/plugins/dynamix/DashStats.page +++ b/emhttp/plugins/dynamix/DashStats.page @@ -14,19 +14,6 @@ Nchan="wg_poller,update_1,update_2,update_3,ups_status:stop,vm_dashusage" */ ?>

+
_(Processor)_
@@ -265,14 +257,16 @@ switch ($theme) { + "; + if ($is_intel_cpu && count($core_types) > 0) $core_type = "({$core_types[$cpu1]})"; else $core_type = ""; if ($cpu2) - echo "CPU $cpu1 - HT $cpu20%
0%
"; + echo "CPU $cpu1 $core_type - HT $cpu2 0%
0%
"; else - echo "CPU $cpu10%
"; + echo "CPU $cpu1 $core_type0%
"; echo ""; } ?> diff --git a/emhttp/plugins/dynamix/include/CPUset.php b/emhttp/plugins/dynamix/include/CPUset.php index bca85c112..e87409e10 100644 --- a/emhttp/plugins/dynamix/include/CPUset.php +++ b/emhttp/plugins/dynamix/include/CPUset.php @@ -17,7 +17,8 @@ require_once "$docroot/webGui/include/Helpers.php"; // add translations $_SERVER['REQUEST_URI'] = 'settings'; require_once "$docroot/webGui/include/Translations.php"; - +$is_intel_cpu = is_intel_cpu(); +$core_types = $is_intel_cpu ? get_intel_core_types() : []; $cpus = explode(';',$_POST['cpus']??''); $corecount = 0; foreach ($cpus as $pair) { @@ -32,7 +33,7 @@ function scan($area, $text) { function create($id, $name, $vcpu) { // create the list of checkboxes. Make multiple rows when CPU cores are many ;) - global $cpus; + global $cpus,$is_intel_cpu,$core_types; $total = count($cpus); $loop = floor(($total-1)/32)+1; $text = []; @@ -48,8 +49,12 @@ function create($id, $name, $vcpu) { $check1 = ($vcpu && in_array($cpu1, $vcpu)) ? 'checked':''; $check2 = $cpu2 ? ($vcpu && (in_array($cpu2, $vcpu)) ? 'checked':''):''; if (empty($text[$n])) $text[$n] = ''; - $text[$n] .="
"; - if ($cpu2) $text[$n] .= "
"; + if ($is_intel_cpu && count($core_types) > 0) $core_type = "{$core_types[$cpu1]}"; else $core_type = ""; + $text[$n] .="
"; + if ($cpu2) { + if ($is_intel_cpu && count($core_types) > 0) $core_type = "{$core_types[$cpu2]}"; else $core_type = ""; + $text[$n] .= "
"; + } } } echo implode(array_map(function($t){return "$t";},$text)); diff --git a/emhttp/plugins/dynamix/include/Helpers.php b/emhttp/plugins/dynamix/include/Helpers.php index 68474afcf..d21633c64 100644 --- a/emhttp/plugins/dynamix/include/Helpers.php +++ b/emhttp/plugins/dynamix/include/Helpers.php @@ -416,4 +416,62 @@ function device_exists($name) global $disks,$devs; return (array_key_exists($name, $disks) && !str_contains(_var($disks[$name],'status'),'_NP')) || (array_key_exists($name, $devs)); } + + +# Check for process Core Types. +function parse_cpu_ranges($file) { + if (!is_file($file)) return null; + $ranges = file_get_contents($file); + $ranges = trim($ranges); + $cores = []; + foreach (explode(',', $ranges) as $range) { + if (strpos($range, '-') !== false) { + list($start, $end) = explode('-', $range); + $cores = array_merge($cores, range((int)$start, (int)$end)); + } else { + $cores[] = (int)$range; + } + } + return $cores; +} + +function get_intel_core_types() { + $core_types = array(); + $cpu_core_file = "/sys/devices/cpu_core/cpus"; + $cpu_atom_file = "/sys/devices/cpu_atom/cpus"; + $p_cores = parse_cpu_ranges($cpu_core_file); + $e_cores = parse_cpu_ranges($cpu_atom_file); + if ($p_cores) { + foreach ($p_cores as $core) { + $core_types[$core] = _("P-Core"); + } + } + if ($e_cores) { + foreach ($e_cores as $core) { + $core_types[$core] = _("E-Core"); + } + } + return $core_types; +} + +function dmidecode($key,$n,$all=true) { + $entries = array_filter(explode($key,shell_exec("dmidecode -qt$n")??"")); + $properties = []; + foreach ($entries as $entry) { + $property = []; + foreach (explode("\n",$entry) as $line) if (strpos($line,': ')!==false) { + [$key,$value] = my_explode(': ',trim($line)); + $property[$key] = $value; + } + $properties[] = $property; + } + return $all ? $properties : $properties[0]??null; +} + +function is_intel_cpu() { + $cpu = dmidecode('Processor Information','4',0); + $cpu_vendor = $cpu['Manufacturer'] ?? ""; + $is_intel_cpu = stripos($cpu_vendor, "intel") !== false ? true : false; + return $is_intel_cpu; +} ?> diff --git a/emhttp/plugins/dynamix/include/SysDevs.php b/emhttp/plugins/dynamix/include/SysDevs.php index 32fbddb22..73b9e09aa 100644 --- a/emhttp/plugins/dynamix/include/SysDevs.php +++ b/emhttp/plugins/dynamix/include/SysDevs.php @@ -211,11 +211,20 @@ EOT; } break; case 't2': + $is_intel_cpu = is_intel_cpu(); + $core_types = $is_intel_cpu ? get_intel_core_types() : []; + var_dump($is_intel_cpu,$core_types); exec('cat /sys/devices/system/cpu/*/topology/thread_siblings_list|sort -nu',$pairs); $i = 1; foreach ($pairs as $line) { + $line2 = $line; $line = preg_replace(['/(\d+)[-,](\d+)/','/(\d+)\b/'],['$1 / $2','cpu $1'],$line); - echo "".(strpos($line,'/')===false?"Single":"Pair ".$i++).":$line"; + if ($is_intel_cpu && count($core_types) > 0) { + [$cpu1, $cpu2] = my_preg_split('/[,-]/',$line2); + $core = $cpu1; + $core_type = "({$core_types[$core]})"; + } else $core_type = ""; + echo "".(strpos($line,'/')===false?"Single":"Pair ".$i++).":$line $core_type"; } break; case 't3':