Skip to content

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

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
GongHeng2017:agent/uos-pmo/ddd670883772
Nov 6, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
GongHeng2017:agent/uos-pmo/ddd670883772

Conversation

@GongHeng2017

@GongHeng2017 GongHeng2017 commented Nov 5, 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

PMS: BUG-380847

Migrate from develop/eagle PR #959 to master.

Summary by Sourcery

Bug Fixes:

  • Add a DRM sysfs fallback to report GPU VRAM for devices whose existing hardware information sources provide no memory value.

@sourcery-ai

sourcery-ai Bot commented Nov 5, 2026

Copy link
Copy Markdown

Reviewer's Guide

When hwinfo/amdgpu detection leaves VRAM unset, the GPU device code now identifies the corresponding DRM card by PCI BDF and reads its sysfs vram_size, while preserving existing reporting paths and formatting the fallback value in GB or MB.

Sequence diagram for DRM sysfs VRAM fallback

sequenceDiagram
    participant GPU as DeviceGpu
    participant Hwinfo as hwinfo/amdgpu
    participant DRM as DRM sysfs
    participant File as vram_size

    GPU->>Hwinfo: setHwinfoInfo(mapInfo)
    alt m_GraphicsMemory is not empty
        Hwinfo-->>GPU: Existing VRAM value
    else m_GraphicsMemory is empty
        GPU->>GPU: Extract PCI BDF from m_SysPath
        GPU->>DRM: Enumerate /sys/class/drm/card[0-9]*
        DRM-->>GPU: Card directories
        GPU->>DRM: Resolve card/device symlink
        alt PCI BDF matches
            GPU->>File: Read card/device/vram_size
            File-->>GPU: VRAM size in MB
            GPU->>GPU: Format value as GB or MB
        end
    end
Loading

File-Level Changes

Change Details Files
Add a DRM sysfs fallback for GPU VRAM detection when existing hardware-information data is unavailable.
  • Extract the GPU PCI BDF from the device sysfs path.
  • Enumerate DRM card directories and skip connector entries.
  • Match the GPU to its DRM card through the device symlink target.
  • Read and parse vram_size, formatting values in GB or MB based on size.
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 2 issues

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="247-249" />
<code_context>
+                    memFile.close();
+                    bool ok;
+                    quint64 vramMB = memStr.toULongLong(&ok);
+                    if (ok && vramMB >= 1024) {
+                        m_GraphicsMemory = QString::number(vramMB / 1024) + "GB";
+                    } else {
+                        m_GraphicsMemory = QString::number(vramMB) + "MB";
+                    }
</code_context>
<issue_to_address>
**VRAM capacities are vastly overstated**

When the DRM fallback reads a valid `vram_size` value, `vram_size` reports bytes, but the fallback treats the value as megabytes and divides by only 1024 for GB (or labels the raw bytes as MB), so a multi-GiB GPU is displayed with a vastly overstated capacity.

Convert the byte count to the intended unit before formatting the capacity.
</issue_to_address>

### Comment 2
<location path="deepin-devicemanager/src/DeviceManager/DeviceGpu.cpp" line_range="242-254" />
<code_context>
+                if (!devicePath.contains(pciBdf))
+                    continue;
+                QFile memFile(QString("/sys/class/drm/%1/device/vram_size").arg(card));
+                if (memFile.open(QIODevice::ReadOnly)) {
+                    QString memStr = memFile.readAll().trimmed();
+                    memFile.close();
+                    bool ok;
+                    quint64 vramMB = memStr.toULongLong(&ok);
+                    if (ok && vramMB >= 1024) {
+                        m_GraphicsMemory = QString::number(vramMB / 1024) + "GB";
+                    } else {
+                        m_GraphicsMemory = QString::number(vramMB) + "MB";
+                    }
+                    break;
+                }
</code_context>
<issue_to_address>
**Fallback failures are invisible**

When the DRM card cannot be matched to the PCI BDF or its `vram_size` file cannot be opened, a failed file open or unmatched DRM card leaves `m_GraphicsMemory` empty without a diagnostic. `setHwinfoInfo` still returns true, so the caller adds the GPU and operators see missing memory without knowing why the fallback failed.

Log when the fallback cannot find a matching card or read its VRAM file.
</issue_to_address>

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

Comment on lines +247 to +249
if (ok && vramMB >= 1024) {
m_GraphicsMemory = QString::number(vramMB / 1024) + "GB";
} else {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 High · VRAM capacities are vastly overstated

When the DRM fallback reads a valid vram_size value, vram_size reports bytes, but the fallback treats the value as megabytes and divides by only 1024 for GB (or labels the raw bytes as MB), so a multi-GiB GPU is displayed with a vastly overstated capacity.

Convert the byte count to the intended unit before formatting the capacity.

Prompt for AI agents
In `deepin-devicemanager/src/DeviceManager/DeviceGpu.cpp` at lines 247-249:

**VRAM capacities are vastly overstated**

When the DRM fallback reads a valid `vram_size` value, `vram_size` reports bytes, but the fallback treats the value as megabytes and divides by only 1024 for GB (or labels the raw bytes as MB), so a multi-GiB GPU is displayed with a vastly overstated capacity.

Convert the byte count to the intended unit before formatting the capacity.

Comment on lines +242 to +254
if (memFile.open(QIODevice::ReadOnly)) {
QString memStr = memFile.readAll().trimmed();
memFile.close();
bool ok;
quint64 vramMB = memStr.toULongLong(&ok);
if (ok && vramMB >= 1024) {
m_GraphicsMemory = QString::number(vramMB / 1024) + "GB";
} else {
m_GraphicsMemory = QString::number(vramMB) + "MB";
}
break;
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚪ Low · Fallback failures are invisible

When the DRM card cannot be matched to the PCI BDF or its vram_size file cannot be opened, a failed file open or unmatched DRM card leaves m_GraphicsMemory empty without a diagnostic. setHwinfoInfo still returns true, so the caller adds the GPU and operators see missing memory without knowing why the fallback failed.

Log when the fallback cannot find a matching card or read its VRAM file.

Prompt for AI agents
In `deepin-devicemanager/src/DeviceManager/DeviceGpu.cpp` at lines 242-254:

**Fallback failures are invisible**

When the DRM card cannot be matched to the PCI BDF or its `vram_size` file cannot be opened, a failed file open or unmatched DRM card leaves `m_GraphicsMemory` empty without a diagnostic. `setHwinfoInfo` still returns true, so the caller adds the GPU and operators see missing memory without knowing why the fallback failed.

Log when the fallback cannot find a matching card or read its VRAM file.

@GongHeng2017
GongHeng2017 force-pushed the agent/uos-pmo/ddd670883772 branch from 22a1154 to 370c5af Compare November 5, 2026 13:55
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

Bug: #380847
Task: #398195

Migrate from develop/eagle PR linuxdeepin#959 to master.
@GongHeng2017
GongHeng2017 force-pushed the agent/uos-pmo/ddd670883772 branch from 370c5af to 197dd29 Compare November 6, 2026 01:30
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@deepin-bot
deepin-bot Bot merged commit d11f499 into linuxdeepin:master Nov 6, 2026
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.

4 participants