Skip to content

Commit a575bcf

Browse files
authored
Merge pull request #67 from mssonicbld/sonicbld/202506-merge
```<br>* f68df4d - (HEAD -> 202506) Merge branch '202505' of https://github.com/sonic-net/sonic-platform-daemons into 202506 (2026-04-08) [Sonic Automation] * 8e36084 - (origin/202505) Make polling intervals in the ThermalMonitor class configurable (#781) (2026-04-07) [mssonicbld]<br>```
2 parents 1e3c395 + f68df4d commit a575bcf

2 files changed

Lines changed: 46 additions & 24 deletions

File tree

sonic-thermalctld/scripts/thermalctld

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
from enum import Enum, auto
9+
import argparse
910
import signal
1011
import sys
1112
import threading
@@ -742,23 +743,24 @@ class TemperatureUpdater(logger.Logger):
742743

743744

744745
class ThermalMonitor(ProcessTaskBase):
745-
# Initial update interval
746-
INITIAL_INTERVAL = 5
747746

748-
# Update interval value
749-
UPDATE_INTERVAL = 60
750-
751-
# Update elapse threshold. If update used time is larger than the value, generate a warning log.
752-
UPDATE_ELAPSED_THRESHOLD = 30
753-
754-
def __init__(self, chassis):
747+
def __init__(
748+
self, chassis, initial_interval, update_interval, update_elapsed_threshold
749+
):
755750
"""
756751
Initializer for ThermalMonitor
757752
:param chassis: Object representing a platform chassis
758753
"""
759754
super(ThermalMonitor, self).__init__()
760755

761-
self.wait_time = self.INITIAL_INTERVAL
756+
# Initial update interval
757+
self.initial_interval = initial_interval
758+
# Update interval value
759+
self.update_interval = update_interval
760+
# Update elapse threshold. If update used time is larger than the value, generate a warning log
761+
self.update_elapsed_threshold = update_elapsed_threshold
762+
763+
self.wait_time = self.initial_interval
762764

763765
# TODO: Refactor to eliminate the need for this Logger instance
764766
self.logger = logger.Logger(SYSLOG_IDENTIFIER)
@@ -774,12 +776,12 @@ class ThermalMonitor(ProcessTaskBase):
774776
self.fan_updater.update()
775777
self.temperature_updater.update()
776778
elapsed = time.time() - begin
777-
if elapsed < self.UPDATE_INTERVAL:
778-
self.wait_time = self.UPDATE_INTERVAL - elapsed
779+
if elapsed < self.update_interval:
780+
self.wait_time = self.update_interval - elapsed
779781
else:
780-
self.wait_time = self.INITIAL_INTERVAL
782+
self.wait_time = self.initial_interval
781783

782-
if elapsed > self.UPDATE_ELAPSED_THRESHOLD:
784+
if elapsed > self.update_elapsed_threshold:
783785
self.logger.log_warning('Update fan and temperature status took {} seconds, '
784786
'there might be performance risk'.format(elapsed))
785787

@@ -808,7 +810,12 @@ class ThermalControlDaemon(daemon_base.DaemonBase):
808810

809811
POLICY_FILE = '/usr/share/sonic/platform/thermal_policy.json'
810812

811-
def __init__(self):
813+
def __init__(
814+
self,
815+
thermal_monitor_initial_interval,
816+
thermal_monitor_update_interval,
817+
thermal_monitor_update_elapsed_threshold,
818+
):
812819
"""
813820
Initializer of ThermalControlDaemon
814821
"""
@@ -823,7 +830,12 @@ class ThermalControlDaemon(daemon_base.DaemonBase):
823830

824831
self.chassis = sonic_platform.platform.Platform().get_chassis()
825832

826-
self.thermal_monitor = ThermalMonitor(self.chassis)
833+
self.thermal_monitor = ThermalMonitor(
834+
self.chassis,
835+
thermal_monitor_initial_interval,
836+
thermal_monitor_update_interval,
837+
thermal_monitor_update_elapsed_threshold
838+
)
827839
self.thermal_monitor.task_run()
828840

829841
self.thermal_manager = None
@@ -912,7 +924,17 @@ class ThermalControlDaemon(daemon_base.DaemonBase):
912924
# Main =========================================================================
913925
#
914926
def main():
915-
thermal_control = ThermalControlDaemon()
927+
parser = argparse.ArgumentParser()
928+
parser.add_argument('--thermal-monitor-initial-interval', type=int, default=5)
929+
parser.add_argument('--thermal-monitor-update-interval', type=int, default=60)
930+
parser.add_argument('--thermal-monitor-update-elapsed-threshold', type=int, default=30)
931+
args = parser.parse_args()
932+
933+
thermal_control = ThermalControlDaemon(
934+
args.thermal_monitor_initial_interval,
935+
args.thermal_monitor_update_interval,
936+
args.thermal_monitor_update_elapsed_threshold
937+
)
916938

917939
thermal_control.log_info("Starting up...")
918940

sonic-thermalctld/tests/test_thermalctld.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ class TestThermalMonitor(object):
294294
"""
295295
def test_main(self):
296296
mock_chassis = MockChassis()
297-
thermal_monitor = thermalctld.ThermalMonitor(mock_chassis)
297+
thermal_monitor = thermalctld.ThermalMonitor(mock_chassis, 5, 60, 30)
298298
thermal_monitor.fan_updater.update = mock.MagicMock()
299299
thermal_monitor.temperature_updater.update = mock.MagicMock()
300300

@@ -680,7 +680,7 @@ def test_updater_thermal_check_min_max():
680680

681681
def test_signal_handler():
682682
# Test SIGHUP
683-
daemon_thermalctld = thermalctld.ThermalControlDaemon()
683+
daemon_thermalctld = thermalctld.ThermalControlDaemon(5, 60, 30)
684684
daemon_thermalctld.stop_event.set = mock.MagicMock()
685685
daemon_thermalctld.log_info = mock.MagicMock()
686686
daemon_thermalctld.log_warning = mock.MagicMock()
@@ -695,7 +695,7 @@ def test_signal_handler():
695695
assert thermalctld.exit_code == thermalctld.ERR_UNKNOWN
696696

697697
# Test SIGINT
698-
daemon_thermalctld = thermalctld.ThermalControlDaemon()
698+
daemon_thermalctld = thermalctld.ThermalControlDaemon(5, 60, 30)
699699
daemon_thermalctld.stop_event.set = mock.MagicMock()
700700
daemon_thermalctld.log_info = mock.MagicMock()
701701
daemon_thermalctld.log_warning = mock.MagicMock()
@@ -712,7 +712,7 @@ def test_signal_handler():
712712

713713
# Test SIGTERM
714714
thermalctld.exit_code = thermalctld.ERR_UNKNOWN
715-
daemon_thermalctld = thermalctld.ThermalControlDaemon()
715+
daemon_thermalctld = thermalctld.ThermalControlDaemon(5, 60, 30)
716716
daemon_thermalctld.stop_event.set = mock.MagicMock()
717717
daemon_thermalctld.log_info = mock.MagicMock()
718718
daemon_thermalctld.log_warning = mock.MagicMock()
@@ -729,7 +729,7 @@ def test_signal_handler():
729729

730730
# Test an unhandled signal
731731
thermalctld.exit_code = thermalctld.ERR_UNKNOWN
732-
daemon_thermalctld = thermalctld.ThermalControlDaemon()
732+
daemon_thermalctld = thermalctld.ThermalControlDaemon(5, 60, 30)
733733
daemon_thermalctld.stop_event.set = mock.MagicMock()
734734
daemon_thermalctld.log_info = mock.MagicMock()
735735
daemon_thermalctld.log_warning = mock.MagicMock()
@@ -745,14 +745,14 @@ def test_signal_handler():
745745

746746

747747
def test_daemon_run():
748-
daemon_thermalctld = thermalctld.ThermalControlDaemon()
748+
daemon_thermalctld = thermalctld.ThermalControlDaemon(5, 60, 30)
749749
daemon_thermalctld.stop_event.wait = mock.MagicMock(return_value=True)
750750
daemon_thermalctld.thermal_manager.get_interval = mock.MagicMock(return_value=60)
751751
ret = daemon_thermalctld.run()
752752
daemon_thermalctld.deinit() # Deinit becuase the test will hang if we assert
753753
assert ret is False
754754

755-
daemon_thermalctld = thermalctld.ThermalControlDaemon()
755+
daemon_thermalctld = thermalctld.ThermalControlDaemon(5, 60, 30)
756756
daemon_thermalctld.stop_event.wait = mock.MagicMock(return_value=False)
757757
daemon_thermalctld.thermal_manager.get_interval = mock.MagicMock(return_value=60)
758758
ret = daemon_thermalctld.run()

0 commit comments

Comments
 (0)