Skip to content

fix(cpu): use constants for CPU frequency fix values#637

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:develop/eaglefrom
add-uos:fix-BUG-355551
Apr 8, 2026
Merged

fix(cpu): use constants for CPU frequency fix values#637
deepin-bot[bot] merged 1 commit intolinuxdeepin:develop/eaglefrom
add-uos:fix-BUG-355551

Conversation

@add-uos
Copy link
Copy Markdown
Contributor

@add-uos add-uos commented Apr 7, 2026

Replace hardcoded frequency strings with named macros to improve code maintainability. Separate the handling logic for kSpecialType9 (2.695GHz) from kSpecialType5/6/7 (2.189GHz) to allow different frequency fix values.

log: use constants for CPU frequency fix values
pms: https://pms.uniontech.com/bug-view-355551.html

Summary by Sourcery

Use named CPU frequency constants and adjust special-type handling for CPU frequency fixes.

Bug Fixes:

  • Correct CPU frequency adjustment logic for kSpecialType9 devices by separating it from kSpecialType5/6/7 handling.

Enhancements:

  • Replace hardcoded CPU frequency strings with named macros to improve maintainability and clarity in DeviceCpu.
  • Update copyright years for DeviceCpu headers to cover 2019–2026 and 2022–2026.

Replace hardcoded frequency strings with named macros to improve code
maintainability. Separate the handling logic for kSpecialType9 (2.695GHz)
from kSpecialType5/6/7 (2.189GHz) to allow different frequency fix values.

log: use constants for CPU frequency fix values
pms: https://pms.uniontech.com/bug-view-355551.html
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Apr 7, 2026

Reviewer's Guide

Refactors CPU frequency correction logic by introducing named constants for special device types and separating kSpecialType9 handling from kSpecialType5/6/7, while updating license year ranges.

Class diagram for updated DeviceCpu CPU frequency fix logic

classDiagram
    class DeviceCpu {
        +void setCpuInfo(QMap_mapLscpu, QMap_mapCpuinfo)
        -QString m_Frequency
        -QString m_MaxFrequency
    }

    class Common {
        <<static>> int specialComType
        <<enum>> kSpecialType5
        <<enum>> kSpecialType6
        <<enum>> kSpecialType7
        <<enum>> kSpecialType9
    }

    class CpuFrequencyFixConstants {
        <<macro>> CPU_FREQ_TYPE5_7_OLD
        <<macro>> CPU_FREQ_TYPE5_7_NEW
        <<macro>> CPU_MAXFREQ_TYPE5_7_OLD
        <<macro>> CPU_MAXFREQ_TYPE5_7_NEW
        <<macro>> CPU_FREQ_TYPE9_OLD
        <<macro>> CPU_FREQ_TYPE9_NEW
        <<macro>> CPU_MAXFREQ_TYPE9_OLD
        <<macro>> CPU_MAXFREQ_TYPE9_NEW
    }

    DeviceCpu ..> Common : uses specialComType
    DeviceCpu ..> CpuFrequencyFixConstants : uses macros in setCpuInfo
Loading

File-Level Changes

Change Details Files
Introduce named macros for CPU frequency correction values used for special device types 5/6/7 and 9.
  • Add macros for old and new CPU frequency strings for types 5/6/7 (2.189 → 2.188)
  • Add macros for old and new CPU max frequency strings for types 5/6/7 (2189 → 2188)
  • Add macros for old and new CPU frequency strings for type 9 (2.695 → 2.7)
  • Add macros for old and new CPU max frequency strings for type 9 (2695 → 2700)
deepin-devicemanager/src/DeviceManager/DeviceCpu.h
Separate and update CPU frequency correction logic for kSpecialType9 from the logic for kSpecialType5/6/7 using the new macros.
  • Restrict shared correction block to kSpecialType5/6/7 only
  • Apply frequency and max frequency replacements for kSpecialType5/6/7 using the new macros
  • Add a dedicated correction block for kSpecialType9 using its own macros
deepin-devicemanager/src/DeviceManager/DeviceCpu.cpp
Update copyright/SPDX year ranges to include 2026.
  • Change header comment in DeviceCpu.h from 2019 ~ 2020 to 2019 - 2026
  • Change SPDX-FileCopyrightText year in DeviceCpu.cpp from 2022 to 2022 - 2026
deepin-devicemanager/src/DeviceManager/DeviceCpu.h
deepin-devicemanager/src/DeviceManager/DeviceCpu.cpp

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

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • The CPU frequency fix values are only used inside DeviceCpu::setCpuInfo, so consider moving the string constants out of the header and into the .cpp file (e.g., as constexpr variables in an anonymous namespace) to avoid polluting the global macro namespace and recompiling dependents unnecessarily.
  • Instead of using #define for the frequency strings, prefer typed constants (constexpr auto or static const QString) to gain type safety, scope control, and debugger friendliness.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The CPU frequency fix values are only used inside DeviceCpu::setCpuInfo, so consider moving the string constants out of the header and into the .cpp file (e.g., as `constexpr` variables in an anonymous namespace) to avoid polluting the global macro namespace and recompiling dependents unnecessarily.
- Instead of using `#define` for the frequency strings, prefer typed constants (`constexpr auto` or `static const QString`) to gain type safety, scope control, and debugger friendliness.

## Individual Comments

### Comment 1
<location path="deepin-devicemanager/src/DeviceManager/DeviceCpu.h" line_range="11-21" />
<code_context>
 #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"
+
 /**
</code_context>
<issue_to_address>
**suggestion:** Prefer typed constants over preprocessor macros for these frequency strings.

Since these are configuration constants, consider replacing the `#define`s with `constexpr auto` or `const QString` (e.g., in an anonymous or dedicated namespace). That keeps them out of the global macro space, maintains type safety, and avoids name collisions if these identifiers appear elsewhere.

```suggestion
namespace {
constexpr auto CPU_FREQ_TYPE5_7_OLD      = "2.189";
constexpr auto CPU_FREQ_TYPE5_7_NEW      = "2.188";
constexpr auto CPU_MAXFREQ_TYPE5_7_OLD   = "2189";
constexpr auto CPU_MAXFREQ_TYPE5_7_NEW   = "2188";

constexpr auto CPU_FREQ_TYPE9_OLD        = "2.695";
constexpr auto CPU_FREQ_TYPE9_NEW        = "2.7";
constexpr auto CPU_MAXFREQ_TYPE9_OLD     = "2695";
constexpr auto CPU_MAXFREQ_TYPE9_NEW     = "2700";
} // namespace
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos, GongHeng2017, max-lvs

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

@add-uos
Copy link
Copy Markdown
Contributor Author

add-uos commented Apr 8, 2026

/forcemerge

@deepin-bot
Copy link
Copy Markdown
Contributor

deepin-bot bot commented Apr 8, 2026

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit 7a7b477 into linuxdeepin:develop/eagle Apr 8, 2026
20 of 22 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.

4 participants