Skip to content

fix(daemon): support single-threshold charging and reject invalid psys - #3

Open
Lightmarey wants to merge 3 commits into
Clearailhc:mainfrom
Lightmarey:feat-asus-fans-and-nvidia
Open

Lightmarey wants to merge 3 commits into
Clearailhc:mainfrom
Lightmarey:feat-asus-fans-and-nvidia

Conversation

@Lightmarey

Copy link
Copy Markdown

摘要

本 PR 修复了华硕笔记本电脑(以及其他采用类似 EC 固件的设备)上的两个硬件兼容性问题:

  1. 单阈值充电 (charge_control.py):
  • 在华硕笔记本电脑上,内核驱动程序 (asus-wmi) 仅公开了 charge_control_end_threshold,而不存在 start_threshold 对应的 sysfs 节点。
  • 向 p_start 写入数据时会引发 FileNotFoundError,进而触发异常处理程序,导致充电限制回退至 100%。
  • 修复方案:在尝试写入阈值之前,先检查路径是否存在 (os.path.exists(path))。
  1. 禁用的 psys 过滤 (rapl.py 和 sampler.py):
  • 在 Alder Lake 架构设备上,如果固件禁用了 intel-rapl:1 (psys)(即 enabled == 0),计数器会产生漂移,表现为微不足道的空闲噪声(约 0.3 W)。
  • ClearPower 误将该噪声视为真实的平台功耗,导致实际约 15 W 的 CPU 功耗被错误地压缩至不足 1 W。
  • 修复方案:在 rapl.py 中跳过 enabled == 0 的区域;在 sampler.py 中,仅当 psys 读数至少达到封装功耗 (package power) 的 70% 时,才将其视为可信数据。

测试环境

  • ASUS ProArt Studiobook 16 OLED (H7600ZM),Intel Core i9-12900H,CachyOS Linux (内核 7.2.x)。

- charge_control: on ASUS and other laptops that expose only
  charge_control_end_threshold without start_threshold, writing to p_start
  raised FileNotFoundError, causing set_limit to roll back to 100% and
  startup initialization to fail. Check path existence before writing.
- rapl: on machines where intel-rapl:1 (psys) is disabled in hardware
  (enabled == 0), the counter drifts with negligible idle noise (~0.3 W).
  Filter out disabled psys zones and validate psys against package power
  to prevent crushing real CPU wattage into fractions of a watt.
- hwmon: detect dual fans on ASUS laptops via asus-nb-wmi hwmon.
- sources.nvidia: add NvidiaGpu reading power usage (W) and temperature (C)
  via ctypes binding to libnvidia-ml.so.1 (NVML). Check PCI sysfs
  runtime_status so NVML is not queried when the card is suspended in
  D3cold/D3hot, preserving hardware runtime suspend.
- sampler: incorporate dGPU power into smoothed telemetry, whole-system power
  breakdown (gpu_w = igpu_w + dgpu_w), and fallback estimates.
- display_cal: validate that calibration points have non-zero slope before
  reporting calibrated status.
@Lightmarey

Copy link
Copy Markdown
Author

摘要

增加了对华硕(ASUS)双风扇遥测数据的支持,以及通过 NVML 监控 NVIDIA 独立显卡的功能,并针对混合显卡笔记本电脑加入了明确的运行时挂起(runtime suspend)保护机制。

主要变更

  1. NVIDIA GPU 监控 (sources/nvidia.py):
  • 通过 ctypes 绑定 libnvidia-ml.so.1 读取独立显卡的功耗(单位:瓦特/W)和核心温度(单位:摄氏度/°C)。
  • D3cold / 运行时电源管理(Runtime PM)休眠保护:在调用 NVML 之前检查 /sys/bus/pci/devices/.../power/runtime_status。如果显卡处于 suspended(挂起)状态,则报告功耗为 0 W 且不调用 NVML,从而确保独立显卡(dGPU)保持在 0 W 深度休眠状态,避免因遥测轮询而被唤醒。
  • 752 W 异常值过滤:针对移动端 GPU 上已知的 SBIOS/EC 硬件异常(即断开交流电源时偶尔报告 752.4 W 的功耗)进行防护,通过与 nvmlDeviceGetPowerManagementLimitConstraints 的限制值进行比对来验证数据有效性。
  1. 华硕双风扇 (sources/hwmon.py):
  • 检测 asus-nb-wmi hwmon 节点,以报告 CPU 风扇 (fan1_input) 和 GPU 风扇 (fan2_input) 的数据。
  • 支持在独立显卡挂起时报告 0 RPM(即 0dB 风扇停转模式)而不报错。
  1. 整机功耗细分 (sampler.py):
  • 将独立显卡功耗 (dgpu) 纳入总 GPU 功耗计算:gpu_w = igpu_w + dgpu。
  • 在计算用于显示器校准和外设的剩余平台功耗时,扣除独立显卡功耗 (dgpu)。

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.

1 participant