Stop presenting stale data as live, and back off broken devices
- readings.py: PowerReadings.total now sums the known parts (None only when nothing is known), with a complete property saying whether it under-counts; the snapshot exposes it as partial and the web UI marks it with a tilde. - display/service.py: telemetry older than 15 s is drawn as -- instead of re-rendering frozen readings as if they were current. - sensors.py: Commander PRO last-known RPMs expire after 10 s instead of feeding the power model forever (empty list = unknown); a runtime MSR failure backs off 15 s instead of re-opening PawnIO every second; GPU NVML reconnects back off 10 s instead of nvmlInit() every second, and the sample-buffer timestamp resets on a driver-reset reconnect. - control.py: CpuTemperature read failures back off 15 s instead of churning the MSR handle every poll.
This commit is contained in:
1 parent
538a464257
commit
9036c6e734
6 files changed
+46
-7
No files matched your search
@@ -22,6 +22,11 @@ class PowerReadings:
|
||||
|
||||
@property
|
||||
def total(self) -> float | None:
|
||||
if self.cpu is None or self.gpu is None or self.other is None:
|
||||
return None
|
||||
return self.cpu + self.gpu + self.other
|
||||
"""The known parts summed; None only when nothing is known. While a part is missing
|
||||
the total under-counts -- `complete` says so."""
|
||||
known = [v for v in (self.cpu, self.gpu, self.other) if v is not None]
|
||||
return sum(known) if known else None
|
||||
|
||||
@property
|
||||
def complete(self) -> bool:
|
||||
return self.cpu is not None and self.gpu is not None and self.other is not None
|
||||
@@ -298,6 +298,10 @@ class IntelPackage:
|
||||
# ----------------------------------------------------------------------------- CPU
|
||||
|
||||
class CpuSensors:
|
||||
# A runtime MSR failure usually means the PawnIO device is gone: pause before re-opening
|
||||
# it, or a broken driver costs a heavy CreateFile+DeviceIoControl every second.
|
||||
RETRY_SECONDS = 15.0
|
||||
|
||||
def __init__(self):
|
||||
base = r"\Processor Information(_Total)"
|
||||
self.pdh = PerfCounters({
|
||||
@@ -347,12 +351,16 @@ class CpuSensors:
|
||||
log.warning("MSR read failed, will retry: %s", e)
|
||||
self.pkg.msr.close()
|
||||
self.pkg = None
|
||||
self._next_pkg_attempt = time.monotonic() + self.RETRY_SECONDS
|
||||
return Readings(temp=temp, load=load, clock=clock, power=power)
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------- GPU
|
||||
|
||||
class GpuSensors:
|
||||
# Pause between re-open attempts while the GPU/driver is gone, like CpuSensors'.
|
||||
RECONNECT_SECONDS = 10.0
|
||||
|
||||
def __init__(self, index: int = 0, load_source: str = "windows"):
|
||||
"""load_source: "windows" = same figure as Task Manager, "nvml" = NVIDIA's kernel-busy figure."""
|
||||
import pynvml
|
||||
@@ -361,6 +369,7 @@ class GpuSensors:
|
||||
self.index = index
|
||||
self.handle = None
|
||||
self._last_sample_ts = 0
|
||||
self._next_connect = 0.0
|
||||
self.engine_load: GpuEngineLoad | None = None
|
||||
if load_source == "windows":
|
||||
try:
|
||||
@@ -418,6 +427,10 @@ class GpuSensors:
|
||||
|
||||
def read(self) -> Readings:
|
||||
if self.handle is None:
|
||||
now = time.monotonic()
|
||||
if now < self._next_connect:
|
||||
return Readings()
|
||||
self._next_connect = now + self.RECONNECT_SECONDS
|
||||
self._connect()
|
||||
if self.handle is None:
|
||||
return Readings()
|
||||
@@ -441,6 +454,7 @@ class GpuSensors:
|
||||
except Exception:
|
||||
pass
|
||||
self.handle = None
|
||||
self._last_sample_ts = 0 # the driver's sample buffer restarts with the driver
|
||||
return Readings(
|
||||
temp=None if temp is None else float(temp),
|
||||
load=util,
|
||||
@@ -596,6 +610,9 @@ class CommanderPro:
|
||||
CMD_FAN_RPM = 0x21
|
||||
PORTS = 6
|
||||
RECHECK = 30.0
|
||||
# Last known RPMs must not feed the power model forever: after this long without a
|
||||
# successful read the fan speeds are unknown, not merely stale.
|
||||
RPM_STALE = 10.0
|
||||
|
||||
def __init__(self):
|
||||
self.ch: HidChannel | None = None
|
||||
@@ -605,6 +622,7 @@ class CommanderPro:
|
||||
self.ports: list[int] = []
|
||||
self.rpm: dict[int, int] = {}
|
||||
self._next_check = 0.0
|
||||
self._read_at = 0.0
|
||||
self._note: str | None = None
|
||||
|
||||
def _say(self, note: str) -> None:
|
||||
@@ -678,13 +696,17 @@ class CommanderPro:
|
||||
for p in self.ports:
|
||||
r = self._cmd(self.CMD_FAN_RPM, p)
|
||||
self.rpm[p] = (r[2] << 8) | r[3]
|
||||
self._read_at = time.monotonic()
|
||||
return {p + 1: rpm for p, rpm in self.rpm.items()}
|
||||
|
||||
def _fresh_rpms(self) -> bool:
|
||||
return time.monotonic() - self._read_at <= self.RPM_STALE
|
||||
|
||||
def read(self) -> list[int]:
|
||||
"""RPM of each connected fan (the last known values while iCUE has the device)."""
|
||||
"""RPM of each connected fan; empty while the device is lost or held by other software."""
|
||||
with self._lock:
|
||||
if self.controlled:
|
||||
return list(self.rpm.values())
|
||||
return list(self.rpm.values()) if self._fresh_rpms() else []
|
||||
return self._read()
|
||||
|
||||
def _read(self) -> list[int]:
|
||||
@@ -712,9 +734,12 @@ class CommanderPro:
|
||||
for p in self.ports:
|
||||
r = self._cmd(self.CMD_FAN_RPM, p)
|
||||
self.rpm[p] = (r[2] << 8) | r[3]
|
||||
self._read_at = time.monotonic()
|
||||
except Exception as e:
|
||||
self.close()
|
||||
self._say(f"lost ({e}), retrying in {self.RECHECK:.0f} s")
|
||||
if not self._fresh_rpms():
|
||||
return []
|
||||
return [self.rpm[p] for p in self.ports if p in self.rpm]
|
||||
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ class Telemetry:
|
||||
"vram_used": None if s.vram is None else s.vram[0],
|
||||
"vram_total": None if s.vram is None else s.vram[1]},
|
||||
"power": {"cpu": _r(s.power.cpu), "gpu": _r(s.power.gpu), "other": _r(s.power.other),
|
||||
"total": _r(s.power.total),
|
||||
"total": _r(s.power.total), "partial": not s.power.complete,
|
||||
"parts": {k: round(v, 1) for k, v in s.power.parts.items()}},
|
||||
"row": s.row(),
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user