Skip to content

fix: add loongarch64 support in device generator - #763

Open
pengfeixx wants to merge 1 commit into
linuxdeepin:develop/eaglefrom
pengfeixx:agent/pms-bug-bot/966cf354720c
Open

pengfeixx wants to merge 1 commit into
linuxdeepin:develop/eaglefrom
pengfeixx:agent/pms-bug-bot/966cf354720c

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Root Cause Analysis

DeviceFactory::getDeviceGenerator() did not recognize the loongarch64 architecture, causing Loongson platforms to fall through to the else branch which creates X86Generator. The X86Generator inherits the base class generatorMonitorDevice() that relies solely on hwinfo --monitor for display detection. On JM7200 GPU environments, hwinfo returns incomplete monitor information, resulting in only one DeviceMonitor object being created and the second monitor being silently discarded. Key evidence: DeviceFactory.cpp:56 (no loongarch64 branch), DeviceGenerator.cpp:310-316 (base class only calls getMonitorInfoFromHwinfo()), HWGenerator.cpp:459-492 (/sys/class/drm EDID enumeration path not used for Loongson).

Fix Approach

Added a loongarch64 branch in DeviceFactory::getDeviceGenerator() that routes to HWGenerator, which uses the /sys/class/drm EDID enumeration logic to correctly detect multiple monitors. The change is a 2-line addition after the aarch64 branch and before the else fallback, matching the existing pattern of architecture-based routing.

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • The target code (the else fallback to X86Generator) has been the default since initial introduction; this change adds a new branch without modifying the fallback behavior for other architectures. Historical commits show a consistent pattern of adding new architecture/机型 branches without altering the else logic.
  • Both callers (GenerateDevicePool.cpp:27 and GenerateDevicePool.cpp:135) use the base class DeviceGenerator * interface and do not depend on the concrete generator subtype, so the new branch is fully compatible.

Business Impact Scope

  • Device Manager — Device Information Collection: On loongarch64 platforms, the generator type changes from X86Generator to HWGenerator, affecting all device info generation (monitor, CPU, memory, disk, NIC, etc.). The core fix target is monitor detection.
  • Device Manager — Display Device Page: Dual-monitor environments on Loongson with JM7200 GPU should now display both monitors correctly.
  • Other architectures (x86_64, mips64, aarch64) are unaffected — no behavior change.

Verification Suggestion

Verify dual-monitor display on the target machine (Hikvision XC-P720P, JM7200 GPU) and confirm HWGenerator's other device generation methods (CPU/memory/disk/NIC) work correctly on the Loongson platform. Regression-test x86_64/aarch64/mips64 to confirm no impact.


根因分析

DeviceFactory::getDeviceGenerator() 未识别 loongarch64 架构,导致龙芯平台落入 else 分支创建 X86Generator。该生成器继承基类 generatorMonitorDevice(),仅依赖 hwinfo --monitor 采集显示器信息。在 JM7200 GPU 环境下 hwinfo 检测不完整,只创建一个 DeviceMonitor 对象,第二台显示器被静默丢弃。关键证据:DeviceFactory.cpp:56(无 loongarch64 分支)、DeviceGenerator.cpp:310-316(基类仅调用 getMonitorInfoFromHwinfo())、HWGenerator.cpp:459-492/sys/class/drm EDID 枚举路径未被龙芯平台使用)。

修复方案

DeviceFactory::getDeviceGenerator() 中增加 loongarch64 分支,路由到 HWGenerator,复用其 /sys/class/drm EDID 枚举逻辑正确检测多屏。改动为 aarch64 分支之后、else 分支之前新增 2 行,与现有架构路由模式一致。

改动安全评估

代码安全评估

  • 风险等级: 低风险
  • 目标代码(else 兜底创建 X86Generator)自初始引入以来未变本质,本次改动新增分支不修改兜底逻辑。历史提交呈一致的"新增架构/机型分支"模式,本次修复符合该模式。
  • 两处调用者(GenerateDevicePool.cpp:27GenerateDevicePool.cpp:135)均使用基类 DeviceGenerator * 接口,不依赖具体生成器子类型,新增分支完全兼容。

业务影响范围

  • 设备管理器 — 设备信息采集loongarch64 平台上生成器类型从 X86Generator 变为 HWGenerator,影响所有设备信息生成(显示器、CPU、内存、磁盘、网卡等)。核心修复目标为显示器检测。
  • 设备管理器 — 显示设备页面:龙芯 JM7200 GPU 双屏环境下应能正确显示两台显示器信息。
  • 其他架构(x86_64、mips64、aarch64)不受影响,无行为变化。

验证建议

在目标机器(海康威视 XC-P720P, JM7200 GPU)上验证双屏显示,并确认 HWGenerator 其他设备生成方法(CPU/内存/磁盘/网卡)在龙芯平台正常工作。回归验证 x86_64/aarch64/mips64 确认无影响。

Summary by Sourcery

Bug Fixes:

  • Route loongarch64 devices to the hardware generator so monitor detection correctly supports Loongson platforms, including multi-monitor setups.

1. Root cause: DeviceFactory::getDeviceGenerator() did not recognize
   loongarch64 architecture, falling through to X86Generator which
   relies solely on hwinfo --monitor for display detection
2. Fix: add loongarch64 branch routing to HWGenerator, which uses
   /sys/class/drm EDID enumeration for complete multi-monitor detection
3. Impact: only affects loongarch64 platform, other architectures
   remain unchanged

Log: fix dual-monitor detection on Loongson platform with JM7200 GPU

Influence:
1. Test dual-monitor display on Loongson platform with JM7200 GPU
2. Verify other device info (CPU/memory/disk/NIC) displays normally
3. Verify x86_64/aarch64/mips64 platforms have no regression

fix: 设备生成器添加 loongarch64 架构支持

1. 根因:DeviceFactory::getDeviceGenerator() 未识别 loongarch64 架构,
   落入 else 分支创建 X86Generator,该生成器仅依赖 hwinfo --monitor
   采集显示器信息,JM7200 GPU 环境下检测不完整
2. 方案:增加 loongarch64 分支路由到 HWGenerator,复用 /sys/class/drm
   EDID 枚举逻辑,正确处理多屏检测
3. 影响:仅影响 loongarch64 平台,其他架构行为不变

Log: 修复龙芯平台 JM7200 GPU 环境下双屏检测不完整的问题

Influence:
1. 在龙芯平台 JM7200 GPU 环境下测试双屏显示
2. 验证其他设备信息(CPU/内存/磁盘/网卡)正常显示
3. 验证 x86_64/aarch64/mips64 平台无回归

PMS: BUG-225103

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

Sorry @pengfeixx, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 5 days and 10 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: pengfeixx

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

@sourcery-ai

sourcery-ai Bot commented Sep 16, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds a dedicated loongarch64 factory branch that selects HWGenerator, allowing Loongson JM7200 systems to use /sys/class/drm EDID enumeration and correctly detect multiple monitors while preserving existing behavior for other architectures.

Flow diagram for architecture-based device generator selection

flowchart TD
    A[DeviceFactory::getDeviceGenerator] --> B{Architecture}
    B -->|loongarch64| C[HWGenerator]
    B -->|aarch64| D[ArmGenerator or HWGenerator]
    B -->|other architectures| E[X86Generator]
    C --> F[Device information generation]
    F --> G["/sys/class/drm EDID enumeration"]
    G --> H[Multiple monitors detected]
Loading

File-Level Changes

Change Details Files
Route LoongArch64 systems to the hardware-specific device generator.
  • Add an architecture check for loongarch64.
  • Instantiate HWGenerator for LoongArch64 instead of the X86 fallback, enabling DRM/EDID-based monitor discovery.
deepin-devicemanager/src/GenerateDevice/DeviceFactory.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
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 100 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 100 分,大于 70 分通过阈值,代码质量符合要求。本次变更为 DeviceFactory::getDeviceGenerator() 新增 loongarch64 架构分支,路由到 HWGenerator,修复龙芯平台 JM7200 GPU 环境下双屏检测不完整的问题。变更简洁、逻辑清晰、无安全风险。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 语法正确,逻辑清晰,无需修改


2. 代码质量 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 代码结构清晰,与现有 if-else-if 链风格一致,无需修改


3. 代码性能 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 性能良好,仅增加一次字符串比较,无需优化


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: 安全合规,无需修改


💡 改进建议代码示例

// 当前代码已符合规范,无需修改
// DeviceFactory.cpp 第56-57行新增分支:
// } else if (arch == "loongarch64") {
//     generator = new HWGenerator();
// 该实现正确地将 loongarch64 架构路由到 HWGenerator,
// 使用 /sys/class/drm EDID 枚举逻辑进行多屏检测

本报告由 AI 代码审查工具自动生成

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