From 477d124a8c60afc677076c49b9f35754019b46d8 Mon Sep 17 00:00:00 2001 From: Marian Pritsak Date: Wed, 2 May 2018 21:32:21 +0300 Subject: [PATCH] [PFCWD]: Periodically poll WD counters (#473) * [PFCWD]: Periodically poll WD counters For every action handler call commitCounters on a periodic basis Signed-off-by: marian-pritsak * Set polling interval to 1s --- orchagent/pfcactionhandler.cpp | 48 ++++++++++++++++++++++++++-------- orchagent/pfcactionhandler.h | 2 +- orchagent/pfcwdorch.cpp | 22 ++++++++++++++++ orchagent/pfcwdorch.h | 1 + 4 files changed, 61 insertions(+), 12 deletions(-) diff --git a/orchagent/pfcactionhandler.cpp b/orchagent/pfcactionhandler.cpp index 4116c0ae06..ba2f233f79 100644 --- a/orchagent/pfcactionhandler.cpp +++ b/orchagent/pfcactionhandler.cpp @@ -58,10 +58,15 @@ void PfcWdActionHandler::initCounters(void) wdQueueStats.detectCount++; wdQueueStats.operational = false; + wdQueueStats.txPktLast = 0; + wdQueueStats.txDropPktLast = 0; + wdQueueStats.rxPktLast = 0; + wdQueueStats.rxDropPktLast = 0; + updateWdCounters(sai_serialize_object_id(m_queue), wdQueueStats); } -void PfcWdActionHandler::commitCounters(void) +void PfcWdActionHandler::commitCounters(bool periodic /* = false */) { SWSS_LOG_ENTER(); @@ -74,18 +79,23 @@ void PfcWdActionHandler::commitCounters(void) auto finalStats = getQueueStats(m_countersTable, sai_serialize_object_id(m_queue)); - finalStats.restoreCount++; - finalStats.operational = true; + if (!periodic) + { + finalStats.restoreCount++; + } + finalStats.operational = !periodic; + + finalStats.txPktLast += hwStats.txPkt - m_hwStats.txPkt; + finalStats.txDropPktLast += hwStats.txDropPkt - m_hwStats.txDropPkt; + finalStats.rxPktLast += hwStats.rxPkt - m_hwStats.rxPkt; + finalStats.rxDropPktLast += hwStats.rxDropPkt - m_hwStats.rxDropPkt; - finalStats.txPktLast = hwStats.txPkt - m_hwStats.txPkt; - finalStats.txDropPktLast = hwStats.txDropPkt - m_hwStats.txDropPkt; - finalStats.rxPktLast = hwStats.rxPkt - m_hwStats.rxPkt; - finalStats.rxDropPktLast = hwStats.rxDropPkt - m_hwStats.rxDropPkt; + finalStats.txPkt += hwStats.txPkt - m_hwStats.txPkt; + finalStats.txDropPkt += hwStats.txDropPkt - m_hwStats.txDropPkt; + finalStats.rxPkt += hwStats.rxPkt - m_hwStats.rxPkt; + finalStats.rxDropPkt += hwStats.rxDropPkt - m_hwStats.rxDropPkt; - finalStats.txPkt += finalStats.txPktLast; - finalStats.txDropPkt += finalStats.txDropPktLast; - finalStats.rxPkt += finalStats.rxPktLast; - finalStats.rxDropPkt += finalStats.rxDropPktLast; + m_hwStats = hwStats; updateWdCounters(sai_serialize_object_id(m_queue), finalStats); } @@ -137,6 +147,22 @@ PfcWdActionHandler::PfcWdQueueStats PfcWdActionHandler::getQueueStats(shared_ptr { stats.rxDropPkt = stoul(value); } + else if (field == PFC_WD_QUEUE_STATS_TX_PACKETS_LAST) + { + stats.txPktLast = stoul(value); + } + else if (field == PFC_WD_QUEUE_STATS_TX_DROPPED_PACKETS_LAST) + { + stats.txDropPktLast = stoul(value); + } + else if (field == PFC_WD_QUEUE_STATS_RX_PACKETS_LAST) + { + stats.rxPktLast = stoul(value); + } + else if (field == PFC_WD_QUEUE_STATS_RX_DROPPED_PACKETS_LAST) + { + stats.rxDropPktLast = stoul(value); + } } return move(stats); diff --git a/orchagent/pfcactionhandler.h b/orchagent/pfcactionhandler.h index 75435dfe08..07a27babec 100644 --- a/orchagent/pfcactionhandler.h +++ b/orchagent/pfcactionhandler.h @@ -48,7 +48,7 @@ class PfcWdActionHandler static void initWdCounters(shared_ptr countersTable, const string &queueIdStr); void initCounters(void); - void commitCounters(void); + void commitCounters(bool periodic = false); virtual bool getHwCounters(PfcWdHwStats& counters) { diff --git a/orchagent/pfcwdorch.cpp b/orchagent/pfcwdorch.cpp index 8e5f3b7152..065bfc4d03 100644 --- a/orchagent/pfcwdorch.cpp +++ b/orchagent/pfcwdorch.cpp @@ -23,6 +23,7 @@ #define PFC_WD_POLL_TIMEOUT 5000 #define SAI_PORT_STAT_PFC_PREFIX "SAI_PORT_STAT_PFC_" #define PFC_WD_TC_MAX 8 +#define COUNTER_CHECK_POLL_TIMEOUT_SEC 1 extern sai_port_api_t *sai_port_api; extern sai_queue_api_t *sai_queue_api; @@ -670,6 +671,12 @@ PfcWdSwOrch::PfcWdSwOrch( "PFC_WD"); auto wdNotification = new Notifier(consumer, this); Orch::addExecutor("PFC_WD", wdNotification); + + auto interv = timespec { .tv_sec = COUNTER_CHECK_POLL_TIMEOUT_SEC, .tv_nsec = 0 }; + auto timer = new SelectableTimer(interv); + auto executor = new ExecutableTimer(timer, this); + Orch::addExecutor("PFC_WD_COUNTERS_POLL", executor); + timer->start(); } template @@ -823,6 +830,21 @@ void PfcWdSwOrch::doTask(swss::NotificationConsumer } } +template +void PfcWdSwOrch::doTask(SelectableTimer &timer) +{ + SWSS_LOG_ENTER(); + + for (auto& handlerPair : m_entryMap) + { + if (handlerPair.second.handler != nullptr) + { + handlerPair.second.handler->commitCounters(true); + } + } + +} + // Trick to keep member functions in a separate file template class PfcWdSwOrch; template class PfcWdSwOrch; diff --git a/orchagent/pfcwdorch.h b/orchagent/pfcwdorch.h index 74b709e46e..fada367689 100644 --- a/orchagent/pfcwdorch.h +++ b/orchagent/pfcwdorch.h @@ -71,6 +71,7 @@ class PfcWdSwOrch: public PfcWdOrch virtual bool stopWdOnPort(const Port& port); void createEntry(const string& key, const vector& data); + virtual void doTask(SelectableTimer &timer); //XXX Add port/queue state change event handlers private: struct PfcWdQueueEntry