From 2a7d2a704b6c1444635cf56896b5f13428378e10 Mon Sep 17 00:00:00 2001 From: Qi Luo Date: Wed, 15 Nov 2017 18:40:25 -0800 Subject: [PATCH] Revert "Revert "Update port and queue stat counters by Flex counter (#358)" (#371)" (#388) This reverts commit 8fc09d04a14529dc83cca454536b9c6a2a1bdf38. --- orchagent/orchdaemon.cpp | 7 ++++-- orchagent/pfcwdorch.cpp | 18 ++++++++------ orchagent/pfcwdorch.h | 5 +++- orchagent/portsorch.cpp | 53 ++++++++++++++++++++++++++++++++++------ orchagent/portsorch.h | 5 ++++ 5 files changed, 70 insertions(+), 18 deletions(-) diff --git a/orchagent/orchdaemon.cpp b/orchagent/orchdaemon.cpp index bc4dd0fe9a29..8e7504b33e37 100644 --- a/orchagent/orchdaemon.cpp +++ b/orchagent/orchdaemon.cpp @@ -11,6 +11,7 @@ using namespace swss; /* select() function timeout retry time */ #define SELECT_TIMEOUT 1000 +#define FLEX_COUNTER_POLL_MSECS 100 extern sai_switch_api_t* sai_switch_api; extern sai_object_id_t gSwitchId; @@ -140,7 +141,8 @@ bool OrchDaemon::init() pfc_wd_tables, portStatIds, queueStatIds, - queueAttrIds)); + queueAttrIds, + FLEX_COUNTER_POLL_MSECS)); } else if (platform == BRCM_PLATFORM_SUBSTRING) { @@ -180,7 +182,8 @@ bool OrchDaemon::init() pfc_wd_tables, portStatIds, queueStatIds, - queueAttrIds)); + queueAttrIds, + FLEX_COUNTER_POLL_MSECS)); } return true; diff --git a/orchagent/pfcwdorch.cpp b/orchagent/pfcwdorch.cpp index ea2fb81a73b3..5876ca62760b 100644 --- a/orchagent/pfcwdorch.cpp +++ b/orchagent/pfcwdorch.cpp @@ -267,13 +267,12 @@ void PfcWdSwOrch::registerInWdDb(const Port& port, if (!c_portStatIds.empty()) { + string key = sai_serialize_object_id(port.m_port_id) + ":" + std::to_string(m_pollInterval); vector fieldValues; string str = counterIdsToStr(c_portStatIds, &sai_serialize_port_stat); fieldValues.emplace_back(PFC_WD_PORT_COUNTER_ID_LIST, str); - m_pfcWdTable->set( - sai_serialize_object_id(port.m_port_id), - fieldValues); + m_pfcWdTable->set(key, fieldValues); } uint8_t pfcMask = attr.value.u8; @@ -317,7 +316,9 @@ void PfcWdSwOrch::registerInWdDb(const Port& port, // Create internal entry m_entryMap.emplace(queueId, PfcWdQueueEntry(action, port.m_port_id, i)); - m_pfcWdTable->set(queueIdStr, queueFieldValues); + string key = queueIdStr + ":" + std::to_string(m_pollInterval); + + m_pfcWdTable->set(key, queueFieldValues); // Initialize PFC WD related counters PfcWdActionHandler::initWdCounters( @@ -334,9 +335,10 @@ void PfcWdSwOrch::unregisterFromWdDb(const Port& po for (uint8_t i = 0; i < PFC_WD_TC_MAX; i++) { sai_object_id_t queueId = port.m_queue_ids[i]; + string key = sai_serialize_object_id(queueId) + ":" + std::to_string(m_pollInterval); // Unregister in syncd - m_pfcWdTable->del(sai_serialize_object_id(queueId)); + m_pfcWdTable->del(key); m_entryMap.erase(queueId); } } @@ -347,13 +349,15 @@ PfcWdSwOrch::PfcWdSwOrch( vector &tableNames, const vector &portStatIds, const vector &queueStatIds, - const vector &queueAttrIds): + const vector &queueAttrIds, + int pollInterval): PfcWdOrch(db, tableNames), m_pfcWdDb(new DBConnector(PFC_WD_DB, DBConnector::DEFAULT_UNIXSOCKET, 0)), m_pfcWdTable(new ProducerStateTable(m_pfcWdDb.get(), PFC_WD_STATE_TABLE)), c_portStatIds(portStatIds), c_queueStatIds(queueStatIds), - c_queueAttrIds(queueAttrIds) + c_queueAttrIds(queueAttrIds), + m_pollInterval(pollInterval) { SWSS_LOG_ENTER(); diff --git a/orchagent/pfcwdorch.h b/orchagent/pfcwdorch.h index e4598e35cd50..b088e0e4f705 100644 --- a/orchagent/pfcwdorch.h +++ b/orchagent/pfcwdorch.h @@ -62,7 +62,8 @@ class PfcWdSwOrch: public PfcWdOrch vector &tableNames, const vector &portStatIds, const vector &queueStatIds, - const vector &queueAttrIds); + const vector &queueAttrIds, + int pollInterval); virtual ~PfcWdSwOrch(void); virtual bool startWdOnPort(const Port& port, @@ -106,6 +107,8 @@ class PfcWdSwOrch: public PfcWdOrch atomic_bool m_runPfcWdSwOrchThread = { false }; shared_ptr m_pfcWatchdogThread = nullptr; + + int m_pollInterval; }; #endif diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index ff7692b99323..645c6766d191 100644 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "net/if.h" @@ -29,6 +30,7 @@ extern sai_object_id_t gSwitchId; #define VLAN_PREFIX "Vlan" #define DEFAULT_VLAN_ID 1 +#define FLEX_STAT_COUNTER_POLL_MSECS "1000" static map fec_mode_map = { @@ -56,16 +58,19 @@ PortsOrch::PortsOrch(DBConnector *db, vector tableNames) : SWSS_LOG_ENTER(); /* Initialize counter table */ - DBConnector *counter_db(new DBConnector(COUNTERS_DB, DBConnector::DEFAULT_UNIXSOCKET, 0)); - m_counterTable = unique_ptr(new Table(counter_db, COUNTERS_PORT_NAME_MAP)); + m_counter_db = shared_ptr(new DBConnector(COUNTERS_DB, DBConnector::DEFAULT_UNIXSOCKET, 0)); + m_counterTable = unique_ptr
(new Table(m_counter_db.get(), COUNTERS_PORT_NAME_MAP)); /* Initialize port table */ m_portTable = unique_ptr
(new Table(db, APP_PORT_TABLE_NAME)); /* Initialize queue tables */ - m_queueTable = unique_ptr
(new Table(counter_db, COUNTERS_QUEUE_NAME_MAP)); - m_queuePortTable = unique_ptr
(new Table(counter_db, COUNTERS_QUEUE_PORT_MAP)); - m_queueIndexTable = unique_ptr
(new Table(counter_db, COUNTERS_QUEUE_INDEX_MAP)); + m_queueTable = unique_ptr
(new Table(m_counter_db.get(), COUNTERS_QUEUE_NAME_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_flex_db = shared_ptr(new DBConnector(PFC_WD_DB, DBConnector::DEFAULT_UNIXSOCKET, 0)); + m_flexCounterTable = unique_ptr(new ProducerStateTable(m_flex_db.get(), PFC_WD_STATE_TABLE)); uint32_t i, j; sai_status_t status; @@ -643,9 +648,25 @@ bool PortsOrch::initPort(const string &alias, const set &lane_set) m_portList[alias] = p; /* Add port name map to counter table */ FieldValueTuple tuple(p.m_alias, sai_serialize_object_id(p.m_port_id)); - vector vector; - vector.push_back(tuple); - m_counterTable->set("", vector); + vector fields; + fields.push_back(tuple); + m_counterTable->set("", fields); + + /* Add port to flex_counter for updating stat counters */ + string key = sai_serialize_object_id(p.m_port_id) + ":" + FLEX_STAT_COUNTER_POLL_MSECS; + + std::string delimiter = ""; + std::ostringstream counters_stream; + for (int cntr = SAI_PORT_STAT_IF_IN_OCTETS; cntr <= SAI_PORT_STAT_PFC_7_ON2OFF_RX_PKTS; ++cntr) + { + counters_stream << delimiter << sai_serialize_port_stat(static_cast(cntr)); + delimiter = ","; + } + + fields.clear(); + fields.emplace_back(PFC_WD_PORT_COUNTER_ID_LIST, counters_stream.str()); + + m_flexCounterTable->set(key, fields); SWSS_LOG_NOTICE("Initialized port %s", alias.c_str()); } @@ -1362,6 +1383,7 @@ 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; @@ -1382,6 +1404,21 @@ void PortsOrch::initializeQueues(Port &port) sai_serialize_object_id(port.m_queue_ids[queueIndex]), to_string(queueIndex)); queueIndexVector.push_back(queueIndexTuple); + + string key = sai_serialize_object_id(port.m_queue_ids[queueIndex]) + ":" + FLEX_STAT_COUNTER_POLL_MSECS; + + std::string delimiter = ""; + std::ostringstream counters_stream; + for (int cntr = SAI_QUEUE_STAT_PACKETS; cntr <= SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES ; ++cntr) + { + counters_stream << delimiter << sai_serialize_queue_stat(static_cast(cntr)); + delimiter = ","; + } + + vector fieldValues; + fieldValues.emplace_back(PFC_WD_QUEUE_COUNTER_ID_LIST, counters_stream.str()); + + m_flexCounterTable->set(key, fieldValues); } m_queueTable->set("", queueVector); diff --git a/orchagent/portsorch.h b/orchagent/portsorch.h index c90d136c56ca..fe1740e231e2 100644 --- a/orchagent/portsorch.h +++ b/orchagent/portsorch.h @@ -7,6 +7,7 @@ #include "port.h" #include "observer.h" #include "macaddress.h" +#include "producerstatetable.h" #include @@ -61,6 +62,10 @@ class PortsOrch : public Orch, public Subject unique_ptr
m_queueTable; unique_ptr
m_queuePortTable; unique_ptr
m_queueIndexTable; + unique_ptr m_flexCounterTable; + + shared_ptr m_counter_db; + shared_ptr m_flex_db; std::map m_portSupportedSpeeds;