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

ASIC temperature sensors support #2267

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions dockers/docker-orchagent/enable_counters.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def enable_counters():
enable_counter_group(db, 'PORT')
enable_counter_group(db, 'QUEUE')
enable_counter_group(db, 'PFCWD')
enable_counter_group(db, 'SENSORS')

def get_uptime():
with open('/proc/uptime') as fp:
Expand Down
117 changes: 117 additions & 0 deletions platform/broadcom/sonic-platform-modules-dell/common/asic_sensors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#! /usr/bin/python
# Retrieve the maximum number of thermal sensors supported on
# the ASIC from the flex counter DB and print the readings
# along wtih the average.

import swsssdk
import json
Copy link
Contributor

Choose a reason for hiding this comment

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

json is not used

import sys
import os
import pickle
from subprocess import Popen, PIPE

# temp files to cache constants
SENSORS_DIR = "/tmp/dell/sensors"
SWITCH_OID = "switch_oid"
MAX_SENSORS = "max_sensors"

# Load a value from a given file
def load_from_file(file):
if os.path.isfile(file):
try:
value = pickle.load(open(file, 'r'))
except IOError as e:
print e.errno, e
sys.exit(e.errno)
return value

# Dump a value into a given file
def dump_to_file(file, value):
if value:
try:
pickle.dump(value, open(file, 'w'))
except IOError as e:
print e.errno, e
sys.exit(e.errno)

# Get the switch OID should the ASIC support sensors
def get_switch_sensors_oid():
switch_oid_file = SENSORS_DIR + "/" + SWITCH_OID

# Check if we saved it in the tmp file already
if os.path.isfile(switch_oid_file):
return load_from_file(switch_oid_file)

if not os.path.exists(SENSORS_DIR):
try:
os.makedirs(SENSORS_DIR)
except IOError as e:
print e.errno, e
sys.exit(1)

# Retrieve the switch oid from the flex counter DB
# and save it in the file cache
proc = Popen("docker exec -i database redis-cli \
--raw -n 5 KEYS FLEX_COUNTER_TABLE:SWITCH_SENSORS*", \
stdout=PIPE, stderr=PIPE, shell=True)
out, err = proc.communicate()

for key in out.splitlines() or [None]:
if key:
id = key.replace('FLEX_COUNTER_TABLE:SWITCH_SENSORS:oid:', '')
if id:
dump_to_file(switch_oid_file, id)
return id
return None

# Get the number of sensor values that will be dumped to counters DB
def get_switch_max_sensors(sensors):
max_sensors_file = SENSORS_DIR + "/" + MAX_SENSORS

if os.path.isfile(max_sensors_file):
return load_from_file(max_sensors_file)

temp_list = [sensors[key] for key in sensors
if key.startswith('SAI_SWITCH_ATTR_TEMP_')]
max_sensors = len(temp_list)
if max_sensors:
dump_to_file(max_sensors_file, max_sensors)
return max_sensors

return 0

# Print the ASIC sensors from the counter DB
def print_asic_sensors():

countersdb = swsssdk.SonicV2Connector(host='127.0.0.1')
countersdb.connect(countersdb.COUNTERS_DB)

id = get_switch_sensors_oid()
if id:
sensors = countersdb.get_all(countersdb.COUNTERS_DB,
'COUNTERS:oid:' + id)
max_sensors = get_switch_max_sensors(sensors)

average_temp = sensors.get('SAI_SWITCH_ATTR_AVERAGE_TEMP')
max_temp = sensors.get('SAI_SWITCH_ATTR_MAX_TEMP')
temp_list = []

# Retrieve the list of individual sensor values
for i in range(max_sensors):
temp_list.append(sensors.get('SAI_SWITCH_ATTR_TEMP_%d' % i))

if (average_temp is not None) and \
(max_temp is not None) and \
(temp_list is not None):
print '\nBCM Internal: ' \
+ str(average_temp) + ' C' \
+ ' (max ' + str(max_temp) + ' C)' \
+ ' (' + ' '.join(str(x) for x in temp_list) + ' C)'
else:
print '\nBCM Internal: ' + 'NA'
Copy link
Contributor

Choose a reason for hiding this comment

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

could you provide a sample output here?


else:
print '\nBCM Internal: ' + 'NA'

countersdb.close(countersdb.COUNTERS_DB)

Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ static const char *const s6100_temp_label[] = {
"U2 Switch board?",
"Front GE",
"Front SFP+",
"BCM Internal",
"CPU Internal",
"Unused",
"Unused",
"",
"PSU 1",
"PSU 2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ common/dell_i2c_utils.sh usr/local/bin
common/fstrim.timer etc/systemd/system
common/fstrim.service etc/systemd/system
s6100/scripts/platform_sensors.py usr/local/bin
common/asic_sensors.py usr/local/bin
s6100/scripts/sensors usr/bin
s6100/systemd/platform-modules-s6100.service etc/systemd/system
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ common/dell_i2c_utils.sh usr/local/bin
common/fstrim.timer etc/systemd/system
common/fstrim.service etc/systemd/system
z9100/scripts/platform_sensors.py usr/local/bin
common/asic_sensors.py usr/local/bin
z9100/scripts/sensors usr/bin
z9100/cfg/z9100-modules.conf etc/modules-load.d
z9100/systemd/platform-modules-z9100.service etc/systemd/system
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import os
import sys
import logging
from asic_sensors import *

S6100_MAX_FAN_TRAYS = 4
S6100_MAX_PSUS = 2
Expand Down Expand Up @@ -319,4 +320,4 @@ def print_psu(psu):
for iom in range(1, S6100_MAX_IOMS+1):
print ' IOM ' + str(iom) + ' :' + iom_status_list[iom - 1]

print '\n'
print_asic_sensors()
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import os
import sys
import logging
from asic_sensors import *

Z9100_MAX_FAN_TRAYS = 5
Z9100_MAX_PSUS = 2
S6100_MAX_IOMS = 4

MAILBOX_DIR = "/sys/devices/platform/SMF.512/hwmon/hwmon0"

Expand Down Expand Up @@ -322,3 +322,6 @@ def print_psu(psu):
logging.error('Unable to check PSU presence')

print '\n Total Power: ', get_pmc_register('current_total_power'), 'W'

print_asic_sensors()