Skip to content

Commit f8792d5

Browse files
mykolafliat-grozovik
authored andcommitted
[watermarkorch] only perform periodic clear if the polling is on (sonic-net#781)
* [watermarkorch] only perform periodic clear if the polling is on Signed-off-by: Mykola Faryma <[email protected]> * [watermarkorch] only set timer interval on change Signed-off-by: Mykola Faryma <[email protected]> * fix logic Signed-off-by: Mykola Faryma <[email protected]> * fix comments Signed-off-by: Mykola Faryma <[email protected]> * fix change timer Signed-off-by: Mykola Faryma <[email protected]>
1 parent 5e4b71d commit f8792d5

File tree

3 files changed

+107
-26
lines changed

3 files changed

+107
-26
lines changed

orchagent/orchdaemon.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,12 @@ bool OrchDaemon::init()
148148
CFG_DTEL_EVENT_TABLE_NAME
149149
};
150150

151-
WatermarkOrch *wm_orch = new WatermarkOrch(m_configDb, CFG_WATERMARK_TABLE_NAME);
151+
vector<string> wm_tables = {
152+
CFG_WATERMARK_TABLE_NAME,
153+
CFG_FLEX_COUNTER_TABLE_NAME
154+
};
155+
156+
WatermarkOrch *wm_orch = new WatermarkOrch(m_configDb, wm_tables);
152157

153158
/*
154159
* The order of the orch list is important for state restore of warm start and

orchagent/watermarkorch.cpp

+79-22
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
extern PortsOrch *gPortsOrch;
1515

1616

17-
WatermarkOrch::WatermarkOrch(DBConnector *db, const string tableName):
18-
Orch(db, tableName)
17+
WatermarkOrch::WatermarkOrch(DBConnector *db, const vector<string> &tables):
18+
Orch(db, tables)
1919
{
2020
SWSS_LOG_ENTER();
2121

@@ -36,9 +36,6 @@ WatermarkOrch::WatermarkOrch(DBConnector *db, const string tableName):
3636
m_telemetryTimer = new SelectableTimer(intervT);
3737
auto executorT = new ExecutableTimer(m_telemetryTimer, this, "WM_TELEMETRY_TIMER");
3838
Orch::addExecutor(executorT);
39-
m_telemetryTimer->start();
40-
41-
m_telemetryInterval = DEFAULT_TELEMETRY_INTERVAL;
4239
}
4340

4441
WatermarkOrch::~WatermarkOrch()
@@ -66,19 +63,13 @@ void WatermarkOrch::doTask(Consumer &consumer)
6663

6764
if (op == SET_COMMAND)
6865
{
69-
if (key == "TELEMETRY_INTERVAL")
66+
if (consumer.getTableName() == CFG_WATERMARK_TABLE_NAME)
7067
{
71-
for (std::pair<std::basic_string<char>, std::basic_string<char> > i: fvt)
72-
{
73-
if (i.first == "interval")
74-
{
75-
m_telemetryInterval = to_uint<uint32_t>(i.second.c_str());
76-
}
77-
else
78-
{
79-
SWSS_LOG_WARN("Unsupported key: %s", i.first.c_str());
80-
}
81-
}
68+
handleWmConfigUpdate(key, fvt);
69+
}
70+
else if (consumer.getTableName() == CFG_FLEX_COUNTER_TABLE_NAME)
71+
{
72+
handleFcConfigUpdate(key, fvt);
8273
}
8374
}
8475
else if (op == DEL_COMMAND)
@@ -94,13 +85,74 @@ void WatermarkOrch::doTask(Consumer &consumer)
9485
}
9586
}
9687

88+
void WatermarkOrch::handleWmConfigUpdate(const std::string &key, const std::vector<FieldValueTuple> &fvt)
89+
{
90+
SWSS_LOG_ENTER();
91+
if (key == "TELEMETRY_INTERVAL")
92+
{
93+
for (std::pair<std::basic_string<char>, std::basic_string<char> > i: fvt)
94+
{
95+
if (i.first == "interval")
96+
{
97+
auto intervT = timespec { .tv_sec = to_uint<uint32_t>(i.second.c_str()) , .tv_nsec = 0 };
98+
m_telemetryTimer->setInterval(intervT);
99+
// reset the timer interval when current timer expires
100+
m_timerChanged = true;
101+
}
102+
else
103+
{
104+
SWSS_LOG_WARN("Unsupported key: %s", i.first.c_str());
105+
}
106+
}
107+
}
108+
}
109+
110+
void WatermarkOrch::handleFcConfigUpdate(const std::string &key, const std::vector<FieldValueTuple> &fvt)
111+
{
112+
SWSS_LOG_ENTER();
113+
uint8_t prevStatus = m_wmStatus;
114+
if (key == "QUEUE_WATERMARK" || key == "PG_WATERMARK")
115+
{
116+
for (std::pair<std::basic_string<char>, std::basic_string<char> > i: fvt)
117+
{
118+
if (i.first == "FLEX_COUNTER_STATUS")
119+
{
120+
if (i.second == "enable")
121+
{
122+
m_wmStatus = (uint8_t) (m_wmStatus | groupToMask.at(key));
123+
}
124+
else if (i.second == "disable")
125+
{
126+
m_wmStatus = (uint8_t) (m_wmStatus & ~(groupToMask.at(key)));
127+
}
128+
}
129+
}
130+
if (!prevStatus && m_wmStatus)
131+
{
132+
m_telemetryTimer->start();
133+
}
134+
SWSS_LOG_DEBUG("Status of WMs: %u", m_wmStatus);
135+
}
136+
}
137+
97138
void WatermarkOrch::doTask(NotificationConsumer &consumer)
98139
{
140+
SWSS_LOG_ENTER();
99141
if (!gPortsOrch->isPortReady())
100142
{
101143
return;
102144
}
103145

146+
if (m_pg_ids.empty())
147+
{
148+
init_pg_ids();
149+
}
150+
151+
if (m_multicast_queue_ids.empty() and m_unicast_queue_ids.empty())
152+
{
153+
init_queue_ids();
154+
}
155+
104156
std::string op;
105157
std::string data;
106158
std::vector<swss::FieldValueTuple> values;
@@ -170,16 +222,21 @@ void WatermarkOrch::doTask(SelectableTimer &timer)
170222

171223
if (&timer == m_telemetryTimer)
172224
{
173-
/* If the interval was changed */
174-
auto intervT = timespec { .tv_sec = m_telemetryInterval , .tv_nsec = 0 };
175-
m_telemetryTimer->setInterval(intervT);
176-
m_telemetryTimer->reset();
225+
if (m_timerChanged)
226+
{
227+
m_telemetryTimer->reset();
228+
m_timerChanged = false;
229+
}
230+
if (!m_wmStatus)
231+
{
232+
m_telemetryTimer->stop();
233+
}
177234

178235
clearSingleWm(m_periodicWatermarkTable.get(), "SAI_INGRESS_PRIORITY_GROUP_STAT_XOFF_ROOM_WATERMARK_BYTES", m_pg_ids);
179236
clearSingleWm(m_periodicWatermarkTable.get(), "SAI_INGRESS_PRIORITY_GROUP_STAT_SHARED_WATERMARK_BYTES", m_pg_ids);
180237
clearSingleWm(m_periodicWatermarkTable.get(), "SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES", m_unicast_queue_ids);
181238
clearSingleWm(m_periodicWatermarkTable.get(), "SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES", m_multicast_queue_ids);
182-
SWSS_LOG_INFO("Periodic watermark cleared by timer!");
239+
SWSS_LOG_DEBUG("Periodic watermark cleared by timer!");
183240
}
184241
}
185242

orchagent/watermarkorch.h

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
#ifndef WATERMARKORCH_H
22
#define WATERMARKORCH_H
33

4+
#include <map>
5+
46
#include "orch.h"
57
#include "port.h"
68

79
#include "notificationconsumer.h"
810
#include "timer.h"
911

12+
const uint8_t queue_wm_status_mask = 1 << 0;
13+
const uint8_t pg_wm_status_mask = 1 << 1;
14+
15+
static const map<string, const uint8_t> groupToMask =
16+
{
17+
{ "QUEUE_WATERMARK", queue_wm_status_mask },
18+
{ "PG_WATERMARK", pg_wm_status_mask }
19+
};
1020

1121
class WatermarkOrch : public Orch
1222
{
1323
public:
14-
WatermarkOrch(DBConnector *db, const std::string tableName);
24+
WatermarkOrch(DBConnector *db, const vector<string> &tables);
1525
virtual ~WatermarkOrch(void);
1626

1727
void doTask(Consumer &consumer);
@@ -21,6 +31,9 @@ class WatermarkOrch : public Orch
2131
void init_pg_ids();
2232
void init_queue_ids();
2333

34+
void handleWmConfigUpdate(const std::string &key, const std::vector<FieldValueTuple> &fvt);
35+
void handleFcConfigUpdate(const std::string &key, const std::vector<FieldValueTuple> &fvt);
36+
2437
void clearSingleWm(Table *table, string wm_name, vector<sai_object_id_t> &obj_ids);
2538

2639
shared_ptr<Table> getCountersTable(void)
@@ -34,6 +47,14 @@ class WatermarkOrch : public Orch
3447
}
3548

3649
private:
50+
/*
51+
[7-2] - unused
52+
[1] - pg wm status
53+
[0] - queue wm status (least significant bit)
54+
*/
55+
uint8_t m_wmStatus = 0;
56+
bool m_timerChanged = false;
57+
3758
shared_ptr<DBConnector> m_countersDb = nullptr;
3859
shared_ptr<DBConnector> m_appDb = nullptr;
3960
shared_ptr<Table> m_countersTable = nullptr;
@@ -47,8 +68,6 @@ class WatermarkOrch : public Orch
4768
vector<sai_object_id_t> m_unicast_queue_ids;
4869
vector<sai_object_id_t> m_multicast_queue_ids;
4970
vector<sai_object_id_t> m_pg_ids;
50-
51-
int m_telemetryInterval;
5271
};
5372

5473
#endif // WATERMARKORCH_H

0 commit comments

Comments
 (0)