Skip to content

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

Closed
Lightmarey wants to merge 1 commit into
Clearailhc:mainfrom
Lightmarey:fix-asus-charge-and-psys
Closed

Lightmarey wants to merge 1 commit into
Clearailhc:mainfrom
Lightmarey:fix-asus-charge-and-psys

Conversation

@Lightmarey

Copy link
Copy Markdown

摘要

此 PR 修复了华硕(及类似厂商)笔记本电脑上的两个硬件兼容性问题:

  1. 单阈值充电控制:当 charge_control_start_threshold 缺失时,防止因 FileNotFoundError 导致的回滚。
  2. 异常 psys 处理:拒绝处理已禁用(enabled: 0)的 intel-rapl psys 域;这些域报告的空闲计数器漂移微乎其微,却会导致实际 CPU 功耗读数被强制压低至 0.5 W 以下。

根本原因与修复方案

1. 单阈值充电控制(例如 asus-wmi)

  • 问题:华硕笔记本电脑(以及部分 HP、LG 和华为机型)仅暴露了 /sys/class/power_supply/BAT0/charge_control_end_threshold,而没有相应的 charge_control_start_threshold。_write_thresholds() 方法在执行时无条件尝试写入这两个阈值,从而引发 FileNotFoundError(OSError 的子类)。这导致 set_limit() 将 self.limit 回滚至 100%,并使 apply_startup() 失败。
  • 修复:在写入阈值之前,先验证文件是否存在。

2. 已禁用/异常的 psys 能量域

  • 问题:在华硕 ProArt Studiobook (i9-12900H) 上,/sys/class/powercap/intel-rapl:1 (psys) 虽存在但其 enabled 状态为 0,且能量计数器仅有约 0.3 W 的漂移。由于满足了 psys > 0 的条件,Sampler 将 psys 视为权威的平台总功耗数据。由于存在 measured > sys_w 的情况(例如 CPU 封装功耗约为 22 W,而 psys 仅约 0.3 W),归一化因子 k = 0.3 / 22 ≈ 0.014 导致 CPU 显示功耗被强制压低至 0.2 W,同时屏幕及其他节点的功耗读数被归零。 * 修复:
  • 在 Rapl 中,若 enabled == 0,则跳过名为 psys 的域。
  • 在 Sampler 中,将 psys 采纳为整机功耗源之前,先验证其是否满足 psys >= package * 0.7。

验证

  • 已在 ASUS ProArt Studiobook 16 (H7600ZM, CachyOS / GNOME 48) 上进行本地测试。
  • python3 -m unittest discover -s daemon/tests -v 测试顺利通过。
  • charge_control_end_threshold 正确显示为 80%,且未发生回退。
  • 交流电源(AC)模式下的整机功耗与 CPU 封装功耗读数已恢复至合理数值。

- 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.
@Lightmarey
Lightmarey force-pushed the fix-asus-charge-and-psys branch from 07cdd61 to b17251e Compare October 3, 2026 12:59
@Lightmarey Lightmarey closed this Oct 3, 2026
@Lightmarey
Lightmarey deleted the fix-asus-charge-and-psys branch October 3, 2026 13:03
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