Skip to content

Commit 415b8c4

Browse files
[thermalctld] Optimize the thermal policy loop to make it execute every 60 seconds (#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.
1 parent 3d1f319 commit 415b8c4

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

sonic-thermalctld/scripts/thermalctld

+15-1
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,9 @@ class ThermalMonitor(ProcessTaskBase):
607607
class ThermalControlDaemon(daemon_base.DaemonBase):
608608
# Interval to run thermal control logic
609609
INTERVAL = 60
610+
RUN_POLICY_WARN_THRESHOLD_SECS = 30
611+
FAST_START_INTERVAL = 15
612+
610613
POLICY_FILE = '/usr/share/sonic/platform/thermal_policy.json'
611614

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

661-
while not self.stop_event.wait(ThermalControlDaemon.INTERVAL):
664+
wait_time = ThermalControlDaemon.INTERVAL
665+
while not self.stop_event.wait(wait_time):
666+
begin = time.time()
662667
try:
663668
if thermal_manager:
664669
thermal_manager.run_policy(chassis)
665670
except Exception as e:
666671
self.log_error('Caught exception while running thermal policy - {}'.format(e))
672+
elapsed = time.time() - begin
673+
if elapsed < ThermalControlDaemon.INTERVAL:
674+
wait_time = ThermalControlDaemon.INTERVAL - elapsed
675+
else:
676+
wait_time = ThermalControlDaemon.FAST_START_INTERVAL
677+
678+
if elapsed > ThermalControlDaemon.RUN_POLICY_WARN_THRESHOLD_SECS:
679+
self.log_warning('Thermal policy execution takes {} seconds, '
680+
'there might be performance risk'.format(elapsed))
667681

668682
try:
669683
if thermal_manager:

0 commit comments

Comments
 (0)