Skip to content

Commit

Permalink
Do not poll counters on priority groups with zero buffer profile as well
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Sun <stephens@nvidia.com>
  • Loading branch information
stephenxs committed Nov 8, 2024
1 parent ffeb85e commit 01cfd59
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 26 deletions.
55 changes: 33 additions & 22 deletions orchagent/bufferorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,25 @@ const object_reference_map &BufferOrch::getBufferPoolNameOidMap(void)
return *m_buffer_type_maps[APP_BUFFER_POOL_TABLE_NAME];
}

void BufferOrch::getBufferObjectsWithNonZeroProfile(vector<string> &nonZeroQueues, const string &table)
{
for (auto &&queueRef: (*m_buffer_type_maps[table]))
{
for (auto &&profileRef: queueRef.second.m_objsReferencingByMe)
{
if (profileRef.second.find("_zero_") == std::string::npos)
{
SWSS_LOG_INFO("Selected key %s with profile %s", queueRef.first.c_str(), profileRef.second.c_str());
nonZeroQueues.push_back(queueRef.first);
}
else
{
SWSS_LOG_INFO("Skipped key %s with profile %s", queueRef.first.c_str(), profileRef.second.c_str());
}
}
}
}

task_process_status BufferOrch::processBufferPool(KeyOpFieldsValuesTuple &tuple)
{
SWSS_LOG_ENTER();
Expand Down Expand Up @@ -1055,25 +1074,6 @@ task_process_status BufferOrch::processQueue(KeyOpFieldsValuesTuple &tuple)
return task_process_status::task_success;
}

void BufferOrch::getNonZeroQueues(vector<string> &nonZeroQueues)
{
for (auto &&queueRef: (*m_buffer_type_maps[APP_BUFFER_QUEUE_TABLE_NAME]))
{
for (auto &&profileRef: queueRef.second.m_objsReferencingByMe)
{
if (profileRef.second.find("_zero_") == std::string::npos)
{
SWSS_LOG_INFO("Selected key %s with profile %s", queueRef.first.c_str(), profileRef.second.c_str());
nonZeroQueues.push_back(queueRef.first);
}
else
{
SWSS_LOG_INFO("Skipped key %s with profile %s", queueRef.first.c_str(), profileRef.second.c_str());
}
}
}
}

/*
Input sample "BUFFER_PG|Ethernet4,Ethernet45|10-15"
*/
Expand All @@ -1087,6 +1087,9 @@ task_process_status BufferOrch::processPriorityGroup(KeyOpFieldsValuesTuple &tup
vector<string> tokens;
sai_uint32_t range_low, range_high;
bool need_update_sai = true;
bool counter_was_added = false;
bool counter_needs_to_add = false;
string old_buffer_profile_name;

SWSS_LOG_DEBUG("processing:%s", key.c_str());
tokens = tokenize(key, delimiter);
Expand Down Expand Up @@ -1119,7 +1122,6 @@ task_process_status BufferOrch::processPriorityGroup(KeyOpFieldsValuesTuple &tup
return task_process_status::task_failed;
}

string old_buffer_profile_name;
if (doesObjectExist(m_buffer_type_maps, APP_BUFFER_PG_TABLE_NAME, key, buffer_profile_field_name, old_buffer_profile_name)
&& (old_buffer_profile_name == buffer_profile_name))
{
Expand All @@ -1130,6 +1132,10 @@ task_process_status BufferOrch::processPriorityGroup(KeyOpFieldsValuesTuple &tup
SWSS_LOG_NOTICE("Set buffer PG %s to %s", key.c_str(), buffer_profile_name.c_str());

setObjectReference(m_buffer_type_maps, APP_BUFFER_PG_TABLE_NAME, key, buffer_profile_field_name, buffer_profile_name);

// Counter operation
counter_needs_to_add = buffer_profile_name.find("_zero_") == std::string::npos;
SWSS_LOG_INFO("%s to create counter for priority group %s with new profile %s", counter_needs_to_add ? "Need" : "No need", key.c_str(), buffer_profile_name.c_str());
}
else if (op == DEL_COMMAND)
{
Expand All @@ -1149,6 +1155,9 @@ task_process_status BufferOrch::processPriorityGroup(KeyOpFieldsValuesTuple &tup
return task_process_status::task_invalid_entry;
}

counter_was_added = !old_buffer_profile_name.empty() && old_buffer_profile_name.find("_zero_") == std::string::npos;
SWSS_LOG_INFO("%s to remove counter for priority group %s with old profile %s", counter_was_added ? "Need" : "No need", key.c_str(), old_buffer_profile_name.c_str());

sai_attribute_t attr;
attr.id = SAI_INGRESS_PRIORITY_GROUP_ATTR_BUFFER_PROFILE;
attr.value.oid = sai_buffer_profile;
Expand Down Expand Up @@ -1191,14 +1200,16 @@ task_process_status BufferOrch::processPriorityGroup(KeyOpFieldsValuesTuple &tup
{
auto flexCounterOrch = gDirectory.get<FlexCounterOrch*>();
auto pgs = tokens[1];
if (op == SET_COMMAND &&
if (!counter_was_added && counter_needs_to_add &&
(flexCounterOrch->getPgCountersState() || flexCounterOrch->getPgWatermarkCountersState()))
{
SWSS_LOG_INFO("Creating counters for priority group %s %lu", port_name.c_str(), ind);
gPortsOrch->createPortBufferPgCounters(port, pgs);
}
else if (op == DEL_COMMAND &&
else if (counter_was_added && !counter_needs_to_add &&
(flexCounterOrch->getPgCountersState() || flexCounterOrch->getPgWatermarkCountersState()))
{
SWSS_LOG_INFO("Removing counters for priority group %s %lu", port_name.c_str(), ind);
gPortsOrch->removePortBufferPgCounters(port, pgs);
}
}
Expand Down
2 changes: 1 addition & 1 deletion orchagent/bufferorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class BufferOrch : public Orch
static type_map m_buffer_type_maps;
void generateBufferPoolWatermarkCounterIdList(void);
const object_reference_map &getBufferPoolNameOidMap(void);
void getNonZeroQueues(std::vector<std::string> &nonZeroQueues);
void getBufferObjectsWithNonZeroProfile(vector<string> &nonZeroQueues, const string &table);

private:
typedef task_process_status (BufferOrch::*buffer_table_handler)(KeyOpFieldsValuesTuple &tuple);
Expand Down
6 changes: 3 additions & 3 deletions orchagent/flexcounterorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ map<string, FlexCounterQueueStates> FlexCounterOrch::getQueueConfigurations()
}

std::vector<std::string> portQueueKeys;
gBufferOrch->getNonZeroQueues(portQueueKeys);
gBufferOrch->getBufferObjectsWithNonZeroProfile(portQueueKeys, APP_BUFFER_QUEUE_TABLE_NAME);

for (const auto& portQueueKey : portQueueKeys)
{
Expand Down Expand Up @@ -432,11 +432,11 @@ map<string, FlexCounterPgStates> FlexCounterOrch::getPgConfigurations()
}

std::vector<std::string> portPgKeys;
m_bufferPgConfigTable.getKeys(portPgKeys);
gBufferOrch->getBufferObjectsWithNonZeroProfile(portPgKeys, APP_BUFFER_PG_TABLE_NAME);

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

0 comments on commit 01cfd59

Please sign in to comment.