66"""
77
88from enum import Enum , auto
9+ import argparse
910import signal
1011import sys
1112import threading
@@ -742,23 +743,24 @@ class TemperatureUpdater(logger.Logger):
742743
743744
744745class 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#
914926def 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
0 commit comments