Skip to content

fix: read GPU VRAM via DRM sysfs vram_size fallback - #959

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/eaglefrom
GongHeng2017:agent/agent/6c6eb4c20026
Oct 29, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/eaglefrom
GongHeng2017:agent/agent/6c6eb4c20026

Conversation

@GongHeng2017

@GongHeng2017 GongHeng2017 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

fix: read GPU VRAM via DRM sysfs vram_size fallback

  1. Root cause: radeon driver does not expose VRAM size through
    hwinfo, leaving m_GraphicsMemory empty for Turks HD 7600 GPU
  2. Fix: when m_GraphicsMemory is empty, match PCI BDF against
    /sys/class/drm/card*/device symlinks and read vram_size file,
    convert to GB (>=1024 MB) or MB
  3. Impact: only triggers when existing amdgpu/hwinfo paths yield
    empty memory, no regression for GPUs already reporting VRAM

Log: GPU VRAM size now displayed for radeon GPUs via DRM sysfs

Influence:

  1. Verify VRAM displays for radeon GPU (Turks HD 7600)
  2. Verify amdgpu GPUs still show VRAM correctly
  3. Verify multi-GPU systems match correct card by PCI BDF

fix: 通过 DRM sysfs vram_size 回退读取显卡显存

  1. 根因:radeon 驱动不通过 hwinfo 暴露显存大小,导致 Turks HD 7600
    显卡的 m_GraphicsMemory 为空
  2. 方案:当 m_GraphicsMemory 为空时,通过 PCI BDF 匹配
    /sys/class/drm/card*/device 符号链接,读取 vram_size 文件,
    按 >=1024 转 GB 否则 MB 填入显存
  3. 影响:仅在已有 amdgpu/hwinfo 路径返回空显存时触发,
    对已正常报告显存的 GPU 无回归

Log: radeon 显卡显存通过 DRM sysfs 正常显示

Influence:

  1. 测试 radeon 显卡(Turks HD 7600)显存是否正常显示
  2. 测试 amdgpu 显卡显存显示无回归
  3. 测试多显卡场景下 PCI BDF 匹配正确 card

PMS: BUG-380847

Summary by Sourcery

Restore GPU VRAM reporting by falling back to the DRM sysfs vram_size value when standard GPU information is unavailable.

Bug Fixes:

  • Add a DRM sysfs fallback to display VRAM for GPUs whose existing hardware information does not report memory, including radeon devices.

Enhancements:

  • Match DRM cards to GPUs by PCI address and format detected VRAM in MB or GB while preserving existing reporting paths.

@GongHeng2017
GongHeng2017 marked this pull request as draft October 29, 2026 06:28
@GongHeng2017
GongHeng2017 force-pushed the agent/agent/6c6eb4c20026 branch from e4f8b42 to fbf4a7c Compare October 29, 2026 06:46
@sourcery-ai

sourcery-ai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Restores VRAM reporting for radeon GPUs by conditionally matching the GPU to its DRM sysfs card through PCI BDF and reading vram_size, without changing behavior when existing amdgpu or hwinfo detection already reports memory.

Sequence diagram for GPU VRAM DRM sysfs fallback

sequenceDiagram
    participant DeviceGpu
    participant Hwinfo
    participant DrmSysfs
    participant Vram

    DeviceGpu->>Hwinfo: setHwinfoInfo(mapInfo)
    alt m_GraphicsMemory is empty
        DeviceGpu->>DrmSysfs: entryList(card[0-9]*)
        loop DRM cards
            DeviceGpu->>DrmSysfs: symLinkTarget(card/device)
            alt PCI BDF matches
                DeviceGpu->>Vram: open(card/device/vram_size)
                Vram-->>DeviceGpu: readAll()
                DeviceGpu->>DeviceGpu: toULongLong()
                alt vramMB >= 1024
                    DeviceGpu->>DeviceGpu: QString::number(vramMB / 1024)
                else vramMB < 1024
                    DeviceGpu->>DeviceGpu: QString::number(vramMB)
                end
            end
        end
    else VRAM already reported
        DeviceGpu->>DeviceGpu: preserve m_GraphicsMemory
    end
Loading

File-Level Changes

Change Details Files
Add a DRM sysfs fallback for GPU VRAM detection when existing hardware information leaves the memory field empty.
  • Derive the GPU PCI BDF from the device sysfs path.
  • Enumerate DRM card directories and match each card’s device symlink to the GPU PCI BDF, skipping connector entries.
  • Read and parse the matched card’s vram_size value.
  • Format values of at least 1024 MB as whole GB, otherwise as MB, while retaining existing detection paths.
deepin-devicemanager/src/DeviceManager/DeviceGpu.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

@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 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="deepin-devicemanager/src/DeviceManager/DeviceGpu.cpp" line_range="214" />
<code_context>
+                    if (ok && vramMB >= 1024) {
+                        m_GraphicsMemory = QString::number(vramMB / 1024.0, 'f', 0) + "GB";
+                    } else {
+                        m_GraphicsMemory = QString::number(vramMB) + "MB";
+                    }
+                    break;
</code_context>
<issue_to_address>
**Invalid VRAM appears as zero**

When a matched `vram_size` file contains empty or malformed data, or reports zero, `toULongLong` leaves `ok` false and `vramBytes` at zero for invalid contents, but the MB branch assigns `0MB` and the loop breaks, so the GPU shows a false capacity instead of leaving memory unset or checking another source.

Validate the conversion and reject zero before assigning a capacity or breaking the scan.
</issue_to_address>

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

1. Root cause: radeon driver does not expose VRAM size through
   hwinfo, leaving m_GraphicsMemory empty for Turks HD 7600 GPU
2. Fix: when m_GraphicsMemory is empty, match PCI BDF against
   /sys/class/drm/card*/device symlinks and read vram_size file,
   use value directly as MB (>=1024 converts to GB via integer
   division), special customization for this GPU model
3. Impact: only triggers when existing amdgpu/hwinfo paths yield
   empty memory, no regression for GPUs already reporting VRAM

Log: GPU VRAM size now displayed for radeon GPUs via DRM sysfs

Influence:
1. Verify VRAM displays for radeon GPU (Turks HD 7600)
2. Verify amdgpu GPUs still show VRAM correctly
3. Verify multi-GPU systems match correct card by PCI BDF

fix: 通过 DRM sysfs vram_size 回退读取显卡显存

1. 根因:radeon 驱动不通过 hwinfo 暴露显存大小,导致 Turks HD 7600
   显卡的 m_GraphicsMemory 为空
2. 方案:当 m_GraphicsMemory 为空时,通过 PCI BDF 匹配
   /sys/class/drm/card*/device 符号链接,读取 vram_size 文件,
   值直接作为 MB(>=1024 时整数除法转 GB),为此显卡型号特殊定制
3. 影响:仅在已有 amdgpu/hwinfo 路径返回空显存时触发,
   对已正常报告显存的 GPU 无回归

Log: radeon 显卡显存通过 DRM sysfs 正常显示

Influence:
1. 测试 radeon 显卡(Turks HD 7600)显存是否正常显示
2. 测试 amdgpu 显卡显存显示无回归
3. 测试多显卡场景下 PCI BDF 匹配正确 card

PMS: BUG-380847
@GongHeng2017
GongHeng2017 force-pushed the agent/agent/6c6eb4c20026 branch from fbf4a7c to 22591fe Compare October 29, 2026 08:21
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 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

@GongHeng2017

Copy link
Copy Markdown
Contributor Author

/merge

@GongHeng2017
GongHeng2017 marked this pull request as ready for review October 29, 2026 08:49
@GongHeng2017

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot

deepin-bot Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

This pr cannot be merged! (status: unstable)

@GongHeng2017

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: unstable)

@deepin-bot
deepin-bot Bot merged commit 0d1da25 into linuxdeepin:develop/eagle Oct 29, 2026
16 of 17 checks passed

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


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

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