Skip to content

Commit caa4f0b

Browse files
authored
[pfcwd]: Only register lossless tc counters in database for query (sonic-net#455)
* [pfcwd]: Only register lossless tc counters in database for query Signed-off-by: Sihui Han <[email protected]> * update as comments Signed-off-by: Sihui Han <[email protected]> * rename the variable and function name Signed-off-by: Sihui Han <[email protected]> * minor change Signed-off-by: Sihui Han <[email protected]> * update Signed-off-by: Sihui Han <[email protected]>
1 parent 8e635fd commit caa4f0b

File tree

2 files changed

+55
-8
lines changed

2 files changed

+55
-8
lines changed

orchagent/pfcwdorch.cpp

+54-8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define PFC_WD_RESTORATION_TIME_MIN 100
2222
#define PFC_WD_POLL_TIMEOUT 5000
2323
#define PFC_WD_LOSSY_POLL_TIMEOUT_SEC (5 * 60)
24+
#define SAI_PORT_STAT_PFC_PREFIX "SAI_PORT_STAT_PFC_"
2425

2526
extern sai_port_api_t *sai_port_api;
2627
extern sai_queue_api_t *sai_queue_api;
@@ -400,24 +401,32 @@ void PfcWdSwOrch<DropHandler, ForwardHandler>::registerInWdDb(const Port& port,
400401
return;
401402
}
402403

404+
set<uint8_t> losslessTc;
405+
uint8_t pfcMask = attr.value.u8;
406+
for (uint8_t i = 0; i < PFC_WD_TC_MAX; i++)
407+
{
408+
if ((pfcMask & (1 << i)) == 0)
409+
{
410+
continue;
411+
}
412+
413+
losslessTc.insert(i);
414+
}
415+
403416
if (!c_portStatIds.empty())
404417
{
405418
string key = getFlexCounterTableKey(sai_serialize_object_id(port.m_port_id));
406419
vector<FieldValueTuple> fieldValues;
420+
// Only register lossless tc counters in database.
407421
string str = counterIdsToStr(c_portStatIds, &sai_serialize_port_stat);
408-
fieldValues.emplace_back(PORT_COUNTER_ID_LIST, str);
422+
string filteredStr = filterPfcCounters(str, losslessTc);
423+
fieldValues.emplace_back(PORT_COUNTER_ID_LIST, filteredStr);
409424

410425
m_flexCounterTable->set(key, fieldValues);
411426
}
412427

413-
uint8_t pfcMask = attr.value.u8;
414-
for (uint8_t i = 0; i < PFC_WD_TC_MAX; i++)
428+
for (auto i : losslessTc)
415429
{
416-
if ((pfcMask & (1 << i)) == 0)
417-
{
418-
continue;
419-
}
420-
421430
sai_object_id_t queueId = port.m_queue_ids[i];
422431
string queueIdStr = sai_serialize_object_id(queueId);
423432

@@ -461,9 +470,46 @@ void PfcWdSwOrch<DropHandler, ForwardHandler>::registerInWdDb(const Port& port,
461470
}
462471
}
463472

473+
template <typename DropHandler, typename ForwardHandler>
474+
string PfcWdSwOrch<DropHandler, ForwardHandler>::filterPfcCounters(string counters, set<uint8_t>& losslessTc)
475+
{
476+
SWSS_LOG_ENTER();
477+
478+
istringstream is(counters);
479+
string counter;
480+
string filterCounters;
481+
482+
while (getline(is, counter, ','))
483+
{
484+
size_t index = 0;
485+
index = counter.find(SAI_PORT_STAT_PFC_PREFIX);
486+
if (index != 0)
487+
{
488+
filterCounters = filterCounters + counter + ",";
489+
}
490+
else
491+
{
492+
uint8_t tc = (uint8_t)atoi(counter.substr(index + sizeof(SAI_PORT_STAT_PFC_PREFIX) - 1, 1).c_str());
493+
if (losslessTc.count(tc))
494+
{
495+
filterCounters = filterCounters + counter + ",";
496+
}
497+
}
498+
}
499+
500+
if (!filterCounters.empty())
501+
{
502+
filterCounters.pop_back();
503+
}
504+
505+
return filterCounters;
506+
}
507+
464508
template <typename DropHandler, typename ForwardHandler>
465509
string PfcWdSwOrch<DropHandler, ForwardHandler>::getFlexCounterTableKey(string key)
466510
{
511+
SWSS_LOG_ENTER();
512+
467513
return string(PFC_WD_FLEX_COUNTER_GROUP) + ":" + key;
468514
}
469515

orchagent/pfcwdorch.h

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class PfcWdSwOrch: public PfcWdOrch<DropHandler, ForwardHandler>
102102
void unregisterFromWdDb(const Port& port);
103103
void doTask(swss::NotificationConsumer &wdNotification);
104104

105+
string filterPfcCounters(string counters, set<uint8_t>& losslessTc);
105106
string getFlexCounterTableKey(string s);
106107
map<sai_object_id_t, PfcWdQueueEntry> m_entryMap;
107108

0 commit comments

Comments
 (0)