Skip to content

Commit f63fc94

Browse files
[thermalctld] Use interval set in thermal policy if available (sonic-net#164)
Description Update thermalctld to retrieve interval from thermal manager (which in turn loads an interval from thermal_policy.json) instead of using a constant. Motivation and Context sonic-net/sonic-platform-common#178 This will allow platform vendors to specify an alternate interval for running thermal policies, e.g. 15 seconds instead of the current 60. How Has This Been Tested? Verified that thermalctld runs without exiting. Also ran test_thermalctld.py
1 parent 8b2227d commit f63fc94

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

sonic-thermalctld/scripts/thermalctld

+5-2
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,8 @@ class ThermalControlDaemon(daemon_base.DaemonBase):
774774
self.thermal_manager.initialize()
775775
self.thermal_manager.load(ThermalControlDaemon.POLICY_FILE)
776776
self.thermal_manager.init_thermal_algorithm(self.chassis)
777+
# Use thermal manager interval if it's available
778+
self.wait_time = self.thermal_manager.get_interval()
777779
except NotImplementedError:
778780
self.log_warning('Thermal manager is not supported on this platform')
779781
except Exception as e:
@@ -832,9 +834,10 @@ class ThermalControlDaemon(daemon_base.DaemonBase):
832834
except Exception as e:
833835
self.log_error('Caught exception while running thermal policy - {}'.format(repr(e)))
834836

837+
interval = self.thermal_manager.get_interval() if self.thermal_manager else self.INTERVAL
835838
elapsed = time.time() - begin
836-
if elapsed < self.INTERVAL:
837-
self.wait_time = self.INTERVAL - elapsed
839+
if elapsed < interval:
840+
self.wait_time = interval - elapsed
838841
else:
839842
self.wait_time = self.FAST_START_INTERVAL
840843

sonic-thermalctld/tests/test_thermalctld.py

+2
Original file line numberDiff line numberDiff line change
@@ -651,12 +651,14 @@ def test_signal_handler():
651651
def test_daemon_run():
652652
daemon_thermalctld = thermalctld.ThermalControlDaemon()
653653
daemon_thermalctld.stop_event.wait = mock.MagicMock(return_value=True)
654+
daemon_thermalctld.thermal_manager.get_interval = mock.MagicMock(return_value=60)
654655
ret = daemon_thermalctld.run()
655656
daemon_thermalctld.deinit() # Deinit becuase the test will hang if we assert
656657
assert ret is False
657658

658659
daemon_thermalctld = thermalctld.ThermalControlDaemon()
659660
daemon_thermalctld.stop_event.wait = mock.MagicMock(return_value=False)
661+
daemon_thermalctld.thermal_manager.get_interval = mock.MagicMock(return_value=60)
660662
ret = daemon_thermalctld.run()
661663
daemon_thermalctld.deinit() # Deinit becuase the test will hang if we assert
662664
assert ret is True

0 commit comments

Comments
 (0)