Skip to content

Commit 9ce76e7

Browse files
marian-pritsakShu0T1an ChenG
authored and
Shu0T1an ChenG
committed
[pfcwd]: Initial support PFC watchdog (sonic-net#227)
* [syncd]: Use COUNTERS_TABLE in PFC WD * [syncd][PFCWD]: Set polling interval to 50 ms * [tests][Makefile.am]: Add PFC WD sources Signed-off-by: marian-pritsak <[email protected]>
1 parent 79bd891 commit 9ce76e7

8 files changed

+438
-10
lines changed

meta/saiserialize.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,14 @@ std::string sai_serialize_port_stat(
708708
return sai_serialize_enum(counter, &sai_metadata_enum_sai_port_stat_t);
709709
}
710710

711+
std::string sai_serialize_queue_stat(
712+
_In_ const sai_queue_stat_t counter)
713+
{
714+
SWSS_LOG_ENTER();
715+
716+
return sai_serialize_enum(counter, &sai_metadata_enum_sai_queue_stat_t);
717+
}
718+
711719
std::string sai_serialize_switch_oper_status(
712720
_In_ sai_object_id_t switch_id,
713721
_In_ sai_switch_oper_status_t status)
@@ -2701,3 +2709,22 @@ void sai_deserialize_free_port_oper_status_ntf(
27012709

27022710
delete port_oper_status;
27032711
}
2712+
2713+
void sai_deserialize_port_stat(
2714+
_In_ const std::string& s,
2715+
_Out_ sai_port_stat_t& stat)
2716+
{
2717+
SWSS_LOG_ENTER();
2718+
2719+
sai_deserialize_enum(s, &sai_metadata_enum_sai_port_stat_t, (int32_t&)stat);
2720+
}
2721+
2722+
void sai_deserialize_queue_stat(
2723+
_In_ const std::string& s,
2724+
_Out_ sai_queue_stat_t& stat)
2725+
{
2726+
SWSS_LOG_ENTER();
2727+
2728+
sai_deserialize_enum(s, &sai_metadata_enum_sai_queue_stat_t, (int32_t&)stat);
2729+
}
2730+

meta/saiserialize.h

+11
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ std::string sai_serialize_common_api(
7272
std::string sai_serialize_port_stat(
7373
_In_ const sai_port_stat_t counter);
7474

75+
std::string sai_serialize_queue_stat(
76+
_In_ const sai_queue_stat_t counter);
77+
7578
std::string sai_serialize_switch_oper_status(
7679
_In_ sai_object_id_t switch_id,
7780
_In_ sai_switch_oper_status_t status);
@@ -196,4 +199,12 @@ void sai_deserialize_free_port_oper_status_ntf(
196199
_In_ uint32_t count,
197200
_In_ sai_port_oper_status_notification_t* portoperstatus);
198201

202+
void sai_deserialize_port_stat(
203+
_In_ const std::string& s,
204+
_Out_ sai_port_stat_t& stat);
205+
206+
void sai_deserialize_queue_stat(
207+
_In_ const std::string& s,
208+
_Out_ sai_queue_stat_t& stat);
209+
199210
#endif // __SAI_SERIALIZE__

syncd/Makefile.am

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ syncd_SOURCES = \
2020
syncd_hard_reinit.cpp \
2121
syncd_notifications.cpp \
2222
syncd_counters.cpp \
23-
syncd_applyview.cpp
23+
syncd_applyview.cpp \
24+
syncd_pfc_watchdog.cpp
2425

2526
syncd_CPPFLAGS = $(DBGFLAGS) $(AM_CPPFLAGS) $(CFLAGS_COMMON) $(SAIFLAGS)
2627
syncd_LDADD = -lhiredis -lswsscommon $(SAILIB) -lpthread -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -ldl

syncd/syncd.cpp

+70-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "syncd.h"
22
#include "syncd_saiswitch.h"
33
#include "sairedis.h"
4+
#include "syncd_pfc_watchdog.h"
45
#include "swss/tokenize.h"
56
#include <limits.h>
67

@@ -2330,6 +2331,62 @@ sai_status_t processEvent(
23302331
return status;
23312332
}
23322333

2334+
void processPfcWdEvent(
2335+
_In_ swss::ConsumerStateTable &consumer)
2336+
{
2337+
std::lock_guard<std::mutex> lock(g_mutex);
2338+
2339+
SWSS_LOG_ENTER();
2340+
2341+
swss::KeyOpFieldsValuesTuple kco;
2342+
consumer.pop(kco);
2343+
2344+
const auto &key = kfvKey(kco);
2345+
const auto &op = kfvOp(kco);
2346+
2347+
sai_object_id_t queueVid = SAI_NULL_OBJECT_ID;
2348+
sai_deserialize_object_id(key, queueVid);
2349+
sai_object_id_t queueId = translate_vid_to_rid(queueVid);
2350+
2351+
const auto values = kfvFieldsValues(kco);
2352+
for (const auto& valuePair : values)
2353+
{
2354+
const auto field = fvField(valuePair);
2355+
const auto value = fvValue(valuePair);
2356+
2357+
if (op == DEL_COMMAND)
2358+
{
2359+
PfcWatchdog::removeQueue(queueVid);
2360+
continue;
2361+
}
2362+
2363+
auto idStrings = swss::tokenize(value, ',');
2364+
2365+
if (field == PFC_WD_PORT_COUNTER_ID_LIST)
2366+
{
2367+
std::vector<sai_port_stat_t> portCounterIds;
2368+
for (const auto &str : idStrings)
2369+
{
2370+
sai_port_stat_t stat;
2371+
sai_deserialize_port_stat(str, stat);
2372+
portCounterIds.push_back(stat);
2373+
}
2374+
PfcWatchdog::setPortCounterList(queueVid, queueId, portCounterIds);
2375+
}
2376+
else if (field == PFC_WD_QUEUE_COUNTER_ID_LIST)
2377+
{
2378+
std::vector<sai_queue_stat_t> queueCounterIds;
2379+
for (const auto &str : idStrings)
2380+
{
2381+
sai_queue_stat_t stat;
2382+
sai_deserialize_queue_stat(str, stat);
2383+
queueCounterIds.push_back(stat);
2384+
}
2385+
PfcWatchdog::setQueueCounterList(queueVid, queueId, queueCounterIds);
2386+
}
2387+
}
2388+
}
2389+
23332390
void printUsage()
23342391
{
23352392
std::cout << "Usage: syncd [-N] [-d] [-p profile] [-i interval] [-t [cold|warm|fast]] [-h] [-u] [-S]" << std::endl;
@@ -2901,21 +2958,23 @@ int main(int argc, char **argv)
29012958
}
29022959
#endif // SAITHRIFT
29032960

2904-
std::shared_ptr<swss::DBConnector> db = std::make_shared<swss::DBConnector>(ASIC_DB, swss::DBConnector::DEFAULT_UNIXSOCKET, 0);
2961+
std::shared_ptr<swss::DBConnector> dbAsic = std::make_shared<swss::DBConnector>(ASIC_DB, swss::DBConnector::DEFAULT_UNIXSOCKET, 0);
29052962
std::shared_ptr<swss::DBConnector> dbNtf = std::make_shared<swss::DBConnector>(ASIC_DB, swss::DBConnector::DEFAULT_UNIXSOCKET, 0);
2963+
std::shared_ptr<swss::DBConnector> dbPfcWatchdog = std::make_shared<swss::DBConnector>(PFC_WD_DB, swss::DBConnector::DEFAULT_UNIXSOCKET, 0);
29062964

2907-
g_redisClient = std::make_shared<swss::RedisClient>(db.get());
2965+
g_redisClient = std::make_shared<swss::RedisClient>(dbAsic.get());
29082966

2909-
std::shared_ptr<swss::ConsumerTable> asicState = std::make_shared<swss::ConsumerTable>(db.get(), ASIC_STATE_TABLE);
2910-
std::shared_ptr<swss::NotificationConsumer> restartQuery = std::make_shared<swss::NotificationConsumer>(db.get(), "RESTARTQUERY");
2967+
std::shared_ptr<swss::ConsumerTable> asicState = std::make_shared<swss::ConsumerTable>(dbAsic.get(), ASIC_STATE_TABLE);
2968+
std::shared_ptr<swss::NotificationConsumer> restartQuery = std::make_shared<swss::NotificationConsumer>(dbAsic.get(), "RESTARTQUERY");
2969+
std::shared_ptr<swss::ConsumerStateTable> pfcWdState = std::make_shared<swss::ConsumerStateTable>(dbPfcWatchdog.get(), PFC_WD_STATE_TABLE);
29112970

29122971
/*
29132972
* At the end we cant use producer consumer concept since if one proces
29142973
* will restart there may be something in the queue also "remove" from
29152974
* response queue will also trigger another "response".
29162975
*/
29172976

2918-
getResponse = std::make_shared<swss::ProducerTable>(db.get(), "GETRESPONSE");
2977+
getResponse = std::make_shared<swss::ProducerTable>(dbAsic.get(), "GETRESPONSE");
29192978
notifications = std::make_shared<swss::NotificationProducer>(dbNtf.get(), "NOTIFICATIONS");
29202979

29212980
g_veryFirstRun = isVeryFirstRun();
@@ -3003,6 +3062,7 @@ int main(int argc, char **argv)
30033062

30043063
s.addSelectable(asicState.get());
30053064
s.addSelectable(restartQuery.get());
3065+
s.addSelectable(pfcWdState.get());
30063066

30073067
SWSS_LOG_NOTICE("starting main loop");
30083068

@@ -3027,8 +3087,11 @@ int main(int argc, char **argv)
30273087
warmRestartHint = handleRestartQuery(*restartQuery);
30283088
break;
30293089
}
3030-
3031-
if (result == swss::Select::OBJECT)
3090+
else if (sel == pfcWdState.get())
3091+
{
3092+
processPfcWdEvent(*(swss::ConsumerStateTable*)sel);
3093+
}
3094+
else if (result == swss::Select::OBJECT)
30323095
{
30333096
processEvent(*(swss::ConsumerTable*)sel);
30343097
}

syncd/syncd.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ extern "C" {
3131
#include "swss/dbconnector.h"
3232
#include "swss/producertable.h"
3333
#include "swss/consumertable.h"
34+
#include "swss/consumerstatetable.h"
3435
#include "swss/notificationconsumer.h"
3536
#include "swss/notificationproducer.h"
3637
#include "swss/selectableevent.h"
@@ -100,7 +101,6 @@ void startCountersThread(
100101
_In_ int intervalInSeconds);
101102

102103
sai_status_t syncdApplyView();
103-
104104
void check_notifications_pointers(
105105
_In_ uint32_t attr_count,
106106
_In_ sai_attribute_t *attr_list);

0 commit comments

Comments
 (0)