Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for syncd first run detection #20

Merged
merged 1 commit into from
May 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions syncd/syncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ swss::NotificationProducer *notifySyncdResponse = NULL;

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

bool g_veryFirstRun = false;

void sai_diag_shell()
{
SWSS_LOG_ENTER();
Expand Down Expand Up @@ -872,6 +874,25 @@ void notifySyncd(swss::NotificationConsumer &consumer)

consumer.pop(op, data, values);

if (g_veryFirstRun)
{
SWSS_LOG_NOTICE("very first run is TRUE, op = %s", op.c_str());

// on the very first start of syncd, "compile" view is directly
// applied on device, since it will make it easier to switch
// to new asic state later on when we restart orch agent

if (op == NOTIFY_SAI_SWITCH_VIEW)
{
g_veryFirstRun = false;

SWSS_LOG_NOTICE("setting very first run to FALSE, op = %s", op.c_str());
}

sendResponse(SAI_STATUS_SUCCESS);
return;
}

sai_status_t status = SAI_STATUS_FAILURE;

if (op == NOTIFY_SAI_COMPILE_VIEW)
Expand Down Expand Up @@ -1058,6 +1079,25 @@ bool handleRestartQuery(swss::NotificationConsumer &restartQuery)
return false;
}

bool isVeryFirstRun()
{
std::lock_guard<std::mutex> lock(g_mutex);

SWSS_LOG_ENTER();

// if lane map is not defined in redis db then
// we assume this is very first start of syncd
// later on we can add additional checks here

auto redisLaneMap = redisGetLaneMap();

bool firstRun = redisLaneMap.size() == 0;

SWSS_LOG_NOTICE("First Run: %s", firstRun ? "True" : "False");

return firstRun;
}

int main(int argc, char **argv)
{
swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_DEBUG);
Expand Down Expand Up @@ -1092,6 +1132,8 @@ int main(int argc, char **argv)
gProfileMap[SAI_KEY_INIT_CONFIG_FILE] = mlnx_config_file;
#endif /* MLNX_SAI */

g_veryFirstRun = isVeryFirstRun();

if (options.warmStart)
{
const char *warmBootReadFile = profile_get_value(0, SAI_KEY_WARM_BOOT_READ_FILE);
Expand All @@ -1106,6 +1148,16 @@ int main(int argc, char **argv)
}
}

if (options.warmStart && g_veryFirstRun)
{
SWSS_LOG_WARN("warm start requested, but this is very first syncd start, forcing cold start");

// we force cold start since if it's first run then redis db is not complete
// so redis asic view will not reflect warm boot asic state, if this happen
// then orch agent needs to be restarted as well to repopulate asic view
options.warmStart = false;
}

gProfileMap[SAI_KEY_WARM_BOOT] = options.warmStart ? "1" : "0";

sai_api_initialize(0, (service_method_table_t*)&test_services);
Expand Down
2 changes: 2 additions & 0 deletions syncd/syncd.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ void populate_sai_apis();
void startCountersThread(int intervalInSeconds);
void endCountersThread();

std::unordered_map<sai_uint32_t, sai_object_id_t> redisGetLaneMap();

std::vector<sai_object_id_t> saiGetPortList();

#endif // __SYNCD_H__