Skip to content

Commit 73ffd5f

Browse files
authored
Revert "[flex-counters] Delay flex counters stats init for faster boot time (sonic-net#1646)" (sonic-net#1743)
This reverts commit ee7a735.
1 parent dc9ece9 commit 73ffd5f

9 files changed

+17
-241
lines changed

orchagent/flexcounterorch.cpp

+3-37
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ extern IntfsOrch *gIntfsOrch;
1616
extern BufferOrch *gBufferOrch;
1717

1818
#define BUFFER_POOL_WATERMARK_KEY "BUFFER_POOL_WATERMARK"
19-
#define PORT_KEY "PORT"
20-
#define PORT_BUFFER_DROP_KEY "PORT_BUFFER_DROP"
21-
#define QUEUE_KEY "QUEUE"
22-
#define PG_WATERMARK_KEY "PG_WATERMARK"
23-
#define RIF_KEY "RIF"
2419

2520
unordered_map<string, string> flexCounterGroupMap =
2621
{
@@ -92,16 +87,6 @@ void FlexCounterOrch::doTask(Consumer &consumer)
9287
}
9388
else if(field == FLEX_COUNTER_STATUS_FIELD)
9489
{
95-
if((key == PORT_KEY) && (value == "enable"))
96-
{
97-
gPortsOrch->generatePortCounterMap();
98-
m_port_counter_enabled = true;
99-
}
100-
if((key == PORT_BUFFER_DROP_KEY) && (value == "enable"))
101-
{
102-
gPortsOrch->generatePortBufferDropCounterMap();
103-
m_port_buffer_drop_counter_enabled = true;
104-
}
10590
// Currently, the counters are disabled for polling by default
10691
// The queue maps will be generated as soon as counters are enabled for polling
10792
// Counter polling is enabled by pushing the COUNTER_ID_LIST/ATTR_ID_LIST, which contains
@@ -116,18 +101,9 @@ void FlexCounterOrch::doTask(Consumer &consumer)
116101
// This can be because generateQueueMap() installs a fundamental list of queue stats
117102
// that need to be polled. So my doubt here is if queue watermark stats shall be piggybacked
118103
// into the same function as they may not be counted as fundamental
119-
if((key == QUEUE_KEY) && (value == "enable"))
120-
{
121-
gPortsOrch->generateQueueMap();
122-
}
123-
if((key == PG_WATERMARK_KEY) && (value == "enable"))
124-
{
125-
gPortsOrch->generatePriorityGroupMap();
126-
}
127-
if((key == RIF_KEY) && (value == "enable"))
128-
{
129-
gIntfsOrch->generateInterfaceMap();
130-
}
104+
gPortsOrch->generateQueueMap();
105+
gPortsOrch->generatePriorityGroupMap();
106+
gIntfsOrch->generateInterfaceMap();
131107
// Install COUNTER_ID_LIST/ATTR_ID_LIST only when hearing buffer pool watermark enable event
132108
if ((key == BUFFER_POOL_WATERMARK_KEY) && (value == "enable"))
133109
{
@@ -148,13 +124,3 @@ void FlexCounterOrch::doTask(Consumer &consumer)
148124
consumer.m_toSync.erase(it++);
149125
}
150126
}
151-
152-
bool FlexCounterOrch::getPortCountersState()
153-
{
154-
return m_port_counter_enabled;
155-
}
156-
157-
bool FlexCounterOrch::getPortBufferDropCountersState()
158-
{
159-
return m_port_buffer_drop_counter_enabled;
160-
}

orchagent/flexcounterorch.h

-4
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,10 @@ class FlexCounterOrch: public Orch
1515
void doTask(Consumer &consumer);
1616
FlexCounterOrch(swss::DBConnector *db, std::vector<std::string> &tableNames);
1717
virtual ~FlexCounterOrch(void);
18-
bool getPortCountersState();
19-
bool getPortBufferDropCountersState();
2018

2119
private:
2220
std::shared_ptr<swss::DBConnector> m_flexCounterDb = nullptr;
2321
std::shared_ptr<swss::ProducerTable> m_flexCounterGroupTable = nullptr;
24-
bool m_port_counter_enabled = false;
25-
bool m_port_buffer_drop_counter_enabled = false;
2622
};
2723

2824
#endif

orchagent/orchdaemon.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,7 @@ bool OrchDaemon::init()
339339
CFG_FLEX_COUNTER_TABLE_NAME
340340
};
341341

342-
auto* flexCounterOrch = new FlexCounterOrch(m_configDb, flex_counter_tables);
343-
m_orchList.push_back(flexCounterOrch);
344-
345-
gDirectory.set(flexCounterOrch);
346-
gDirectory.set(gPortsOrch);
342+
m_orchList.push_back(new FlexCounterOrch(m_configDb, flex_counter_tables));
347343

348344
vector<string> pfc_wd_tables = {
349345
CFG_PFC_WD_TABLE_NAME

orchagent/portsorch.cpp

+13-70
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,9 @@ static char* hostif_vlan_tag[] = {
233233
*/
234234
PortsOrch::PortsOrch(DBConnector *db, vector<table_name_with_pri_t> &tableNames, DBConnector *chassisAppDb) :
235235
Orch(db, tableNames),
236-
port_stat_manager(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, false),
237-
port_buffer_drop_stat_manager(PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_BUFFER_DROP_STAT_POLLING_INTERVAL_MS, false),
238-
queue_stat_manager(QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, QUEUE_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, false)
236+
port_stat_manager(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true),
237+
port_buffer_drop_stat_manager(PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_BUFFER_DROP_STAT_POLLING_INTERVAL_MS, true),
238+
queue_stat_manager(QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, QUEUE_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true)
239239
{
240240
SWSS_LOG_ENTER();
241241

@@ -2131,21 +2131,19 @@ bool PortsOrch::initPort(const string &alias, const int index, const set<int> &l
21312131
vector<FieldValueTuple> fields;
21322132
fields.push_back(tuple);
21332133
m_counterTable->set("", fields);
2134-
21352134
// Install a flex counter for this port to track stats
2136-
auto flex_counters_orch = gDirectory.get<FlexCounterOrch*>();
2137-
/* Delay installing the counters if they are yet enabled
2138-
If they are enabled, install the counters immediately */
2139-
if (flex_counters_orch->getPortCountersState())
2135+
std::unordered_set<std::string> counter_stats;
2136+
for (const auto& it: port_stat_ids)
21402137
{
2141-
auto port_counter_stats = generateCounterStats(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP);
2142-
port_stat_manager.setCounterIdList(p.m_port_id, CounterType::PORT, port_counter_stats);
2138+
counter_stats.emplace(sai_serialize_port_stat(it));
21432139
}
2144-
if (flex_counters_orch->getPortBufferDropCountersState())
2140+
port_stat_manager.setCounterIdList(p.m_port_id, CounterType::PORT, counter_stats);
2141+
std::unordered_set<std::string> port_buffer_drop_stats;
2142+
for (const auto& it: port_buffer_drop_stat_ids)
21452143
{
2146-
auto port_buffer_drop_stats = generateCounterStats(PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP);
2147-
port_buffer_drop_stat_manager.setCounterIdList(p.m_port_id, CounterType::PORT, port_buffer_drop_stats);
2144+
port_buffer_drop_stats.emplace(sai_serialize_port_stat(it));
21482145
}
2146+
port_buffer_drop_stat_manager.setCounterIdList(p.m_port_id, CounterType::PORT, port_buffer_drop_stats);
21492147

21502148
PortUpdate update = { p, true };
21512149
notify(SUBJECT_TYPE_PORT_CHANGE, static_cast<void *>(&update));
@@ -2178,11 +2176,8 @@ void PortsOrch::deInitPort(string alias, sai_object_id_t port_id)
21782176
p.m_port_id = port_id;
21792177

21802178
/* remove port from flex_counter_table for updating counters */
2181-
auto flex_counters_orch = gDirectory.get<FlexCounterOrch*>();
2182-
if ((flex_counters_orch->getPortCountersState()))
2183-
{
2184-
port_stat_manager.clearCounterIdList(p.m_port_id);
2185-
}
2179+
port_stat_manager.clearCounterIdList(p.m_port_id);
2180+
21862181
/* remove port name map from counter table */
21872182
m_counter_db->hdel(COUNTERS_PORT_NAME_MAP, alias);
21882183

@@ -4704,38 +4699,6 @@ void PortsOrch::generatePriorityGroupMapPerPort(const Port& port)
47044699
CounterCheckOrch::getInstance().addPort(port);
47054700
}
47064701

4707-
void PortsOrch::generatePortCounterMap()
4708-
{
4709-
if (m_isPortCounterMapGenerated)
4710-
{
4711-
return;
4712-
}
4713-
4714-
auto port_counter_stats = generateCounterStats(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP);
4715-
for (const auto& it: m_portList)
4716-
{
4717-
port_stat_manager.setCounterIdList(it.second.m_port_id, CounterType::PORT, port_counter_stats);
4718-
}
4719-
4720-
m_isPortCounterMapGenerated = true;
4721-
}
4722-
4723-
void PortsOrch::generatePortBufferDropCounterMap()
4724-
{
4725-
if (m_isPortBufferDropCounterMapGenerated)
4726-
{
4727-
return;
4728-
}
4729-
4730-
auto port_buffer_drop_stats = generateCounterStats(PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP);
4731-
for (const auto& it: m_portList)
4732-
{
4733-
port_buffer_drop_stat_manager.setCounterIdList(it.second.m_port_id, CounterType::PORT, port_buffer_drop_stats);
4734-
}
4735-
4736-
m_isPortBufferDropCounterMapGenerated = true;
4737-
}
4738-
47394702
void PortsOrch::doTask(NotificationConsumer &consumer)
47404703
{
47414704
SWSS_LOG_ENTER();
@@ -5602,26 +5565,6 @@ bool PortsOrch::setVoqInbandIntf(string &alias, string &type)
56025565
return true;
56035566
}
56045567

5605-
std::unordered_set<std::string> PortsOrch::generateCounterStats(const string& type)
5606-
{
5607-
std::unordered_set<std::string> counter_stats;
5608-
if (type == PORT_STAT_COUNTER_FLEX_COUNTER_GROUP)
5609-
{
5610-
for (const auto& it: port_stat_ids)
5611-
{
5612-
counter_stats.emplace(sai_serialize_port_stat(it));
5613-
}
5614-
}
5615-
else if (type == PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP)
5616-
{
5617-
for (const auto& it: port_buffer_drop_stat_ids)
5618-
{
5619-
counter_stats.emplace(sai_serialize_port_stat(it));
5620-
}
5621-
}
5622-
return counter_stats;
5623-
}
5624-
56255568
void PortsOrch::voqSyncAddLag (Port &lag)
56265569
{
56275570
int32_t switch_id = lag.m_system_lag_info.switch_id;

orchagent/portsorch.h

-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "flex_counter_manager.h"
1313
#include "gearboxutils.h"
1414
#include "saihelper.h"
15-
#include "flexcounterorch.h"
1615
#include "lagid.h"
1716

1817

@@ -126,8 +125,6 @@ class PortsOrch : public Orch, public Subject
126125

127126
void generateQueueMap();
128127
void generatePriorityGroupMap();
129-
void generatePortCounterMap();
130-
void generatePortBufferDropCounterMap();
131128

132129
void refreshPortStatus();
133130
bool removeAclTableGroup(const Port &p);
@@ -286,9 +283,6 @@ class PortsOrch : public Orch, public Subject
286283
bool m_isPriorityGroupMapGenerated = false;
287284
void generatePriorityGroupMapPerPort(const Port& port);
288285

289-
bool m_isPortCounterMapGenerated = false;
290-
bool m_isPortBufferDropCounterMapGenerated = false;
291-
292286
bool setPortAutoNeg(sai_object_id_t id, int an);
293287
bool setPortFecMode(sai_object_id_t id, int fec);
294288

@@ -313,9 +307,6 @@ class PortsOrch : public Orch, public Subject
313307
sai_uint32_t m_systemPortCount;
314308
bool getSystemPorts();
315309
bool addSystemPorts();
316-
317-
std::unordered_set<std::string> generateCounterStats(const string& type);
318-
319310
unique_ptr<Table> m_tableVoqSystemLagTable;
320311
unique_ptr<Table> m_tableVoqSystemLagMemberTable;
321312
void voqSyncAddLag(Port &lag);

tests/mock_tests/mock_orchagent_main.h

-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#include "vxlanorch.h"
1616
#include "policerorch.h"
1717
#include "fgnhgorch.h"
18-
#include "flexcounterorch.h"
19-
#include "directory.h"
2018

2119
extern int gBatchSize;
2220
extern bool gSwssRecord;
@@ -44,7 +42,6 @@ extern FdbOrch *gFdbOrch;
4442
extern MirrorOrch *gMirrorOrch;
4543
extern BufferOrch *gBufferOrch;
4644
extern VRFOrch *gVrfOrch;
47-
extern Directory<Orch*> gDirectory;
4845

4946
extern sai_acl_api_t *sai_acl_api;
5047
extern sai_switch_api_t *sai_switch_api;

tests/mock_tests/portsorch_ut.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,7 @@ namespace portsorch_test
145145
};
146146

147147
ASSERT_EQ(gPortsOrch, nullptr);
148-
149-
vector<string> flex_counter_tables = {
150-
CFG_FLEX_COUNTER_TABLE_NAME
151-
};
152-
153-
auto* flexCounterOrch = new FlexCounterOrch(m_config_db.get(), flex_counter_tables);
154-
gDirectory.set(flexCounterOrch);
155-
156148
gPortsOrch = new PortsOrch(m_app_db.get(), ports_tables, m_chassis_app_db.get());
157-
158149
vector<string> buffer_tables = { APP_BUFFER_POOL_TABLE_NAME,
159150
APP_BUFFER_PROFILE_TABLE_NAME,
160151
APP_BUFFER_QUEUE_TABLE_NAME,

tests/test_flex_counters.py

-102
This file was deleted.

0 commit comments

Comments
 (0)