Skip to content

Commit

Permalink
[thermalctld] Use interval set in thermal policy if available (#164)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
andywongarista authored Aug 6, 2021
1 parent 8b2227d commit f63fc94
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions sonic-thermalctld/scripts/thermalctld
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,8 @@ class ThermalControlDaemon(daemon_base.DaemonBase):
self.thermal_manager.initialize()
self.thermal_manager.load(ThermalControlDaemon.POLICY_FILE)
self.thermal_manager.init_thermal_algorithm(self.chassis)
# Use thermal manager interval if it's available
self.wait_time = self.thermal_manager.get_interval()
except NotImplementedError:
self.log_warning('Thermal manager is not supported on this platform')
except Exception as e:
Expand Down Expand Up @@ -832,9 +834,10 @@ class ThermalControlDaemon(daemon_base.DaemonBase):
except Exception as e:
self.log_error('Caught exception while running thermal policy - {}'.format(repr(e)))

interval = self.thermal_manager.get_interval() if self.thermal_manager else self.INTERVAL
elapsed = time.time() - begin
if elapsed < self.INTERVAL:
self.wait_time = self.INTERVAL - elapsed
if elapsed < interval:
self.wait_time = interval - elapsed
else:
self.wait_time = self.FAST_START_INTERVAL

Expand Down
2 changes: 2 additions & 0 deletions sonic-thermalctld/tests/test_thermalctld.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,12 +651,14 @@ def test_signal_handler():
def test_daemon_run():
daemon_thermalctld = thermalctld.ThermalControlDaemon()
daemon_thermalctld.stop_event.wait = mock.MagicMock(return_value=True)
daemon_thermalctld.thermal_manager.get_interval = mock.MagicMock(return_value=60)
ret = daemon_thermalctld.run()
daemon_thermalctld.deinit() # Deinit becuase the test will hang if we assert
assert ret is False

daemon_thermalctld = thermalctld.ThermalControlDaemon()
daemon_thermalctld.stop_event.wait = mock.MagicMock(return_value=False)
daemon_thermalctld.thermal_manager.get_interval = mock.MagicMock(return_value=60)
ret = daemon_thermalctld.run()
daemon_thermalctld.deinit() # Deinit becuase the test will hang if we assert
assert ret is True
Expand Down

0 comments on commit f63fc94

Please sign in to comment.