Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json fix thermal #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions device/barefoot/x86_64-accton_wedge100bf_32x-r0/platform.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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] + ['']
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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):
Expand All @@ -56,8 +53,18 @@ def get_interval(self):
def initialize(self):
pass

def load(self, json_file):
pass
def load(self, policy_file_name):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to override this method which is defined in base class?

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
Expand Down