Skip to content

Commit 0187c64

Browse files
author
Shuotian Cheng
authored
[syncd]: Only query queue counters that are needed by the application (sonic-net#261)
The previous hardcoded for loop to iterate items defined in the SAI header file was not ideal. Update the logic here so that only needed attributes are checked for the support. Signed-off-by: Shu0T1an ChenG <[email protected]>
1 parent f1f7f26 commit 0187c64

2 files changed

Lines changed: 18 additions & 12 deletions

File tree

syncd/syncd_flex_counter.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ FlexCounter::QueueAttrIds::QueueAttrIds(
2727
{
2828
}
2929

30+
/* The current implementation of 'setPortCounterList' and 'setQueueCounterList' are
31+
* not the same. Need to refactor these two functions to have the similar logic.
32+
* Either the full SAI attributes are queried once, or each of the needed counters
33+
* will be queried when they are set.
34+
*/
3035
void FlexCounter::setPortCounterList(
3136
_In_ sai_object_id_t portVid,
3237
_In_ sai_object_id_t portId,
@@ -90,11 +95,7 @@ void FlexCounter::setQueueCounterList(
9095

9196
FlexCounter &fc = getInstance(pollInterval);
9297

93-
// Initialize the supported counters list before setting
94-
if (fc.m_supportedQueueCounters.size() == 0)
95-
{
96-
fc.saiUpdateSupportedQueueCounters(queueId);
97-
}
98+
fc.saiUpdateSupportedQueueCounters(queueId, counterIds);
9899

99100
// Remove unsupported counters
100101
std::vector<sai_queue_stat_t> supportedIds;
@@ -579,25 +580,30 @@ void FlexCounter::saiUpdateSupportedPortCounters(sai_object_id_t portId)
579580
}
580581
}
581582

582-
void FlexCounter::saiUpdateSupportedQueueCounters(sai_object_id_t queueId)
583+
void FlexCounter::saiUpdateSupportedQueueCounters(
584+
_In_ sai_object_id_t queueId,
585+
_In_ const std::vector<sai_queue_stat_t> &counterIds)
583586
{
584587
uint64_t value;
585-
for (int cntr_id = SAI_QUEUE_STAT_PACKETS; cntr_id <= SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES; ++cntr_id)
586-
{
587-
sai_queue_stat_t counter = static_cast<sai_queue_stat_t>(cntr_id);
588+
m_supportedQueueCounters.clear();
588589

590+
for (auto &counter : counterIds)
591+
{
589592
sai_status_t status = sai_metadata_sai_queue_api->get_queue_stats(queueId, 1, &counter, &value);
590593

591594
if (status != SAI_STATUS_SUCCESS)
592595
{
593-
SWSS_LOG_WARN("Counter %s is not supported on port RID %s: %s",
596+
SWSS_LOG_WARN("Counter %s is not supported on queue %s, rv: %s",
594597
sai_serialize_queue_stat(counter).c_str(),
595598
sai_serialize_object_id(queueId).c_str(),
596599
sai_serialize_status(status).c_str());
597600

598601
continue;
599602
}
603+
else
604+
{
605+
m_supportedQueueCounters.insert(counter);
606+
}
600607

601-
m_supportedQueueCounters.insert(counter);
602608
}
603609
}

syncd/syncd_flex_counter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class FlexCounter
9393
void endFlexCounterThread(void);
9494

9595
void saiUpdateSupportedPortCounters(sai_object_id_t portId);
96-
void saiUpdateSupportedQueueCounters(sai_object_id_t queueId);
96+
void saiUpdateSupportedQueueCounters(sai_object_id_t queueId, const std::vector<sai_queue_stat_t> &counterIds);
9797
bool isPortCounterSupported(sai_port_stat_t counter) const;
9898
bool isQueueCounterSupported(sai_queue_stat_t counter) const;
9999

0 commit comments

Comments
 (0)