Skip to content

Commit 1fcaa57

Browse files
[pcied] Add PCIe AER stats collection (sonic-net#100)
In pcied, added support to collect AER stats belonging to different severities for AER supported PCIe devices and update it in STATE_DB. The key used to represent a PCIE device for storing its AER stats in STATE_DB is of the format PCIE_DEVICE|<Bus>:<Dev>.<Fn>. For every device, AER stats will be stored as key, value pairs where key is of the format <severity>|<AER Error type> and the device ID will be stored with key id. HLD: sonic-net/SONiC#678, sonic-net/SONiC#720 Depends on: sonic-net/sonic-platform-common#144
1 parent e72f6cd commit 1fcaa57

File tree

1 file changed

+47
-4
lines changed

1 file changed

+47
-4
lines changed

sonic-pcied/scripts/pcied

+47-4
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
try:
99
import os
1010
import signal
11-
import subprocess
1211
import sys
1312
import threading
1413

1514
import swsssdk
16-
from sonic_py_common.daemon_base import DaemonBase
17-
from sonic_py_common import device_info
15+
from sonic_py_common import daemon_base, device_info
16+
from swsscommon import swsscommon
1817
except ImportError as e:
1918
raise ImportError(str(e) + " - required module not found")
2019

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

2625
PCIE_RESULT_REGEX = "PCIe Device Checking All Test"
2726
PCIE_TABLE_NAME = "PCIE_STATUS"
27+
PCIE_DEVICE_TABLE_NAME = "PCIE_DEVICE"
2828

2929
PCIE_CONF_FILE = 'pcie.yaml'
3030

@@ -36,7 +36,7 @@ REDIS_HOSTIP = "127.0.0.1"
3636
#
3737

3838

39-
class DaemonPcied(DaemonBase):
39+
class DaemonPcied(daemon_base.DaemonBase):
4040
def __init__(self, log_identifier):
4141
super(DaemonPcied, self).__init__(log_identifier)
4242

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

5353
self.state_db = swsssdk.SonicV2Connector(host=REDIS_HOSTIP)
5454
self.state_db.connect("STATE_DB")
55+
state_db = daemon_base.db_connect("STATE_DB")
56+
self.device_table = swsscommon.Table(state_db, PCIE_DEVICE_TABLE_NAME)
57+
58+
# Load AER-fields into STATEDB
59+
def update_aer_to_statedb(self, device_name, aer_stats):
60+
61+
aer_fields = {}
62+
63+
for field, value in aer_stats['correctable'].items():
64+
correctable_field = "correctable|" + field
65+
aer_fields[correctable_field] = value
66+
67+
for field, value in aer_stats['fatal'].items():
68+
fatal_field = "fatal|" + field
69+
aer_fields[fatal_field] = value
70+
71+
for field, value in aer_stats['non_fatal'].items():
72+
non_fatal_field = "non_fatal|" + field
73+
aer_fields[non_fatal_field] = value
74+
75+
if aer_fields:
76+
formatted_fields = swsscommon.FieldValuePairs(list(aer_fields.items()))
77+
self.device_table.set(device_name, formatted_fields)
78+
else:
79+
self.log_debug("PCIe device {} has no AER attriutes".format(device_name))
5580

5681
# Check the PCIe devices
5782
def check_pcie_devices(self):
@@ -84,6 +109,24 @@ class DaemonPcied(DaemonBase):
84109
self.update_state_db("PCIE_DEVICES", "status", "PASSED")
85110
self.log_info("PCIe device status check : PASSED")
86111

112+
# update AER-attributes to DB
113+
for item in resultInfo:
114+
if item["result"] == "Failed":
115+
continue
116+
117+
Bus = int(item["bus"], 16)
118+
Dev = int(item["dev"], 16)
119+
Fn = int(item["fn"], 16)
120+
121+
device_name = "%02x:%02x.%d" % (Bus, Dev, Fn)
122+
dev_id_path = '/sys/bus/pci/devices/0000:%s/device' % device_name
123+
with open(dev_id_path, 'r') as fd:
124+
Id = fd.read().strip()
125+
126+
self.device_table.set(device_name, [('id', Id)])
127+
aer_stats = platform_pcieutil.get_pcie_aer_stats(bus=Bus, device=Dev, func=Fn)
128+
self.update_aer_to_statedb(device_name, aer_stats)
129+
87130
def read_state_db(self, key1, key2):
88131
return self.state_db.get('STATE_DB', key1, key2)
89132

0 commit comments

Comments
 (0)