Skip to content

Conversation

@add-uos
Copy link
Contributor

@add-uos add-uos commented Sep 11, 2025

Modified CPU frequency display for kSpecialType6 devices include current frequency and max frequency to correct hardware reporting inaccuracies.

Log: Fix CPU frequency display for special device type
Task: https://pms.uniontech.com/task-view-381765.html
Change-Id: I3a715b263868c6825ee42941b64a7c5de6a53035

Summary by Sourcery

Adjust CPU frequency display for kSpecialType6 devices to correct hardware reporting inaccuracies

Enhancements:

  • Apply value correction for special type 6 devices by replacing reported current frequency "2.189" with "2.188"
  • Apply value correction for special type 6 devices by replacing reported max frequency "2189" with "2188"

Modified CPU frequency display for kSpecialType6 devices
include current frequency and max frequency to correct hardware reporting inaccuracies.

Log: Fix CPU frequency display for special device type
Task: https://pms.uniontech.com/task-view-381765.html
Change-Id: I3a715b263868c6825ee42941b64a7c5de6a53035
@sourcery-ai
Copy link

sourcery-ai bot commented Sep 11, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Added a special-case adjustment in DeviceCpu to correct misreported CPU frequency values for kSpecialType6 devices by replacing specific frequency substrings.

Class diagram for updated DeviceCpu frequency adjustment

classDiagram
class DeviceCpu {
  - m_Name: QString
  - m_Frequency: QString
  - m_MaxFrequency: QString
  - m_LogicalCPUNum: int
  - m_CPUCoreNum: int
  + setCpuInfo(mapLscpu: QMap<QString, QString>, mapCpuinfo: QMap<QString, QString>, logicalNum: int, coreNum: int)
}
class Common {
  + specialComType: int
  + kSpecialType6: int
}
DeviceCpu --|> Common: uses
Loading

File-Level Changes

Change Details Files
Adjust CPU frequency strings for kSpecialType6 devices to correct misreported values
  • Insert conditional branch checking for kSpecialType6 device type
  • Replace '2.189' with '2.188' in current frequency string
  • Replace '2189' with '2188' in max frequency string
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

@deepin-ci-robot
Copy link

deepin pr auto review

这段代码是对CPU设备信息处理的diff修改,我来分析一下:

  1. 代码逻辑:
  • 新增了一个特殊处理条件,当Common::specialComType等于Common::kSpecialType6时,会将CPU频率中的"2.189"替换为"2.188",将最大频率中的"2189"替换为"2188"。
  • 这种硬编码的数值替换看起来像是针对特定硬件型号的临时修正方案。
  1. 代码质量:
  • 使用了硬编码的字符串值进行替换,这降低了代码的可维护性和可读性。
  • 缺少注释说明为什么需要这个特殊处理,以及这个特殊处理的具体目的。
  • 使用了魔法数字(kSpecialType6),应该使用有意义的命名来替代。
  1. 代码性能:
  • 字符串替换操作对性能影响不大,因为只在初始化时执行一次。
  1. 代码安全:
  • 字符串替换操作是安全的,但这种方式不够优雅,可能会引入其他问题。
  • 如果未来需要修改这个特殊处理的值,需要修改代码,不够灵活。

改进建议:

  1. 使用配置文件或常量定义来替代硬编码值:
// 在适当的位置定义常量
static const QString SPECIAL_CPU_FREQ_FIX = "2.189";
static const QString SPECIAL_CPU_FREQ_FIXED = "2.188";
static const QString SPECIAL_MAX_FREQ_FIX = "2189";
static const QString SPECIAL_MAX_FREQ_FIXED = "2188";

// 修改代码
if (Common::specialComType == Common::kSpecialType6) {
    m_Frequency.replace(SPECIAL_CPU_FREQ_FIX, SPECIAL_CPU_FREQ_FIXED);
    m_MaxFrequency.replace(SPECIAL_MAX_FREQ_FIX, SPECIAL_MAX_FREQ_FIXED);
}
  1. 添加详细注释说明特殊处理的目的:
// 特殊处理:针对特定型号CPU的频率校准问题
// 当设备类型为kSpecialType6时,需要修正CPU频率显示值
if (Common::specialComType == Common::kSpecialType6) {
    m_Frequency.replace("2.189", "2.188");
    m_MaxFrequency.replace("2189", "2188");
}
  1. 考虑使用更优雅的方式处理这种特殊情况,例如:
  • 将特殊处理逻辑封装到单独的函数中
  • 使用策略模式,根据不同设备类型采用不同的频率处理方式
  • 考虑从配置文件或数据库中读取这些特殊值
  1. 如果可能的话,建议与硬件供应商沟通,从源头解决频率显示不准确的问题,而不是通过软件层面进行修正。

这些改进可以提高代码的可维护性、可读性和灵活性,同时保持代码的安全性。

Copy link

@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 there - I've reviewed your changes and they look great!


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

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos, 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
Contributor Author

add-uos commented Sep 11, 2025

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Sep 11, 2025

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit 6b2e2cd into linuxdeepin:develop/eagle Sep 11, 2025
15 of 17 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