From fecfa5a5414f1e4660c2ab5d77dd72c47886f8bd Mon Sep 17 00:00:00 2001 From: Vadym Yashchenko Date: Thu, 27 Jan 2022 07:40:43 -0800 Subject: [PATCH 1/3] Stayed only new changing in thermal and removed therm_manager Signed-off-by: Vadym Yashchenko --- .../sonic_platform/chassis.py | 21 +------- .../sonic_platform/thermal.py | 52 +++++++++++++++++-- 2 files changed, 49 insertions(+), 24 deletions(-) diff --git a/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/chassis.py b/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/chassis.py index 85f860b377f5..cd437bc14f40 100644 --- a/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/chassis.py +++ b/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/chassis.py @@ -10,7 +10,6 @@ from sonic_platform.fan_drawer import fan_drawer_list_get from sonic_platform.thermal import thermal_list_get from eeprom import Eeprom - from sonic_platform.thermal_manager import ThermalManager from sonic_platform.platform_thrift_client import pltfm_mgr_ready from sonic_platform.platform_thrift_client import thrift_try @@ -41,8 +40,6 @@ def __init__(self): self.__thermals = None self.__psu_list = None self.__sfp_list = None - self.__thermal_mngr = None - self.__polling_thermal_time = 30 self.ready = False self.phy_port_cur_state = {} @@ -114,16 +111,6 @@ def _sfp_list(self): def _sfp_list(self, value): pass - @property - def _thermal_mngr(self): - if self.__thermal_mngr is None: - self.__thermal_mngr = ThermalManager(self.__polling_thermal_time) - return self.__thermal_mngr - - @_thermal_mngr.setter - def _thermal_mngr(self, value): - self.__thermal_mngr = ThermalManager(value) - def __update_port_info(self): def qsfp_max_port_get(client): return client.pltfm_mgr.pltfm_mgr_qsfp_get_max_port() @@ -346,10 +333,4 @@ def get_status_led(self): specified. """ return self.system_led - - def get_thermal_manager(self): - return self._thermal_mngr - - def __del__(self): - if self.__thermal_mngr is not None: - self.__thermal_mngr.stop() + \ No newline at end of file diff --git a/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/thermal.py b/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/thermal.py index ef3c571ac301..c16bedcb11cd 100644 --- a/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/thermal.py +++ b/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/thermal.py @@ -1,6 +1,6 @@ try: import subprocess - + from collections import namedtuple from bfn_extensions.platform_sensors import platform_sensors_get from sonic_platform_base.thermal_base import ThermalBase except ImportError as e: @@ -18,6 +18,8 @@ temp2_input: 37.000 ... ''' +Threshold = namedtuple('Threshold', ['crit', 'max', 'min', 'alarm'], defaults=[0.1]*4) + def _sensors_chip_parsed(data: str): def kv(line): k, v, *_ = [t.strip(': ') for t in line.split(':') if t] + [''] @@ -68,6 +70,30 @@ def _value_get(d: dict, key_prefix, key_suffix=''): # Thermal -> ThermalBase -> DeviceBase class Thermal(ThermalBase): + _thresholds = { + "com_e_driver-i2c-4-33:memory-temp": Threshold(85.0, 80.75, 0.2, 0.1), + "com_e_driver-i2c-4-33:cpu-temp": Threshold(99.9, 99.75, 0.2, 0.1), + "psu_driver-i2c-7-5a:psu1-temp1": Threshold(50.0, 47.5, 0.2, 0.1), + "psu_driver-i2c-7-5a:psu1-temp2": Threshold(90.0, 85.5, 0.2, 0.1), + "psu_driver-i2c-7-5a:psu1-temp3": Threshold(50.0, 47.5, 0.2, 0.1), + "tmp75-i2c-3-48:chip-temp": Threshold(90.0, 85.5, 0.2, 0.1), + "tmp75-i2c-3-49:exhaust2-temp": Threshold(80.0, 76.0, 0.2, 0.1), + "tmp75-i2c-3-4a:exhaust-temp": Threshold(60.0, 57.0, 0.2, 0.1), + "tmp75-i2c-3-4b:intake-temp": Threshold(60.0, 57.0, 0.2, 0.1), + "tmp75-i2c-3-4c:tofino-temp": Threshold(99.9, 99.75, 0.2, 0.1), + "tmp75-i2c-3-4d:intake2-temp": Threshold(60.0, 57.0, 0.2, 0.1), + "coretemp-isa-0000:package-id-0": Threshold(80.0, 76.0, 0.2, 0.1), + "coretemp-isa-0000:core-0": Threshold(99.9, 82.0, 0.2, 0.1), + "coretemp-isa-0000:core-1": Threshold(99.9, 82.0, 0.2, 0.1), + "coretemp-isa-0000:core-2": Threshold(99.9, 82.0, 0.2, 0.1), + "coretemp-isa-0000:core-3": Threshold(99.9, 82.0, 0.2, 0.1), + # add from Montara" + "psu_driver-i2c-7-59:psu2-temp1": Threshold(50.0, 47.5, 0.2, 0.1), + "psu_driver-i2c-7-59:psu2-temp2": Threshold(90.0, 85.5, 0.2, 0.1), + "tmp75-i2c-8-48:outlet-right-temp": Threshold(60.0, 57.0, 0.2, 0.1), + "tmp75-i2c-8-49:outlet-left-temp": Threshold(60.0, 57.0, 0.2, 0.1) + } + def __init__(self, chip, label, index = 0): self.__chip = chip self.__label = label @@ -78,13 +104,29 @@ def __init__(self, chip, label, index = 0): def __get(self, attr_prefix, attr_suffix): sensor_data = _sensors_get().get(self.__chip, {}).get(self.__label, {}) value = _value_get(sensor_data, attr_prefix, attr_suffix) - return value if value is not None else -999.9 + if value is not None: + return value + elif attr_prefix == 'temp': + if attr_suffix == 'crit': + return self._thresholds[self.__name].crit + elif attr_suffix == 'max': + return self._thresholds[self.__name].max + elif attr_suffix == 'min': + return self._thresholds[self.__name].min + elif attr_suffix == 'alarm': + return self._thresholds[self.__name].alarm + else: + return 1.0 + else: + return 0.1 # ThermalBase interface methods: def get_temperature(self) -> float: temp = self.__get('temp', 'input') self.__collect_temp.append(float(temp)) self.__collect_temp.sort() + if len(self.__collect_temp) == 3: + del self.__collect_temp[1] return float(temp) def get_high_threshold(self) -> float: @@ -119,13 +161,15 @@ def get_serial(self): return 'N/A' def get_minimum_recorded(self) -> float: - temp = self.__collect_temp[0] if len(self.__collect_temp) > 0 else 0.1 + temp = self.__collect_temp[0] if len(self.__collect_temp) > 0 else 36.6 + temp = temp if temp <= 100.0 else 100.0 temp = temp if temp > 0.0 else 0.1 return float(temp) def get_maximum_recorded(self) -> float: - temp = self.__collect_temp[-1] if len(self.__collect_temp) > 0 else 100.0 + temp = self.__collect_temp[-1] if len(self.__collect_temp) > 0 else 36.6 temp = temp if temp <= 100.0 else 100.0 + temp = temp if temp > 0.0 else 0.1 return float(temp) def get_position_in_parent(self): From 5d55577f2ef478705557710c3bf11ef29927c46a Mon Sep 17 00:00:00 2001 From: Vadym Yashchenko Date: Thu, 27 Jan 2022 08:15:02 -0800 Subject: [PATCH 2/3] Changed due to tests Signed-off-by: Vadym Yashchenko --- .../platform.json | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/platform.json b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/platform.json index 769386a14ce0..c17996069798 100644 --- a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/platform.json +++ b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/platform.json @@ -105,6 +105,33 @@ }, { "name": "pch_haswell-virtual-0:temp1" + }, + { + "name": "psu_driver-i2c-7-59:psu2-temp2" + }, + { + "name": "psu_driver-i2c-7-5a:psu1-temp1" + }, + { + "name": "psu_driver-i2c-7-5a:psu1-temp2" + }, + { + "name": "tmp75-i2c-3-48:chip-temp" + }, + { + "name": "tmp75-i2c-3-49:exhaust2-temp" + }, + { + "name": "tmp75-i2c-3-4a:exhaust-temp" + }, + { + "name": "tmp75-i2c-3-4b:intake-temp" + }, + { + "name": "tmp75-i2c-3-4c:tofino-temp" + }, + { + "name": "tmp75-i2c-3-4d:intake2-temp" } ], "sfps": [ From 26437296fd2e1e81489b17651c540c5c5f67e21d Mon Sep 17 00:00:00 2001 From: Vadym Yashchenko Date: Thu, 27 Jan 2022 09:01:51 -0800 Subject: [PATCH 3/3] Removed thermal_manager Signed-off-by: Vadym Yashchenko --- .../sonic_platform/thermal_manager.py | 67 ------------------- 1 file changed, 67 deletions(-) delete mode 100644 platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/thermal_manager.py diff --git a/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/thermal_manager.py b/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/thermal_manager.py deleted file mode 100644 index 1f932f2d3ce6..000000000000 --- a/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/thermal_manager.py +++ /dev/null @@ -1,67 +0,0 @@ -try: - from threading import Timer -except ImportError as e: - raise ImportError (str(e) + "- required module not found") - -class ThermalManager(): - def __init__(self, polling_time = 30.0): - self.__polling_thermal_time = polling_time - self.__thermals = None - self.__timer = None - self.__chassis = None - - def start(self): - self.work() - self.__timer = Timer(self.__polling_thermal_time, self.start) - self.__timer.start() - - def work(self): - if self.__chassis is not None: - self.__thermals = self.__chassis._thermal_list - for term in self.__thermals: - self.check(term) - - def check(self, sensor): - temperature = sensor.get_temperature() - if temperature is not None: - temp_high = sensor.get_high_threshold() - temp_low = sensor.get_low_threshold() - if temp_high > -999.0: - if temperature > temp_high: - print('Sensor ', sensor.get_name(), ' temperature more then', temp_high, '!!!') - else: - print('Sensor ', sensor.get_name(), ' has no high temperature threshold') - - if temp_low > -999.0: - if temperature < temp_low: - print('Sensor ', sensor.get_name(), ' temperature less then', temp_low, '!!!') - else: - print('Sensor ', sensor.get_name(), ' has no low temperature threshold') - - def stop(self): - if self.__timer is not None: - self.__timer.cancel() - - def __del__(self): - if self.__timer is not None: - self.__timer.cancel() - - # for compatibility with old version - def run_policy(self, chassis_def): - self.__chassis = chassis_def - - def get_interval(self): - return self.__polling_thermal_time - - def initialize(self): - pass - - def load(self, json_file): - pass - - def init_thermal_algorithm(self, chassis_def): - self.__chassis = chassis_def - self.start() - - def deinitialize(self): - self.stop()