From 258ffe64c7f11a3e63f7cff09ae8bd2f98788c03 Mon Sep 17 00:00:00 2001 From: pavel-shirshov Date: Tue, 26 Jun 2018 12:17:54 -0700 Subject: [PATCH] Pospone QueueMap initialization until activation of counters (#527) --- orchagent/flexcounterorch.cpp | 4 ++ orchagent/portsorch.cpp | 118 ++++++++++++++++++---------------- orchagent/portsorch.h | 5 ++ 3 files changed, 72 insertions(+), 55 deletions(-) diff --git a/orchagent/flexcounterorch.cpp b/orchagent/flexcounterorch.cpp index 45b839c756..5aaec6b986 100644 --- a/orchagent/flexcounterorch.cpp +++ b/orchagent/flexcounterorch.cpp @@ -72,6 +72,10 @@ void FlexCounterOrch::doTask(Consumer &consumer) } else if(field == FLEX_COUNTER_STATUS_FIELD) { + // Currently the counters are disabled by default + // The queue maps will be generated as soon as counters are enabled + gPortsOrch->generateQueueMap(); + vector fieldValues; fieldValues.emplace_back(FLEX_COUNTER_STATUS_FIELD, value); m_flexCounterGroupTable->set(flexCounterGroupMap[key], fieldValues); diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index 70991edfe8..745a814252 100644 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -1817,61 +1817,6 @@ void PortsOrch::initializeQueues(Port &port) } SWSS_LOG_INFO("Get queues for port %s", port.m_alias.c_str()); - - /* Create the Queue map in the Counter DB */ - /* Add stat counters to flex_counter */ - vector queueVector; - vector queuePortVector; - vector queueIndexVector; - vector queueTypeVector; - - for (size_t queueIndex = 0; queueIndex < port.m_queue_ids.size(); ++queueIndex) - { - std::ostringstream name; - name << port.m_alias << ":" << queueIndex; - FieldValueTuple tuple(name.str(), sai_serialize_object_id(port.m_queue_ids[queueIndex])); - queueVector.push_back(tuple); - - FieldValueTuple queuePortTuple( - sai_serialize_object_id(port.m_queue_ids[queueIndex]), - sai_serialize_object_id(port.m_port_id)); - queuePortVector.push_back(queuePortTuple); - - FieldValueTuple queueIndexTuple( - sai_serialize_object_id(port.m_queue_ids[queueIndex]), - to_string(queueIndex)); - queueIndexVector.push_back(queueIndexTuple); - - - string queueType; - if (getQueueType(port.m_queue_ids[queueIndex], queueType)) - { - FieldValueTuple queueTypeTuple( - sai_serialize_object_id(port.m_queue_ids[queueIndex]), - queueType); - queueTypeVector.push_back(queueTypeTuple); - } - - string key = getQueueFlexCounterTableKey(sai_serialize_object_id(port.m_queue_ids[queueIndex])); - - std::string delimiter = ""; - std::ostringstream counters_stream; - for (auto it = queueStatIds.begin(); it != queueStatIds.end(); it++) - { - counters_stream << delimiter << sai_serialize_queue_stat(*it); - delimiter = ","; - } - - vector fieldValues; - fieldValues.emplace_back(QUEUE_COUNTER_ID_LIST, counters_stream.str()); - - m_flexCounterTable->set(key, fieldValues); - } - - m_queueTable->set("", queueVector); - m_queuePortTable->set("", queuePortVector); - m_queueIndexTable->set("", queueIndexVector); - m_queueTypeTable->set("", queueTypeVector); } void PortsOrch::initializePriorityGroups(Port &port) @@ -2420,6 +2365,69 @@ bool PortsOrch::removeLagMember(Port &lag, Port &port) return true; } +void PortsOrch::generateQueueMap() +{ + if (m_isQueueMapGenerated) + { + return; + } + + for (const auto& it: m_portList) + { + generateQueueMapPerPort(it.second); + } + + m_isQueueMapGenerated = true; +} + +void PortsOrch::generateQueueMapPerPort(const Port& port) +{ + /* Create the Queue map in the Counter DB */ + /* Add stat counters to flex_counter */ + vector queueVector; + vector queuePortVector; + vector queueIndexVector; + vector queueTypeVector; + + for (size_t queueIndex = 0; queueIndex < port.m_queue_ids.size(); ++queueIndex) + { + std::ostringstream name; + name << port.m_alias << ":" << queueIndex; + + const auto id = sai_serialize_object_id(port.m_queue_ids[queueIndex]); + + queueVector.emplace_back(name.str(), id); + queuePortVector.emplace_back(id, sai_serialize_object_id(port.m_port_id)); + queueIndexVector.emplace_back(id, to_string(queueIndex)); + + string queueType; + if (getQueueType(port.m_queue_ids[queueIndex], queueType)) + { + queueTypeVector.emplace_back(id, queueType); + } + + string key = getQueueFlexCounterTableKey(id); + + std::string delimiter = ""; + std::ostringstream counters_stream; + for (const auto& it: queueStatIds) + { + counters_stream << delimiter << sai_serialize_queue_stat(it); + delimiter = ","; + } + + vector fieldValues; + fieldValues.emplace_back(QUEUE_COUNTER_ID_LIST, counters_stream.str()); + + m_flexCounterTable->set(key, fieldValues); + } + + m_queueTable->set("", queueVector); + m_queuePortTable->set("", queuePortVector); + m_queueIndexTable->set("", queueIndexVector); + m_queueTypeTable->set("", queueTypeVector); +} + void PortsOrch::doTask(NotificationConsumer &consumer) { SWSS_LOG_ENTER(); diff --git a/orchagent/portsorch.h b/orchagent/portsorch.h index 322cc5c956..45ab72c2db 100644 --- a/orchagent/portsorch.h +++ b/orchagent/portsorch.h @@ -61,6 +61,8 @@ class PortsOrch : public Orch, public Subject bool setHostIntfsOperStatus(sai_object_id_t id, bool up); void updateDbPortOperStatus(sai_object_id_t id, sai_port_oper_status_t status); bool bindAclTable(sai_object_id_t id, sai_object_id_t table_oid, sai_object_id_t &group_member_oid, acl_stage_type_t acl_stage = ACL_STAGE_INGRESS); + + void generateQueueMap(); private: unique_ptr m_counterTable; unique_ptr
m_portTable; @@ -143,6 +145,9 @@ class PortsOrch : public Orch, public Subject bool getPortSpeed(sai_object_id_t port_id, sai_uint32_t &speed); bool getQueueType(sai_object_id_t queue_id, string &type); + + bool m_isQueueMapGenerated = false; + void generateQueueMapPerPort(const Port& port); }; #endif /* SWSS_PORTSORCH_H */