Skip to content

Commit

Permalink
[flex_counter]: Check if plugin lists are empty (sonic-net#297)
Browse files Browse the repository at this point in the history
* [flex_counter]: Check if plugin lists are empty

Check plugin lists along with counter IDs lists
before trying to remove FC instance

* Rename isCounteMapsEmpty to isEmpty

Signed-off-by: marian-pritsak <marianp@mellanox.com>

* Fix comments

Signed-off-by: marian-pritsak <marianp@mellanox.com>
  • Loading branch information
marian-pritsak authored and lguohan committed Feb 21, 2018
1 parent fecd1b6 commit 077af8f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
40 changes: 22 additions & 18 deletions syncd/syncd_flex_counter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ void FlexCounter::setPortCounterList(
{
SWSS_LOG_ERROR("Port %s does not has supported counters", sai_serialize_object_id(portId).c_str());

// Remove flex counter if counter IDs map is empty
if (fc.isCounterMapsEmpty())
// Remove flex counter if all counter IDs and plugins are unregistered
if (fc.isEmpty())
{
removeInstance(instanceId);
}
Expand Down Expand Up @@ -124,8 +124,8 @@ void FlexCounter::setQueueCounterList(
{
SWSS_LOG_ERROR("Queue %s does not has supported counters", sai_serialize_object_id(queueId).c_str());

// Remove flex counter if counter IDs map is empty
if (fc.isCounterMapsEmpty())
// Remove flex counter if all counter IDs and plugins are unregistered
if (fc.isEmpty())
{
removeInstance(instanceId);
}
Expand All @@ -145,8 +145,8 @@ void FlexCounter::setQueueCounterList(
{
SWSS_LOG_ERROR("Queue %s can't provide the statistic", sai_serialize_object_id(queueId).c_str());

// Remove flex counter if counter IDs map is empty
if (fc.isCounterMapsEmpty())
// Remove flex counter if all counter IDs and plugins are unregistered
if (fc.isEmpty())
{
removeInstance(instanceId);
}
Expand Down Expand Up @@ -205,8 +205,8 @@ void FlexCounter::removePort(
if (it == fc.m_portCounterIdsMap.end())
{
SWSS_LOG_NOTICE("Trying to remove nonexisting port counter Ids 0x%lx", portVid);
// Remove flex counter if counter IDs map is empty
if (fc.isCounterMapsEmpty())
// Remove flex counter if all counter IDs and plugins are unregistered
if (fc.isEmpty())
{
removeInstance(instanceId);
}
Expand All @@ -215,8 +215,8 @@ void FlexCounter::removePort(

fc.m_portCounterIdsMap.erase(it);

// Remove flex counter if counter IDs map is empty
if (fc.isCounterMapsEmpty())
// Remove flex counter if all counter IDs and plugins are unregistered
if (fc.isEmpty())
{
removeInstance(instanceId);
}
Expand Down Expand Up @@ -251,8 +251,8 @@ void FlexCounter::removeQueue(
return;
}

// Remove flex counter if counter IDs map is empty
if (fc.isCounterMapsEmpty())
// Remove flex counter if all counter IDs and plugins are unregistered
if (fc.isEmpty())
{
removeInstance(instanceId);
}
Expand Down Expand Up @@ -305,8 +305,8 @@ void FlexCounter::removeCounterPlugin(
fc.m_queuePlugins.erase(sha);
fc.m_portPlugins.erase(sha);

// Remove flex counter if counter IDs maps are empty
if (fc.isCounterMapsEmpty() && fc.m_queuePlugins.empty() && fc.m_portPlugins.empty())
// Remove flex counter if all counter IDs and plugins are unregistered
if (fc.isEmpty())
{
removeInstance(instanceId);
}
Expand All @@ -322,8 +322,8 @@ void FlexCounter::removeCounterPlugin(
fc.m_queuePlugins.clear();
fc.m_portPlugins.clear();

// Remove flex counter if counter IDs maps are empty
if (fc.isCounterMapsEmpty() && fc.m_queuePlugins.empty() && fc.m_portPlugins.empty())
// Remove flex counter if all counter IDs and plugins are unregistered
if (fc.isEmpty())
{
removeInstance(instanceId);
}
Expand All @@ -337,11 +337,15 @@ FlexCounter::~FlexCounter(void)
endFlexCounterThread();
}

bool FlexCounter::isCounterMapsEmpty()
bool FlexCounter::isEmpty()
{
SWSS_LOG_ENTER();

return m_queueCounterIdsMap.empty() && m_portCounterIdsMap.empty() && m_queueAttrIdsMap.empty();
return m_queueCounterIdsMap.empty() &&
m_portCounterIdsMap.empty() &&
m_queueAttrIdsMap.empty() &&
m_queuePlugins.empty() &&
m_portPlugins.empty();
}

bool FlexCounter::isPortCounterSupported(sai_port_stat_t counter) const
Expand Down
2 changes: 1 addition & 1 deletion syncd/syncd_flex_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class FlexCounter
void saiUpdateSupportedQueueCounters(sai_object_id_t queueId, const std::vector<sai_queue_stat_t> &counterIds);
bool isPortCounterSupported(sai_port_stat_t counter) const;
bool isQueueCounterSupported(sai_queue_stat_t counter) const;
bool isCounterMapsEmpty();
bool isEmpty();

// Key is a Virtual ID
std::map<sai_object_id_t, std::shared_ptr<PortCounterIds>> m_portCounterIdsMap;
Expand Down

0 comments on commit 077af8f

Please sign in to comment.