Skip to content

Commit

Permalink
[watermarkorch] only perform periodic clear if the polling is on
Browse files Browse the repository at this point in the history
Signed-off-by: Mykola Faryma <mykolaf@mellanox.com>
  • Loading branch information
Mykola Faryma committed Feb 4, 2019
1 parent b78cc8d commit 8287ae7
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 22 deletions.
7 changes: 6 additions & 1 deletion orchagent/orchdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ bool OrchDaemon::init()
CFG_DTEL_EVENT_TABLE_NAME
};

WatermarkOrch *wm_orch = new WatermarkOrch(m_configDb, CFG_WATERMARK_TABLE_NAME);
vector<string> wm_tables = {
CFG_WATERMARK_TABLE_NAME,
CFG_FLEX_COUNTER_TABLE_NAME
};

WatermarkOrch *wm_orch = new WatermarkOrch(m_configDb, wm_tables);

/*
* The order of the orch list is important for state restore of warm start and
Expand Down
75 changes: 55 additions & 20 deletions orchagent/watermarkorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
extern PortsOrch *gPortsOrch;


WatermarkOrch::WatermarkOrch(DBConnector *db, const string tableName):
Orch(db, tableName)
WatermarkOrch::WatermarkOrch(DBConnector *db, const vector<string> &tables):
Orch(db, tables)
{
SWSS_LOG_ENTER();

Expand All @@ -36,7 +36,6 @@ WatermarkOrch::WatermarkOrch(DBConnector *db, const string tableName):
m_telemetryTimer = new SelectableTimer(intervT);
auto executorT = new ExecutableTimer(m_telemetryTimer, this, "WM_TELEMETRY_TIMER");
Orch::addExecutor(executorT);
m_telemetryTimer->start();

m_telemetryInterval = DEFAULT_TELEMETRY_INTERVAL;
}
Expand Down Expand Up @@ -66,19 +65,13 @@ void WatermarkOrch::doTask(Consumer &consumer)

if (op == SET_COMMAND)
{
if (key == "TELEMETRY_INTERVAL")
if (consumer.getTableName() == CFG_WATERMARK_TABLE_NAME)
{
for (std::pair<std::basic_string<char>, std::basic_string<char> > i: fvt)
{
if (i.first == "interval")
{
m_telemetryInterval = to_uint<uint32_t>(i.second.c_str());
}
else
{
SWSS_LOG_WARN("Unsupported key: %s", i.first.c_str());
}
}
handleWmConfigUpdate(key, fvt);
}
else if (consumer.getTableName() == CFG_FLEX_COUNTER_TABLE_NAME)
{
handleWmConfigUpdate(key, fvt);
}
}
else if (op == DEL_COMMAND)
Expand All @@ -94,6 +87,44 @@ void WatermarkOrch::doTask(Consumer &consumer)
}
}

void WatermarkOrch::handleWmConfigUpdate(const std::string &key, const std::vector<FieldValueTuple> &fvt)
{
if (key == "TELEMETRY_INTERVAL")
{
for (std::pair<std::basic_string<char>, std::basic_string<char> > i: fvt)
{
if (i.first == "interval")
{
m_telemetryInterval = to_uint<uint32_t>(i.second.c_str());
}
else
{
SWSS_LOG_WARN("Unsupported key: %s", i.first.c_str());
}
}
}
}

void WatermarkOrch::handleWmConfigUpdate(const std::string &key, const std::vector<FieldValueTuple> &fvt)
{
if (key == "QUEUE_WATERMARK" || key == "PG_WATERMARK")
{
for (std::pair<std::basic_string<char>, std::basic_string<char> > i: fvt)
{
if (i.first == "FLEX_COUNTER_STATUS" && i.second == "enable" && m_isTimerEnabled == false)
{
m_telemetryTimer->start();
m_isTimerEnabled = true;
}
else if (i.first == "FLEX_COUNTER_STATUS" && i.second == "disable" && m_isTimerEnabled == true)
{
/* no need to stop timer here - it won't be reset after end of this interval */
m_isTimerEnabled = false;
}
}
}
}

void WatermarkOrch::doTask(NotificationConsumer &consumer)
{
if (!gPortsOrch->isPortReady())
Expand Down Expand Up @@ -170,16 +201,20 @@ void WatermarkOrch::doTask(SelectableTimer &timer)

if (&timer == m_telemetryTimer)
{
/* If the interval was changed */
auto intervT = timespec { .tv_sec = m_telemetryInterval , .tv_nsec = 0 };
m_telemetryTimer->setInterval(intervT);
m_telemetryTimer->reset();
/* Timer is only running when the watermark polling is on *
* if it is disabled we will not restart the timer at the end of current interval */
if (m_isTimerEnabled)
{
auto intervT = timespec { .tv_sec = m_telemetryInterval , .tv_nsec = 0 };
m_telemetryTimer->setInterval(intervT);
m_telemetryTimer->reset();
}

clearSingleWm(m_periodicWatermarkTable.get(), "SAI_INGRESS_PRIORITY_GROUP_STAT_XOFF_ROOM_WATERMARK_BYTES", m_pg_ids);
clearSingleWm(m_periodicWatermarkTable.get(), "SAI_INGRESS_PRIORITY_GROUP_STAT_SHARED_WATERMARK_BYTES", m_pg_ids);
clearSingleWm(m_periodicWatermarkTable.get(), "SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES", m_unicast_queue_ids);
clearSingleWm(m_periodicWatermarkTable.get(), "SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES", m_multicast_queue_ids);
SWSS_LOG_INFO("Periodic watermark cleared by timer!");
SWSS_LOG_DEBUG("Periodic watermark cleared by timer!");
}
}

Expand Down
7 changes: 6 additions & 1 deletion orchagent/watermarkorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class WatermarkOrch : public Orch
{
public:
WatermarkOrch(DBConnector *db, const std::string tableName);
WatermarkOrch(DBConnector *db, const vector<string> &tables);
virtual ~WatermarkOrch(void);

void doTask(Consumer &consumer);
Expand All @@ -21,6 +21,9 @@ class WatermarkOrch : public Orch
void init_pg_ids();
void init_queue_ids();

void handleWmConfigUpdate(const std::string &key, const std::vector<FieldValueTuple> &fvt);
void handleFcConfigUpdate(const std::string &key, const std::vector<FieldValueTuple> &fvt);

void clearSingleWm(Table *table, string wm_name, vector<sai_object_id_t> &obj_ids);

shared_ptr<Table> getCountersTable(void)
Expand All @@ -34,6 +37,8 @@ class WatermarkOrch : public Orch
}

private:
bool m_isTimerEnabled = false;

shared_ptr<DBConnector> m_countersDb = nullptr;
shared_ptr<DBConnector> m_appDb = nullptr;
shared_ptr<Table> m_countersTable = nullptr;
Expand Down

0 comments on commit 8287ae7

Please sign in to comment.