Skip to content

fix(cpu): correct special-type CPU frequency via numeric adjustment - #989

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/eaglefrom
Resurgamz:fix/cpu-freq-355551
Nov 24, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/eaglefrom
Resurgamz:fix/cpu-freq-355551

Conversation

@Resurgamz

@Resurgamz Resurgamz commented Nov 24, 2026 •

Copy link
Copy Markdown

问题

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* 宏。

验证

  • Qt 逻辑模拟:
    • type9(2.695→2.7)→ 2.7 GHz / 2700MHz
    • type9 频率范围(0.418–2.695)→ 0.42-2.7 GHz / 2700MHz
    • type5/7(2.189→2.188)→ 2.188 GHz / 2188MHz
    • 普通机型(0.8–4.2)→ 0.80-4.20 GHz / 4200MHz(带单位),不受影响
  • 目标机实机验证:FlemingZ(arm64,specialComType=9,lscpu CPU max MHz=2695)
  • 保持 setInfoFromLscpu 对普通机型的既有两位小数输出不变

影响

  • 仅影响特殊机型(type5/6/7/9/10)的频率修正路径,普通机型行为不变
  • 修正了普通机型最大频率丢失 MHz 单位的回归

关联

Summary by Sourcery

Correct special-device CPU frequency reporting and preserve consistent maximum-frequency units across device types.

Bug Fixes:

  • Correct CPU frequency reporting for special device types by applying numeric hardware-to-specification adjustments before formatting.
  • Preserve the MHz unit in maximum-frequency output for standard device types.

Enhancements:

  • Keep corrected special-device specification values in their natural precision while retaining two-decimal formatting for standard CPU frequencies.
  • Remove obsolete CPU frequency correction macros.

@sourcery-ai

sourcery-ai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Replace string-based special-CPU frequency substitutions with numeric corrections before formatting, preserve corrected values and MHz units in output, and remove the obsolete macros.

  • deepin-devicemanager/src/DeviceManager/DeviceCpu.cpp L143-187, L332-339 (+3 small edits)
  • deepin-devicemanager/src/DeviceManager/DeviceCpu.h L11 (removed lines)

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment on lines -182 to -193
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);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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`.

Comment on lines +333 to +335
m_MaxFrequency = (minFixed || maxFixed)
? QString("%1MHz").arg(maxHz * 1000, 0, 'f', 0)
: maxS;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

@Resurgamz
Resurgamz force-pushed the fix/cpu-freq-355551 branch 2 times, most recently from 16b7e81 to f54b523 Compare November 24, 2026 06:58
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
@deepin-ci-robot

Copy link
Copy Markdown

[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.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@Resurgamz

Copy link
Copy Markdown
Author

/merge

@deepin-bot

deepin-bot Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

This pr cannot be merged! (status: unstable)

@Resurgamz

Copy link
Copy Markdown
Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: unstable)

@deepin-bot
deepin-bot Bot merged commit 7dfee1b into linuxdeepin:develop/eagle Nov 24, 2026
18 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants