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

Add support as7326 thermal plan. Monitor fan/psu #2344

Merged
merged 3 commits into from
Dec 6, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -18,9 +18,9 @@
# ------------------------------------------------------------------
# HISTORY:
# mm/dd/yyyy (A.D.)
# 11/13/2017: Polly Hsu, Create
# 1/10/2018: Jostar modify for as7716_32
# 3/32/2018: Roy Lee modify for as7326_56x
# 3/23/2018: Roy Lee modify for as7326_56x
# 6/26/2018: Jostar implement by new thermal policy from HW RD
# ------------------------------------------------------------------
# ------------------------------------------------------------------

try:
Expand All @@ -44,7 +44,6 @@ class FanUtil(object):

FAN_NODE_NUM_OF_MAP = 2
FAN_NODE_FAULT_IDX_OF_MAP = 1
#FAN_NODE_SPEED_IDX_OF_MAP = 2
FAN_NODE_DIR_IDX_OF_MAP = 2
#FAN_NODE_DUTY_IDX_OF_MAP = 4
#FANR_NODE_FAULT_IDX_OF_MAP = 5
Expand Down Expand Up @@ -215,7 +214,6 @@ def set_fan_duty_cycle(self, val):
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
Expand All @@ -232,7 +230,7 @@ def get_fan_status(self, 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)
#logging.debug('GET. FAN fault. fan_num, %d', fan_num)
return False

#if self.get_fanr_fault(fan_num) is not None and self.get_fanr_fault(fan_num) > 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,79 +18,133 @@
# ------------------------------------------------------------------
# HISTORY:
# mm/dd/yyyy (A.D.)
# 11/13/2017: Polly Hsu, Create
# 1/10/2018:Jostar modify for as7716_32x
# 3/23/2018: Roy Lee modify for as7326_56x
# 6/26/2018: Jostar implement by new thermal policy from HW RD
# ------------------------------------------------------------------

try:
import os
import time
import logging
import glob
import commands
from collections import namedtuple
except ImportError as e:
raise ImportError('%s - required module not found' % str(e))


class ThermalUtil(object):
"""Platform-specific ThermalUtil class"""
def log_os_system(cmd, show):
logging.info('Run :'+cmd)
status = 1
output = ""
status, output = commands.getstatusoutput(cmd)
if show:
print "ACC: " + str(cmd) + " , result:"+ str(status)

if status:
logging.info('Failed :'+cmd)
if show:
print('Failed :'+cmd)
return status, output

THERMAL_NUM_ON_MAIN_BROAD = 3
THERMAL_NUM_1_IDX = 1 # 1_ON_MAIN_BROAD
THERMAL_NUM_2_IDX = 2 # 2_ON_MAIN_BROAD
THERMAL_NUM_3_IDX = 3 # 3_ON_MAIN_BROAD

BASE_VAL_PATH = '/sys/bus/i2c/devices/{0}-00{1}/hwmon/hwmon*/temp1_input'
class ThermalUtil(object):
"""Platform-specific ThermalUtil class"""

THERMAL_NUM_MAX = 6
THERMAL_NUM_1_IDX = 1 # 1_ON_MAIN_BROAD. LM75
THERMAL_NUM_2_IDX = 2 # 2_ON_MAIN_BROAD. LM75
THERMAL_NUM_3_IDX = 3 # 3_ON_MAIN_BROAD. LM75
THERMAL_NUM_4_IDX = 4 # CPU board. LM75
THERMAL_NUM_5_IDX = 5 # CPU core thermal
THERMAL_NUM_6_IDX = 6 # BCM thermal

BCM_thermal_cmd = 'bcmcmd "show temp" > /tmp/bcm_thermal'
BCM_thermal_path = '/tmp/bcm_thermal'
#BCM_thermal_path = '/tmp/bcm_debug'
""" Dictionary where
key1 = thermal id index (integer) starting from 1
value = path to fan device file (string) """
_thermal_to_device_path_mapping = {}
#_thermal_to_device_path_mapping = {}

_thermal_to_device_node_mapping = {
THERMAL_NUM_1_IDX: ['15', '48'],
THERMAL_NUM_2_IDX: ['15', '49'],
THERMAL_NUM_3_IDX: ['15', '4a'],
THERMAL_NUM_4_IDX: ['15', '4b'],
}
thermal_sysfspath ={
THERMAL_NUM_1_IDX: ["/sys/bus/i2c/drivers/lm75/15-0048/hwmon/hwmon2/temp1_input"],
THERMAL_NUM_2_IDX: ["/sys/bus/i2c/drivers/lm75/15-0049/hwmon/hwmon3/temp1_input"],
THERMAL_NUM_3_IDX: ["/sys/bus/i2c/drivers/lm75/15-004a/hwmon/hwmon4/temp1_input"],
THERMAL_NUM_4_IDX: ["/sys/bus/i2c/drivers/lm75/15-004b/hwmon/hwmon5/temp1_input"],
THERMAL_NUM_5_IDX: ["/sys/class/hwmon/hwmon0/temp1_input"],
}

def __init__(self):
thermal_path = self.BASE_VAL_PATH
#def __init__(self):

for x in range(self.THERMAL_NUM_1_IDX, self.THERMAL_NUM_ON_MAIN_BROAD+1):
self._thermal_to_device_path_mapping[x] = thermal_path.format(
self._thermal_to_device_node_mapping[x][0],
self._thermal_to_device_node_mapping[x][1])

def _get_thermal_node_val(self, thermal_num):
if thermal_num < self.THERMAL_NUM_1_IDX or thermal_num > self.THERMAL_NUM_ON_MAIN_BROAD:
def _get_thermal_val(self, thermal_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)
return None

if thermal_num < self.THERMAL_NUM_6_IDX:
device_path = self.get_thermal_to_device_path(thermal_num)
if(os.path.isfile(device_path)):
for filename in glob.glob(device_path):
try:
val_file = open(filename, 'r')
except IOError as e:
logging.error('GET. unable to open file: %s', str(e))
return None

content = val_file.readline().rstrip()

if content == '':
logging.debug('GET. content is NULL. device_path:%s', device_path)
return None

try:
val_file.close()
except:
logging.debug('GET. unable to close file. device_path:%s', device_path)
return None
return int(content)

return int(content)

else:
print "No such device_path=%s"%device_path
return 0

else:
log_os_system(self.BCM_thermal_cmd,0)
file_path = self.BCM_thermal_path
check_file = open(file_path)
try:
check_file = open(file_path)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return 0
file_str = check_file.read()
search_str="average current temperature is"
print "file_str.find=%s"%file_str.find(search_str)
str_len = len(search_str)
idx=file_str.find(search_str)
if idx==-1:
print "bcm sdk is not ready ,retrun 0"
return 0
else:
#print "file_str[idx]=%c"%file_str[idx+str_len+1]
#print "file_str[idx]=%c"%file_str[idx+str_len+2]
#print "file_str[idx]=%c"%file_str[idx+str_len+2+1]
#print "file_str[idx]=%c"%file_str[idx+str_len+2+2]
#print "file_str[idx]=%c"%file_str[idx+str_len+2+3]
#print "file_str[idx]=%c"%file_str[idx+str_len+2+4]
#print "file_str[idx]=%c"%file_str[idx+str_len+2+5]
#print "file_str[idx]=%c"%file_str[idx+str_len+2+6]
temp_str=file_str[idx+str_len+1] + file_str[idx+str_len+2] + file_str[idx+str_len+3]+file_str[idx+str_len+4] +file_str[idx+str_len+5]
print "bcm temp_str=%s"%temp_str
check_file.close()
return float(temp_str)*1000

def get_num_thermals(self):
return self.THERMAL_NUM_ON_MAIN_BROAD
return self.THERMAL_NUM_MAX

def get_idx_thermal_start(self):
return self.THERMAL_NUM_1_IDX
Expand All @@ -99,10 +153,10 @@ def get_size_node_map(self):
return len(self._thermal_to_device_node_mapping)

def get_size_path_map(self):
return len(self._thermal_to_device_path_mapping)
return len(self.thermal_sysfspath)

def get_thermal_to_device_path(self, thermal_num):
return self._thermal_to_device_path_mapping[thermal_num]
return self.thermal_sysfspath[thermal_num][0]

def get_thermal_1_val(self):
return self._get_thermal_node_val(self.THERMAL_NUM_1_IDX)
Expand All @@ -112,13 +166,19 @@ def get_thermal_2_val(self):
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():
# thermal = ThermalUtil()
def main():
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)
print "termal6=%d" %thermal._get_thermal_val(6)
#
# print 'get_size_node_map : %d' % thermal.get_size_node_map()
# print 'get_size_path_map : %d' % thermal.get_size_path_map()
# for x in range(thermal.get_idx_thermal_start(), thermal.get_num_thermals()+1):
# print thermal.get_thermal_to_device_path(x)
#
#if __name__ == '__main__':
# main()
if __name__ == '__main__':
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
Description=Accton AS7326-56X Platform MAC hnadle service
Before=pmon.service
After=sysinit.target
DefaultDependencies=no

[Service]
ExecStart=/usr/local/bin/accton_handle_idt.sh
KillSignal=SIGKILL
SuccessExitStatus=SIGKILL

# Resource Limitations
LimitCORE=infinity

[Install]
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
Description=Accton AS7326-56X Platform Monitoring FAN service
Before=pmon.service
After=sysinit.target
DefaultDependencies=no

[Service]
ExecStart=/usr/local/bin/accton_as7326_monitor_fan.py
KillSignal=SIGKILL
SuccessExitStatus=SIGKILL

# Resource Limitations
LimitCORE=infinity

[Install]
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
Description=Accton AS7326-56X Platform Monitoring PSU service
Before=pmon.service
After=sysinit.target
DefaultDependencies=no

[Service]
ExecStart=/usr/local/bin/accton_as7326_monitor_psu.py
KillSignal=SIGKILL
SuccessExitStatus=SIGKILL

# Resource Limitations
LimitCORE=infinity

[Install]
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Unit]
Description=Accton AS7326-56X Platform Monitoring service
Before=pmon.service
After=sysinit.target
After=as7326-platform-handle_mac.service
DefaultDependencies=no

[Service]
Expand Down
Loading