Skip to content

Commit b750a4b

Browse files
mykolaflguohan
authored andcommitted
[watermarkorch] add watermarkorch, extend queue and pg counters with wat… (sonic-net#629)
* [watermarks] add watermarkorch, extend queue and pg counters with watermark stats Signed-off-by: Mykola Faryma <[email protected]> * [watermark] add VS tests Signed-off-by: Mykola Faryma <[email protected]> * [watermark] resolve conflict Signed-off-by: Mykola Faryma <[email protected]> * address review comments Signed-off-by: Mykola Faryma <[email protected]> * update VS test to use set counters and cover the flex counter flow Signed-off-by: Mykola Faryma <[email protected]>
1 parent c74dc60 commit b750a4b

12 files changed

+747
-5
lines changed

orchagent/Makefile.am

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ dist_swss_DATA = \
88
pfc_detect_mellanox.lua \
99
pfc_detect_broadcom.lua \
1010
pfc_detect_barefoot.lua \
11-
pfc_restore.lua
11+
pfc_restore.lua \
12+
watermark_queue.lua \
13+
watermark_pg.lua
1214

1315
bin_PROGRAMS = orchagent routeresync orchagent_restart_check
1416

@@ -46,6 +48,7 @@ orchagent_SOURCES = \
4648
vnetorch.cpp \
4749
dtelorch.cpp \
4850
flexcounterorch.cpp \
51+
watermarkorch.cpp \
4952
acltable.h \
5053
aclorch.h \
5154
bufferorch.h \
@@ -76,7 +79,8 @@ orchagent_SOURCES = \
7679
countercheckorch.h \
7780
vxlanorch.h \
7881
vnetorch.h \
79-
flexcounterorch.h
82+
flexcounterorch.h \
83+
watermarkorch.h
8084

8185
orchagent_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)
8286
orchagent_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)

orchagent/flexcounterorch.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ unordered_map<string, string> flexCounterGroupMap =
1616
{"PORT", PORT_STAT_COUNTER_FLEX_COUNTER_GROUP},
1717
{"QUEUE", QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP},
1818
{"PFCWD", PFC_WD_FLEX_COUNTER_GROUP},
19+
{"QUEUE_WATERMARK", QUEUE_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP},
20+
{"PG_WATERMARK", PG_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP},
1921
};
2022

2123

@@ -75,6 +77,7 @@ void FlexCounterOrch::doTask(Consumer &consumer)
7577
// Currently the counters are disabled by default
7678
// The queue maps will be generated as soon as counters are enabled
7779
gPortsOrch->generateQueueMap();
80+
gPortsOrch->generatePriorityGroupMap();
7881

7982
vector<FieldValueTuple> fieldValues;
8083
fieldValues.emplace_back(FLEX_COUNTER_STATUS_FIELD, value);

orchagent/orchdaemon.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ bool OrchDaemon::init()
138138
CFG_DTEL_EVENT_TABLE_NAME
139139
};
140140

141+
WatermarkOrch *wm_orch = new WatermarkOrch(m_configDb, CFG_WATERMARK_TABLE_NAME);
142+
141143
/*
142144
* The order of the orch list is important for state restore of warm start and
143145
* the queued processing in m_toSync map after gPortsOrch->isInitDone() is set.
@@ -146,7 +148,8 @@ bool OrchDaemon::init()
146148
* when iterating ConsumerMap.
147149
* That is ensured implicitly by the order of map key, "LAG_TABLE" is smaller than "VLAN_TABLE" in lexicographic order.
148150
*/
149-
m_orchList = { gSwitchOrch, gCrmOrch, gBufferOrch, gPortsOrch, gIntfsOrch, gNeighOrch, gRouteOrch, copp_orch, tunnel_decap_orch, qos_orch};
151+
m_orchList = { gSwitchOrch, gCrmOrch, gBufferOrch, gPortsOrch, gIntfsOrch, gNeighOrch, gRouteOrch, copp_orch, tunnel_decap_orch, qos_orch, wm_orch };
152+
150153

151154
bool initialize_dtel = false;
152155
if (platform == BFN_PLATFORM_SUBSTRING || platform == VS_PLATFORM_SUBSTRING)

orchagent/orchdaemon.h

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "vnetorch.h"
2626
#include "countercheckorch.h"
2727
#include "flexcounterorch.h"
28+
#include "watermarkorch.h"
2829
#include "directory.h"
2930

3031
using namespace swss;

orchagent/pfcwdorch.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ PfcWdSwOrch<DropHandler, ForwardHandler>::PfcWdSwOrch(
650650
vector<FieldValueTuple> fieldValues;
651651
fieldValues.emplace_back(QUEUE_PLUGIN_FIELD, detectSha + "," + restoreSha);
652652
fieldValues.emplace_back(POLL_INTERVAL_FIELD, to_string(m_pollInterval));
653+
fieldValues.emplace_back(STATS_MODE_FIELD, STATS_MODE_READ);
653654
m_flexCounterGroupTable->set(PFC_WD_FLEX_COUNTER_GROUP, fieldValues);
654655
}
655656
catch (...)

orchagent/portsorch.cpp

+141-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "logger.h"
1818
#include "schema.h"
19+
#include "redisapi.h"
1920
#include "converter.h"
2021
#include "sai_serialize.h"
2122
#include "crmorch.h"
@@ -40,6 +41,9 @@ extern BufferOrch *gBufferOrch;
4041
#define DEFAULT_VLAN_ID 1
4142
#define PORT_FLEX_STAT_COUNTER_POLL_MSECS "1000"
4243
#define QUEUE_FLEX_STAT_COUNTER_POLL_MSECS "10000"
44+
#define QUEUE_WATERMARK_FLEX_STAT_COUNTER_POLL_MSECS "1000"
45+
#define PG_WATERMARK_FLEX_STAT_COUNTER_POLL_MSECS "1000"
46+
4347

4448
static map<string, sai_port_fec_mode_t> fec_mode_map =
4549
{
@@ -105,6 +109,17 @@ static const vector<sai_queue_stat_t> queueStatIds =
105109
SAI_QUEUE_STAT_DROPPED_BYTES,
106110
};
107111

112+
static const vector<sai_queue_stat_t> queueWatermarkStatIds =
113+
{
114+
SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES,
115+
};
116+
117+
static const vector<sai_ingress_priority_group_stat_t> ingressPriorityGroupWatermarkStatIds =
118+
{
119+
SAI_INGRESS_PRIORITY_GROUP_STAT_XOFF_ROOM_WATERMARK_BYTES,
120+
SAI_INGRESS_PRIORITY_GROUP_STAT_SHARED_WATERMARK_BYTES,
121+
};
122+
108123
static char* hostif_vlan_tag[] = {
109124
[SAI_HOSTIF_VLAN_TAG_STRIP] = "SAI_HOSTIF_VLAN_TAG_STRIP",
110125
[SAI_HOSTIF_VLAN_TAG_KEEP] = "SAI_HOSTIF_VLAN_TAG_KEEP",
@@ -141,17 +156,53 @@ PortsOrch::PortsOrch(DBConnector *db, vector<table_name_with_pri_t> &tableNames)
141156
m_queueIndexTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_QUEUE_INDEX_MAP));
142157
m_queueTypeTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_QUEUE_TYPE_MAP));
143158

159+
/* Initialize ingress priority group tables */
160+
m_pgTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_PG_NAME_MAP));
161+
m_pgPortTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_PG_PORT_MAP));
162+
m_pgIndexTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_PG_INDEX_MAP));
163+
144164
m_flex_db = shared_ptr<DBConnector>(new DBConnector(FLEX_COUNTER_DB, DBConnector::DEFAULT_UNIXSOCKET, 0));
145165
m_flexCounterTable = unique_ptr<ProducerTable>(new ProducerTable(m_flex_db.get(), FLEX_COUNTER_TABLE));
146166
m_flexCounterGroupTable = unique_ptr<ProducerTable>(new ProducerTable(m_flex_db.get(), FLEX_COUNTER_GROUP_TABLE));
147167

148168
vector<FieldValueTuple> fields;
149169
fields.emplace_back(POLL_INTERVAL_FIELD, PORT_FLEX_STAT_COUNTER_POLL_MSECS);
170+
fields.emplace_back(STATS_MODE_FIELD, STATS_MODE_READ);
150171
m_flexCounterGroupTable->set(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, fields);
151172

152173
fields.emplace_back(POLL_INTERVAL_FIELD, QUEUE_FLEX_STAT_COUNTER_POLL_MSECS);
174+
fields.emplace_back(STATS_MODE_FIELD, STATS_MODE_READ);
153175
m_flexCounterGroupTable->set(QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP, fields);
154176

177+
string queueWmSha, pgWmSha;
178+
string queueWmPluginName = "watermark_queue.lua";
179+
string pgWmPluginName = "watermark_pg.lua";
180+
181+
try
182+
{
183+
string queueLuaScript = swss::loadLuaScript(queueWmPluginName);
184+
queueWmSha = swss::loadRedisScript(m_counter_db.get(), queueLuaScript);
185+
186+
string pgLuaScript = swss::loadLuaScript(pgWmPluginName);
187+
pgWmSha = swss::loadRedisScript(m_counter_db.get(), pgLuaScript);
188+
189+
vector<FieldValueTuple> fieldValues;
190+
fieldValues.emplace_back(QUEUE_PLUGIN_FIELD, queueWmSha);
191+
fieldValues.emplace_back(POLL_INTERVAL_FIELD, QUEUE_WATERMARK_FLEX_STAT_COUNTER_POLL_MSECS);
192+
fieldValues.emplace_back(STATS_MODE_FIELD, STATS_MODE_READ_AND_CLEAR);
193+
m_flexCounterGroupTable->set(QUEUE_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP, fieldValues);
194+
195+
fieldValues.clear();
196+
fieldValues.emplace_back(PG_PLUGIN_FIELD, pgWmSha);
197+
fieldValues.emplace_back(POLL_INTERVAL_FIELD, PG_WATERMARK_FLEX_STAT_COUNTER_POLL_MSECS);
198+
fieldValues.emplace_back(STATS_MODE_FIELD, STATS_MODE_READ_AND_CLEAR);
199+
m_flexCounterGroupTable->set(PG_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP, fieldValues);
200+
}
201+
catch (...)
202+
{
203+
SWSS_LOG_WARN("Watermark flex counter groups were not set successfully");
204+
}
205+
155206
uint32_t i, j;
156207
sai_status_t status;
157208
sai_attribute_t attr;
@@ -1248,6 +1299,16 @@ string PortsOrch::getQueueFlexCounterTableKey(string key)
12481299
return string(QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP) + ":" + key;
12491300
}
12501301

1302+
string PortsOrch::getQueueWatermarkFlexCounterTableKey(string key)
1303+
{
1304+
return string(QUEUE_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP) + ":" + key;
1305+
}
1306+
1307+
string PortsOrch::getPriorityGroupWatermarkFlexCounterTableKey(string key)
1308+
{
1309+
return string(PG_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP) + ":" + key;
1310+
}
1311+
12511312
bool PortsOrch::initPort(const string &alias, const set<int> &lane_set)
12521313
{
12531314
SWSS_LOG_ENTER();
@@ -1287,7 +1348,7 @@ bool PortsOrch::initPort(const string &alias, const set<int> &lane_set)
12871348
for (const auto &id: portStatIds)
12881349
{
12891350
counters_stream << delimiter << sai_serialize_port_stat(id);
1290-
delimiter = ",";
1351+
delimiter = comma;
12911352
}
12921353

12931354
fields.clear();
@@ -2873,20 +2934,37 @@ void PortsOrch::generateQueueMapPerPort(const Port& port)
28732934
queueIndexVector.emplace_back(id, to_string(queueRealIndex));
28742935
}
28752936

2937+
/* add ordinary Queue stat counters */
28762938
string key = getQueueFlexCounterTableKey(id);
28772939

28782940
std::string delimiter = "";
28792941
std::ostringstream counters_stream;
28802942
for (const auto& it: queueStatIds)
28812943
{
28822944
counters_stream << delimiter << sai_serialize_queue_stat(it);
2883-
delimiter = ",";
2945+
delimiter = comma;
28842946
}
28852947

28862948
vector<FieldValueTuple> fieldValues;
28872949
fieldValues.emplace_back(QUEUE_COUNTER_ID_LIST, counters_stream.str());
28882950

28892951
m_flexCounterTable->set(key, fieldValues);
2952+
2953+
/* add watermark queue counters */
2954+
key = getQueueWatermarkFlexCounterTableKey(id);
2955+
2956+
delimiter = "";
2957+
counters_stream.str("");
2958+
for (const auto& it: queueWatermarkStatIds)
2959+
{
2960+
counters_stream << delimiter << sai_serialize_queue_stat(it);
2961+
delimiter = comma;
2962+
}
2963+
2964+
fieldValues.clear();
2965+
fieldValues.emplace_back(QUEUE_COUNTER_ID_LIST, counters_stream.str());
2966+
2967+
m_flexCounterTable->set(key, fieldValues);
28902968
}
28912969

28922970
m_queueTable->set("", queueVector);
@@ -2897,6 +2975,67 @@ void PortsOrch::generateQueueMapPerPort(const Port& port)
28972975
CounterCheckOrch::getInstance().addPort(port);
28982976
}
28992977

2978+
void PortsOrch::generatePriorityGroupMap()
2979+
{
2980+
if (m_isPriorityGroupMapGenerated)
2981+
{
2982+
return;
2983+
}
2984+
2985+
for (const auto& it: m_portList)
2986+
{
2987+
if (it.second.m_type == Port::PHY)
2988+
{
2989+
generatePriorityGroupMapPerPort(it.second);
2990+
}
2991+
}
2992+
2993+
m_isPriorityGroupMapGenerated = true;
2994+
}
2995+
2996+
void PortsOrch::generatePriorityGroupMapPerPort(const Port& port)
2997+
{
2998+
/* Create the PG map in the Counter DB */
2999+
/* Add stat counters to flex_counter */
3000+
vector<FieldValueTuple> pgVector;
3001+
vector<FieldValueTuple> pgPortVector;
3002+
vector<FieldValueTuple> pgIndexVector;
3003+
3004+
for (size_t pgIndex = 0; pgIndex < port.m_priority_group_ids.size(); ++pgIndex)
3005+
{
3006+
std::ostringstream name;
3007+
name << port.m_alias << ":" << pgIndex;
3008+
3009+
const auto id = sai_serialize_object_id(port.m_priority_group_ids[pgIndex]);
3010+
3011+
pgVector.emplace_back(name.str(), id);
3012+
pgPortVector.emplace_back(id, sai_serialize_object_id(port.m_port_id));
3013+
pgIndexVector.emplace_back(id, to_string(pgIndex));
3014+
3015+
string key = getPriorityGroupWatermarkFlexCounterTableKey(id);
3016+
3017+
std::string delimiter = "";
3018+
std::ostringstream counters_stream;
3019+
/* Add watermark counters to flex_counter */
3020+
for (const auto& it: ingressPriorityGroupWatermarkStatIds)
3021+
{
3022+
counters_stream << delimiter << sai_serialize_ingress_priority_group_stat(it);
3023+
delimiter = comma;
3024+
}
3025+
3026+
vector<FieldValueTuple> fieldValues;
3027+
fieldValues.emplace_back(PG_COUNTER_ID_LIST, counters_stream.str());
3028+
3029+
m_flexCounterTable->set(key, fieldValues);
3030+
}
3031+
3032+
m_pgTable->set("", pgVector);
3033+
m_pgPortTable->set("", pgPortVector);
3034+
m_pgIndexTable->set("", pgIndexVector);
3035+
3036+
CounterCheckOrch::getInstance().addPort(port);
3037+
}
3038+
29003039
void PortsOrch::doTask(NotificationConsumer &consumer)
29013040
{
29023041
SWSS_LOG_ENTER();

orchagent/portsorch.h

+13
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#define VLAN_TAG_LEN 4
1515
#define PORT_STAT_COUNTER_FLEX_COUNTER_GROUP "PORT_STAT_COUNTER"
1616
#define QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP "QUEUE_STAT_COUNTER"
17+
#define QUEUE_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP "QUEUE_WATERMARK_STAT_COUNTER"
18+
#define PG_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP "PG_WATERMARK_STAT_COUNTER"
1719

1820

1921
typedef std::vector<sai_uint32_t> PortSupportedSpeeds;
@@ -76,19 +78,27 @@ class PortsOrch : public Orch, public Subject
7678
bool setPortPfc(sai_object_id_t portId, uint8_t pfc_bitmask);
7779

7880
void generateQueueMap();
81+
void generatePriorityGroupMap();
82+
7983
void refreshPortStatus();
84+
8085
private:
8186
unique_ptr<Table> m_counterTable;
8287
unique_ptr<Table> m_portTable;
8388
unique_ptr<Table> m_queueTable;
8489
unique_ptr<Table> m_queuePortTable;
8590
unique_ptr<Table> m_queueIndexTable;
8691
unique_ptr<Table> m_queueTypeTable;
92+
unique_ptr<Table> m_pgTable;
93+
unique_ptr<Table> m_pgPortTable;
94+
unique_ptr<Table> m_pgIndexTable;
8795
unique_ptr<ProducerTable> m_flexCounterTable;
8896
unique_ptr<ProducerTable> m_flexCounterGroupTable;
8997

9098
std::string getQueueFlexCounterTableKey(std::string s);
99+
std::string getQueueWatermarkFlexCounterTableKey(std::string s);
91100
std::string getPortFlexCounterTableKey(std::string s);
101+
std::string getPriorityGroupWatermarkFlexCounterTableKey(std::string s);
92102

93103
shared_ptr<DBConnector> m_counter_db;
94104
shared_ptr<DBConnector> m_flex_db;
@@ -166,6 +176,9 @@ class PortsOrch : public Orch, public Subject
166176
bool m_isQueueMapGenerated = false;
167177
void generateQueueMapPerPort(const Port& port);
168178

179+
bool m_isPriorityGroupMapGenerated = false;
180+
void generatePriorityGroupMapPerPort(const Port& port);
181+
169182
bool setPortAutoNeg(sai_object_id_t id, int an);
170183
bool setPortFecMode(sai_object_id_t id, int fec);
171184

0 commit comments

Comments
 (0)