[devices]: Add thermal plan to as4630_54pe (#3665)

This commit is contained in:
jostar-yang 2019-11-08 13:53:21 +08:00 committed by lguohan
parent 6c0ab4b926
commit ac2908ef03
4 changed files with 207 additions and 452 deletions

View File

@ -1,114 +1,69 @@
#!/usr/bin/env python #!/usr/bin/env python
# Copyright (c) 2019 Edgecore Networks Corporation
# #
# Copyright (C) 2017 Accton Technology Corporation # Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
# #
# This program is free software: you can redistribute it and/or modify # THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR
# it under the terms of the GNU General Public License as published by # CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
# the Free Software Foundation, either version 3 of the License, or # LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS
# (at your option) any later version. # FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
# #
# This program is distributed in the hope that it will be useful, # See the Apache Version 2.0 License for specific language governing
# but WITHOUT ANY WARRANTY; without even the implied warranty of # permissions and limitations under the License.
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# ------------------------------------------------------------------ # ------------------------------------------------------------------
# HISTORY: # HISTORY:
# mm/dd/yyyy (A.D.) # mm/dd/yyyy (A.D.)
# 11/13/2017: Polly Hsu, Create # 10/24/2019:Jostar craete for as4630_54pe
# 1/10/2018: Jostar modify for as7716_32
# 12/03/2018: Jostar modify for as7726_32
# ------------------------------------------------------------------ # ------------------------------------------------------------------
try: try:
import os
import time import time
import logging import logging
import glob
import commands
from collections import namedtuple from collections import namedtuple
except ImportError as e: except ImportError as e:
raise ImportError('%s - required module not found' % str(e)) raise ImportError('%s - required module not found' % str(e))
class ThermalUtil(object):
class FanUtil(object): """Platform-specific ThermalUtil class"""
"""Platform-specific FanUtil class""" THERMAL_NUM_MAX = 4
THERMAL_NUM_1_IDX = 1
FAN_NUM_ON_MAIN_BROAD = 6 THERMAL_NUM_2_IDX = 2
FAN_NUM_1_IDX = 1 THERMAL_NUM_3_IDX = 3
FAN_NUM_2_IDX = 2 THERMAL_NUM_4_IDX = 4
FAN_NUM_3_IDX = 3
FAN_NUM_4_IDX = 4
FAN_NUM_5_IDX = 5
FAN_NUM_6_IDX = 6
FAN_NODE_NUM_OF_MAP = 2
FAN_NODE_FAULT_IDX_OF_MAP = 1
FAN_NODE_DIR_IDX_OF_MAP = 2
BASE_VAL_PATH = '/sys/bus/i2c/devices/54-0066/{0}'
FAN_DUTY_PATH = '/sys/bus/i2c/devices/54-0066/fan_duty_cycle_percentage'
#logfile = ''
#loglevel = logging.INFO
""" Dictionary where """ Dictionary where
key1 = fan id index (integer) starting from 1 key1 = thermal id index (integer) starting from 1
key2 = fan node index (interger) starting from 1
value = path to fan device file (string) """ value = path to fan device file (string) """
_fan_to_device_path_mapping = {}
#fan1_direction thermal_sysfspath ={
#fan1_fault THERMAL_NUM_1_IDX: ["/sys/bus/i2c/devices/14-0048/hwmon/hwmon*/temp1_input"],
#fan1_present THERMAL_NUM_2_IDX: ["/sys/bus/i2c/devices/24-004b/hwmon/hwmon*/temp1_input"],
THERMAL_NUM_3_IDX: ["/sys/bus/i2c/devices/25-004a/hwmon/hwmon*/temp1_input"],
#(FAN_NUM_2_IDX, FAN_NODE_DUTY_IDX_OF_MAP): 'fan2_duty_cycle_percentage', THERMAL_NUM_4_IDX: ["/sys/class/hwmon/hwmon1/temp1_input"],
_fan_to_device_node_mapping = {
(FAN_NUM_1_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan1_fault',
(FAN_NUM_1_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan1_direction',
(FAN_NUM_2_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan2_fault',
(FAN_NUM_2_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan2_direction',
(FAN_NUM_3_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan3_fault',
(FAN_NUM_3_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan3_direction',
(FAN_NUM_4_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan4_fault',
(FAN_NUM_4_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan4_direction',
(FAN_NUM_5_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan5_fault',
(FAN_NUM_5_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan5_direction',
(FAN_NUM_6_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan6_fault',
(FAN_NUM_6_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan6_direction',
} }
def _get_fan_to_device_node(self, fan_num, node_num): def _get_thermal_val(self, thermal_num):
return self._fan_to_device_node_mapping[(fan_num, node_num)] if thermal_num < self.THERMAL_NUM_1_IDX or thermal_num > self.THERMAL_NUM_MAX:
logging.debug('GET. Parameter error. thermal_num, %d', thermal_num)
def _get_fan_node_val(self, fan_num, node_num):
if fan_num < self.FAN_NUM_1_IDX or fan_num > self.FAN_NUM_ON_MAIN_BROAD:
logging.debug('GET. Parameter error. fan_num:%d', fan_num)
return None return None
if node_num < self.FAN_NODE_FAULT_IDX_OF_MAP or node_num > self.FAN_NODE_NUM_OF_MAP: device_path = self.get_thermal_path(thermal_num)
logging.debug('GET. Parameter error. node_num:%d', node_num) for filename in glob.glob(device_path):
return None
device_path = self.get_fan_to_device_path(fan_num, node_num)
try: try:
val_file = open(device_path, 'r') val_file = open(filename, 'r')
except IOError as e: except IOError as e:
logging.error('GET. unable to open file: %s', str(e)) logging.error('GET. unable to open file: %s', str(e))
return None return None
content = val_file.readline().rstrip() content = val_file.readline().rstrip()
if content == '': if content == '':
logging.debug('GET. content is NULL. device_path:%s', device_path) logging.debug('GET. content is NULL. device_path:%s', device_path)
return None return None
try: try:
val_file.close() val_file.close()
except: except:
@ -117,107 +72,19 @@ class FanUtil(object):
return int(content) return int(content)
def _set_fan_node_val(self, fan_num, node_num, val): return 0
if fan_num < self.FAN_NUM_1_IDX or fan_num > self.FAN_NUM_ON_MAIN_BROAD:
logging.debug('GET. Parameter error. fan_num:%d', fan_num)
return None
if node_num < self.FAN_NODE_FAULT_IDX_OF_MAP or node_num > self.FAN_NODE_NUM_OF_MAP: def get_num_thermals(self):
logging.debug('GET. Parameter error. node_num:%d', node_num) return self.THERMAL_NUM_MAX
return None
content = str(val)
if content == '':
logging.debug('GET. content is NULL. device_path:%s', device_path)
return None
device_path = self.get_fan_to_device_path(fan_num, node_num)
try:
val_file = open(device_path, 'w')
except IOError as e:
logging.error('GET. unable to open file: %s', str(e))
return None
val_file.write(content)
try:
val_file.close()
except:
logging.debug('GET. unable to close file. device_path:%s', device_path)
return None
return True
def __init__(self):
fan_path = self.BASE_VAL_PATH
for fan_num in range(self.FAN_NUM_1_IDX, self.FAN_NUM_ON_MAIN_BROAD+1):
for node_num in range(self.FAN_NODE_FAULT_IDX_OF_MAP, self.FAN_NODE_NUM_OF_MAP+1):
self._fan_to_device_path_mapping[(fan_num, node_num)] = fan_path.format(
self._fan_to_device_node_mapping[(fan_num, node_num)])
def get_num_fans(self):
return self.FAN_NUM_ON_MAIN_BROAD
def get_idx_fan_start(self):
return self.FAN_NUM_1_IDX
def get_num_nodes(self):
return self.FAN_NODE_NUM_OF_MAP
def get_idx_node_start(self):
return self.FAN_NODE_FAULT_IDX_OF_MAP
def get_size_node_map(self):
return len(self._fan_to_device_node_mapping)
def get_size_path_map(self): def get_size_path_map(self):
return len(self._fan_to_device_path_mapping) return len(self.thermal_sysfspath)
def get_fan_to_device_path(self, fan_num, node_num): def get_thermal_path(self, thermal_num):
return self._fan_to_device_path_mapping[(fan_num, node_num)] return self.thermal_sysfspath[thermal_num][0]
def get_fan_fault(self, fan_num): def main():
return self._get_fan_node_val(fan_num, self.FAN_NODE_FAULT_IDX_OF_MAP) thermal = ThermalUtil()
def get_fan_dir(self, fan_num):
return self._get_fan_node_val(fan_num, self.FAN_NODE_DIR_IDX_OF_MAP)
def get_fan_duty_cycle(self):
#duty_path = self.FAN_DUTY_PATH
try:
val_file = open(self.FAN_DUTY_PATH)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False
content = val_file.readline().rstrip()
val_file.close()
return int(content)
def set_fan_duty_cycle(self, val):
try:
fan_file = open(self.FAN_DUTY_PATH, 'r+')
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False
#val = ((val + 1 ) * 625 +75 ) / 100
fan_file.write(str(val))
fan_file.close()
return True
def get_fanr_speed(self, fan_num):
return self._get_fan_node_val(fan_num, self.FANR_NODE_SPEED_IDX_OF_MAP)
def get_fan_status(self, fan_num):
if fan_num < self.FAN_NUM_1_IDX or fan_num > self.FAN_NUM_ON_MAIN_BROAD:
logging.debug('GET. Parameter error. fan_num, %d', fan_num)
return None
if self.get_fan_fault(fan_num) is not None and self.get_fan_fault(fan_num) > 0:
logging.debug('GET. FAN fault. fan_num, %d', fan_num)
return False
return True
if __name__ == '__main__':
main()

View File

@ -1,26 +1,22 @@
#!/usr/bin/env python #!/usr/bin/env python
# Copyright (c) 2019 Edgecore Networks Corporation
# #
# Copyright (C) 2017 Accton Technology Corporation # Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
# #
# This program is free software: you can redistribute it and/or modify # THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR
# it under the terms of the GNU General Public License as published by # CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
# the Free Software Foundation, either version 3 of the License, or # LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS
# (at your option) any later version. # FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
# #
# This program is distributed in the hope that it will be useful, # See the Apache Version 2.0 License for specific language governing
# but WITHOUT ANY WARRANTY; without even the implied warranty of # permissions and limitations under the License.
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# ------------------------------------------------------------------ # ------------------------------------------------------------------
# HISTORY: # HISTORY:
# mm/dd/yyyy (A.D.) # mm/dd/yyyy (A.D.)
# 11/13/2017: Polly Hsu, Create # 10/24/2019:Jostar craete for as4630_54pe
# 1/10/2018:Jostar modify for as7716_32x
# 12/03/2018:Jostar modify for as7726_32x thermal plan
# ------------------------------------------------------------------ # ------------------------------------------------------------------
try: try:
@ -35,40 +31,29 @@ except ImportError as e:
class ThermalUtil(object): class ThermalUtil(object):
"""Platform-specific ThermalUtil class""" """Platform-specific ThermalUtil class"""
THERMAL_NUM_MAX = 5 THERMAL_NUM_MAX = 4
THERMAL_NUM_1_IDX = 1 # 1_ON_MAIN_BROAD. LM75 THERMAL_NUM_1_IDX = 1
THERMAL_NUM_2_IDX = 2 # 2_ON_MAIN_BROAD. LM75 THERMAL_NUM_2_IDX = 2
THERMAL_NUM_3_IDX = 3 # 3_ON_MAIN_BROAD. LM75 THERMAL_NUM_3_IDX = 3
THERMAL_NUM_4_IDX = 4 # 4_ON_MAIN_BROAD. LM75 THERMAL_NUM_4_IDX = 4
THERMAL_NUM_5_IDX = 5 # 5_ON_MAIN_BROAD. LM75
""" Dictionary where """ Dictionary where
key1 = thermal id index (integer) starting from 1 key1 = thermal id index (integer) starting from 1
value = path to fan device file (string) """ value = path to fan device file (string) """
_thermal_to_device_node_mapping = {
THERMAL_NUM_1_IDX: ['55', '48'],
THERMAL_NUM_2_IDX: ['55', '49'],
THERMAL_NUM_3_IDX: ['55', '4a'],
THERMAL_NUM_4_IDX: ['55', '4b'],
THERMAL_NUM_5_IDX: ['54', '4c'],
}
thermal_sysfspath ={ thermal_sysfspath ={
THERMAL_NUM_1_IDX: ["/sys/bus/i2c/devices/55-0048/hwmon/hwmon4/temp1_input"], THERMAL_NUM_1_IDX: ["/sys/bus/i2c/devices/14-0048/hwmon/hwmon*/temp1_input"],
THERMAL_NUM_2_IDX: ["/sys/bus/i2c/devices/55-0049/hwmon/hwmon5/temp1_input"], THERMAL_NUM_2_IDX: ["/sys/bus/i2c/devices/24-004b/hwmon/hwmon*/temp1_input"],
THERMAL_NUM_3_IDX: ["/sys/bus/i2c/devices/55-004a/hwmon/hwmon6/temp1_input"], THERMAL_NUM_3_IDX: ["/sys/bus/i2c/devices/25-004a/hwmon/hwmon*/temp1_input"],
THERMAL_NUM_4_IDX: ["/sys/bus/i2c/devices/55-004b/hwmon/hwmon7/temp1_input"], THERMAL_NUM_4_IDX: ["/sys/class/hwmon/hwmon1/temp1_input"],
THERMAL_NUM_5_IDX: ["/sys/bus/i2c/devices/54-004c/hwmon/hwmon3/temp1_input"],
} }
#def __init__(self):
def _get_thermal_val(self, thermal_num): def _get_thermal_val(self, thermal_num):
if thermal_num < self.THERMAL_NUM_1_IDX or thermal_num > self.THERMAL_NUM_MAX: if thermal_num < self.THERMAL_NUM_1_IDX or thermal_num > self.THERMAL_NUM_MAX:
logging.debug('GET. Parameter error. thermal_num, %d', thermal_num) logging.debug('GET. Parameter error. thermal_num, %d', thermal_num)
return None return None
device_path = self.get_thermal_to_device_path(thermal_num) device_path = self.get_thermal_path(thermal_num)
if(os.path.isfile(device_path)):
for filename in glob.glob(device_path): for filename in glob.glob(device_path):
try: try:
val_file = open(filename, 'r') val_file = open(filename, 'r')
@ -84,42 +69,22 @@ class ThermalUtil(object):
except: except:
logging.debug('GET. unable to close file. device_path:%s', device_path) logging.debug('GET. unable to close file. device_path:%s', device_path)
return None return None
return int(content) return int(content)
else:
print "No such device_path=%s"%device_path
return 0 return 0
def get_num_thermals(self): def get_num_thermals(self):
return self.THERMAL_NUM_MAX return self.THERMAL_NUM_MAX
def get_idx_thermal_start(self):
return self.THERMAL_NUM_1_IDX
def get_size_node_map(self):
return len(self._thermal_to_device_node_mapping)
def get_size_path_map(self): def get_size_path_map(self):
return len(self.thermal_sysfspath) return len(self.thermal_sysfspath)
def get_thermal_to_device_path(self, thermal_num): def get_thermal_path(self, thermal_num):
return self.thermal_sysfspath[thermal_num][0] return self.thermal_sysfspath[thermal_num][0]
def get_thermal_1_val(self):
return self._get_thermal_node_val(self.THERMAL_NUM_1_IDX)
def get_thermal_2_val(self):
return self._get_thermal_node_val(self.THERMAL_NUM_2_IDX)
def get_thermal_temp(self):
return (self._get_thermal_node_val(self.THERMAL_NUM_1_IDX) + self._get_thermal_node_val(self.THERMAL_NUM_2_IDX) +self._get_thermal_node_val(self.THERMAL_NUM_3_IDX))
def main(): def main():
thermal = ThermalUtil() thermal = ThermalUtil()
print "termal1=%d" %thermal._get_thermal_val(1)
print "termal2=%d" %thermal._get_thermal_val(2)
print "termal3=%d" %thermal._get_thermal_val(3)
print "termal4=%d" %thermal._get_thermal_val(4)
print "termal5=%d" %thermal._get_thermal_val(5)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -1,25 +1,22 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*
# Copyright (c) 2019 Edgecore Networks Corporation
# #
# Copyright (C) 2017 Accton Technology Corporation # Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
# #
# This program is free software: you can redistribute it and/or modify # THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR
# it under the terms of the GNU General Public License as published by # CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
# the Free Software Foundation, either version 3 of the License, or # LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS
# (at your option) any later version. # FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
# #
# This program is distributed in the hope that it will be useful, # See the Apache Version 2.0 License for specific language governing
# but WITHOUT ANY WARRANTY; without even the implied warranty of # permissions and limitations under the License.
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# ------------------------------------------------------------------
# HISTORY: # HISTORY:
# mm/dd/yyyy (A.D.)# # mm/dd/yyyy (A.D.)#
# 4/20/2018: Jostar modify for as7726_32x # 10/24/2019:Jostar create for as4630_54pe thermal plan
# 12/03/2018:Jostar modify for as7726_32x thermal plan
# ------------------------------------------------------------------ # ------------------------------------------------------------------
try: try:
@ -32,11 +29,12 @@ try:
import logging.config import logging.config
import logging.handlers import logging.handlers
import types import types
import time # this is only being used as part of the example import time
import traceback import traceback
import commands
from tabulate import tabulate from tabulate import tabulate
from as7726_32x.fanutil import FanUtil from as4630_54pe.fanutil import FanUtil
from as7726_32x.thermalutil import ThermalUtil from as4630_54pe.thermalutil import ThermalUtil
except ImportError as e: except ImportError as e:
raise ImportError('%s - required module not found' % str(e)) raise ImportError('%s - required module not found' % str(e))
@ -48,25 +46,20 @@ global log_file
global log_level global log_level
# Air Flow Front to Back :
# (Thermal sensor_LM75_4A + Thermal sensor_LM75_CPU) /2 <=38C : Keep 37.5%(0x04) Fan speed
# (Thermal sensor_LM75_4A + Thermal sensor_LM75_CPU) /2 > 38C : Change Fan speed from 37.5%(0x04) to 62.5%(0x08)
# (Thermal sensor_LM75_4A + Thermal sensor_LM75_CPU) /2 > 46C : Change Fan speed from 62.5%(0x08) to 100%(0x0E)
# (Thermal sensor_LM75_4A + Thermal sensor_LM75_CPU) /2 > 58C : Send alarm message
# (Thermal sensor_LM75_4A + Thermal sensor_LM75_CPU) /2 > 66C : Shut down system
# One Fan fail : Change Fan speed to 100%(0x0E)
# Air Flow Back to Front :
# (Thermal sensor_LM75_4A + Thermal sensor_LM75_CPU) /2 <=34C : Keep 37.5%(0x04) Fan speed
# (Thermal sensor_LM75_4A + Thermal sensor_LM75_CPU) /2 > 34C : Change Fan speed from 37.5%(0x04) to 62.5%(0x08)
# (Thermal sensor_LM75_4A + Thermal sensor_LM75_CPU) /2 > 44C : Change Fan speed from 62.5%(0x08) to 100%(0x0E)
# (Thermal sensor_LM75_4A + Thermal sensor_LM75_CPU) /2 > 59C : Send alarm message
# (Thermal sensor_LM75_4A + Thermal sensor_LM75_CPU) /2 > 67C : Shut down system
# One Fan fail: Change Fan speed to 100%(0x0E)
# sensor_LM75_CPU == sensor_LM75_4B
# Temperature Policy
# If any fan fail , please set fan speed register to 16
# The max value of fan speed register is 14
# LM77(48)+LM75(4B)+LM75(4A) > 140, Set 10
# LM77(48)+LM75(4B)+LM75(4A) > 150, Set 12
# LM77(48)+LM75(4B)+LM75(4A) > 160, Set 14
# LM77(48)+LM75(4B)+LM75(4A) < 140, Set 8
# LM77(48)+LM75(4B)+LM75(4A) < 150, Set 10
# LM77(48)+LM75(4B)+LM75(4A) < 160, Set 12
# Reset DUT:LM77(48)>=70C
#
class switch(object): class switch(object):
def __init__(self, value): def __init__(self, value):
self.value = value self.value = value
@ -87,13 +80,13 @@ class switch(object):
else: else:
return False return False
fan_policy_state=0
fan_policy_state=1
fan_fail=0 fan_fail=0
alarm_state = 0 #0->default or clear, 1-->alarm detect alarm_state = 0 #0->default or clear, 1-->alarm detect
test_temp = 0 test_temp = 0
test_temp_list = [0, 0, 0, 0, 0, 0] test_temp_list = [0, 0, 0]
temp_test_data=0 temp_test_data=0
test_temp_revert=0
# Make a class we can use to capture stdout and sterr in the log # Make a class we can use to capture stdout and sterr in the log
class device_monitor(object): class device_monitor(object):
# static temp var # static temp var
@ -125,118 +118,70 @@ class device_monitor(object):
sys_handler.setLevel(logging.WARNING) sys_handler.setLevel(logging.WARNING)
logging.getLogger('').addHandler(sys_handler) logging.getLogger('').addHandler(sys_handler)
#logging.debug('SET. logfile:%s / loglevel:%d', log_file, log_level)
def get_state_from_fan_policy(self, temp, policy): def get_state_from_fan_policy(self, temp, policy):
state=0 state=0
logging.debug('temp=%d', temp)
for i in range(0, len(policy)): for i in range(0, len(policy)):
#logging.debug('policy[%d][0]=%d, policy[%d][1]=%d, policy[%d][2]=%d', i,policy[i][0],i, policy[i][1], i, policy[i][2]) if (temp > policy[i][2]): #temp_down
if temp > policy[i][2]: if temp <= policy[i][3]: #temp_up
if temp <= policy[i][3]:
state =i state =i
logging.debug ('temp=%d >= policy[%d][2]=%d, temp=%d < policy[%d][3]=%d' , temp, i, policy[i][2], temp, i, policy[i][3])
logging.debug ('fan_state=%d', state)
break
return state return state
def manage_fans(self): def manage_fans(self):
global fan_policy_state global fan_policy_state
global fan_fail global fan_fail
global test_temp global test_temp
global test_temp_list global test_temp_list
global alarm_state global alarm_state
global temp_test_data global temp_test_data
global test_temp_revert
LEVEL_FAN_DEF=0 LEVEL_FAN_MIN=0
LEVEL_FAN_MID=1 LEVEL_FAN_NORMAL=1
LEVEL_FAN_MAX=2 LEVEL_FAN_MID=2
LEVEL_TEMP_HIGH=3 LEVEL_FAN_HIGH=3
LEVEL_TEMP_CRITICAL=4 LEVEL_TEMP_CRITICAL=4
fan_policy = {
LEVEL_FAN_MIN: [50, 8, 0, 140000],
fan_policy_f2b = { LEVEL_FAN_NORMAL: [62, 10, 140000, 150000],
LEVEL_FAN_DEF: [38, 0x4, 0, 38000], LEVEL_FAN_MID: [75, 12, 150000, 160000],
LEVEL_FAN_MID: [63, 0x6, 38000, 46000], LEVEL_FAN_HIGH: [88, 14, 160000, 240000],
LEVEL_FAN_MAX: [100, 0xE, 46000, 58000], LEVEL_TEMP_CRITICAL: [100, 16, 240000, 300000],
LEVEL_TEMP_HIGH: [100, 0xE, 58000, 66000],
LEVEL_TEMP_CRITICAL: [100, 0xE, 58000, 200000],
} }
fan_policy_b2f = { temp = [0, 0 , 0]
LEVEL_FAN_DEF: [38, 0x4, 0, 34000], temp_fail=0
LEVEL_FAN_MID: [63, 0x8, 34000, 44000],
LEVEL_FAN_MAX: [100, 0xE, 44000, 59000],
LEVEL_TEMP_HIGH: [100, 0xE, 59000, 67000],
LEVEL_TEMP_CRITICAL: [100, 0xE, 59000, 200000],
}
fan_policy = fan_policy_f2b
thermal = ThermalUtil() thermal = ThermalUtil()
fan = FanUtil() fan = FanUtil()
fan_dir=fan.get_fan_dir(1) ori_duty_cycle=fan.get_fan_duty_cycle()
if fan_dir == 1: new_duty_cycle=0
fan_dri=1 #something wrong, set fan_dir to default val
else:
fan_policy = fan_policy_b2f
ori_pwm=fan.get_fan_duty_cycle()
new_pwm=0
logging.debug('fan_dir=%d, ori_pwm=%d', fan_dir, ori_pwm)
logging.debug('test_temp=%d', test_temp)
if test_temp==0: if test_temp==0:
temp1 = thermal._get_thermal_val(1) for i in range(0,3):
temp2 = thermal._get_thermal_val(2) temp[i]=thermal._get_thermal_val(i+1)
temp3 = thermal._get_thermal_val(3) if temp[i]==0 or temp[i]==None:
temp4 = thermal._get_thermal_val(4) temp_fail=1
temp5 = thermal._get_thermal_val(5) logging.warning("Get temp-%d fail", i);
return False
else: else:
temp1 = test_temp_list[0] if test_temp_revert==0:
temp2 = test_temp_list[1] temp_test_data=temp_test_data+2000
temp3 = test_temp_list[2] else:
temp4 = test_temp_list[3] temp_test_data=temp_test_data-2000
temp5 = test_temp_list[4]
for i in range(0,3):
temp[i]=test_temp_list[i]+temp_test_data
fan_fail=0 fan_fail=0
if temp3==0: temp_val=0
temp_get=50000 # if one detect sensor is fail or zero, assign temp=50000, let fan to 75% for i in range(0,3):
logging.debug('lm75_49 detect fail, so set temp_get=50000, let fan to 75%') if temp[i]==None:
elif temp4==0: break
temp_get=50000 # if one detect sensor is fail or zero, assign temp=50000, let fan to 75% temp_val+=temp[i]
logging.debug('lm75_4b detect fail, so set temp_get=50000, let fan to 75%')
else:
temp_get= (temp3 + temp4)/2 # Use (sensor_LM75_4a + sensor_LM75_4b) /2
ori_state=fan_policy_state
#temp_test_data=temp_test_data+1000
#temp_get = temp_get + temp_test_data
#print "Unit test:temp_get=%d"%temp_get
fan_policy_state=self.get_state_from_fan_policy(temp_get, fan_policy)
#print "temp3=%d"%temp3
#print "temp4=%d"%temp4
#print "temp_get=%d"%temp_get
logging.debug('lm75_48=%d, lm75_49=%d, lm75_4a=%d, lm_4b=%d, lm_4b=%d', temp1,temp2,temp3,temp4,temp5)
logging.debug('ori_state=%d, fan_policy_state=%d', ori_state, fan_policy_state)
new_pwm = fan_policy[fan_policy_state][0]
if fan_fail==0:
logging.debug('new_fan_cycle=%d', new_pwm)
if fan_fail==0:
if new_pwm!=ori_pwm:
fan.set_fan_duty_cycle(new_pwm)
logging.info('Set fan speed from %d to %d', ori_pwm, new_pwm)
#Check Fan status #Check Fan status
for i in range (fan.FAN_NUM_1_IDX, fan.FAN_NUM_ON_MAIN_BROAD+1): for i in range (fan.FAN_NUM_1_IDX, fan.FAN_NUM_ON_MAIN_BROAD+1):
if fan.get_fan_status(i)==0: if fan.get_fan_status(i)==0:
new_pwm=100 new_pwm=100
logging.debug('fan_%d fail, set pwm to 100',i) logging.warning('Fan_%d fail, set pwm to 100',i)
if test_temp==0: if test_temp==0:
fan_fail=1 fan_fail=1
fan.set_fan_duty_cycle(new_pwm) fan.set_fan_duty_cycle(new_pwm)
@ -244,58 +189,37 @@ class device_monitor(object):
else: else:
fan_fail=0 fan_fail=0
#if fan_policy_state == ori_state: ori_state=fan_policy_state
# return True fan_policy_state=self.get_state_from_fan_policy(temp_val, fan_policy)
#else:
new_state = fan_policy_state
#logging.warning('Temperature high alarm testing') if fan_policy_state > LEVEL_TEMP_CRITICAL or fan_policy_state < LEVEL_FAN_MIN:
if ori_state==LEVEL_FAN_DEF: logging.error("Get error fan current_state\n");
if new_state==LEVEL_TEMP_HIGH: return 0
#Decision : Decide new fan pwm percent.
if fan_fail==0 and ori_duty_cycle!=fan_policy[fan_policy_state][0]:
new_duty_cycle = fan_policy[fan_policy_state][0];
fan.set_fan_duty_cycle(new_duty_cycle)
if temp[0] >= 70000: #LM75-48
#critical case*/
logging.critical('Alarm-Critical for temperature critical is detected, reset DUT')
cmd_str="i2cset -y -f 3 0x60 0x4 0xE4"
time.sleep(2);
status, output = commands.getstatusoutput(cmd_str)
#logging.debug('ori_state=%d, current_state=%d, temp_val=%d\n\n',ori_state, fan_policy_state, temp_val)
if ori_state < LEVEL_FAN_HIGH:
if fan_policy_state >= LEVEL_FAN_HIGH:
if alarm_state==0: if alarm_state==0:
logging.warning('Alarm for temperature high is detected') logging.warning('Alarm for temperature high is detected')
alarm_state=1 alarm_state=1
if new_state==LEVEL_TEMP_CRITICAL:
logging.critical('Alarm for temperature critical is detected, reboot DUT') if fan_policy_state < LEVEL_FAN_MID:
time.sleep(2)
os.system('reboot')
if ori_state==LEVEL_FAN_MID:
if new_state==LEVEL_TEMP_HIGH:
if alarm_state==0:
logging.warning('Alarm for temperature high is detected')
alarm_state=1
if new_state==LEVEL_TEMP_CRITICAL:
logging.critical('Alarm for temperature critical is detected')
time.sleep(2)
os.system('reboot')
if ori_state==LEVEL_FAN_MAX:
if new_state==LEVEL_TEMP_HIGH:
if alarm_state==0:
logging.warning('Alarm for temperature high is detected')
alarm_state=1
if new_state==LEVEL_TEMP_CRITICAL:
logging.critical('Alarm for temperature critical is detected')
time.sleep(2)
os.system('reboot')
if alarm_state==1: if alarm_state==1:
if temp_get < (fan_policy[3][0] - 5000): #below 65 C, clear alarm logging.info('Alarm for temperature high is cleared')
logging.warning('Alarm for temperature high is cleared')
alarm_state=0 alarm_state=0
if ori_state==LEVEL_TEMP_HIGH:
if new_state==LEVEL_TEMP_CRITICAL:
logging.critical('Alarm for temperature critical is detected')
time.sleep(2)
os.system('reboot')
if new_state <= LEVEL_FAN_MID:
logging.warning('Alarm for temperature high is cleared')
alarm_state=0
if new_state <= LEVEL_FAN_MAX:
if temp_get < (fan_policy[3][0] - 5000): #below 65 C, clear alarm
logging.warning('Alarm for temperature high is cleared')
alarm_state=0
if ori_state==LEVEL_TEMP_CRITICAL:
if new_state <= LEVEL_FAN_MAX:
logging.warning('Alarm for temperature critical is cleared')
return True return True
@ -319,12 +243,12 @@ def main(argv):
log_file = arg log_file = arg
if sys.argv[1]== '-t': if sys.argv[1]== '-t':
if len(sys.argv)!=7: if len(sys.argv)!=5:
print "temp test, need input six temp" print "temp test, need input three temp"
return 0 return 0
i=0 i=0
for x in range(2, 7): for x in range(2, 5):
test_temp_list[i]= int(sys.argv[x])*1000 test_temp_list[i]= int(sys.argv[x])*1000
i=i+1 i=i+1
test_temp = 1 test_temp = 1
@ -332,13 +256,13 @@ def main(argv):
print test_temp_list print test_temp_list
fan = FanUtil() fan = FanUtil()
fan.set_fan_duty_cycle(38) fan.set_fan_duty_cycle(50)
print "set default fan speed to 37.5%" print "set default fan speed to 50%"
monitor = device_monitor(log_file, log_level) monitor = device_monitor(log_file, log_level)
# Loop forever, doing something useful hopefully: # Loop forever, doing something useful hopefully:
while True: while True:
#monitor.manage_fans() monitor.manage_fans()
time.sleep(5) time.sleep(10) #10sec
if __name__ == '__main__': if __name__ == '__main__':
main(sys.argv[1:]) main(sys.argv[1:])

View File

@ -68,7 +68,6 @@ Description: kernel modules for platform devices such as fan, led, sfp
Package: sonic-platform-accton-as5835-54t Package: sonic-platform-accton-as5835-54t
Architecture: amd64 Architecture: amd64
Description: kernel modules for platform devices such as fan, led, sfp Description: kernel modules for platform devices such as fan, led, sfp
Package: sonic-platform-accton-as7312-54xs Package: sonic-platform-accton-as7312-54xs
Architecture: amd64 Architecture: amd64
Description: kernel modules for platform devices such as fan, led, sfp Description: kernel modules for platform devices such as fan, led, sfp