Skip to content

Fix sai api loglevel #365

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

Merged
merged 7 commits into from
Jul 22, 2020
Merged

Fix sai api loglevel #365

merged 7 commits into from
Jul 22, 2020

Conversation

shi-su
Copy link
Contributor

@shi-su shi-su commented Jul 17, 2020

  • Why I did it
    This PR contains the code changes to fix the SAI API log level issue "swssloglevel -l SAI_LOG_LEVEL_ERROR -s -c switch" or any SAI API component no longer works in Master branch #366

  • Why this issue happens
    In the initialization of syncd, the main function first calls linkToDbNative function to initialize the log level for syncd. Then the log levels for SAI APIs are initialized using linkToDb. Since the settingThread of logger is set up by linkToDbNative function and the ConsumerStateTables are set up only in the initialization of the thread, the SAI API log levels in only added to m_settingChangeObservers, whereas the corresponding ConsumerStateTables are not created. Therefore, the SAI API log levels are not successfully initialized.

  • How I did it
    Instead of creating ConsumerStateTables at the initialization of settingThread, I create ConsumerStateTables in the execution loop of the thread. Such a change fixes the issue by allowing to create the corresponding ConsumerStateTables when there are new items added to m_settingChangeObservers.

  • How to verify it
    Verify all SAI API log levels are correctly initialized and can be modified in vs tests. A unit test is also added to simulate the scenario and verify the log levels can be properly handled.

shi-su and others added 2 commits July 17, 2020 12:27
Add support for attribute capability query in lua script (sonic-net#362)
@qiluo-msft
Copy link
Contributor

qiluo-msft commented Jul 18, 2020

@gechiang Could you help test this PR? #Closed

{
for (const auto& i : m_settingChangeObservers)
{
if(selectableKeys.find(i.first) == selectableKeys.end())
Copy link
Contributor

@qiluo-msft qiluo-msft Jul 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i.first [](start = 39, length = 7)

i.first is used multiple times. Could you give it a name to improve readability? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

{
if(selectableKeys.find(i.first) == selectableKeys.end())
{
std::shared_ptr<ConsumerStateTable> table = std::make_shared<ConsumerStateTable>(&db, i.first);
Copy link
Contributor

@qiluo-msft qiluo-msft Jul 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::shared_ptr [](start = 20, length = 35)

auto #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@lguohan
Copy link
Contributor

lguohan commented Jul 18, 2020

@shi-su, can you provide more detail description of the pr? what is the bug, how the bug is fixed.

{
for (const auto& i : m_settingChangeObservers)
{
if(selectableKeys.find(i.first) == selectableKeys.end())
Copy link
Contributor

@qiluo-msft qiluo-msft Jul 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

selectableKeys [](start = 19, length = 14)

You can insert and check return value. No need to find beforehand. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the vector selectables and the set selectableKeys in now combined as a map, inserting into the map requires a pointer to a consumerStateTable. In such a case, I think it might be better to find before creating the consumerStateTable.

{
std::shared_ptr<ConsumerStateTable> table = std::make_shared<ConsumerStateTable>(&db, i.first);
selectableKeys.insert(i.first);
selectables.push_back(table);
Copy link
Contributor

@qiluo-msft qiluo-msft Jul 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

push_back [](start = 32, length = 9)

emplace_back? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It now becomes inserting into a map.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to emplace.

select.addSelectable(table.get());
}
std::vector<std::shared_ptr<ConsumerStateTable>> selectables;
std::set<std::string> selectableKeys;

while(true)
Copy link
Contributor

@qiluo-msft qiluo-msft Jul 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while(true) [](start = 4, length = 11)

Add one blank after while #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank added.

@gechiang
Copy link

gechiang commented Jul 18, 2020

@gechiang Could you help test this PR?

sure I will help test this out
Is there a buildimage that I can find to load this to my DUT?

select.addSelectable(table.get());
}
std::vector<std::shared_ptr<ConsumerStateTable>> selectables;
std::set<std::string> selectableKeys;
Copy link
Contributor

@qiluo-msft qiluo-msft Jul 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems selectables is only used to manage memory. You may use a map instead of vector + set. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed as prescribed.

Selectable *selectable = nullptr;

int ret = select.select(&selectable);
int ret = select.select(&selectable, 1000);
Copy link
Contributor

@qiluo-msft qiluo-msft Jul 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1000 [](start = 45, length = 4)

Add comment about constant unit. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Selectable *selectable = nullptr;

int ret = select.select(&selectable);
int ret = select.select(&selectable, 1000);
Copy link
Contributor

@qiluo-msft qiluo-msft Jul 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

select [](start = 25, length = 6)

Add a unit test case to simulate the fixed bug. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A unit test is added.

Copy link
Contributor

@qiluo-msft qiluo-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As comments


if (ret == Select::ERROR)
{
SWSS_LOG_NOTICE("%s select error %s", __PRETTY_FUNCTION__, strerror(errno));
continue;
}

if (ret == Select::TIMEOUT)
{
continue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is not intended to happen, please add log line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since a timeout is added to select selectables, the timeout is actually intended. I added an info level log to the timeout.

@gechiang
Copy link

@gechiang Could you help test this PR?

sure I will help test this out
Is there a buildimage that I can find to load this to my DUT?

I have tested this change and find it resolved the issue I raised. I was able to set the levels of all the SAI component via the "-a" option as well as individual SAI component via the "-c" option. Fix looks good.
Thanks!

@shi-su shi-su requested a review from qiluo-msft July 20, 2020 17:26
{
for (const auto& i : m_settingChangeObservers)
{
std::string dbName = i.first;
Copy link
Contributor

@qiluo-msft qiluo-msft Jul 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::string [](start = 16, length = 11)

const std::string& or const auto& #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@lguohan lguohan merged commit ed9c497 into sonic-net:master Jul 22, 2020
@lguohan
Copy link
Contributor

lguohan commented Jul 22, 2020

@shi-su, can you updat the submodule pointer on sonic-buildimage?

prgeor pushed a commit to prgeor/sonic-swss-common that referenced this pull request Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"swssloglevel -l SAI_LOG_LEVEL_ERROR -s -c switch" or any SAI API component no longer works in Master branch
5 participants