Skip to content

Commit

Permalink
Revert Process flex counters requests in separate thread (sonic-net#483
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored and lguohan committed Sep 3, 2019
1 parent 1d03c55 commit 5fc89b5
Showing 1 changed file with 6 additions and 88 deletions.
94 changes: 6 additions & 88 deletions syncd/syncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ std::shared_ptr<swss::RedisClient> g_redisClient;
std::shared_ptr<swss::ProducerTable> getResponse;
std::shared_ptr<swss::NotificationProducer> notifications;

std::shared_ptr<std::thread> g_processFlexCounterEventThread;
volatile bool g_processFlexCounterEventThreadRun = true;

/*
* TODO: Those are hard coded values for mlnx integration for v1.0.1 they need
* to be updated.
Expand Down Expand Up @@ -3002,62 +2999,6 @@ void processFlexCounterGroupEvent(
}
}

std::queue<swss::KeyOpFieldsValuesTuple> g_flexCounterEventQueue;

bool tryPopFlexCounterEvent(
_Out_ swss::KeyOpFieldsValuesTuple& kco)
{
SWSS_LOG_ENTER();

std::lock_guard<std::mutex> lock(g_mutex);

if (g_flexCounterEventQueue.empty())
{
return false;
}

kco = g_flexCounterEventQueue.front();

g_flexCounterEventQueue.pop();

return true;
}

void pushFlexCounterEvent(
_In_ const swss::KeyOpFieldsValuesTuple& kco)
{
SWSS_LOG_ENTER();

std::lock_guard<std::mutex> lock(g_mutex);

g_flexCounterEventQueue.push(kco);
}

bool processFlexCounterEvent(
_In_ const swss::KeyOpFieldsValuesTuple kco);

void processFlexCounterEventThread()
{
SWSS_LOG_ENTER();

while (g_processFlexCounterEventThreadRun)
{
swss::KeyOpFieldsValuesTuple kco;

if (tryPopFlexCounterEvent(kco))
{
if (!processFlexCounterEvent(kco))
{
// event was not successfully processed, put it again to the queue

pushFlexCounterEvent(kco);
}
}

sleep(1);
}
}

void processFlexCounterEvent(
_In_ swss::ConsumerTable &consumer)
{
Expand All @@ -3070,30 +3011,15 @@ void processFlexCounterEvent(
consumer.pop(kco);
}

// because flex counter event can arrive independently (on RIF interface)
// it may happen that it will be picked up from the select api before
// actual interface will be created, and subscription for counters will
// fail, so let's process each request in the thread and use queue for
// arriving events, and failed events will be put back to the queue until
// they will be processed

pushFlexCounterEvent(kco);
}

bool processFlexCounterEvent(
_In_ const swss::KeyOpFieldsValuesTuple kco)
{
SWSS_LOG_ENTER();

const auto &key = kfvKey(kco);
const std::string &op = kfvOp(kco);
std::string op = kfvOp(kco);

std::size_t delimiter = key.find_first_of(":");
if (delimiter == std::string::npos)
{
SWSS_LOG_ERROR("Failed to parse the key %s", key.c_str());

return true; // if key is invalid there is no need to process this event again
return; // if key is invalid there is no need to process this event again
}

const auto groupName = key.substr(0, delimiter);
Expand All @@ -3105,10 +3031,11 @@ bool processFlexCounterEvent(
{
std::lock_guard<std::mutex> lock(g_mutex);
if (!try_translate_vid_to_rid(vid, rid))
{
{
SWSS_LOG_WARN("port VID %s, was not found (probably port was removed/splitted) and will remove from counters now",
sai_serialize_object_id(vid).c_str());
return false;

op = DEL_COMMAND;
}
}

Expand Down Expand Up @@ -3255,7 +3182,7 @@ bool processFlexCounterEvent(
FlexCounter::setBufferPoolCounterList(vid, rid, groupName, bufferPoolCounterIds, statsMode);
}

return true;
return;
}

void printUsage()
Expand Down Expand Up @@ -3979,11 +3906,6 @@ int syncd_main(int argc, char **argv)

twd.setCallback(timerWatchdogCallback);

g_processFlexCounterEventThreadRun = true;

g_processFlexCounterEventThread = std::make_shared<std::thread>(processFlexCounterEventThread);


while(runMainLoop)
{
try
Expand Down Expand Up @@ -4167,10 +4089,6 @@ int syncd_main(int argc, char **argv)

#endif

g_processFlexCounterEventThreadRun = false;

g_processFlexCounterEventThread->join();

FlexCounter::removeAllCounters();

{
Expand Down

0 comments on commit 5fc89b5

Please sign in to comment.