Skip to content

Commit 2a7d2a7

Browse files
qiluo-msftlguohan
authored andcommitted
Revert "Revert "Update port and queue stat counters by Flex counter (sonic-net#358)" (sonic-net#371)" (sonic-net#388)
This reverts commit 8fc09d0.
1 parent 8f4d3c4 commit 2a7d2a7

File tree

5 files changed

+70
-18
lines changed

5 files changed

+70
-18
lines changed

orchagent/orchdaemon.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ using namespace swss;
1111

1212
/* select() function timeout retry time */
1313
#define SELECT_TIMEOUT 1000
14+
#define FLEX_COUNTER_POLL_MSECS 100
1415

1516
extern sai_switch_api_t* sai_switch_api;
1617
extern sai_object_id_t gSwitchId;
@@ -140,7 +141,8 @@ bool OrchDaemon::init()
140141
pfc_wd_tables,
141142
portStatIds,
142143
queueStatIds,
143-
queueAttrIds));
144+
queueAttrIds,
145+
FLEX_COUNTER_POLL_MSECS));
144146
}
145147
else if (platform == BRCM_PLATFORM_SUBSTRING)
146148
{
@@ -180,7 +182,8 @@ bool OrchDaemon::init()
180182
pfc_wd_tables,
181183
portStatIds,
182184
queueStatIds,
183-
queueAttrIds));
185+
queueAttrIds,
186+
FLEX_COUNTER_POLL_MSECS));
184187
}
185188

186189
return true;

orchagent/pfcwdorch.cpp

+11-7
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,12 @@ void PfcWdSwOrch<DropHandler, ForwardHandler>::registerInWdDb(const Port& port,
267267

268268
if (!c_portStatIds.empty())
269269
{
270+
string key = sai_serialize_object_id(port.m_port_id) + ":" + std::to_string(m_pollInterval);
270271
vector<FieldValueTuple> fieldValues;
271272
string str = counterIdsToStr(c_portStatIds, &sai_serialize_port_stat);
272273
fieldValues.emplace_back(PFC_WD_PORT_COUNTER_ID_LIST, str);
273274

274-
m_pfcWdTable->set(
275-
sai_serialize_object_id(port.m_port_id),
276-
fieldValues);
275+
m_pfcWdTable->set(key, fieldValues);
277276
}
278277

279278
uint8_t pfcMask = attr.value.u8;
@@ -317,7 +316,9 @@ void PfcWdSwOrch<DropHandler, ForwardHandler>::registerInWdDb(const Port& port,
317316
// Create internal entry
318317
m_entryMap.emplace(queueId, PfcWdQueueEntry(action, port.m_port_id, i));
319318

320-
m_pfcWdTable->set(queueIdStr, queueFieldValues);
319+
string key = queueIdStr + ":" + std::to_string(m_pollInterval);
320+
321+
m_pfcWdTable->set(key, queueFieldValues);
321322

322323
// Initialize PFC WD related counters
323324
PfcWdActionHandler::initWdCounters(
@@ -334,9 +335,10 @@ void PfcWdSwOrch<DropHandler, ForwardHandler>::unregisterFromWdDb(const Port& po
334335
for (uint8_t i = 0; i < PFC_WD_TC_MAX; i++)
335336
{
336337
sai_object_id_t queueId = port.m_queue_ids[i];
338+
string key = sai_serialize_object_id(queueId) + ":" + std::to_string(m_pollInterval);
337339

338340
// Unregister in syncd
339-
m_pfcWdTable->del(sai_serialize_object_id(queueId));
341+
m_pfcWdTable->del(key);
340342
m_entryMap.erase(queueId);
341343
}
342344
}
@@ -347,13 +349,15 @@ PfcWdSwOrch<DropHandler, ForwardHandler>::PfcWdSwOrch(
347349
vector<string> &tableNames,
348350
const vector<sai_port_stat_t> &portStatIds,
349351
const vector<sai_queue_stat_t> &queueStatIds,
350-
const vector<sai_queue_attr_t> &queueAttrIds):
352+
const vector<sai_queue_attr_t> &queueAttrIds,
353+
int pollInterval):
351354
PfcWdOrch<DropHandler, ForwardHandler>(db, tableNames),
352355
m_pfcWdDb(new DBConnector(PFC_WD_DB, DBConnector::DEFAULT_UNIXSOCKET, 0)),
353356
m_pfcWdTable(new ProducerStateTable(m_pfcWdDb.get(), PFC_WD_STATE_TABLE)),
354357
c_portStatIds(portStatIds),
355358
c_queueStatIds(queueStatIds),
356-
c_queueAttrIds(queueAttrIds)
359+
c_queueAttrIds(queueAttrIds),
360+
m_pollInterval(pollInterval)
357361
{
358362
SWSS_LOG_ENTER();
359363

orchagent/pfcwdorch.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ class PfcWdSwOrch: public PfcWdOrch<DropHandler, ForwardHandler>
6262
vector<string> &tableNames,
6363
const vector<sai_port_stat_t> &portStatIds,
6464
const vector<sai_queue_stat_t> &queueStatIds,
65-
const vector<sai_queue_attr_t> &queueAttrIds);
65+
const vector<sai_queue_attr_t> &queueAttrIds,
66+
int pollInterval);
6667
virtual ~PfcWdSwOrch(void);
6768

6869
virtual bool startWdOnPort(const Port& port,
@@ -106,6 +107,8 @@ class PfcWdSwOrch: public PfcWdOrch<DropHandler, ForwardHandler>
106107

107108
atomic_bool m_runPfcWdSwOrchThread = { false };
108109
shared_ptr<thread> m_pfcWatchdogThread = nullptr;
110+
111+
int m_pollInterval;
109112
};
110113

111114
#endif

orchagent/portsorch.cpp

+45-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <set>
77
#include <algorithm>
88
#include <tuple>
9+
#include <sstream>
910

1011
#include <netinet/if_ether.h>
1112
#include "net/if.h"
@@ -29,6 +30,7 @@ extern sai_object_id_t gSwitchId;
2930

3031
#define VLAN_PREFIX "Vlan"
3132
#define DEFAULT_VLAN_ID 1
33+
#define FLEX_STAT_COUNTER_POLL_MSECS "1000"
3234

3335
static map<string, sai_port_fec_mode_t> fec_mode_map =
3436
{
@@ -56,16 +58,19 @@ PortsOrch::PortsOrch(DBConnector *db, vector<string> tableNames) :
5658
SWSS_LOG_ENTER();
5759

5860
/* Initialize counter table */
59-
DBConnector *counter_db(new DBConnector(COUNTERS_DB, DBConnector::DEFAULT_UNIXSOCKET, 0));
60-
m_counterTable = unique_ptr<Table>(new Table(counter_db, COUNTERS_PORT_NAME_MAP));
61+
m_counter_db = shared_ptr<DBConnector>(new DBConnector(COUNTERS_DB, DBConnector::DEFAULT_UNIXSOCKET, 0));
62+
m_counterTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_PORT_NAME_MAP));
6163

6264
/* Initialize port table */
6365
m_portTable = unique_ptr<Table>(new Table(db, APP_PORT_TABLE_NAME));
6466

6567
/* Initialize queue tables */
66-
m_queueTable = unique_ptr<Table>(new Table(counter_db, COUNTERS_QUEUE_NAME_MAP));
67-
m_queuePortTable = unique_ptr<Table>(new Table(counter_db, COUNTERS_QUEUE_PORT_MAP));
68-
m_queueIndexTable = unique_ptr<Table>(new Table(counter_db, COUNTERS_QUEUE_INDEX_MAP));
68+
m_queueTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_QUEUE_NAME_MAP));
69+
m_queuePortTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_QUEUE_PORT_MAP));
70+
m_queueIndexTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_QUEUE_INDEX_MAP));
71+
72+
m_flex_db = shared_ptr<DBConnector>(new DBConnector(PFC_WD_DB, DBConnector::DEFAULT_UNIXSOCKET, 0));
73+
m_flexCounterTable = unique_ptr<ProducerStateTable>(new ProducerStateTable(m_flex_db.get(), PFC_WD_STATE_TABLE));
6974

7075
uint32_t i, j;
7176
sai_status_t status;
@@ -643,9 +648,25 @@ bool PortsOrch::initPort(const string &alias, const set<int> &lane_set)
643648
m_portList[alias] = p;
644649
/* Add port name map to counter table */
645650
FieldValueTuple tuple(p.m_alias, sai_serialize_object_id(p.m_port_id));
646-
vector<FieldValueTuple> vector;
647-
vector.push_back(tuple);
648-
m_counterTable->set("", vector);
651+
vector<FieldValueTuple> fields;
652+
fields.push_back(tuple);
653+
m_counterTable->set("", fields);
654+
655+
/* Add port to flex_counter for updating stat counters */
656+
string key = sai_serialize_object_id(p.m_port_id) + ":" + FLEX_STAT_COUNTER_POLL_MSECS;
657+
658+
std::string delimiter = "";
659+
std::ostringstream counters_stream;
660+
for (int cntr = SAI_PORT_STAT_IF_IN_OCTETS; cntr <= SAI_PORT_STAT_PFC_7_ON2OFF_RX_PKTS; ++cntr)
661+
{
662+
counters_stream << delimiter << sai_serialize_port_stat(static_cast<sai_port_stat_t>(cntr));
663+
delimiter = ",";
664+
}
665+
666+
fields.clear();
667+
fields.emplace_back(PFC_WD_PORT_COUNTER_ID_LIST, counters_stream.str());
668+
669+
m_flexCounterTable->set(key, fields);
649670

650671
SWSS_LOG_NOTICE("Initialized port %s", alias.c_str());
651672
}
@@ -1362,6 +1383,7 @@ void PortsOrch::initializeQueues(Port &port)
13621383
SWSS_LOG_INFO("Get queues for port %s", port.m_alias.c_str());
13631384

13641385
/* Create the Queue map in the Counter DB */
1386+
/* Add stat counters to flex_counter */
13651387
vector<FieldValueTuple> queueVector;
13661388
vector<FieldValueTuple> queuePortVector;
13671389
vector<FieldValueTuple> queueIndexVector;
@@ -1382,6 +1404,21 @@ void PortsOrch::initializeQueues(Port &port)
13821404
sai_serialize_object_id(port.m_queue_ids[queueIndex]),
13831405
to_string(queueIndex));
13841406
queueIndexVector.push_back(queueIndexTuple);
1407+
1408+
string key = sai_serialize_object_id(port.m_queue_ids[queueIndex]) + ":" + FLEX_STAT_COUNTER_POLL_MSECS;
1409+
1410+
std::string delimiter = "";
1411+
std::ostringstream counters_stream;
1412+
for (int cntr = SAI_QUEUE_STAT_PACKETS; cntr <= SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES ; ++cntr)
1413+
{
1414+
counters_stream << delimiter << sai_serialize_queue_stat(static_cast<sai_queue_stat_t>(cntr));
1415+
delimiter = ",";
1416+
}
1417+
1418+
vector<FieldValueTuple> fieldValues;
1419+
fieldValues.emplace_back(PFC_WD_QUEUE_COUNTER_ID_LIST, counters_stream.str());
1420+
1421+
m_flexCounterTable->set(key, fieldValues);
13851422
}
13861423

13871424
m_queueTable->set("", queueVector);

orchagent/portsorch.h

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "port.h"
88
#include "observer.h"
99
#include "macaddress.h"
10+
#include "producerstatetable.h"
1011

1112
#include <map>
1213

@@ -61,6 +62,10 @@ class PortsOrch : public Orch, public Subject
6162
unique_ptr<Table> m_queueTable;
6263
unique_ptr<Table> m_queuePortTable;
6364
unique_ptr<Table> m_queueIndexTable;
65+
unique_ptr<ProducerStateTable> m_flexCounterTable;
66+
67+
shared_ptr<DBConnector> m_counter_db;
68+
shared_ptr<DBConnector> m_flex_db;
6469

6570
std::map<sai_object_id_t, PortSupportedSpeeds> m_portSupportedSpeeds;
6671

0 commit comments

Comments
 (0)