From 0187c64a57b288f9e4898bc9db00f7427eb61ca6 Mon Sep 17 00:00:00 2001 From: Shuotian Cheng Date: Mon, 20 Nov 2017 17:13:46 -0800 Subject: [PATCH] [syncd]: Only query queue counters that are needed by the application (#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 --- syncd/syncd_flex_counter.cpp | 28 +++++++++++++++++----------- syncd/syncd_flex_counter.h | 2 +- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/syncd/syncd_flex_counter.cpp b/syncd/syncd_flex_counter.cpp index b602497f070f..8eacd980c92c 100644 --- a/syncd/syncd_flex_counter.cpp +++ b/syncd/syncd_flex_counter.cpp @@ -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, @@ -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 supportedIds; @@ -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 &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(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); } } diff --git a/syncd/syncd_flex_counter.h b/syncd/syncd_flex_counter.h index 7e86633f6640..548447dfe4f8 100644 --- a/syncd/syncd_flex_counter.h +++ b/syncd/syncd_flex_counter.h @@ -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 &counterIds); bool isPortCounterSupported(sai_port_stat_t counter) const; bool isQueueCounterSupported(sai_queue_stat_t counter) const;