Skip to content

Commit

Permalink
[thermalctld] Optimize the thermal policy loop to make it execute eve…
Browse files Browse the repository at this point in the history
…ry 60 seconds (sonic-net#77)

In regression, we found that thermal policy loop takes 8 to 15 seconds sometimes which would enhance the loop interval to 68 to 75 seconds. This change is to make the loop interval more accurate.

Record the elapse time for thermal policy, and start next iteration in (60 - elapsed) seconds.
  • Loading branch information
Junchao-Mellanox authored Aug 19, 2020
1 parent 3d1f319 commit 415b8c4
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion sonic-thermalctld/scripts/thermalctld
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,9 @@ class ThermalMonitor(ProcessTaskBase):
class ThermalControlDaemon(daemon_base.DaemonBase):
# Interval to run thermal control logic
INTERVAL = 60
RUN_POLICY_WARN_THRESHOLD_SECS = 30
FAST_START_INTERVAL = 15

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

def __init__(self, log_identifier):
Expand Down Expand Up @@ -658,12 +661,23 @@ class ThermalControlDaemon(daemon_base.DaemonBase):
except Exception as e:
self.log_error('Caught exception while initializing thermal manager - {}'.format(e))

while not self.stop_event.wait(ThermalControlDaemon.INTERVAL):
wait_time = ThermalControlDaemon.INTERVAL
while not self.stop_event.wait(wait_time):
begin = time.time()
try:
if thermal_manager:
thermal_manager.run_policy(chassis)
except Exception as e:
self.log_error('Caught exception while running thermal policy - {}'.format(e))
elapsed = time.time() - begin
if elapsed < ThermalControlDaemon.INTERVAL:
wait_time = ThermalControlDaemon.INTERVAL - elapsed
else:
wait_time = ThermalControlDaemon.FAST_START_INTERVAL

if elapsed > ThermalControlDaemon.RUN_POLICY_WARN_THRESHOLD_SECS:
self.log_warning('Thermal policy execution takes {} seconds, '
'there might be performance risk'.format(elapsed))

try:
if thermal_manager:
Expand Down

0 comments on commit 415b8c4

Please sign in to comment.