Skip to content

Commit

Permalink
Revert "[Counters] Improve performance by polling only configured por…
Browse files Browse the repository at this point in the history
…ts buffer queue/pg counters (sonic-net#2143)" (sonic-net#2315)

This reverts commit eba212d.
  • Loading branch information
yxieca authored and preetham-singh committed Aug 6, 2022
1 parent 24dbef1 commit 27da1cb
Show file tree
Hide file tree
Showing 11 changed files with 223 additions and 556 deletions.
32 changes: 1 addition & 31 deletions orchagent/bufferorch.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "tokenize.h"
#include "bufferorch.h"
#include "directory.h"
#include "logger.h"
#include "sai_serialize.h"
#include "warm_restart.h"
Expand All @@ -17,7 +16,6 @@ extern sai_switch_api_t *sai_switch_api;
extern sai_buffer_api_t *sai_buffer_api;

extern PortsOrch *gPortsOrch;
extern Directory<Orch*> gDirectory;
extern sai_object_id_t gSwitchId;

#define BUFFER_POOL_WATERMARK_FLEX_STAT_COUNTER_POLL_MSECS "60000"
Expand Down Expand Up @@ -950,20 +948,6 @@ task_process_status BufferOrch::processQueue(KeyOpFieldsValuesTuple &tuple)
return handle_status;
}
}
// create/remove a port queue counter for the queue buffer
else
{
auto flexCounterOrch = gDirectory.get<FlexCounterOrch*>();
auto queues = tokens[1];
if (op == SET_COMMAND && flexCounterOrch->getQueueCountersState())
{
gPortsOrch->createPortBufferQueueCounters(port, queues);
}
else if (op == DEL_COMMAND && flexCounterOrch->getQueueCountersState())
{
gPortsOrch->removePortBufferQueueCounters(port, queues);
}
}
}
}
}
Expand Down Expand Up @@ -1023,7 +1007,7 @@ task_process_status BufferOrch::processPriorityGroup(KeyOpFieldsValuesTuple &tup
if (op == SET_COMMAND)
{
ref_resolve_status resolve_result = resolveFieldRefValue(m_buffer_type_maps, buffer_profile_field_name,
buffer_to_ref_table_map.at(buffer_profile_field_name), tuple,
buffer_to_ref_table_map.at(buffer_profile_field_name), tuple,
sai_buffer_profile, buffer_profile_name);
if (ref_resolve_status::success != resolve_result)
{
Expand Down Expand Up @@ -1103,20 +1087,6 @@ task_process_status BufferOrch::processPriorityGroup(KeyOpFieldsValuesTuple &tup
return handle_status;
}
}
// create or remove a port PG counter for the PG buffer
else
{
auto flexCounterOrch = gDirectory.get<FlexCounterOrch*>();
auto pgs = tokens[1];
if (op == SET_COMMAND && flexCounterOrch->getPgWatermarkCountersState())
{
gPortsOrch->createPortBufferPgCounters(port, pgs);
}
else if (op == DEL_COMMAND && flexCounterOrch->getPgWatermarkCountersState())
{
gPortsOrch->removePortBufferPgCounters(port, pgs);
}
}
}
}
}
Expand Down
181 changes: 2 additions & 179 deletions orchagent/flexcounterorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "debugcounterorch.h"
#include "directory.h"
#include "copporch.h"
#include <swss/tokenize.h>
#include "routeorch.h"
#include "flowcounterrouteorch.h"

Expand Down Expand Up @@ -59,8 +58,6 @@ unordered_map<string, string> flexCounterGroupMap =
FlexCounterOrch::FlexCounterOrch(DBConnector *db, vector<string> &tableNames):
Orch(db, tableNames),
m_flexCounterConfigTable(db, CFG_FLEX_COUNTER_TABLE_NAME),
m_bufferQueueConfigTable(db, CFG_BUFFER_QUEUE_TABLE_NAME),
m_bufferPgConfigTable(db, CFG_BUFFER_PG_TABLE_NAME),
m_flexCounterDb(new DBConnector("FLEX_COUNTER_DB", 0)),
m_flexCounterGroupTable(new ProducerTable(m_flexCounterDb.get(), FLEX_COUNTER_GROUP_TABLE))
{
Expand Down Expand Up @@ -147,13 +144,11 @@ void FlexCounterOrch::doTask(Consumer &consumer)
}
else if(key == QUEUE_KEY)
{
gPortsOrch->generateQueueMap(getQueueConfigurations());
m_queue_enabled = true;
gPortsOrch->generateQueueMap();
}
else if(key == PG_WATERMARK_KEY)
{
gPortsOrch->generatePriorityGroupMap(getPgConfigurations());
m_pg_watermark_enabled = true;
gPortsOrch->generatePriorityGroupMap();
}
}
if(gIntfsOrch && (key == RIF_KEY) && (value == "enable"))
Expand Down Expand Up @@ -235,16 +230,6 @@ bool FlexCounterOrch::getPortBufferDropCountersState() const
return m_port_buffer_drop_counter_enabled;
}

bool FlexCounterOrch::getPgWatermarkCountersState() const
{
return m_pg_watermark_enabled;
}

bool FlexCounterOrch::getQueueCountersState() const
{
return m_queue_enabled;
}

bool FlexCounterOrch::bake()
{
/*
Expand Down Expand Up @@ -286,165 +271,3 @@ bool FlexCounterOrch::bake()
Consumer* consumer = dynamic_cast<Consumer *>(getExecutor(CFG_FLEX_COUNTER_TABLE_NAME));
return consumer->addToSync(entries);
}

map<string, FlexCounterQueueStates> FlexCounterOrch::getQueueConfigurations()
{
SWSS_LOG_ENTER();

map<string, FlexCounterQueueStates> queuesStateVector;
std::vector<std::string> portQueueKeys;
m_bufferQueueConfigTable.getKeys(portQueueKeys);

for (const auto& portQueueKey : portQueueKeys)
{
auto toks = tokenize(portQueueKey, '|');
if (toks.size() != 2)
{
SWSS_LOG_ERROR("Invalid BUFFER_QUEUE key: [%s]", portQueueKey.c_str());
continue;
}

auto configPortNames = tokenize(toks[0], ',');
auto configPortQueues = toks[1];
toks = tokenize(configPortQueues, '-');

for (const auto& configPortName : configPortNames)
{
uint32_t maxQueueNumber = gPortsOrch->getNumberOfPortSupportedQueueCounters(configPortName);
uint32_t maxQueueIndex = maxQueueNumber - 1;
uint32_t minQueueIndex = 0;

if (!queuesStateVector.count(configPortName))
{
FlexCounterQueueStates flexCounterQueueState(maxQueueNumber);
queuesStateVector.insert(make_pair(configPortName, flexCounterQueueState));
}

try {
auto startIndex = to_uint<uint32_t>(toks[0], minQueueIndex, maxQueueIndex);
if (toks.size() > 1)
{
auto endIndex = to_uint<uint32_t>(toks[1], minQueueIndex, maxQueueIndex);
queuesStateVector.at(configPortName).enableQueueCounters(startIndex, endIndex);
}
else
{
queuesStateVector.at(configPortName).enableQueueCounter(startIndex);
}
} catch (std::invalid_argument const& e) {
SWSS_LOG_ERROR("Invalid queue index [%s] for port [%s]", configPortQueues.c_str(), configPortName.c_str());
continue;
}
}
}

return queuesStateVector;
}

map<string, FlexCounterPgStates> FlexCounterOrch::getPgConfigurations()
{
SWSS_LOG_ENTER();

map<string, FlexCounterPgStates> pgsStateVector;
std::vector<std::string> portPgKeys;
m_bufferPgConfigTable.getKeys(portPgKeys);

for (const auto& portPgKey : portPgKeys)
{
auto toks = tokenize(portPgKey, '|');
if (toks.size() != 2)
{
SWSS_LOG_ERROR("Invalid BUFFER_PG key: [%s]", portPgKey.c_str());
continue;
}

auto configPortNames = tokenize(toks[0], ',');
auto configPortPgs = toks[1];
toks = tokenize(configPortPgs, '-');

for (const auto& configPortName : configPortNames)
{
uint32_t maxPgNumber = gPortsOrch->getNumberOfPortSupportedPgCounters(configPortName);
uint32_t maxPgIndex = maxPgNumber - 1;
uint32_t minPgIndex = 0;

if (!pgsStateVector.count(configPortName))
{
FlexCounterPgStates flexCounterPgState(maxPgNumber);
pgsStateVector.insert(make_pair(configPortName, flexCounterPgState));
}

try {
auto startIndex = to_uint<uint32_t>(toks[0], minPgIndex, maxPgIndex);
if (toks.size() > 1)
{
auto endIndex = to_uint<uint32_t>(toks[1], minPgIndex, maxPgIndex);
pgsStateVector.at(configPortName).enablePgCounters(startIndex, endIndex);
}
else
{
pgsStateVector.at(configPortName).enablePgCounter(startIndex);
}
} catch (std::invalid_argument const& e) {
SWSS_LOG_ERROR("Invalid pg index [%s] for port [%s]", configPortPgs.c_str(), configPortName.c_str());
continue;
}
}
}

return pgsStateVector;
}

FlexCounterQueueStates::FlexCounterQueueStates(uint32_t maxQueueNumber)
{
SWSS_LOG_ENTER();
m_queueStates.resize(maxQueueNumber, false);
}

bool FlexCounterQueueStates::isQueueCounterEnabled(uint32_t index) const
{
SWSS_LOG_ENTER();
return m_queueStates[index];
}

void FlexCounterQueueStates::enableQueueCounters(uint32_t startIndex, uint32_t endIndex)
{
SWSS_LOG_ENTER();
for (uint32_t queueIndex = startIndex; queueIndex <= endIndex; queueIndex++)
{
enableQueueCounter(queueIndex);
}
}

void FlexCounterQueueStates::enableQueueCounter(uint32_t queueIndex)
{
SWSS_LOG_ENTER();
m_queueStates[queueIndex] = true;
}

FlexCounterPgStates::FlexCounterPgStates(uint32_t maxPgNumber)
{
SWSS_LOG_ENTER();
m_pgStates.resize(maxPgNumber, false);
}

bool FlexCounterPgStates::isPgCounterEnabled(uint32_t index) const
{
SWSS_LOG_ENTER();
return m_pgStates[index];
}

void FlexCounterPgStates::enablePgCounters(uint32_t startIndex, uint32_t endIndex)
{
SWSS_LOG_ENTER();
for (uint32_t pgIndex = startIndex; pgIndex <= endIndex; pgIndex++)
{
enablePgCounter(pgIndex);
}
}

void FlexCounterPgStates::enablePgCounter(uint32_t pgIndex)
{
SWSS_LOG_ENTER();
m_pgStates[pgIndex] = true;
}
32 changes: 0 additions & 32 deletions orchagent/flexcounterorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,6 @@ extern "C" {
#include "sai.h"
}

class FlexCounterQueueStates
{
public:
FlexCounterQueueStates(uint32_t maxQueueNumber);
bool isQueueCounterEnabled(uint32_t index) const;
void enableQueueCounters(uint32_t startIndex, uint32_t endIndex);
void enableQueueCounter(uint32_t queueIndex);

private:
std::vector<bool> m_queueStates{};
};

class FlexCounterPgStates
{
public:
FlexCounterPgStates(uint32_t maxPgNumber);
bool isPgCounterEnabled(uint32_t index) const;
void enablePgCounters(uint32_t startIndex, uint32_t endIndex);
void enablePgCounter(uint32_t pgIndex);

private:
std::vector<bool> m_pgStates{};
};

class FlexCounterOrch: public Orch
{
public:
Expand All @@ -42,10 +18,6 @@ class FlexCounterOrch: public Orch
virtual ~FlexCounterOrch(void);
bool getPortCountersState() const;
bool getPortBufferDropCountersState() const;
bool getPgWatermarkCountersState() const;
bool getQueueCountersState() const;
map<string, FlexCounterQueueStates> getQueueConfigurations();
map<string, FlexCounterPgStates> getPgConfigurations();
bool getHostIfTrapCounterState() const {return m_hostif_trap_counter_enabled;}
bool getRouteFlowCountersState() const {return m_route_flow_counter_enabled;}
bool bake() override;
Expand All @@ -55,13 +27,9 @@ class FlexCounterOrch: public Orch
std::shared_ptr<swss::ProducerTable> m_flexCounterGroupTable = nullptr;
bool m_port_counter_enabled = false;
bool m_port_buffer_drop_counter_enabled = false;
bool m_pg_watermark_enabled = false;
bool m_queue_enabled = false;
bool m_hostif_trap_counter_enabled = false;
bool m_route_flow_counter_enabled = false;
Table m_flexCounterConfigTable;
Table m_bufferQueueConfigTable;
Table m_bufferPgConfigTable;
};

#endif
Loading

0 comments on commit 27da1cb

Please sign in to comment.