From 0b43ce74eb648e46ab2c20bad7240b9d98c379ea Mon Sep 17 00:00:00 2001 From: junchao Date: Fri, 15 May 2020 11:20:35 +0800 Subject: [PATCH 1/3] Trigger thermal action log only if thermal condition changes --- .../mlnx-platform-api/sonic_platform/fan.py | 2 +- .../mlnx-platform-api/sonic_platform/thermal.py | 6 +++++- .../sonic_platform/thermal_actions.py | 17 ++++++++++------- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py b/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py index d123b6c6c3a3..412e0ae54062 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py @@ -220,7 +220,7 @@ def set_speed(self, speed): """ status = True - if self.is_psu_fan: + if self.is_psu_fan and self.get_presence(): from .thermal import logger try: with open(self.psu_i2c_bus_path, 'r') as f: diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/thermal.py b/platform/mellanox/mlnx-platform-api/sonic_platform/thermal.py index 3c25ebb642e8..54e2d1a478c0 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/thermal.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/thermal.py @@ -495,12 +495,15 @@ def set_thermal_algorithm_status(cls, status, force=True): We usually disable the algorithm when we want to set a fix speed. E.g, when a fan unit is removed from system, we will set fan speed to 100% and disable the algorithm to avoid it adjust the speed. + + Returns: + True if thermal algorithm status changed. """ if not cls.thermal_profile: raise Exception("Fail to get thermal profile for this switch") if not force and cls.thermal_algorithm_status == status: - return + return False cls.thermal_algorithm_status = status content = "enabled" if status else "disabled" @@ -521,6 +524,7 @@ def set_thermal_algorithm_status(cls, status, force=True): for index in range(count): cls._write_generic_file(join(THERMAL_ZONE_GEARBOX_PATH.format(start + index), THERMAL_ZONE_MODE), content) cls._write_generic_file(join(THERMAL_ZONE_GEARBOX_PATH.format(start + index), THERMAL_ZONE_POLICY), policy) + return True @classmethod def check_thermal_zone_temperature(cls): diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/thermal_actions.py b/platform/mellanox/mlnx-platform-api/sonic_platform/thermal_actions.py index 3a4d5f2a8a68..35a2a8491b84 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/thermal_actions.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/thermal_actions.py @@ -131,14 +131,17 @@ def execute(self, thermal_info_dict): from .thermal import Thermal from .thermal_conditions import UpdateCoolingLevelToMinCondition from .fan import Fan - Thermal.set_thermal_algorithm_status(self.status, False) - if self.status: - # Check thermal zone temperature, if all thermal zone temperature - # back to normal, set it to minimum allowed speed to - # save power - UpdateCoolingLevelToMinAction.update_cooling_level_to_minimum(thermal_info_dict) + status_changed = Thermal.set_thermal_algorithm_status(self.status, False) + + # Only update cooling level if thermal algorithm status changed + if status_changed: + if self.status: + # Check thermal zone temperature, if all thermal zone temperature + # back to normal, set it to minimum allowed speed to + # save power + UpdateCoolingLevelToMinAction.update_cooling_level_to_minimum(thermal_info_dict) - logger.log_info('Changed thermal algorithm status to {}'.format(self.status)) + logger.log_info('Changed thermal algorithm status to {}'.format(self.status)) class ChangeMinCoolingLevelAction(ThermalPolicyActionBase): From d485389b31777c0bfd600479de5c0c0e1985beb2 Mon Sep 17 00:00:00 2001 From: junchao Date: Fri, 22 May 2020 09:28:40 +0800 Subject: [PATCH 2/3] test file existence before read file content --- platform/mellanox/mlnx-platform-api/sonic_platform/psu.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py b/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py index a323132faf97..5541402916a0 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py @@ -122,6 +122,8 @@ def _read_generic_file(self, filename, len): """ result = 0 try: + if not os.path.exists(filename): + return result with open(filename, 'r') as fileobj: result = int(fileobj.read().strip()) except Exception as e: From 40c05f9c12b87548fa957bfd416ce78807d30239 Mon Sep 17 00:00:00 2001 From: junchao Date: Fri, 22 May 2020 10:09:32 +0800 Subject: [PATCH 3/3] fix error for set psu fan speed --- platform/mellanox/mlnx-platform-api/sonic_platform/fan.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py b/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py index 412e0ae54062..491be834aa2e 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py @@ -220,7 +220,9 @@ def set_speed(self, speed): """ status = True - if self.is_psu_fan and self.get_presence(): + if self.is_psu_fan: + if not self.get_presence(): + return False from .thermal import logger try: with open(self.psu_i2c_bus_path, 'r') as f: