From dd6b5ed8b9a8166907df5f5b8fd09da0939325da Mon Sep 17 00:00:00 2001 From: GershonWang Date: Tue, 14 Jul 2026 10:40:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Intel=E6=A0=B8=E6=98=BE=E5=9B=9E?= =?UTF-8?q?=E9=80=80=E6=95=B0=E6=8D=AE=E6=BA=90=EF=BC=8C=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=B8=A9=E5=BA=A6=E5=92=8C=E5=85=B1=E4=BA=AB=E5=86=85=E5=AD=98?= =?UTF-8?q?=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Intel 核显无 hwmon/gpu_busy_percent/mem_info_vram 等 sysfs 接口, 增加回退逻辑: - 温度:扫描 thermal_zone 匹配 B0D4(Intel GPU ACPI 标识) - 显存:读取 /proc/meminfo 获取系统共享内存总量和已用量 - GPU 使用率:Skylake i915 不支持,仍显示占位符 --- graphicsdriverapplet.cpp | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/graphicsdriverapplet.cpp b/graphicsdriverapplet.cpp index 76fcfd8..02a5237 100644 --- a/graphicsdriverapplet.cpp +++ b/graphicsdriverapplet.cpp @@ -395,6 +395,52 @@ void GraphicsDriverApplet::readGpuStats() } } } + + // --- 以下为 Intel 核显等无 hwmon/vram sysfs 接口时的回退逻辑 --- + + // 温度回退:扫描 thermal_zone,匹配 Intel GPU 的 ACPI 标识 (B0D4) + // B0D4 是 Intel GPU 在 ACPI 规范中的标准热区标识 + if (gpu.temperature < 0) { + QDir thermalDir("/sys/class/thermal"); + QStringList zones = thermalDir.entryList(QStringList() << "thermal_zone*", QDir::Dirs | QDir::NoDotAndDotDot); + for (const QString &zone : zones) { + QFile typeFile(thermalDir.absoluteFilePath(zone + "/type")); + if (typeFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + QString type = QTextStream(&typeFile).readAll().trimmed(); + if (type == "B0D4") { + QFile tempFile(thermalDir.absoluteFilePath(zone + "/temp")); + if (tempFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + int tempMilli = QTextStream(&tempFile).readAll().trimmed().toInt(); + gpu.temperature = tempMilli / 1000; + } + break; + } + } + } + } + + // 显存回退:Intel 核显使用共享系统内存,读取 /proc/meminfo 作为参考 + // 注意:这是系统内存使用量,非核显独占,仅作参考 + if (gpu.memTotal < 0) { + QFile meminfo("/proc/meminfo"); + if (meminfo.open(QIODevice::ReadOnly | QIODevice::Text)) { + QString content = QTextStream(&meminfo).readAll(); + QRegularExpression totalRe("MemTotal:\\s*(\\d+)\\s*kB"); + QRegularExpression availRe("MemAvailable:\\s*(\\d+)\\s*kB"); + auto totalMatch = totalRe.match(content); + auto availMatch = availRe.match(content); + if (totalMatch.hasMatch()) { + gpu.memTotal = totalMatch.captured(1).toLongLong() / 1024; // kB -> MB + } + if (availMatch.hasMatch() && gpu.memTotal > 0) { + qint64 availMB = availMatch.captured(1).toLongLong() / 1024; + gpu.memUsed = gpu.memTotal - availMB; + if (gpu.memUsed >= 0) { + gpu.memUsage = gpu.memUsed * 100 / gpu.memTotal; + } + } + } + } } // 生成统计数据 (格式: temp|gpuUsage|memUsage|memUsed|memTotal)