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": [ 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): 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 index 1f932f2d3ce6..fda99cc2ff0c 100644 --- 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 @@ -1,19 +1,23 @@ try: from threading import Timer + import json except ImportError as e: raise ImportError (str(e) + "- required module not found") class ThermalManager(): + JSON_FIELD_POLICIES = 'policies' def __init__(self, polling_time = 30.0): self.__polling_thermal_time = polling_time self.__thermals = None self.__timer = None self.__chassis = None + self.__running = False def start(self): - self.work() - self.__timer = Timer(self.__polling_thermal_time, self.start) - self.__timer.start() + if self.__running == True: + self.work() + self.__timer = Timer(self.__polling_thermal_time, self.start) + self.__timer.start() def work(self): if self.__chassis is not None: @@ -26,25 +30,18 @@ def check(self, sensor): 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') + if temperature > temp_high: + print('Sensor ', sensor.get_name(), ' temperature more then', temp_high, '!!!') + if temperature < temp_low: + print('Sensor ', sensor.get_name(), ' temperature less then', temp_low, '!!!') def stop(self): if self.__timer is not None: + self.__running = False self.__timer.cancel() def __del__(self): - if self.__timer is not None: - self.__timer.cancel() + self.stop() # for compatibility with old version def run_policy(self, chassis_def): @@ -56,8 +53,18 @@ def get_interval(self): def initialize(self): pass - def load(self, json_file): - pass + def load(self, policy_file_name): + with open(policy_file_name, 'r') as policy_file: + json_obj = json.load(policy_file) + if self.JSON_FIELD_POLICIES in json_obj: + json_policies = json_obj[self.JSON_FIELD_POLICIES] + count = 0 + for json_policy in json_policies: + count += 1 + if count == 0: + raise Exception('Policies are not exists') + else: + raise Exception('Policies are not exists') def init_thermal_algorithm(self, chassis_def): self.__chassis = chassis_def