Skip to content

Commit

Permalink
Load interval from thermal_policy.json (sonic-net#178)
Browse files Browse the repository at this point in the history
Description
Update ThermalManagerBase to load an interval field from thermal_policy.json if it is available and provide a getter for this interval.

Motivation and Context
This interval can be used by thermalctld to run policies at an interval specified in thermal_policy.json, rather than a fixed constant (currently 60 seconds).

How Has This Been Tested?
Verified that thermalctld runs without exiting.
Also ran test_thermalctld.py
  • Loading branch information
andywongarista authored Aug 4, 2021
1 parent c43dc17 commit bd694b2
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ThermalManagerBase(object):
JSON_FIELD_THERMAL_ALGORITHM = "thermal_control_algorithm"
JSON_FIELD_FAN_SPEED_WHEN_SUSPEND = "fan_speed_when_suspend"
JSON_FIELD_RUN_AT_BOOT_UP = "run_at_boot_up"
JSON_FIELD_INTERVAL = "interval"

# Dictionary of ThermalPolicy objects.
_policy_dict = {}
Expand All @@ -25,6 +26,8 @@ class ThermalManagerBase(object):

_run_thermal_algorithm_at_boot_up = None

_interval = 60

_running = True

@classmethod
Expand Down Expand Up @@ -118,7 +121,8 @@ def load(cls, policy_file_name):
}
]
}
]
],
"interval": "30",
}
:param policy_file_name: Path of JSON policy file.
:return:
Expand Down Expand Up @@ -147,6 +151,10 @@ def load(cls, policy_file_name):
cls._fan_speed_when_suspend = \
int(json_thermal_algorithm_config[cls.JSON_FIELD_FAN_SPEED_WHEN_SUSPEND])

if cls.JSON_FIELD_INTERVAL in json_obj:
cls._interval = int(json_obj[cls.JSON_FIELD_INTERVAL])


@classmethod
def _load_policy(cls, json_policy):
"""
Expand Down Expand Up @@ -215,3 +223,10 @@ def init_thermal_algorithm(cls, chassis):
for psu in chassis.get_all_psus():
for fan in psu.get_all_fans():
fan.set_speed(cls._fan_speed_when_suspend)

@classmethod
def get_interval(cls):
"""
Get the wait interval for executing thermal policies
"""
return cls._interval

0 comments on commit bd694b2

Please sign in to comment.