Skip to content

Commit 3b31b36

Browse files
committed
Add support for syncd first run detection (sonic-net#20)
1 parent 52491ff commit 3b31b36

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

syncd/syncd.cpp

+52
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ swss::NotificationProducer *notifySyncdResponse = NULL;
77

88
std::map<std::string, std::string> gProfileMap;
99

10+
bool g_veryFirstRun = false;
11+
1012
void sai_diag_shell()
1113
{
1214
SWSS_LOG_ENTER();
@@ -872,6 +874,25 @@ void notifySyncd(swss::NotificationConsumer &consumer)
872874

873875
consumer.pop(op, data, values);
874876

877+
if (g_veryFirstRun)
878+
{
879+
SWSS_LOG_NOTICE("very first run is TRUE, op = %s", op.c_str());
880+
881+
// on the very first start of syncd, "compile" view is directly
882+
// applied on device, since it will make it easier to switch
883+
// to new asic state later on when we restart orch agent
884+
885+
if (op == NOTIFY_SAI_SWITCH_VIEW)
886+
{
887+
g_veryFirstRun = false;
888+
889+
SWSS_LOG_NOTICE("setting very first run to FALSE, op = %s", op.c_str());
890+
}
891+
892+
sendResponse(SAI_STATUS_SUCCESS);
893+
return;
894+
}
895+
875896
sai_status_t status = SAI_STATUS_FAILURE;
876897

877898
if (op == NOTIFY_SAI_INIT_VIEW)
@@ -1058,6 +1079,25 @@ bool handleRestartQuery(swss::NotificationConsumer &restartQuery)
10581079
return false;
10591080
}
10601081

1082+
bool isVeryFirstRun()
1083+
{
1084+
std::lock_guard<std::mutex> lock(g_mutex);
1085+
1086+
SWSS_LOG_ENTER();
1087+
1088+
// if lane map is not defined in redis db then
1089+
// we assume this is very first start of syncd
1090+
// later on we can add additional checks here
1091+
1092+
auto redisLaneMap = redisGetLaneMap();
1093+
1094+
bool firstRun = redisLaneMap.size() == 0;
1095+
1096+
SWSS_LOG_NOTICE("First Run: %s", firstRun ? "True" : "False");
1097+
1098+
return firstRun;
1099+
}
1100+
10611101
int main(int argc, char **argv)
10621102
{
10631103
swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_DEBUG);
@@ -1092,6 +1132,8 @@ int main(int argc, char **argv)
10921132
gProfileMap[SAI_KEY_INIT_CONFIG_FILE] = mlnx_config_file;
10931133
#endif /* MLNX_SAI */
10941134

1135+
g_veryFirstRun = isVeryFirstRun();
1136+
10951137
if (options.warmStart)
10961138
{
10971139
const char *warmBootReadFile = profile_get_value(0, SAI_KEY_WARM_BOOT_READ_FILE);
@@ -1106,6 +1148,16 @@ int main(int argc, char **argv)
11061148
}
11071149
}
11081150

1151+
if (options.warmStart && g_veryFirstRun)
1152+
{
1153+
SWSS_LOG_WARN("warm start requested, but this is very first syncd start, forcing cold start");
1154+
1155+
// we force cold start since if it's first run then redis db is not complete
1156+
// so redis asic view will not reflect warm boot asic state, if this happen
1157+
// then orch agent needs to be restarted as well to repopulate asic view
1158+
options.warmStart = false;
1159+
}
1160+
11091161
gProfileMap[SAI_KEY_WARM_BOOT] = options.warmStart ? "1" : "0";
11101162

11111163
sai_api_initialize(0, (service_method_table_t*)&test_services);

syncd/syncd.h

+2
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ void populate_sai_apis();
151151
void startCountersThread(int intervalInSeconds);
152152
void endCountersThread();
153153

154+
std::unordered_map<sai_uint32_t, sai_object_id_t> redisGetLaneMap();
155+
154156
std::vector<sai_object_id_t> saiGetPortList();
155157

156158
#endif // __SYNCD_H__

0 commit comments

Comments
 (0)