diff --git a/syncd/Makefile.am b/syncd/Makefile.am index 6237f73117f4..de59b3619ae6 100644 --- a/syncd/Makefile.am +++ b/syncd/Makefile.am @@ -22,7 +22,7 @@ syncd_SOURCES = \ syncd_notifications.cpp \ syncd_counters.cpp \ syncd_applyview.cpp \ - syncd_pfc_watchdog.cpp + syncd_flex_counter.cpp syncd_CPPFLAGS = $(DBGFLAGS) $(AM_CPPFLAGS) $(CFLAGS_COMMON) $(SAIFLAGS) syncd_LDADD = -lhiredis -lswsscommon $(SAILIB) -lpthread -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -ldl @@ -44,7 +44,7 @@ tests_SOURCES = \ syncd_notifications.cpp \ syncd_counters.cpp \ syncd_applyview.cpp \ - syncd_pfc_watchdog.cpp + syncd_flex_counter.cpp tests_CPPFLAGS = $(DBGFLAGS) $(AM_CPPFLAGS) $(CFLAGS_COMMON) tests_LDADD = -lhiredis -lswsscommon -lpthread -L$(top_srcdir)/lib/src/.libs -lsairedis -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta diff --git a/syncd/syncd.cpp b/syncd/syncd.cpp index 5c2f25f0e035..a6230fbf5333 100644 --- a/syncd/syncd.cpp +++ b/syncd/syncd.cpp @@ -1,7 +1,7 @@ #include "syncd.h" #include "syncd_saiswitch.h" #include "sairedis.h" -#include "syncd_pfc_watchdog.h" +#include "syncd_flex_counter.h" #include "swss/tokenize.h" #include @@ -2352,7 +2352,7 @@ sai_status_t processEvent( return status; } -void processPfcWdEvent( +void processFlexCounterEvent( _In_ swss::ConsumerStateTable &consumer) { std::lock_guard lock(g_mutex); @@ -2380,11 +2380,11 @@ void processPfcWdEvent( { if (objectType == SAI_OBJECT_TYPE_PORT) { - PfcWatchdog::removePort(vid); + FlexCounter::removePort(vid); } else if (objectType == SAI_OBJECT_TYPE_QUEUE) { - PfcWatchdog::removeQueue(vid); + FlexCounter::removeQueue(vid); } else { @@ -2404,7 +2404,7 @@ void processPfcWdEvent( sai_deserialize_port_stat(str, stat); portCounterIds.push_back(stat); } - PfcWatchdog::setPortCounterList(vid, rid, portCounterIds); + FlexCounter::setPortCounterList(vid, rid, portCounterIds); } else if (objectType == SAI_OBJECT_TYPE_QUEUE && field == PFC_WD_QUEUE_COUNTER_ID_LIST) { @@ -2415,7 +2415,7 @@ void processPfcWdEvent( sai_deserialize_queue_stat(str, stat); queueCounterIds.push_back(stat); } - PfcWatchdog::setQueueCounterList(vid, rid, queueCounterIds); + FlexCounter::setQueueCounterList(vid, rid, queueCounterIds); } else if (objectType == SAI_OBJECT_TYPE_QUEUE && field == PFC_WD_QUEUE_ATTR_ID_LIST) { @@ -2427,7 +2427,7 @@ void processPfcWdEvent( queueAttrIds.push_back(attr); } - PfcWatchdog::setQueueAttrList(vid, rid, queueAttrIds); + FlexCounter::setQueueAttrList(vid, rid, queueAttrIds); } else { @@ -2437,7 +2437,7 @@ void processPfcWdEvent( } } -void processPfcWdPluginEvent( +void processFlexCounterPluginEvent( _In_ swss::ConsumerStateTable &consumer) { std::lock_guard lock(g_mutex); @@ -2452,7 +2452,7 @@ void processPfcWdPluginEvent( if (op == DEL_COMMAND) { - PfcWatchdog::removeCounterPlugin(key); + FlexCounter::removeCounterPlugin(key); return; } @@ -2469,11 +2469,11 @@ void processPfcWdPluginEvent( if (value == sai_serialize_object_type(SAI_OBJECT_TYPE_PORT)) { - PfcWatchdog::addPortCounterPlugin(key); + FlexCounter::addPortCounterPlugin(key); } else if (value == sai_serialize_object_type(SAI_OBJECT_TYPE_QUEUE)) { - PfcWatchdog::addQueueCounterPlugin(key); + FlexCounter::addQueueCounterPlugin(key); } else { @@ -3055,14 +3055,14 @@ int syncd_main(int argc, char **argv) std::shared_ptr dbAsic = std::make_shared(ASIC_DB, swss::DBConnector::DEFAULT_UNIXSOCKET, 0); std::shared_ptr dbNtf = std::make_shared(ASIC_DB, swss::DBConnector::DEFAULT_UNIXSOCKET, 0); - std::shared_ptr dbPfcWatchdog = std::make_shared(PFC_WD_DB, swss::DBConnector::DEFAULT_UNIXSOCKET, 0); + std::shared_ptr dbFlexCounter = std::make_shared(PFC_WD_DB, swss::DBConnector::DEFAULT_UNIXSOCKET, 0); g_redisClient = std::make_shared(dbAsic.get()); std::shared_ptr asicState = std::make_shared(dbAsic.get(), ASIC_STATE_TABLE); std::shared_ptr restartQuery = std::make_shared(dbAsic.get(), "RESTARTQUERY"); - std::shared_ptr pfcWdState = std::make_shared(dbPfcWatchdog.get(), PFC_WD_STATE_TABLE); - std::shared_ptr pfcWdPlugin = std::make_shared(dbPfcWatchdog.get(), PLUGIN_TABLE); + std::shared_ptr flexCounterState = std::make_shared(dbFlexCounter.get(), PFC_WD_STATE_TABLE); + std::shared_ptr flexCounterPlugin = std::make_shared(dbFlexCounter.get(), PLUGIN_TABLE); /* * At the end we cant use producer consumer concept since if one proces @@ -3158,8 +3158,8 @@ int syncd_main(int argc, char **argv) s.addSelectable(asicState.get()); s.addSelectable(restartQuery.get()); - s.addSelectable(pfcWdState.get()); - s.addSelectable(pfcWdPlugin.get()); + s.addSelectable(flexCounterState.get()); + s.addSelectable(flexCounterPlugin.get()); SWSS_LOG_NOTICE("starting main loop"); @@ -3184,13 +3184,13 @@ int syncd_main(int argc, char **argv) warmRestartHint = handleRestartQuery(*restartQuery); break; } - else if (sel == pfcWdState.get()) + else if (sel == flexCounterState.get()) { - processPfcWdEvent(*(swss::ConsumerStateTable*)sel); + processFlexCounterEvent(*(swss::ConsumerStateTable*)sel); } - else if (sel == pfcWdPlugin.get()) + else if (sel == flexCounterPlugin.get()) { - processPfcWdPluginEvent(*(swss::ConsumerStateTable*)sel); + processFlexCounterPluginEvent(*(swss::ConsumerStateTable*)sel); } else if (result == swss::Select::OBJECT) { diff --git a/syncd/syncd_pfc_watchdog.cpp b/syncd/syncd_flex_counter.cpp similarity index 66% rename from syncd/syncd_pfc_watchdog.cpp rename to syncd/syncd_flex_counter.cpp index 6c58b6ec6aaf..7d3f5ec8ee16 100644 --- a/syncd/syncd_pfc_watchdog.cpp +++ b/syncd/syncd_flex_counter.cpp @@ -1,217 +1,217 @@ -#include "syncd_pfc_watchdog.h" +#include "syncd_flex_counter.h" #include "syncd.h" #include "swss/redisapi.h" -#define PFC_WD_POLL_MSECS 100 +#define FLEX_COUNTER_POLL_MSECS 100 -PfcWatchdog::PortCounterIds::PortCounterIds( +FlexCounter::PortCounterIds::PortCounterIds( _In_ sai_object_id_t port, _In_ const std::vector &portIds): portId(port), portCounterIds(portIds) { } -PfcWatchdog::QueueCounterIds::QueueCounterIds( +FlexCounter::QueueCounterIds::QueueCounterIds( _In_ sai_object_id_t queue, _In_ const std::vector &queueIds): queueId(queue), queueCounterIds(queueIds) { } -PfcWatchdog::QueueAttrIds::QueueAttrIds( +FlexCounter::QueueAttrIds::QueueAttrIds( _In_ sai_object_id_t queue, _In_ const std::vector &queueIds): queueId(queue), queueAttrIds(queueIds) { } -void PfcWatchdog::setPortCounterList( +void FlexCounter::setPortCounterList( _In_ sai_object_id_t portVid, _In_ sai_object_id_t portId, _In_ const std::vector &counterIds) { SWSS_LOG_ENTER(); - PfcWatchdog &wd = getInstance(); + FlexCounter &fc = getInstance(); - auto it = wd.m_portCounterIdsMap.find(portVid); - if (it != wd.m_portCounterIdsMap.end()) + auto it = fc.m_portCounterIdsMap.find(portVid); + if (it != fc.m_portCounterIdsMap.end()) { (*it).second->portCounterIds = counterIds; return; } auto portCounterIds = std::make_shared(portId, counterIds); - wd.m_portCounterIdsMap.emplace(portVid, portCounterIds); + fc.m_portCounterIdsMap.emplace(portVid, portCounterIds); - // Start watchdog thread in case it was not running due to empty counter IDs map - wd.startWatchdogThread(); + // Start flex counter thread in case it was not running due to empty counter IDs map + fc.startFlexCounterThread(); } -void PfcWatchdog::setQueueCounterList( +void FlexCounter::setQueueCounterList( _In_ sai_object_id_t queueVid, _In_ sai_object_id_t queueId, _In_ const std::vector &counterIds) { SWSS_LOG_ENTER(); - PfcWatchdog &wd = getInstance(); + FlexCounter &fc = getInstance(); - auto it = wd.m_queueCounterIdsMap.find(queueVid); - if (it != wd.m_queueCounterIdsMap.end()) + auto it = fc.m_queueCounterIdsMap.find(queueVid); + if (it != fc.m_queueCounterIdsMap.end()) { (*it).second->queueCounterIds = counterIds; return; } auto queueCounterIds = std::make_shared(queueId, counterIds); - wd.m_queueCounterIdsMap.emplace(queueVid, queueCounterIds); + fc.m_queueCounterIdsMap.emplace(queueVid, queueCounterIds); - // Start watchdog thread in case it was not running due to empty counter IDs map - wd.startWatchdogThread(); + // Start flex counter thread in case it was not running due to empty counter IDs map + fc.startFlexCounterThread(); } -void PfcWatchdog::setQueueAttrList( +void FlexCounter::setQueueAttrList( _In_ sai_object_id_t queueVid, _In_ sai_object_id_t queueId, _In_ const std::vector &attrIds) { SWSS_LOG_ENTER(); - PfcWatchdog &wd = getInstance(); + FlexCounter &fc = getInstance(); - auto it = wd.m_queueAttrIdsMap.find(queueVid); - if (it != wd.m_queueAttrIdsMap.end()) + auto it = fc.m_queueAttrIdsMap.find(queueVid); + if (it != fc.m_queueAttrIdsMap.end()) { (*it).second->queueAttrIds = attrIds; return; } auto queueAttrIds = std::make_shared(queueId, attrIds); - wd.m_queueAttrIdsMap.emplace(queueVid, queueAttrIds); + fc.m_queueAttrIdsMap.emplace(queueVid, queueAttrIds); - // Start watchdog thread in case it was not running due to empty counter IDs map - wd.startWatchdogThread(); + // Start flex counter thread in case it was not running due to empty counter IDs map + fc.startFlexCounterThread(); } -void PfcWatchdog::removePort( +void FlexCounter::removePort( _In_ sai_object_id_t portVid) { SWSS_LOG_ENTER(); - PfcWatchdog &wd = getInstance(); + FlexCounter &fc = getInstance(); - auto it = wd.m_portCounterIdsMap.find(portVid); - if (it == wd.m_portCounterIdsMap.end()) + auto it = fc.m_portCounterIdsMap.find(portVid); + if (it == fc.m_portCounterIdsMap.end()) { SWSS_LOG_ERROR("Trying to remove nonexisting port counter Ids 0x%lx", portVid); return; } - wd.m_portCounterIdsMap.erase(it); + fc.m_portCounterIdsMap.erase(it); - // Stop watchdog thread if counter IDs map is empty - if (wd.m_queueCounterIdsMap.empty() && wd.m_portCounterIdsMap.empty() && wd.m_queueAttrIdsMap.empty()) + // Stop flex counter thread if counter IDs map is empty + if (fc.m_queueCounterIdsMap.empty() && fc.m_portCounterIdsMap.empty() && fc.m_queueAttrIdsMap.empty()) { - wd.endWatchdogThread(); + fc.endFlexCounterThread(); } } -void PfcWatchdog::removeQueue( +void FlexCounter::removeQueue( _In_ sai_object_id_t queueVid) { SWSS_LOG_ENTER(); - PfcWatchdog &wd = getInstance(); + FlexCounter &fc = getInstance(); - auto counterIter = wd.m_queueCounterIdsMap.find(queueVid); - if (counterIter == wd.m_queueCounterIdsMap.end()) + auto counterIter = fc.m_queueCounterIdsMap.find(queueVid); + if (counterIter == fc.m_queueCounterIdsMap.end()) { SWSS_LOG_ERROR("Trying to remove nonexisting queue counter Ids 0x%lx", queueVid); return; } - wd.m_queueCounterIdsMap.erase(counterIter); + fc.m_queueCounterIdsMap.erase(counterIter); - auto attrIter = wd.m_queueAttrIdsMap.find(queueVid); - if (attrIter == wd.m_queueAttrIdsMap.end()) + auto attrIter = fc.m_queueAttrIdsMap.find(queueVid); + if (attrIter == fc.m_queueAttrIdsMap.end()) { SWSS_LOG_ERROR("Trying to remove nonexisting queue attr Ids 0x%lx", queueVid); return; } - wd.m_queueAttrIdsMap.erase(attrIter); + fc.m_queueAttrIdsMap.erase(attrIter); - // Stop watchdog thread if counter IDs map is empty - if (wd.m_queueCounterIdsMap.empty() && wd.m_portCounterIdsMap.empty() && wd.m_queueAttrIdsMap.empty()) + // Stop flex counter thread if counter IDs map is empty + if (fc.m_queueCounterIdsMap.empty() && fc.m_portCounterIdsMap.empty() && fc.m_queueAttrIdsMap.empty()) { - wd.endWatchdogThread(); + fc.endFlexCounterThread(); } } -void PfcWatchdog::addPortCounterPlugin( +void FlexCounter::addPortCounterPlugin( _In_ std::string sha) { SWSS_LOG_ENTER(); - PfcWatchdog &wd = getInstance(); + FlexCounter &fc = getInstance(); - if (wd.m_portPlugins.find(sha) != wd.m_portPlugins.end() || - wd.m_queuePlugins.find(sha) != wd.m_queuePlugins.end()) + if (fc.m_portPlugins.find(sha) != fc.m_portPlugins.end() || + fc.m_queuePlugins.find(sha) != fc.m_queuePlugins.end()) { SWSS_LOG_ERROR("Plugin %s already registered", sha.c_str()); } - wd.m_portPlugins.insert(sha); + fc.m_portPlugins.insert(sha); SWSS_LOG_NOTICE("Port counters plugin %s registered", sha.c_str()); } -void PfcWatchdog::addQueueCounterPlugin( +void FlexCounter::addQueueCounterPlugin( _In_ std::string sha) { SWSS_LOG_ENTER(); - PfcWatchdog &wd = getInstance(); + FlexCounter &fc = getInstance(); - if (wd.m_portPlugins.find(sha) != wd.m_portPlugins.end() || - wd.m_queuePlugins.find(sha) != wd.m_queuePlugins.end()) + if (fc.m_portPlugins.find(sha) != fc.m_portPlugins.end() || + fc.m_queuePlugins.find(sha) != fc.m_queuePlugins.end()) { SWSS_LOG_ERROR("Plugin %s already registered", sha.c_str()); } - wd.m_queuePlugins.insert(sha); + fc.m_queuePlugins.insert(sha); SWSS_LOG_NOTICE("Queue counters plugin %s registered", sha.c_str()); } -void PfcWatchdog::removeCounterPlugin( +void FlexCounter::removeCounterPlugin( _In_ std::string sha) { SWSS_LOG_ENTER(); - PfcWatchdog &wd = getInstance(); + FlexCounter &fc = getInstance(); - wd.m_queuePlugins.erase(sha); - wd.m_portPlugins.erase(sha); + fc.m_queuePlugins.erase(sha); + fc.m_portPlugins.erase(sha); } -PfcWatchdog::~PfcWatchdog(void) +FlexCounter::~FlexCounter(void) { - endWatchdogThread(); + endFlexCounterThread(); } -PfcWatchdog::PfcWatchdog(void) +FlexCounter::FlexCounter(void) { } -PfcWatchdog& PfcWatchdog::getInstance(void) +FlexCounter& FlexCounter::getInstance(void) { - static PfcWatchdog wd; + static FlexCounter fc; - return wd; + return fc; } -void PfcWatchdog::collectCounters( +void FlexCounter::collectCounters( _In_ swss::Table &countersTable) { SWSS_LOG_ENTER(); @@ -332,7 +332,7 @@ void PfcWatchdog::collectCounters( } -void PfcWatchdog::runPlugins( +void FlexCounter::runPlugins( _In_ swss::DBConnector& db) { SWSS_LOG_ENTER(); @@ -341,7 +341,7 @@ void PfcWatchdog::runPlugins( { std::to_string(COUNTERS_DB), COUNTERS_TABLE, - std::to_string(PFC_WD_POLL_MSECS * 1000) + std::to_string(FLEX_COUNTER_POLL_MSECS * 1000) }; std::vector portList; @@ -369,14 +369,14 @@ void PfcWatchdog::runPlugins( } } -void PfcWatchdog::pfcWatchdogThread(void) +void FlexCounter::flexCounterThread(void) { SWSS_LOG_ENTER(); swss::DBConnector db(COUNTERS_DB, swss::DBConnector::DEFAULT_UNIXSOCKET, 0); swss::Table countersTable(&db, COUNTERS_TABLE); - while (m_runPfcWatchdogThread) + while (m_runFlexCounterThread) { std::lock_guard lock(g_mutex); @@ -384,45 +384,45 @@ void PfcWatchdog::pfcWatchdogThread(void) runPlugins(db); std::unique_lock lk(m_mtxSleep); - m_cvSleep.wait_for(lk, std::chrono::milliseconds(PFC_WD_POLL_MSECS)); + m_cvSleep.wait_for(lk, std::chrono::milliseconds(FLEX_COUNTER_POLL_MSECS)); } } -void PfcWatchdog::startWatchdogThread(void) +void FlexCounter::startFlexCounterThread(void) { SWSS_LOG_ENTER(); - if (m_runPfcWatchdogThread.load() == true) + if (m_runFlexCounterThread.load() == true) { return; } - m_runPfcWatchdogThread = true; + m_runFlexCounterThread = true; - m_pfcWatchdogThread = std::make_shared(&PfcWatchdog::pfcWatchdogThread, this); + m_flexCounterThread = std::make_shared(&FlexCounter::flexCounterThread, this); - SWSS_LOG_INFO("PFC Watchdog thread started"); + SWSS_LOG_INFO("Flex Counter thread started"); } -void PfcWatchdog::endWatchdogThread(void) +void FlexCounter::endFlexCounterThread(void) { SWSS_LOG_ENTER(); - if (m_runPfcWatchdogThread.load() == false) + if (m_runFlexCounterThread.load() == false) { return; } - m_runPfcWatchdogThread = false; + m_runFlexCounterThread = false; m_cvSleep.notify_all(); - if (m_pfcWatchdogThread != nullptr) + if (m_flexCounterThread != nullptr) { - SWSS_LOG_INFO("Wait for PFC Watchdog thread to end"); + SWSS_LOG_INFO("Wait for Flex Counter thread to end"); - m_pfcWatchdogThread->join(); + m_flexCounterThread->join(); } - SWSS_LOG_INFO("PFC Watchdog thread ended"); + SWSS_LOG_INFO("Flex Counter thread ended"); } diff --git a/syncd/syncd_pfc_watchdog.h b/syncd/syncd_flex_counter.h similarity index 84% rename from syncd/syncd_pfc_watchdog.h rename to syncd/syncd_flex_counter.h index 5af1e91cfcd5..3ad50f9daedb 100644 --- a/syncd/syncd_pfc_watchdog.h +++ b/syncd/syncd_flex_counter.h @@ -1,5 +1,5 @@ -#ifndef PFC_WATCHDOG_H -#define PFC_WATCHDOG_H +#ifndef FLEX_COUNTER_H +#define FLEX_COUNTER_H extern "C" { #include "sai.h" @@ -11,7 +11,7 @@ extern "C" { #include #include "swss/table.h" -class PfcWatchdog +class FlexCounter { public: static void setPortCounterList( @@ -39,9 +39,9 @@ class PfcWatchdog static void removeCounterPlugin( _In_ std::string sha); - PfcWatchdog( - _In_ const PfcWatchdog&) = delete; - ~PfcWatchdog(void); + FlexCounter( + _In_ const FlexCounter&) = delete; + ~FlexCounter(void); private: struct QueueCounterIds @@ -74,15 +74,15 @@ class PfcWatchdog std::vector portCounterIds; }; - PfcWatchdog(void); - static PfcWatchdog& getInstance(void); + FlexCounter(void); + static FlexCounter& getInstance(void); void collectCounters( _In_ swss::Table &countersTable); void runPlugins( _In_ swss::DBConnector& db); - void pfcWatchdogThread(void); - void startWatchdogThread(void); - void endWatchdogThread(void); + void flexCounterThread(void); + void startFlexCounterThread(void); + void endFlexCounterThread(void); // Key is a Virtual ID std::map> m_portCounterIdsMap; @@ -93,8 +93,8 @@ class PfcWatchdog std::set m_queuePlugins; std::set m_portPlugins; - std::atomic_bool m_runPfcWatchdogThread = { false }; - std::shared_ptr m_pfcWatchdogThread = nullptr; + std::atomic_bool m_runFlexCounterThread = { false }; + std::shared_ptr m_flexCounterThread = nullptr; std::mutex m_mtxSleep; std::condition_variable m_cvSleep; }; diff --git a/tests/Makefile.am b/tests/Makefile.am index 728b0879ae22..f28723c030ea 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -18,7 +18,7 @@ vssyncd_SOURCES = \ ../syncd/syncd_notifications.cpp \ ../syncd/syncd_counters.cpp \ ../syncd/syncd_applyview.cpp \ - ../syncd/syncd_pfc_watchdog.cpp + ../syncd/syncd_flex_counter.cpp vssyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CPPFLAGS) $(CFLAGS_COMMON) $(SAIFLAGS) vssyncd_LDADD = -lhiredis -lswsscommon $(SAILIB) -lpthread -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -ldl