Skip to content

Commit

Permalink
[PfcWd]: Make polling interval configurable (sonic-net#435)
Browse files Browse the repository at this point in the history
* [PfcWd]: Make polling interval configurable

Signed-off-by: Sihui Han <sihan@microsoft.com>

* rebase master

* fix the build error

Signed-off-by: Sihui Han <sihan@microsoft.com>
  • Loading branch information
sihuihan88 committed Feb 7, 2018
1 parent 6b2a591 commit 9a037b8
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 37 deletions.
3 changes: 2 additions & 1 deletion orchagent/orchdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ using namespace swss;

/* select() function timeout retry time */
#define SELECT_TIMEOUT 1000
#define PFC_WD_POLL_MSECS 100

extern sai_switch_api_t* sai_switch_api;
extern sai_object_id_t gSwitchId;
Expand Down Expand Up @@ -103,7 +104,7 @@ bool OrchDaemon::init()
m_select = new Select();

vector<string> pfc_wd_tables = {
APP_PFC_WD_TABLE_NAME
CFG_PFC_WD_TABLE_NAME
};

if (platform == MLNX_PLATFORM_SUBSTRING)
Expand Down
74 changes: 52 additions & 22 deletions orchagent/pfcwdorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "notifier.h"
#include "redisclient.h"

#define PFC_WD_FLEX_COUNTER_GROUP "PFC_WD"
#define PFC_WD_GLOBAL "GLOBAL"
#define PFC_WD_ACTION "action"
#define PFC_WD_DETECTION_TIME "detection_time"
#define PFC_WD_RESTORATION_TIME "restoration_time"
Expand Down Expand Up @@ -357,6 +359,31 @@ void PfcWdOrch<DropHandler, ForwardHandler>::deleteEntry(const string& name)
SWSS_LOG_NOTICE("Stopped PFC Watchdog on port %s", name.c_str());
}

template <typename DropHandler, typename ForwardHandler>
void PfcWdSwOrch<DropHandler, ForwardHandler>::createEntry(const string& key,
const vector<FieldValueTuple>& data)
{
if (key == PFC_WD_GLOBAL)
{
for (auto valuePair: data)
{
const auto &field = fvField(valuePair);
const auto &value = fvValue(valuePair);

if (field == POLL_INTERVAL_FIELD)
{
vector<FieldValueTuple> fieldValues;
fieldValues.emplace_back(POLL_INTERVAL_FIELD, value);
m_flexCounterGroupTable->set(PFC_WD_FLEX_COUNTER_GROUP, fieldValues);
}
}
}
else
{
PfcWdOrch<DropHandler, ForwardHandler>::createEntry(key, data);
}
}

template <typename DropHandler, typename ForwardHandler>
void PfcWdSwOrch<DropHandler, ForwardHandler>::registerInWdDb(const Port& port,
uint32_t detectionTime, uint32_t restorationTime, PfcWdAction action)
Expand All @@ -375,12 +402,12 @@ void PfcWdSwOrch<DropHandler, ForwardHandler>::registerInWdDb(const Port& port,

if (!c_portStatIds.empty())
{
string key = sai_serialize_object_id(port.m_port_id) + ":" + std::to_string(m_pollInterval);
string key = getFlexCounterTableKey(sai_serialize_object_id(port.m_port_id));
vector<FieldValueTuple> fieldValues;
string str = counterIdsToStr(c_portStatIds, &sai_serialize_port_stat);
fieldValues.emplace_back(PFC_WD_PORT_COUNTER_ID_LIST, str);
fieldValues.emplace_back(PORT_COUNTER_ID_LIST, str);

m_pfcWdTable->set(key, fieldValues);
m_flexCounterTable->set(key, fieldValues);
}

uint8_t pfcMask = attr.value.u8;
Expand Down Expand Up @@ -412,21 +439,20 @@ void PfcWdSwOrch<DropHandler, ForwardHandler>::registerInWdDb(const Port& port,
if (!c_queueStatIds.empty())
{
string str = counterIdsToStr(c_queueStatIds, sai_serialize_queue_stat);
queueFieldValues.emplace_back(PFC_WD_QUEUE_COUNTER_ID_LIST, str);
queueFieldValues.emplace_back(QUEUE_COUNTER_ID_LIST, str);
}

if (!c_queueAttrIds.empty())
{
string str = counterIdsToStr(c_queueAttrIds, sai_serialize_queue_attr);
queueFieldValues.emplace_back(PFC_WD_QUEUE_ATTR_ID_LIST, str);
queueFieldValues.emplace_back(QUEUE_ATTR_ID_LIST, str);
}

// Create internal entry
m_entryMap.emplace(queueId, PfcWdQueueEntry(action, port.m_port_id, i));

string key = queueIdStr + ":" + std::to_string(m_pollInterval);

m_pfcWdTable->set(key, queueFieldValues);
string key = getFlexCounterTableKey(queueIdStr);
m_flexCounterTable->set(key, queueFieldValues);

// Initialize PFC WD related counters
PfcWdActionHandler::initWdCounters(
Expand All @@ -435,21 +461,27 @@ void PfcWdSwOrch<DropHandler, ForwardHandler>::registerInWdDb(const Port& port,
}
}

template <typename DropHandler, typename ForwardHandler>
string PfcWdSwOrch<DropHandler, ForwardHandler>::getFlexCounterTableKey(string key)
{
return string(PFC_WD_FLEX_COUNTER_GROUP) + ":" + key;
}

template <typename DropHandler, typename ForwardHandler>
void PfcWdSwOrch<DropHandler, ForwardHandler>::unregisterFromWdDb(const Port& port)
{
SWSS_LOG_ENTER();

string key = sai_serialize_object_id(port.m_port_id) + ":" + std::to_string(m_pollInterval);
m_pfcWdTable->del(key);
string key = getFlexCounterTableKey(sai_serialize_object_id(port.m_port_id));
m_flexCounterTable->del(key);

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);
string key = getFlexCounterTableKey(sai_serialize_object_id(queueId));

// Unregister in syncd
m_pfcWdTable->del(key);
m_flexCounterTable->del(key);
m_entryMap.erase(queueId);

// Clean up
Expand All @@ -471,8 +503,9 @@ PfcWdSwOrch<DropHandler, ForwardHandler>::PfcWdSwOrch(
const vector<sai_queue_attr_t> &queueAttrIds,
int pollInterval):
PfcWdOrch<DropHandler, ForwardHandler>(db, tableNames),
m_pfcWdDb(new DBConnector(PFC_WD_DB, DBConnector::DEFAULT_UNIXSOCKET, 0)),
m_pfcWdTable(new ProducerStateTable(m_pfcWdDb.get(), PFC_WD_STATE_TABLE)),
m_flexCounterDb(new DBConnector(FLEX_COUNTER_DB, DBConnector::DEFAULT_UNIXSOCKET, 0)),
m_flexCounterTable(new ProducerTable(m_flexCounterDb.get(), FLEX_COUNTER_TABLE)),
m_flexCounterGroupTable(new ProducerTable(m_flexCounterDb.get(), FLEX_COUNTER_GROUP_TABLE)),
c_portStatIds(portStatIds),
c_queueStatIds(queueStatIds),
c_queueAttrIds(queueAttrIds),
Expand Down Expand Up @@ -504,17 +537,13 @@ PfcWdSwOrch<DropHandler, ForwardHandler>::PfcWdSwOrch(
restoreLuaScript);

vector<FieldValueTuple> fieldValues;
fieldValues.emplace_back(SAI_OBJECT_TYPE, sai_serialize_object_type(SAI_OBJECT_TYPE_QUEUE));

auto pluginTable = ProducerStateTable(m_pfcWdDb.get(), PLUGIN_TABLE);
string detectShaKey = detectSha + ":" + std::to_string(m_pollInterval);
string restoreShaKey = restoreSha + ":" + std::to_string(m_pollInterval);
pluginTable.set(detectShaKey, fieldValues);
pluginTable.set(restoreShaKey, fieldValues);
fieldValues.emplace_back(QUEUE_PLUGIN_FIELD, detectSha + "," + restoreSha);
fieldValues.emplace_back(POLL_INTERVAL_FIELD, to_string(m_pollInterval));
m_flexCounterGroupTable->set(PFC_WD_FLEX_COUNTER_GROUP, fieldValues);
}
catch (...)
{
SWSS_LOG_WARN("Lua scripts for PFC watchdog were not loaded");
SWSS_LOG_WARN("Lua scripts and polling interval for PFC watchdog were not set successfully");
}

auto consumer = new swss::NotificationConsumer(
Expand All @@ -528,6 +557,7 @@ template <typename DropHandler, typename ForwardHandler>
PfcWdSwOrch<DropHandler, ForwardHandler>::~PfcWdSwOrch(void)
{
SWSS_LOG_ENTER();
m_flexCounterGroupTable->del(PFC_WD_FLEX_COUNTER_GROUP);
}

template <typename DropHandler, typename ForwardHandler>
Expand Down
13 changes: 8 additions & 5 deletions orchagent/pfcwdorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "orch.h"
#include "port.h"
#include "pfcactionhandler.h"
#include "producerstatetable.h"
#include "producertable.h"
#include "notificationconsumer.h"
#include "timer.h"
#include <array>
Expand Down Expand Up @@ -51,9 +51,9 @@ class PfcWdOrch: public Orch
static PfcWdAction deserializeAction(const string& key);
static string serializeAction(const PfcWdAction &action);

private:
void createEntry(const string& key, const vector<FieldValueTuple>& data);
virtual void createEntry(const string& key, const vector<FieldValueTuple>& data);
void deleteEntry(const string& name);
private:
PfcFrameCounters getPfcFrameCounters(sai_object_id_t portId);

shared_ptr<DBConnector> m_countersDb = nullptr;
Expand All @@ -79,6 +79,7 @@ class PfcWdSwOrch: public PfcWdOrch<DropHandler, ForwardHandler>
uint32_t detectionTime, uint32_t restorationTime, PfcWdAction action);
virtual bool stopWdOnPort(const Port& port);

void createEntry(const string& key, const vector<FieldValueTuple>& data);
//XXX Add port/queue state change event handlers
private:
struct PfcWdQueueEntry
Expand All @@ -101,14 +102,16 @@ class PfcWdSwOrch: public PfcWdOrch<DropHandler, ForwardHandler>
void unregisterFromWdDb(const Port& port);
void doTask(swss::NotificationConsumer &wdNotification);

string getFlexCounterTableKey(string s);
map<sai_object_id_t, PfcWdQueueEntry> m_entryMap;

const vector<sai_port_stat_t> c_portStatIds;
const vector<sai_queue_stat_t> c_queueStatIds;
const vector<sai_queue_attr_t> c_queueAttrIds;

shared_ptr<DBConnector> m_pfcWdDb = nullptr;
shared_ptr<ProducerStateTable> m_pfcWdTable = nullptr;
shared_ptr<DBConnector> m_flexCounterDb = nullptr;
shared_ptr<ProducerTable> m_flexCounterTable = nullptr;
shared_ptr<ProducerTable> m_flexCounterGroupTable = nullptr;

atomic_bool m_runPfcWdSwOrchThread = { false };
shared_ptr<thread> m_pfcWatchdogThread = nullptr;
Expand Down
24 changes: 17 additions & 7 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extern sai_object_id_t gSwitchId;
#define VLAN_PREFIX "Vlan"
#define DEFAULT_VLAN_ID 1
#define FLEX_STAT_COUNTER_POLL_MSECS "1000"
#define STAT_COUNTER_FLEX_COUNTER_GROUP "STAT_COUNTER"

static map<string, sai_port_fec_mode_t> fec_mode_map =
{
Expand Down Expand Up @@ -113,8 +114,13 @@ PortsOrch::PortsOrch(DBConnector *db, vector<string> tableNames) :
m_queueIndexTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_QUEUE_INDEX_MAP));
m_queueTypeTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_QUEUE_TYPE_MAP));

m_flex_db = shared_ptr<DBConnector>(new DBConnector(PFC_WD_DB, DBConnector::DEFAULT_UNIXSOCKET, 0));
m_flexCounterTable = unique_ptr<ProducerStateTable>(new ProducerStateTable(m_flex_db.get(), PFC_WD_STATE_TABLE));
m_flex_db = shared_ptr<DBConnector>(new DBConnector(FLEX_COUNTER_DB, DBConnector::DEFAULT_UNIXSOCKET, 0));
m_flexCounterTable = unique_ptr<ProducerTable>(new ProducerTable(m_flex_db.get(), FLEX_COUNTER_TABLE));
m_flexCounterGroupTable = unique_ptr<ProducerTable>(new ProducerTable(m_flex_db.get(), FLEX_COUNTER_GROUP_TABLE));

vector<FieldValueTuple> fields;
fields.emplace_back(POLL_INTERVAL_FIELD, FLEX_STAT_COUNTER_POLL_MSECS);
m_flexCounterGroupTable->set(STAT_COUNTER_FLEX_COUNTER_GROUP, fields);

uint32_t i, j;
sai_status_t status;
Expand Down Expand Up @@ -923,6 +929,11 @@ bool PortsOrch::removePort(sai_object_id_t port_id)
return true;
}

string PortsOrch::getFlexCounterTableKey(string key)
{
return string(STAT_COUNTER_FLEX_COUNTER_GROUP) + ":" + key;
}

bool PortsOrch::initPort(const string &alias, const set<int> &lane_set)
{
SWSS_LOG_ENTER();
Expand Down Expand Up @@ -956,8 +967,7 @@ bool PortsOrch::initPort(const string &alias, const set<int> &lane_set)
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;

string key = getFlexCounterTableKey(sai_serialize_object_id(p.m_port_id));
std::string delimiter = "";
std::ostringstream counters_stream;
for (const auto &id: portStatIds)
Expand All @@ -967,7 +977,7 @@ bool PortsOrch::initPort(const string &alias, const set<int> &lane_set)
}

fields.clear();
fields.emplace_back(PFC_WD_PORT_COUNTER_ID_LIST, counters_stream.str());
fields.emplace_back(PORT_COUNTER_ID_LIST, counters_stream.str());

m_flexCounterTable->set(key, fields);

Expand Down Expand Up @@ -1720,7 +1730,7 @@ void PortsOrch::initializeQueues(Port &port)
queueTypeVector.push_back(queueTypeTuple);
}

string key = sai_serialize_object_id(port.m_queue_ids[queueIndex]) + ":" + FLEX_STAT_COUNTER_POLL_MSECS;
string key = getFlexCounterTableKey(sai_serialize_object_id(port.m_queue_ids[queueIndex]));

std::string delimiter = "";
std::ostringstream counters_stream;
Expand All @@ -1731,7 +1741,7 @@ void PortsOrch::initializeQueues(Port &port)
}

vector<FieldValueTuple> fieldValues;
fieldValues.emplace_back(PFC_WD_QUEUE_COUNTER_ID_LIST, counters_stream.str());
fieldValues.emplace_back(QUEUE_COUNTER_ID_LIST, counters_stream.str());

m_flexCounterTable->set(key, fieldValues);
}
Expand Down
6 changes: 4 additions & 2 deletions orchagent/portsorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "port.h"
#include "observer.h"
#include "macaddress.h"
#include "producerstatetable.h"
#include "producertable.h"

#define FCS_LEN 4
#define VLAN_TAG_LEN 4
Expand Down Expand Up @@ -63,8 +63,10 @@ class PortsOrch : public Orch, public Subject
unique_ptr<Table> m_queuePortTable;
unique_ptr<Table> m_queueIndexTable;
unique_ptr<Table> m_queueTypeTable;
unique_ptr<ProducerStateTable> m_flexCounterTable;
unique_ptr<ProducerTable> m_flexCounterTable;
unique_ptr<ProducerTable> m_flexCounterGroupTable;

std:: string getFlexCounterTableKey(std::string s);
shared_ptr<DBConnector> m_counter_db;
shared_ptr<DBConnector> m_flex_db;

Expand Down

0 comments on commit 9a037b8

Please sign in to comment.