Skip to content
Merged
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
16 changes: 16 additions & 0 deletions meta/saiserialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,14 @@ std::string sai_serialize_queue_stat(
return sai_serialize_enum(counter, &sai_metadata_enum_sai_queue_stat_t);
}

std::string sai_serialize_queue_attr(
_In_ const sai_queue_attr_t attr)
{
SWSS_LOG_ENTER();

return sai_serialize_enum(attr, &sai_metadata_enum_sai_queue_attr_t);
}

std::string sai_serialize_switch_oper_status(
_In_ sai_object_id_t switch_id,
_In_ sai_switch_oper_status_t status)
Expand Down Expand Up @@ -2804,3 +2812,11 @@ void sai_deserialize_queue_stat(
sai_deserialize_enum(s, &sai_metadata_enum_sai_queue_stat_t, (int32_t&)stat);
}

void sai_deserialize_queue_attr(
_In_ const std::string& s,
_Out_ sai_queue_attr_t& attr)
{
SWSS_LOG_ENTER();

sai_deserialize_enum(s, &sai_metadata_enum_sai_queue_attr_t, (int32_t&)attr);
}
6 changes: 6 additions & 0 deletions meta/saiserialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ std::string sai_serialize_port_stat(
std::string sai_serialize_queue_stat(
_In_ const sai_queue_stat_t counter);

std::string sai_serialize_queue_attr(
_In_ const sai_queue_attr_t attr);

std::string sai_serialize_switch_oper_status(
_In_ sai_object_id_t switch_id,
_In_ sai_switch_oper_status_t status);
Expand Down Expand Up @@ -220,4 +223,7 @@ void sai_deserialize_queue_stat(
_In_ const std::string& s,
_Out_ sai_queue_stat_t& stat);

void sai_deserialize_queue_attr(
_In_ const std::string& s,
_Out_ sai_queue_attr_t& attr);
#endif // __SAI_SERIALIZE__
12 changes: 12 additions & 0 deletions syncd/syncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2410,6 +2410,18 @@ void processPfcWdEvent(
}
PfcWatchdog::setQueueCounterList(vid, rid, queueCounterIds);
}
else if (objectType == SAI_OBJECT_TYPE_QUEUE && field == PFC_WD_QUEUE_ATTR_ID_LIST)
{
std::vector<sai_queue_attr_t> queueAttrIds;
for (const auto &str : idStrings)
{
sai_queue_attr_t attr;
sai_deserialize_queue_attr(str, attr);
queueAttrIds.push_back(attr);
}

PfcWatchdog::setQueueAttrList(vid, rid, queueAttrIds);
}
else
{
SWSS_LOG_ERROR("Object type not supported");
Expand Down
99 changes: 90 additions & 9 deletions syncd/syncd_pfc_watchdog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ PfcWatchdog::QueueCounterIds::QueueCounterIds(
{
}

PfcWatchdog::QueueAttrIds::QueueAttrIds(
_In_ sai_object_id_t queue,
_In_ const std::vector<sai_queue_attr_t> &queueIds):
queueId(queue), queueAttrIds(queueIds)
{
}

void PfcWatchdog::setPortCounterList(
_In_ sai_object_id_t portVid,
_In_ sai_object_id_t portId,
Expand Down Expand Up @@ -64,6 +71,30 @@ void PfcWatchdog::setQueueCounterList(
wd.startWatchdogThread();
}

void PfcWatchdog::setQueueAttrList(
_In_ sai_object_id_t queueVid,
_In_ sai_object_id_t queueId,
_In_ const std::vector<sai_queue_attr_t> &attrIds)
{
SWSS_LOG_ENTER();

PfcWatchdog &wd = getInstance();

auto it = wd.m_queueAttrIdsMap.find(queueVid);
if (it != wd.m_queueAttrIdsMap.end())
{
(*it).second->queueAttrIds = attrIds;
return;
}

auto queueAttrIds = std::make_shared<QueueAttrIds>(queueId, attrIds);
wd.m_queueAttrIdsMap.emplace(queueVid, queueAttrIds);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Need to erase IDs on delete

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Updated


// Start watchdog thread in case it was not running due to empty counter IDs map
wd.startWatchdogThread();
}


void PfcWatchdog::removePort(
_In_ sai_object_id_t portVid)
{
Expand All @@ -81,7 +112,7 @@ void PfcWatchdog::removePort(
wd.m_portCounterIdsMap.erase(it);

// Stop watchdog thread if counter IDs map is empty
if (wd.m_queueCounterIdsMap.empty() && wd.m_portCounterIdsMap.empty())
if (wd.m_queueCounterIdsMap.empty() && wd.m_portCounterIdsMap.empty() && wd.m_queueAttrIdsMap.empty())
{
wd.endWatchdogThread();
}
Expand All @@ -94,17 +125,26 @@ void PfcWatchdog::removeQueue(

PfcWatchdog &wd = getInstance();

auto it = wd.m_queueCounterIdsMap.find(queueVid);
if (it == wd.m_queueCounterIdsMap.end())
auto counterIter = wd.m_queueCounterIdsMap.find(queueVid);
if (counterIter == wd.m_queueCounterIdsMap.end())
{
SWSS_LOG_ERROR("Trying to remove nonexisting queue counter Ids 0x%lx", queueVid);
return;
}

wd.m_queueCounterIdsMap.erase(it);
wd.m_queueCounterIdsMap.erase(counterIter);

auto attrIter = wd.m_queueAttrIdsMap.find(queueVid);
if (attrIter == wd.m_queueAttrIdsMap.end())
{
SWSS_LOG_ERROR("Trying to remove nonexisting queue attr Ids 0x%lx", queueVid);
return;
}

wd.m_queueAttrIdsMap.erase(attrIter);

// Stop watchdog thread if counter IDs map is empty
if (wd.m_queueCounterIdsMap.empty() && wd.m_portCounterIdsMap.empty())
if (wd.m_queueCounterIdsMap.empty() && wd.m_portCounterIdsMap.empty() && wd.m_queueAttrIdsMap.empty())
{
wd.endWatchdogThread();
}
Expand Down Expand Up @@ -176,8 +216,6 @@ void PfcWatchdog::collectCounters(
{
SWSS_LOG_ENTER();

std::lock_guard<std::mutex> lock(g_mutex);

// Collect stats for every registered port
for (const auto &kv: m_portCounterIdsMap)
{
Expand Down Expand Up @@ -249,15 +287,56 @@ void PfcWatchdog::collectCounters(

countersTable.set(queueVidStr, values, "");
}

// Collect stats for every registered queue
for (const auto &kv: m_queueAttrIdsMap)
{
const auto &queueVid = kv.first;
const auto &queueId = kv.second->queueId;
const auto &queueAttrIds = kv.second->queueAttrIds;

std::vector<sai_attribute_t> queueAttr(queueAttrIds.size());

for (uint64_t i =0; i< queueAttrIds.size(); i++)
{
queueAttr[i].id = queueAttrIds[i];
}

// Get queue attr
sai_status_t status = sai_metadata_sai_queue_api->get_queue_attribute(
queueId,
static_cast<uint32_t>(queueAttrIds.size()),
queueAttr.data());

if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to get attr of queue 0x%lx: %d", queueVid, status);
continue;
}

// Push all counter values to a single vector
std::vector<swss::FieldValueTuple> values;

for (size_t i = 0; i != queueAttrIds.size(); i++)
{
const std::string &counterName = sai_serialize_queue_attr(queueAttrIds[i]);
auto meta = sai_metadata_get_attr_metadata(SAI_OBJECT_TYPE_QUEUE, queueAttr[i].id);

values.emplace_back(counterName, sai_serialize_attr_value(*meta, queueAttr[i]));
}
// Write counters to DB
std::string queueVidStr = sai_serialize_object_id(queueVid);

countersTable.set(queueVidStr, values, "");
}

}

void PfcWatchdog::runPlugins(
_In_ swss::DBConnector& db)
{
SWSS_LOG_ENTER();

std::lock_guard<std::mutex> lock(g_mutex);

const std::vector<std::string> argv =
{
std::to_string(COUNTERS_DB),
Expand Down Expand Up @@ -299,6 +378,8 @@ void PfcWatchdog::pfcWatchdogThread(void)

while (m_runPfcWatchdogThread)
{

std::lock_guard<std::mutex> lock(g_mutex);
collectCounters(countersTable);
runPlugins(db);

Expand Down
16 changes: 16 additions & 0 deletions syncd/syncd_pfc_watchdog.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class PfcWatchdog
_In_ sai_object_id_t queueVid,
_In_ sai_object_id_t queueId,
_In_ const std::vector<sai_queue_stat_t> &counterIds);
static void setQueueAttrList(
_In_ sai_object_id_t queueVid,
_In_ sai_object_id_t queueId,
_In_ const std::vector<sai_queue_attr_t> &attrIds);

static void removePort(
_In_ sai_object_id_t portVid);
static void removeQueue(
Expand Down Expand Up @@ -49,6 +54,16 @@ class PfcWatchdog
std::vector<sai_queue_stat_t> queueCounterIds;
};

struct QueueAttrIds
{
QueueAttrIds(
_In_ sai_object_id_t queue,
_In_ const std::vector<sai_queue_attr_t> &queueIds);

sai_object_id_t queueId;
std::vector<sai_queue_attr_t> queueAttrIds;
};

struct PortCounterIds
{
PortCounterIds(
Expand All @@ -72,6 +87,7 @@ class PfcWatchdog
// Key is a Virtual ID
std::map<sai_object_id_t, std::shared_ptr<PortCounterIds>> m_portCounterIdsMap;
std::map<sai_object_id_t, std::shared_ptr<QueueCounterIds>> m_queueCounterIdsMap;
std::map<sai_object_id_t, std::shared_ptr<QueueAttrIds>> m_queueAttrIdsMap;

// Plugins
std::set<std::string> m_queuePlugins;
Expand Down