From fe29d7c5f56422fe82bfe5f726cea24e0250daf4 Mon Sep 17 00:00:00 2001 From: vivekverma Date: Tue, 6 Feb 2024 23:29:01 -0800 Subject: [PATCH 1/5] Added aggregate VOQ counters orchagent implementation. --- orchagent/portsorch.cpp | 70 +++++++++++++++++++++++++++++++++++++++++ orchagent/portsorch.h | 6 ++++ 2 files changed, 76 insertions(+) diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index 0ce38850d0..2aed5d5c02 100755 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -670,6 +670,12 @@ PortsOrch::PortsOrch(DBConnector *db, DBConnector *stateDb, vector(new Table(chassisAppDb, CHASSIS_APP_LAG_MEMBER_TABLE_NAME)); m_lagIdAllocator = unique_ptr (new LagIdAllocator(chassisAppDb)); + m_tableVoqQueueCounter = unique_ptr(new Table(chassisAppDb, CHASSIS_APP_COUNTERS_TABLE_NAME)); + m_agg_voq_poller = new SelectableTimer(timespec { .tv_sec = AGG_VOQ_POLL_SEC, .tv_nsec = 0 }); + + auto agg_voq_executor = new ExecutableTimer(m_agg_voq_poller, this, "AGG_VOQ_POLLER"); + Orch::addExecutor(agg_voq_executor); + m_agg_voq_poller->start(); } auto executor = new ExecutableTimer(m_port_state_poller, this, "PORT_STATE_POLLER"); @@ -8995,7 +9001,19 @@ void PortsOrch::updatePortStatePoll(const Port &port, port_state_poll_t type, bo void PortsOrch::doTask(swss::SelectableTimer &timer) { Port port; + if (timer.getFd() == m_port_state_poller->getFd()) + { + updatePortState(); + } + else if(m_agg_voq_poller && timer.getFd() == m_agg_voq_poller->getFd()) + { + updateVoqStatsChassisDb(); + } +} +void PortsOrch::updatePortState() +{ + Port port; for (auto it = m_port_state_poll.begin(); it != m_port_state_poll.end(); ) { if ((it->second == PORT_STATE_POLL_NONE) || !getPort(it->first, port)) @@ -9024,3 +9042,55 @@ void PortsOrch::doTask(swss::SelectableTimer &timer) } } +void PortsOrch::updateVoqStatsPerPortChassisDb(const Port& port) +{ + std::vector queue_ids; + static const vector queueStatIds = + { + SAI_QUEUE_STAT_PACKETS, + SAI_QUEUE_STAT_BYTES, + SAI_QUEUE_STAT_DROPPED_PACKETS, + SAI_QUEUE_STAT_DROPPED_BYTES, + }; + vector queueStats(queueStatIds.size()); + + queue_ids = m_port_voq_ids[port.m_alias]; + SWSS_LOG_ENTER(); + + for (size_t queueIndex = 0; queueIndex < queue_ids.size(); ++queueIndex) + { + std::ostringstream key; + key << port.m_system_port_info.alias << "@" << gMyHostName << "|" << gMyAsicName << ":" << queueIndex; + + sai_status_t status = sai_queue_api->get_queue_stats( + queue_ids[queueIndex], + static_cast(queueStatIds.size()), + queueStatIds.data(), + queueStats.data()); + + if (status != SAI_STATUS_SUCCESS) + { + SWSS_LOG_ERROR("Failed to fetch queue 0x%" PRIx64 " status: %d", queue_ids[queueIndex], status); + continue; + } + + //Add to CHASSIS_APP_DB + int index = 0; + for (const auto& it: queue_stat_ids) + { + SWSS_LOG_DEBUG("%s %s %s",key.str().c_str(), sai_serialize_queue_stat(it).c_str(), + to_string(queueStats[index]).c_str()); + m_tableVoqQueueCounter->hset(key.str(), sai_serialize_queue_stat(it), to_string(queueStats[index++])); + } + } +} + +void PortsOrch::updateVoqStatsChassisDb(){ + for (const auto& it: m_portList) + { + if (it.second.m_type != Port::PHY && it.second.m_type != Port::SYSTEM) + continue; + updateVoqStatsPerPortChassisDb( it.second ); + } +} + diff --git a/orchagent/portsorch.h b/orchagent/portsorch.h index 4d069ccfc5..378b7a929f 100755 --- a/orchagent/portsorch.h +++ b/orchagent/portsorch.h @@ -334,6 +334,7 @@ class PortsOrch : public Orch, public Subject bool oper_fec_sup = false; swss::SelectableTimer *m_port_state_poller = nullptr; + swss::SelectableTimer *m_agg_voq_poller = nullptr; bool m_cmisModuleAsicSyncSupported = false; @@ -469,6 +470,7 @@ class PortsOrch : public Orch, public Subject void updatePortStatePoll(const Port &port, port_state_poll_t type, bool active); void refreshPortStateAutoNeg(const Port &port); void refreshPortStateLinkTraining(const Port &port); + void updatePortState(); void getPortSerdesVal(const std::string& s, std::vector &lane_values, int base = 16); bool setPortSerdesAttribute(sai_object_id_t port_id, sai_object_id_t switch_id, @@ -506,6 +508,10 @@ class PortsOrch : public Orch, public Subject std::unordered_set generateCounterStats(const string& type, bool gearbox = false); map m_queueInfo; + void updateVoqStatsChassisDb(); + void updateVoqStatsPerPortChassisDb(const Port& port); + unique_ptr
m_tableVoqQueueCounter; + private: void initializeCpuPort(); void initializePorts(); From cb6b9684d1549e036da93679b50adb33d95215b8 Mon Sep 17 00:00:00 2001 From: Vivek Verma <137406113+vivekverma-arista@users.noreply.github.com> Date: Tue, 13 Feb 2024 14:55:27 +0530 Subject: [PATCH 2/5] Update portsorch.cpp --- orchagent/portsorch.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index 2aed5d5c02..de6e28746b 100755 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -75,6 +75,7 @@ extern event_handle_t g_events_handle; #define PG_WATERMARK_FLEX_STAT_COUNTER_POLL_MSECS "60000" #define PG_DROP_FLEX_STAT_COUNTER_POLL_MSECS "10000" #define PORT_RATE_FLEX_COUNTER_POLLING_INTERVAL_MS "1000" +#define AGG_VOQ_POLL_SEC 10 // types -------------------------------------------------------------------------------------------------------------- From 72aafec6852e165c7ed9bf3c32b625326f6fb2d7 Mon Sep 17 00:00:00 2001 From: Vivek Subbarao Date: Thu, 16 May 2024 04:33:51 -0700 Subject: [PATCH 3/5] Revert "Update portsorch.cpp" This reverts commit cb6b9684d1549e036da93679b50adb33d95215b8. --- orchagent/portsorch.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index fec1979aef..5361e68076 100755 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -76,7 +76,6 @@ extern event_handle_t g_events_handle; #define PG_WATERMARK_FLEX_STAT_COUNTER_POLL_MSECS "60000" #define PG_DROP_FLEX_STAT_COUNTER_POLL_MSECS "10000" #define PORT_RATE_FLEX_COUNTER_POLLING_INTERVAL_MS "1000" -#define AGG_VOQ_POLL_SEC 10 // types -------------------------------------------------------------------------------------------------------------- From 0465818e79b1b5bfb7019ed43f8af70e8a797f3f Mon Sep 17 00:00:00 2001 From: Vivek Subbarao Date: Thu, 16 May 2024 04:34:03 -0700 Subject: [PATCH 4/5] Revert "Added aggregate VOQ counters orchagent implementation." This reverts commit fe29d7c5f56422fe82bfe5f726cea24e0250daf4. --- orchagent/portsorch.cpp | 70 ----------------------------------------- orchagent/portsorch.h | 6 ---- 2 files changed, 76 deletions(-) diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index 5361e68076..23c1bc324e 100755 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -682,12 +682,6 @@ PortsOrch::PortsOrch(DBConnector *db, DBConnector *stateDb, vector(new Table(chassisAppDb, CHASSIS_APP_LAG_MEMBER_TABLE_NAME)); m_lagIdAllocator = unique_ptr (new LagIdAllocator(chassisAppDb)); - m_tableVoqQueueCounter = unique_ptr
(new Table(chassisAppDb, CHASSIS_APP_COUNTERS_TABLE_NAME)); - m_agg_voq_poller = new SelectableTimer(timespec { .tv_sec = AGG_VOQ_POLL_SEC, .tv_nsec = 0 }); - - auto agg_voq_executor = new ExecutableTimer(m_agg_voq_poller, this, "AGG_VOQ_POLLER"); - Orch::addExecutor(agg_voq_executor); - m_agg_voq_poller->start(); } auto executor = new ExecutableTimer(m_port_state_poller, this, "PORT_STATE_POLLER"); @@ -9064,19 +9058,7 @@ void PortsOrch::updatePortStatePoll(const Port &port, port_state_poll_t type, bo void PortsOrch::doTask(swss::SelectableTimer &timer) { Port port; - if (timer.getFd() == m_port_state_poller->getFd()) - { - updatePortState(); - } - else if(m_agg_voq_poller && timer.getFd() == m_agg_voq_poller->getFd()) - { - updateVoqStatsChassisDb(); - } -} -void PortsOrch::updatePortState() -{ - Port port; for (auto it = m_port_state_poll.begin(); it != m_port_state_poll.end(); ) { if ((it->second == PORT_STATE_POLL_NONE) || !getPort(it->first, port)) @@ -9105,55 +9087,3 @@ void PortsOrch::updatePortState() } } -void PortsOrch::updateVoqStatsPerPortChassisDb(const Port& port) -{ - std::vector queue_ids; - static const vector queueStatIds = - { - SAI_QUEUE_STAT_PACKETS, - SAI_QUEUE_STAT_BYTES, - SAI_QUEUE_STAT_DROPPED_PACKETS, - SAI_QUEUE_STAT_DROPPED_BYTES, - }; - vector queueStats(queueStatIds.size()); - - queue_ids = m_port_voq_ids[port.m_alias]; - SWSS_LOG_ENTER(); - - for (size_t queueIndex = 0; queueIndex < queue_ids.size(); ++queueIndex) - { - std::ostringstream key; - key << port.m_system_port_info.alias << "@" << gMyHostName << "|" << gMyAsicName << ":" << queueIndex; - - sai_status_t status = sai_queue_api->get_queue_stats( - queue_ids[queueIndex], - static_cast(queueStatIds.size()), - queueStatIds.data(), - queueStats.data()); - - if (status != SAI_STATUS_SUCCESS) - { - SWSS_LOG_ERROR("Failed to fetch queue 0x%" PRIx64 " status: %d", queue_ids[queueIndex], status); - continue; - } - - //Add to CHASSIS_APP_DB - int index = 0; - for (const auto& it: queue_stat_ids) - { - SWSS_LOG_DEBUG("%s %s %s",key.str().c_str(), sai_serialize_queue_stat(it).c_str(), - to_string(queueStats[index]).c_str()); - m_tableVoqQueueCounter->hset(key.str(), sai_serialize_queue_stat(it), to_string(queueStats[index++])); - } - } -} - -void PortsOrch::updateVoqStatsChassisDb(){ - for (const auto& it: m_portList) - { - if (it.second.m_type != Port::PHY && it.second.m_type != Port::SYSTEM) - continue; - updateVoqStatsPerPortChassisDb( it.second ); - } -} - diff --git a/orchagent/portsorch.h b/orchagent/portsorch.h index 40d33a4c82..21ed299681 100755 --- a/orchagent/portsorch.h +++ b/orchagent/portsorch.h @@ -339,7 +339,6 @@ class PortsOrch : public Orch, public Subject bool oper_fec_sup = false; swss::SelectableTimer *m_port_state_poller = nullptr; - swss::SelectableTimer *m_agg_voq_poller = nullptr; bool m_cmisModuleAsicSyncSupported = false; @@ -475,7 +474,6 @@ class PortsOrch : public Orch, public Subject void updatePortStatePoll(const Port &port, port_state_poll_t type, bool active); void refreshPortStateAutoNeg(const Port &port); void refreshPortStateLinkTraining(const Port &port); - void updatePortState(); void getPortSerdesVal(const std::string& s, std::vector &lane_values, int base = 16); bool setPortSerdesAttribute(sai_object_id_t port_id, sai_object_id_t switch_id, @@ -513,10 +511,6 @@ class PortsOrch : public Orch, public Subject std::unordered_set generateCounterStats(const string& type, bool gearbox = false); map m_queueInfo; - void updateVoqStatsChassisDb(); - void updateVoqStatsPerPortChassisDb(const Port& port); - unique_ptr
m_tableVoqQueueCounter; - private: void initializeCpuPort(); void initializePorts(); From 3df86c237ea55184c68a4aa69fe2fae0b209176a Mon Sep 17 00:00:00 2001 From: Vivek Subbarao Date: Thu, 16 May 2024 04:34:54 -0700 Subject: [PATCH 5/5] What I did? Create voq to port name map during port initializa Why I did it? When ports are getting created and voq's are being assigned to them, create a voq to port name map table in counter DB so that it is easy to find the port name for a specific voq when creating an entry in chassis_app_db to calculate agg voq counters. --- orchagent/portsorch.cpp | 4 ++++ orchagent/portsorch.h | 1 + 2 files changed, 5 insertions(+) diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index 23c1bc324e..f3175a30f5 100755 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -442,6 +442,7 @@ PortsOrch::PortsOrch(DBConnector *db, DBConnector *stateDb, vector(new Table(m_counter_db.get(), COUNTERS_QUEUE_NAME_MAP)); m_voqTable = unique_ptr
(new Table(m_counter_db.get(), COUNTERS_VOQ_NAME_MAP)); + m_voqToPortNamTable = unique_ptr
(new Table(m_counter_db.get(), COUNTERS_PORT_NAME_VOQ_MAP)); m_queuePortTable = unique_ptr
(new Table(m_counter_db.get(), COUNTERS_QUEUE_PORT_MAP)); m_queueIndexTable = unique_ptr
(new Table(m_counter_db.get(), COUNTERS_QUEUE_INDEX_MAP)); m_queueTypeTable = unique_ptr
(new Table(m_counter_db.get(), COUNTERS_QUEUE_TYPE_MAP)); @@ -6817,6 +6818,7 @@ void PortsOrch::generateQueueMapPerPort(const Port& port, FlexCounterQueueStates vector queuePortVector; vector queueIndexVector; vector queueTypeVector; + vector voqToPortNameVector; std::vector queue_ids; if (voq) @@ -6865,6 +6867,7 @@ void PortsOrch::generateQueueMapPerPort(const Port& port, FlexCounterQueueStates // flexcounter orch logic. Always enabled voq counters. addQueueFlexCountersPerPortPerQueueIndex(port, queueIndex, true); queuePortVector.emplace_back(id, sai_serialize_object_id(port.m_system_port_oid)); + voqToPortNameVector.emplace_back(id, port.m_system_port_info.alias); } else { @@ -6885,6 +6888,7 @@ void PortsOrch::generateQueueMapPerPort(const Port& port, FlexCounterQueueStates if (voq) { m_voqTable->set("", queueVector); + m_voqToPortNamTable->set("", voqToPortNameVector); } else { diff --git a/orchagent/portsorch.h b/orchagent/portsorch.h index 21ed299681..e80dfc7de8 100755 --- a/orchagent/portsorch.h +++ b/orchagent/portsorch.h @@ -248,6 +248,7 @@ class PortsOrch : public Orch, public Subject unique_ptr
m_gearboxTable; unique_ptr
m_queueTable; unique_ptr
m_voqTable; + unique_ptr
m_voqToPortNamTable; unique_ptr
m_queuePortTable; unique_ptr
m_queueIndexTable; unique_ptr
m_queueTypeTable;