From d4031a086ab771aca7dd4b1d6d9003bf1a5e15f3 Mon Sep 17 00:00:00 2001 From: zhangjiarui Date: Tue, 24 Nov 2026 14:06:42 +0800 Subject: [PATCH] fix(cpu): correct special-type CPU frequency and keep spec value as-is MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adjust the special-computer-type CPU frequency on the numeric min/max values before formatting instead of replacing hardcoded strings afterwards, and render the corrected specification value as-is (e.g. 2.7) without forcing it to two decimal places. The old string replacement stopped matching once the frequency was formatted to two decimals (e.g. "2.695" -> "2.69"), so FlemingZ (kSpecialType9) displayed 2.69/2.695 GHz instead of the specified 2.7GHz. Correcting the numeric value decouples the fix from the display formatting, while the corrected value is printed exactly as specified. Note maxS is mutated in place by QString::replace when the "MHz" unit is stripped, so build m_MaxFrequency from the numeric value as integer MHz with the unit instead of reusing maxS; this preserves the unit for non-special machines (e.g. 4200MHz) as before. Also remove the now-unused CPU_FREQ_TYPE*/CPU_MAXFREQ_TYPE* macros. Log: 特殊机型CPU频率修正改为数值层处理,且修正后的规格值(如2.7)按原样显示,不强制两位小数 Influence: FlemingZ(kSpecialType9)等特殊机型主频按规格显示为2.7 GHz、最大频率2700MHz;普通机型最大频率仍带 MHz 单位(如4200MHz),主频仍统一两位小数 PMS: https://pms.uniontech.com/bug-view-355551.html --- .../src/DeviceManager/DeviceCpu.cpp | 71 ++++++++++++++----- .../src/DeviceManager/DeviceCpu.h | 12 ---- 2 files changed, 55 insertions(+), 28 deletions(-) diff --git a/deepin-devicemanager/src/DeviceManager/DeviceCpu.cpp b/deepin-devicemanager/src/DeviceManager/DeviceCpu.cpp index 8caa65d66..3faee7dc8 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceCpu.cpp +++ b/deepin-devicemanager/src/DeviceManager/DeviceCpu.cpp @@ -140,6 +140,51 @@ const QMap DeviceCpu::m_trNumber = { {256, QT_TR_NOOP("Two hundred and fifty-six")} }; +namespace { + +// 特殊机型 CPU 频率修正规则:将硬件上报值(旧值)修正为规格值(新值),单位 GHz +struct SpecialCpuFrequencyFix { + bool valid; + double oldGhz; + double newGhz; +}; + +SpecialCpuFrequencyFix specialCpuFrequencyFix() +{ + switch (Common::specialComType) { + case Common::kSpecialType5: + case Common::kSpecialType6: + case Common::kSpecialType7: + return {true, 2.189, 2.188}; + case Common::kSpecialType9: + case Common::kSpecialType10: + return {true, 2.695, 2.7}; + default: + return {false, 0.0, 0.0}; + } +} + +// 将 value(GHz) 命中旧值时修正为新值,返回是否发生修正;0.5MHz 容差规避浮点误差 +bool applySpecialFrequencyFix(double &value, const SpecialCpuFrequencyFix &fix) +{ + if (!fix.valid) + return false; + + if (fabs(value - fix.oldGhz) < 0.0005) { + value = fix.newGhz; + return true; + } + return false; +} + +// 格式化频率(GHz):特殊机型修正后的规格值按原样显示(如 2.7),不做两位小数强制;其余保持两位小数 +QString formatGhz(double value, bool corrected) +{ + return corrected ? QString::number(value, 'g', 6) : QString::number(value, 'f', 2); +} + +} // namespace + DeviceCpu::DeviceCpu() : DeviceBaseInfo() , m_PhysicalID("") @@ -179,19 +224,6 @@ void DeviceCpu::setCpuInfo(const QMap &mapLscpu, const QMap &mapInfo) if (min && max) { QString minS = mapInfo["CPU min MHz"]; QString maxS = mapInfo["CPU max MHz"]; - m_MaxFrequency = maxS; double minHz = minS.replace("MHz", "").toDouble() / 1000; double maxHz = maxS.replace("MHz", "").toDouble() / 1000; + + // 特殊机型:在格式化前按机型修正频率数值,避免与具体格式化精度产生字符串耦合 + const SpecialCpuFrequencyFix fix = specialCpuFrequencyFix(); + const bool minFixed = applySpecialFrequencyFix(minHz, fix); + const bool maxFixed = applySpecialFrequencyFix(maxHz, fix); + + // 上面 maxS 已被 replace 就地剥离了 "MHz",不能再直接使用;统一按整数 MHz 输出并保留单位 + m_MaxFrequency = QString("%1MHz").arg(maxHz * 1000, 0, 'f', 0); m_FrequencyIsRange = true; // 如果最大最小频率相等则不显示范围 if (fabs(minHz - maxHz) < 0.001) { m_FrequencyIsRange = false; - m_Frequency = maxHz > 1 ? QString("%1 GHz").arg(maxHz, 0, 'f', 2) : QString("%1 MHz").arg(maxHz * 1000, 0, 'f', 2); + m_Frequency = maxHz > 1 ? QString("%1 GHz").arg(formatGhz(maxHz, maxFixed)) : QString("%1 MHz").arg(maxHz * 1000, 0, 'f', 2); } else { - m_Frequency = QString("%1-%2 GHz").arg(minHz, 0, 'f', 2).arg(maxHz, 0, 'f', 2); + m_Frequency = QString("%1-%2 GHz").arg(formatGhz(minHz, minFixed)).arg(formatGhz(maxHz, maxFixed)); } } else if (mapInfo.find("CPU MHz") != mapInfo.end()) { QString maxS = mapInfo["CPU MHz"]; diff --git a/deepin-devicemanager/src/DeviceManager/DeviceCpu.h b/deepin-devicemanager/src/DeviceManager/DeviceCpu.h index c662cb168..7f893c91e 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceCpu.h +++ b/deepin-devicemanager/src/DeviceManager/DeviceCpu.h @@ -8,18 +8,6 @@ #include "DeviceInfo.h" #include "commonfunction.h" -// kSpecialType5/6/7 -#define CPU_FREQ_TYPE5_7_OLD "2.189" -#define CPU_FREQ_TYPE5_7_NEW "2.188" -#define CPU_MAXFREQ_TYPE5_7_OLD "2189" -#define CPU_MAXFREQ_TYPE5_7_NEW "2188" - -// kSpecialType9 -#define CPU_FREQ_TYPE9_OLD "2.695" -#define CPU_FREQ_TYPE9_NEW "2.7" -#define CPU_MAXFREQ_TYPE9_OLD "2695" -#define CPU_MAXFREQ_TYPE9_NEW "2700" - /** * @brief The DeviceCpu class * 用来描述CPU的类