Skip to content

Commit

Permalink
[PFCWD]: Periodically poll WD counters (#473)
Browse files Browse the repository at this point in the history
* [PFCWD]: Periodically poll WD counters

For every action handler call commitCounters on a periodic basis

Signed-off-by: marian-pritsak <[email protected]>

* Set polling interval to 1s
  • Loading branch information
marian-pritsak authored and sihuihan88 committed May 2, 2018
1 parent f71005a commit 477d124
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 12 deletions.
48 changes: 37 additions & 11 deletions orchagent/pfcactionhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion orchagent/pfcactionhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class PfcWdActionHandler

static void initWdCounters(shared_ptr<Table> countersTable, const string &queueIdStr);
void initCounters(void);
void commitCounters(void);
void commitCounters(bool periodic = false);

virtual bool getHwCounters(PfcWdHwStats& counters)
{
Expand Down
22 changes: 22 additions & 0 deletions orchagent/pfcwdorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -670,6 +671,12 @@ PfcWdSwOrch<DropHandler, ForwardHandler>::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 <typename DropHandler, typename ForwardHandler>
Expand Down Expand Up @@ -823,6 +830,21 @@ void PfcWdSwOrch<DropHandler, ForwardHandler>::doTask(swss::NotificationConsumer
}
}

template <typename DropHandler, typename ForwardHandler>
void PfcWdSwOrch<DropHandler, ForwardHandler>::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<PfcWdZeroBufferHandler, PfcWdLossyHandler>;
template class PfcWdSwOrch<PfcWdAclHandler, PfcWdLossyHandler>;
1 change: 1 addition & 0 deletions orchagent/pfcwdorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class PfcWdSwOrch: public PfcWdOrch<DropHandler, ForwardHandler>
virtual bool stopWdOnPort(const Port& port);

void createEntry(const string& key, const vector<FieldValueTuple>& data);
virtual void doTask(SelectableTimer &timer);
//XXX Add port/queue state change event handlers
private:
struct PfcWdQueueEntry
Expand Down

0 comments on commit 477d124

Please sign in to comment.