Repository navigation
fix(cpu): correct special-type CPU frequency via numeric adjustment - #989
Conversation
Reviewer's GuideImplementationReplace string-based special-CPU frequency substitutions with numeric corrections before formatting, preserve corrected values and MHz units in output, and remove the obsolete macros.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="deepin-devicemanager/src/DeviceManager/DeviceCpu.cpp" line_range="182-193" />
<code_context>
m_Name.replace(QRegExp("/[0-9]*$"), "");
m_Name.replace(QRegExp("x [0-9]*$"), "");
- if (Common::specialComType == Common::kSpecialType5 ||
- Common::specialComType == Common::kSpecialType6 ||
- Common::specialComType == Common::kSpecialType7) {
- m_Frequency = m_Frequency.replace(CPU_FREQ_TYPE5_7_OLD, CPU_FREQ_TYPE5_7_NEW);
- m_MaxFrequency = m_MaxFrequency.replace(CPU_MAXFREQ_TYPE5_7_OLD, CPU_MAXFREQ_TYPE5_7_NEW);
- }
-
- if (Common::specialComType == Common::kSpecialType9 ||
</code_context>
<issue_to_address>
**Special CPU frequencies stay uncorrected**
When a supported special-type CPU gets its frequency from `CPU MHz` or dmidecode because either lscpu range key is absent, `specialCpuFrequencyFix()` and `applySpecialFrequencyFix()` run only in the range branch, so fallback values remain uncorrected and callers see the reported old frequency, such as 2695 MHz instead of 2700 MHz.
Apply the special frequency correction to fallback values from `CPU MHz` and dmidecode as well as values from the range branch.
Also at `deepin-devicemanager/src/DeviceManager/DeviceCpu.cpp:327-333`.
</issue_to_address>
### Comment 2
<location path="deepin-devicemanager/src/DeviceManager/DeviceCpu.cpp" line_range="333-334" />
<code_context>
+ const bool maxFixed = applySpecialFrequencyFix(maxHz, fix);
+
+ // 修正后同步最大频率字符串,保证与主频一致
+ m_MaxFrequency = (minFixed || maxFixed)
+ ? QString("%1MHz").arg(maxHz * 1000, 0, 'f', 0)
+ : maxS;
m_FrequencyIsRange = true;
</code_context>
<issue_to_address>
**Fractional maximums are rounded**
When the minimum matches a special-type correction but the nonmatching maximum has a fractional MHz value, `minFixed || maxFixed` rebuilds `m_MaxFrequency` from `maxHz` with zero decimal places even when only the minimum matched, so callers see an inaccurate rounded maximum.
Rebuild `m_MaxFrequency` only when `maxFixed` is true, and otherwise preserve `maxS`.
</issue_to_address>
### Comment 3
<location path="deepin-devicemanager/src/DeviceManager/DeviceCpu.cpp" line_range="333-335" />
<code_context>
+ const bool maxFixed = applySpecialFrequencyFix(maxHz, fix);
+
+ // 修正后同步最大频率字符串,保证与主频一致
+ m_MaxFrequency = (minFixed || maxFixed)
+ ? QString("%1MHz").arg(maxHz * 1000, 0, 'f', 0)
+ : maxS;
m_FrequencyIsRange = true;
</code_context>
<issue_to_address>
**DMI maximum speed is ignored**
When an ordinary CPU has both lscpu range values and a DMI `Max Speed` that differs from lscpu's `CPU max MHz`, `setInfoFromLscpu` now fills `m_MaxFrequency` from lscpu even when no correction occurred, so the later non-overwriting DMI assignment cannot supply its `Max Speed` value. Machines where those sources differ show a different maximum frequency even when they are not special types.
Only assign `m_MaxFrequency` from lscpu when a special correction requires it, preserving the existing DMI fallback for ordinary CPUs.
</issue_to_address>| if (Common::specialComType == Common::kSpecialType5 || | ||
| Common::specialComType == Common::kSpecialType6 || | ||
| Common::specialComType == Common::kSpecialType7) { | ||
| m_Frequency = m_Frequency.replace(CPU_FREQ_TYPE5_7_OLD, CPU_FREQ_TYPE5_7_NEW); | ||
| m_MaxFrequency = m_MaxFrequency.replace(CPU_MAXFREQ_TYPE5_7_OLD, CPU_MAXFREQ_TYPE5_7_NEW); | ||
| } | ||
|
|
||
| if (Common::specialComType == Common::kSpecialType9 || | ||
| Common::specialComType == Common::kSpecialType10) { | ||
| m_Frequency = m_Frequency.replace(CPU_FREQ_TYPE9_OLD, CPU_FREQ_TYPE9_NEW); | ||
| m_MaxFrequency = m_MaxFrequency.replace(CPU_MAXFREQ_TYPE9_OLD, CPU_MAXFREQ_TYPE9_NEW); | ||
| } |
There was a problem hiding this comment.
🟡 Medium · Special CPU frequencies stay uncorrected
When a supported special-type CPU gets its frequency from CPU MHz or dmidecode because either lscpu range key is absent, specialCpuFrequencyFix() and applySpecialFrequencyFix() run only in the range branch, so fallback values remain uncorrected and callers see the reported old frequency, such as 2695 MHz instead of 2700 MHz.
Apply the special frequency correction to fallback values from CPU MHz and dmidecode as well as values from the range branch.
Also at deepin-devicemanager/src/DeviceManager/DeviceCpu.cpp:327-333.
Prompt for AI agents
In `deepin-devicemanager/src/DeviceManager/DeviceCpu.cpp` at lines 182-193:
**Special CPU frequencies stay uncorrected**
When a supported special-type CPU gets its frequency from `CPU MHz` or dmidecode because either lscpu range key is absent, `specialCpuFrequencyFix()` and `applySpecialFrequencyFix()` run only in the range branch, so fallback values remain uncorrected and callers see the reported old frequency, such as 2695 MHz instead of 2700 MHz.
Apply the special frequency correction to fallback values from `CPU MHz` and dmidecode as well as values from the range branch.
Also at `deepin-devicemanager/src/DeviceManager/DeviceCpu.cpp:327-333`.| m_MaxFrequency = (minFixed || maxFixed) | ||
| ? QString("%1MHz").arg(maxHz * 1000, 0, 'f', 0) | ||
| : maxS; |
There was a problem hiding this comment.
🟡 Medium · DMI maximum speed is ignored
When an ordinary CPU has both lscpu range values and a DMI Max Speed that differs from lscpu's CPU max MHz, setInfoFromLscpu now fills m_MaxFrequency from lscpu even when no correction occurred, so the later non-overwriting DMI assignment cannot supply its Max Speed value. Machines where those sources differ show a different maximum frequency even when they are not special types.
Only assign m_MaxFrequency from lscpu when a special correction requires it, preserving the existing DMI fallback for ordinary CPUs.
Prompt for AI agents
In `deepin-devicemanager/src/DeviceManager/DeviceCpu.cpp` at lines 333-335:
**DMI maximum speed is ignored**
When an ordinary CPU has both lscpu range values and a DMI `Max Speed` that differs from lscpu's `CPU max MHz`, `setInfoFromLscpu` now fills `m_MaxFrequency` from lscpu even when no correction occurred, so the later non-overwriting DMI assignment cannot supply its `Max Speed` value. Machines where those sources differ show a different maximum frequency even when they are not special types.
Only assign `m_MaxFrequency` from lscpu when a special correction requires it, preserving the existing DMI fallback for ordinary CPUs.16b7e81 to
f54b523
Compare
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
f54b523 to
d4031a0
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: max-lvs, Resurgamz The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/merge |
|
This pr cannot be merged! (status: unstable) |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
7dfee1b
into
linuxdeepin:develop/eagle
问题
PMS: https://pms.uniontech.com/bug-view-355551.html
FlemingZ(
specialComType = kSpecialType9)设备管理器-处理器主频显示为2.695 GHz/2695MHz,产品规格要求为2.7GHz(2/2 DUT、3/3 轮必现)。根因
DeviceCpu::setCpuInfo对特殊机型 CPU 频率采用字符串替换修正:kSpecialType9与kSpecialType5/6/7同组,套用了"2.189" -> "2.188"的替换;而 FlemingZ 实际频率为2.695/2695,替换目标不命中,导致原值被原样显示。此前 PR #637 虽已将 type9 拆出并替换
"2.695" -> "2.7",但随后合入的两位小数格式化(QString("%1 GHz").arg(maxHz, 0, 'f', 2))会把2.695变成"2.69",使字符串替换再次失配。修复
将特殊机型频率修正从“字符串替换”改为数值层修正:在
DeviceCpu::setInfoFromLscpu得到minHz/maxHz之后、格式化之前按机型修正数值;并让修正后的规格值按原样显示、不强制两位小数:kSpecialType5/6/7: 2.189 → 2.188 (GHz)kSpecialType9/10: 2.695 → 2.7 (GHz)即 type9 显示
2.7 GHz(而非2.70 GHz),type5/6/7 显示2.188 GHz(而非2.19 GHz);普通机型仍保持原有两位小数格式不变。同时修正最大频率的构造:
maxS会被QString::replace("MHz","")就地剥离单位,不能再直接复用;改为统一由数值构造QString("%1MHz").arg(maxHz*1000),普通机型输出4200MHz、特殊机型2700MHz/2188MHz,保留MHz单位(避免普通机型“最大频率”丢失单位)。并删除不再使用的
CPU_FREQ_TYPE* / CPU_MAXFREQ_TYPE*宏。验证
2.7 GHz/2700MHz0.42-2.7 GHz/2700MHz2.188 GHz/2188MHz0.80-4.20 GHz/4200MHz(带单位),不受影响specialComType=9,lscpu CPU max MHz=2695)setInfoFromLscpu对普通机型的既有两位小数输出不变影响
MHz单位的回归关联
kSpecialType9)kSpecialType9频率常量,task-view-385813)Summary by Sourcery
Correct special-device CPU frequency reporting and preserve consistent maximum-frequency units across device types.
Bug Fixes:
Enhancements: