Top fans: stall detection from the tach registers, and no manual duty left behind
- control.py: TopFanCurve reads the NCT6687D tach registers while the fans are commanded to spin. A channel whose fan was seen turning and then reads 0 RPM on three consecutive polls raises everything to 100% and says FAILSAFE. A channel whose tach has never been seen turning (SYS_FAN1's is not wired on this board) is left alone, so an unwired or empty header cannot cry wolf. The latest readings are in the snapshot. - control.py: CaseFanGroup's stall check now needs three consecutive low readings instead of one; a single glitchy RPM no longer forces 100%. - control.py: when a top-fan write fails, the channels are handed back to the BIOS curve at once (best effort); the status says so, or names the duty the fans are left at when even the hand-back fails. Previously the UI claimed "BIOS curve keeps control" even while the fans sat at a manual duty. - Tests (three new, one reworked, board doubles given rpms) and README updated to match.
This commit is contained in:
1 parent
8969a57045
commit
b2da2213b7
4 files changed
+117
-6
No files matched your search
@@ -38,6 +38,7 @@ class TopFanCurveTest(unittest.TestCase):
|
||||
self.mask = 0
|
||||
self.duties = []
|
||||
self.board.manual_mask.side_effect = lambda: self.mask
|
||||
self.board.rpms.return_value = [0] * 16 # nothing has been seen turning yet
|
||||
|
||||
def manual(ch, duty):
|
||||
self.mask |= 0x24
|
||||
@@ -110,6 +111,49 @@ class TopFanCurveTest(unittest.TestCase):
|
||||
top.update(100, 60, 31)
|
||||
self.board.set_manual.assert_called_once_with((2, 5), 100)
|
||||
|
||||
def test_a_failed_write_hands_the_fans_back_to_the_bios_curve(self):
|
||||
self.top.update(40, 70, 0) # manual 100% written on channels 2,5
|
||||
self.mask = 0 # the EC forgot (sleep, crash): a rewrite is due ...
|
||||
self.board.set_manual.side_effect = OSError("bus busy") # ... and fails
|
||||
with self.assertLogs("kurgan.cooling.control", level="WARNING"):
|
||||
self.top.update(40, 70, 1)
|
||||
self.board.set_auto.assert_called_with((2, 5))
|
||||
self.assertIn("BIOS curve keeps control", self.top.status)
|
||||
|
||||
def test_a_failed_hand_back_says_what_the_fans_are_left_at(self):
|
||||
self.top.update(40, 70, 0)
|
||||
self.mask = 0
|
||||
self.board.set_manual.side_effect = OSError("bus busy")
|
||||
self.board.set_auto.side_effect = OSError("still busy") # even the hand-back fails
|
||||
with self.assertLogs("kurgan.cooling.control", level="WARNING"):
|
||||
self.top.update(40, 70, 1)
|
||||
self.assertIn("held at the last written duty (100%)", self.top.status)
|
||||
|
||||
def test_a_top_fan_that_stops_turning_is_detected(self):
|
||||
tachs = [0] * 16
|
||||
self.board.rpms.return_value = tachs
|
||||
for now in range(10): # spinning, but no tach has been seen turning: no evidence yet
|
||||
self.top.update(40, 55, now)
|
||||
self.assertNotIn("FAILSAFE", self.top.status)
|
||||
tachs[2], tachs[5] = 1500, 1400
|
||||
self.top.update(40, 55, 10)
|
||||
self.top.update(40, 55, 11)
|
||||
self.assertNotIn("FAILSAFE", self.top.status) # learned: both tachs turn
|
||||
tachs[5] = 0
|
||||
self.top.update(40, 55, 12)
|
||||
self.top.update(40, 55, 13)
|
||||
self.assertNotIn("FAILSAFE", self.top.status) # one glitchy reading is not a stall
|
||||
with self.assertLogs("kurgan.cooling.control", level="WARNING"):
|
||||
self.top.update(40, 55, 14)
|
||||
self.assertIn("FAILSAFE", self.top.status)
|
||||
self.assertIn("[5]", self.top.status)
|
||||
self.assertEqual(self.top.duty, 100)
|
||||
self.board.set_manual.assert_called_with((2, 5), 100)
|
||||
tachs[5] = 1300 # the fan turns again: the failsafe lifts on the next poll
|
||||
self.top.update(40, 55, 15)
|
||||
self.assertNotIn("FAILSAFE", self.top.status)
|
||||
self.assertEqual(self.top.snapshot()["rpms"], {"2": 1500, "5": 1300})
|
||||
|
||||
def test_gpu_worker_drives_top_fans_and_releases_them_on_exit(self):
|
||||
commander = Mock(spec=CommanderPro)
|
||||
commander.set_duty.return_value = {p: 900 for p in range(1, 7)}
|
||||
@@ -224,8 +268,13 @@ class FanWorkerTest(unittest.TestCase):
|
||||
self.commander.set_duty.return_value = {1: 0, 4: 900, 5: 900, 6: 900}
|
||||
self.settle()
|
||||
self.assertNotIn("FAILSAFE", self.control.status)
|
||||
# One glitchy reading is not a stall; STALL_READINGS in a row are.
|
||||
self.commander.set_duty.return_value = {4: 900, 5: 0, 6: 900}
|
||||
self.control.update(50, 36)
|
||||
self.control.update(50, 37)
|
||||
self.assertNotIn("FAILSAFE", self.control.status)
|
||||
self.commander.set_duty.reset_mock()
|
||||
self.control.update(50, 38)
|
||||
self.commander.set_duty.assert_called_with((4, 5, 6), 100)
|
||||
self.assertIn("FAILSAFE", self.control.status)
|
||||
self.assertIn("[5]", self.control.status)
|
||||
|
||||
@@ -34,6 +34,7 @@ class ProfileSwitchTest(unittest.TestCase):
|
||||
self.commander.set_duty.side_effect = lambda ports, duty: {p: 1200 for p in ports}
|
||||
board = Mock(spec=Nct6687)
|
||||
board.manual_mask.return_value = 0x24
|
||||
board.rpms.return_value = [0] * 16 # no tach has been seen turning: stall detection stays quiet
|
||||
self.top = TopFanCurve((2, 5), board_factory=lambda: board)
|
||||
self.fans = CaseFanControl(self.commander, (4, 5, 6), (1, 2, 3), top=self.top, profile=BALANCED)
|
||||
self.now = 0.0
|
||||
|
||||
Reference in new issue
Block a user