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

[AS9716-32D] Modify thermal code to python3 #9969

Open
wants to merge 1 commit 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
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,12 @@ class FanUtil(object):
BASE_VAL_PATH = '/sys/bus/i2c/devices/17-0066/{0}'
FAN_DUTY_PATH = '/sys/bus/i2c/devices/17-0066/fan_duty_cycle_percentage'

#logfile = ''
#loglevel = logging.INFO

""" Dictionary where
key1 = fan id index (integer) starting from 1
key2 = fan node index (interger) starting from 1
value = path to fan device file (string) """
_fan_device_path_mapping = {}

#fan1_direction
#fan1_fault
#fan1_present

#(FAN_NUM_2_IDX, FAN_NODE_DUTY_IDX_OF_MAP): 'fan2_duty_cycle_percentage',
_fan_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',
Expand Down Expand Up @@ -106,7 +98,7 @@ def _get_fan_node_val(self, fan_num, node_num):
return None

try:
val_file.close()
val_file.close()
except:
logging.debug('GET. unable to close file. device_path:%s', device_path)
return None
Expand Down Expand Up @@ -137,7 +129,7 @@ def _set_fan_node_val(self, fan_num, node_num, val):
val_file.write(content)

try:
val_file.close()
val_file.close()
except:
logging.debug('GET. unable to close file. device_path:%s', device_path)
return None
Expand Down Expand Up @@ -184,7 +176,7 @@ def get_fan_duty_cycle(self):
try:
val_file = open(self.FAN_DUTY_PATH)
except IOError as e:
print("Error: unable to open file: %s" % str(e))
print("Error: unable to open file: %s" % str(e))
return False

content = val_file.readline().rstrip()
Expand All @@ -196,7 +188,7 @@ 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))
print("Error: unable to open file: %s" % str(e))
return False

fan_file.write(str(val))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import time
import logging
import glob
import subprocess
from collections import namedtuple
except ImportError as e:
raise ImportError('%s - required module not found' % str(e))
Expand Down Expand Up @@ -76,7 +75,7 @@ def _get_thermal_val(self, thermal_num):
logging.debug('GET. content is NULL. device_path:%s', device_path)
return None
try:
val_file.close()
val_file.close()
except:
logging.debug('GET. unable to close file. device_path:%s', device_path)
return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import logging
import logging.config
import logging.handlers
import time # this is only being used as part of the example
import time
from as9716_32d.fanutil import FanUtil
from as9716_32d.thermalutil import ThermalUtil
except ImportError as e:
Expand Down Expand Up @@ -289,7 +289,7 @@ def __init__(self, log_file, log_level):
console.setFormatter(formatter)
logging.getLogger('').addHandler(console)

sys_handler = handler = logging.handlers.SysLogHandler(address = '/dev/log')
sys_handler = logging.handlers.SysLogHandler(address = '/dev/log')
sys_handler.setLevel(logging.WARNING)
logging.getLogger('').addHandler(sys_handler)
#logging.debug('SET. logfile:%s / loglevel:%d', log_file, log_level)
Expand All @@ -313,8 +313,7 @@ def manage_fans(self):
LEVEL_FAN_INIT=0
LEVEL_FAN_MIN=1
LEVEL_FAN_MID=2
LEVEL_FAN_MAX=3
LEVEL_FAN_DEF=LEVEL_FAN_MAX
LEVEL_FAN_MAX=3 #LEVEL_FAN_DEF
LEVEL_FAN_YELLOW_ALARM=4
LEVEL_FAN_RED_ALARM=5
LEVEL_FAN_SHUTDOWN=6
Expand Down Expand Up @@ -360,7 +359,6 @@ def manage_fans(self):
count_check=0

thermal = ThermalUtil()
fan_dir=1
fan_dir=fan.get_fan_dir(1)

if fan_dir==1: # AFI
Expand Down Expand Up @@ -405,8 +403,9 @@ def manage_fans(self):
max_to_mid=max_to_mid+1

if max_to_mid==thermal.THERMAL_NUM_MAX and fan_policy_state==LEVEL_FAN_MAX:
current_state=LEVEL_FAN_MID
logging.debug("current_state=LEVEL_FAN_MID")
if fan_fail==0:
current_state=LEVEL_FAN_MID
logging.debug("current_state=LEVEL_FAN_MID")
else: #AFO
psu_full_load=check_psu_loading()
for i in range (0, thermal.THERMAL_NUM_MAX):
Expand All @@ -418,10 +417,10 @@ def manage_fans(self):
if psu_full_load!=True and thermal_val[i] <= fan_thermal_spec["mid_to_min_temp"][i]:
mid_to_min=mid_to_min+1
elif ori_state==LEVEL_FAN_MIN:
if psu_full_load==True:
if psu_full_load==True and fan_fail==0:
current_state=LEVEL_FAN_MID
logging.debug("psu_full_load, set current_state=LEVEL_FAN_MID")
if thermal_val[i] >= fan_thermal_spec["min_to_mid_temp"][i]:
if thermal_val[i] >= fan_thermal_spec["min_to_mid_temp"][i] and fan_fail==0:
current_state=LEVEL_FAN_MID

else:
Expand All @@ -447,14 +446,15 @@ def manage_fans(self):
power_off_dut()

if max_to_mid==thermal.THERMAL_NUM_MAX and ori_state==LEVEL_FAN_MAX:
current_state=LEVEL_FAN_MID
if fan_fail==0:
current_state=LEVEL_FAN_MID
logging.debug("current_state=LEVEL_FAN_MID")
if fan_policy_alarm!=0:
logging.warning('Alarm for temperature high is cleared')
fan_policy_alarm=0
send_yellow_alarm=0
send_red_alarm=0
test_temp_revert=0
logging.debug("current_state=LEVEL_FAN_MID")

if mid_to_min==thermal.THERMAL_NUM_MAX and ori_state==LEVEL_FAN_MID:
if psu_full_load==0:
Expand All @@ -468,6 +468,16 @@ def manage_fans(self):
logging.debug('fan_%d fail, set duty_cycle to 100',i)
if test_temp==0:
fan_fail=1
#1.When insert/remove fan, fan speed/log still according to thermal policy.
#2.If thermal policy state is bigger than LEVEL_FAN_MAX:
# Do not change back to LEVEL_FAN_MAX, beacuse still need to deal with LOG or shutdown case.
#3.If thermal policy state is smaller than LEVEL_FAN_MAX, set state=MAX.
# When remove and insert back fan test, policy check temp and set to correct fan_speed.
#

if current_state < LEVEL_FAN_MAX:
current_state=LEVEL_FAN_MAX
logging.debug('fan_%d fail, current_state=LEVEL_FAN_MAX', i)
fan.set_fan_duty_cycle(new_duty_cycle)
break
else:
Expand Down