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

[pcied] Add PCIe AER stats collection #100

Merged
merged 3 commits into from
Jan 26, 2021
Merged
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
51 changes: 47 additions & 4 deletions sonic-pcied/scripts/pcied
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
try:
import os
import signal
import subprocess
import sys
import threading

import swsssdk
from sonic_py_common.daemon_base import DaemonBase
from sonic_py_common import device_info
from sonic_py_common import daemon_base, device_info
from swsscommon import swsscommon
except ImportError as e:
raise ImportError(str(e) + " - required module not found")

Expand All @@ -25,6 +24,7 @@ SYSLOG_IDENTIFIER = "pcied"

PCIE_RESULT_REGEX = "PCIe Device Checking All Test"
PCIE_TABLE_NAME = "PCIE_STATUS"
PCIE_DEVICE_TABLE_NAME = "PCIE_DEVICE"

PCIE_CONF_FILE = 'pcie.yaml'

Expand All @@ -36,7 +36,7 @@ REDIS_HOSTIP = "127.0.0.1"
#


class DaemonPcied(DaemonBase):
class DaemonPcied(daemon_base.DaemonBase):
def __init__(self, log_identifier):
super(DaemonPcied, self).__init__(log_identifier)

Expand All @@ -52,6 +52,31 @@ class DaemonPcied(DaemonBase):

self.state_db = swsssdk.SonicV2Connector(host=REDIS_HOSTIP)
self.state_db.connect("STATE_DB")
state_db = daemon_base.db_connect("STATE_DB")
self.device_table = swsscommon.Table(state_db, PCIE_DEVICE_TABLE_NAME)

# Load AER-fields into STATEDB
def update_aer_to_statedb(self, device_name, aer_stats):

aer_fields = {}

for field, value in aer_stats['correctable'].items():
correctable_field = "correctable|" + field
aer_fields[correctable_field] = value

for field, value in aer_stats['fatal'].items():
fatal_field = "fatal|" + field
aer_fields[fatal_field] = value

for field, value in aer_stats['non_fatal'].items():
non_fatal_field = "non_fatal|" + field
aer_fields[non_fatal_field] = value

if aer_fields:
formatted_fields = swsscommon.FieldValuePairs(list(aer_fields.items()))
self.device_table.set(device_name, formatted_fields)
else:
self.log_debug("PCIe device {} has no AER attriutes".format(device_name))

# Check the PCIe devices
def check_pcie_devices(self):
Expand Down Expand Up @@ -84,6 +109,24 @@ class DaemonPcied(DaemonBase):
self.update_state_db("PCIE_DEVICES", "status", "PASSED")
self.log_info("PCIe device status check : PASSED")

# update AER-attributes to DB
for item in resultInfo:
if item["result"] == "Failed":
sujinmkang marked this conversation as resolved.
Show resolved Hide resolved
continue

Bus = int(item["bus"], 16)
Dev = int(item["dev"], 16)
Fn = int(item["fn"], 16)

device_name = "%02x:%02x.%d" % (Bus, Dev, Fn)
dev_id_path = '/sys/bus/pci/devices/0000:%s/device' % device_name
with open(dev_id_path, 'r') as fd:
Id = fd.read().strip()

self.device_table.set(device_name, [('id', Id)])
aer_stats = platform_pcieutil.get_pcie_aer_stats(bus=Bus, device=Dev, func=Fn)
self.update_aer_to_statedb(device_name, aer_stats)

def read_state_db(self, key1, key2):
return self.state_db.get('STATE_DB', key1, key2)

Expand Down