Skip to content

Commit

Permalink
[syncd]: Only query queue counters that are needed by the application (
Browse files Browse the repository at this point in the history
…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]>
  • Loading branch information
Shuotian Cheng authored Nov 21, 2017
1 parent f1f7f26 commit 0187c64
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
28 changes: 17 additions & 11 deletions syncd/syncd_flex_counter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ FlexCounter::QueueAttrIds::QueueAttrIds(
{
}

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

FlexCounter &fc = getInstance(pollInterval);

// Initialize the supported counters list before setting
if (fc.m_supportedQueueCounters.size() == 0)
{
fc.saiUpdateSupportedQueueCounters(queueId);
}
fc.saiUpdateSupportedQueueCounters(queueId, counterIds);

// Remove unsupported counters
std::vector<sai_queue_stat_t> supportedIds;
Expand Down Expand Up @@ -579,25 +580,30 @@ void FlexCounter::saiUpdateSupportedPortCounters(sai_object_id_t portId)
}
}

void FlexCounter::saiUpdateSupportedQueueCounters(sai_object_id_t queueId)
void FlexCounter::saiUpdateSupportedQueueCounters(
_In_ sai_object_id_t queueId,
_In_ const std::vector<sai_queue_stat_t> &counterIds)
{
uint64_t value;
for (int cntr_id = SAI_QUEUE_STAT_PACKETS; cntr_id <= SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES; ++cntr_id)
{
sai_queue_stat_t counter = static_cast<sai_queue_stat_t>(cntr_id);
m_supportedQueueCounters.clear();

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

if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_WARN("Counter %s is not supported on port RID %s: %s",
SWSS_LOG_WARN("Counter %s is not supported on queue %s, rv: %s",
sai_serialize_queue_stat(counter).c_str(),
sai_serialize_object_id(queueId).c_str(),
sai_serialize_status(status).c_str());

continue;
}
else
{
m_supportedQueueCounters.insert(counter);
}

m_supportedQueueCounters.insert(counter);
}
}
2 changes: 1 addition & 1 deletion syncd/syncd_flex_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class FlexCounter
void endFlexCounterThread(void);

void saiUpdateSupportedPortCounters(sai_object_id_t portId);
void saiUpdateSupportedQueueCounters(sai_object_id_t queueId);
void saiUpdateSupportedQueueCounters(sai_object_id_t queueId, const std::vector<sai_queue_stat_t> &counterIds);
bool isPortCounterSupported(sai_port_stat_t counter) const;
bool isQueueCounterSupported(sai_queue_stat_t counter) const;

Expand Down

0 comments on commit 0187c64

Please sign in to comment.