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

selectabletimer: add mutex to start() and stop() #614

Merged
merged 3 commits into from
May 11, 2022

Conversation

ds952811
Copy link
Contributor

Add mutex protection to avoid having the timer expiration reset due to
subsequent calls of start()

Avoid having the timer expiration reset due to subsequent calls of start()

Add mutex protection to start() and stop()

Signed-off-by: Dante Su dante.su@broadcom.com

Add mutex protection to avoid having the timer expiration reset due to
subsequent calls of start()

Avoid having the timer expiration reset due to subsequent calls of start()

Add mutex protection to start() and stop()

Signed-off-by: Dante Su <dante.su@broadcom.com>
@adyeung
Copy link

adyeung commented May 5, 2022

@zhangyanzhao @yxieca @qiluo-msft pls help signoff and merge

@@ -21,6 +21,7 @@ SelectableTimer::SelectableTimer(const timespec& interval, int pri)
SWSS_LOG_THROW("failed to create timerfd, errno: %s", strerror(errno));
}
setInterval(interval);
m_alive = false;
Copy link
Contributor

@qiluo-msft qiluo-msft May 6, 2022

Choose a reason for hiding this comment

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

m_alive

better name m_running. #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

@@ -36,22 +37,40 @@ SelectableTimer::~SelectableTimer()

void SelectableTimer::start()
Copy link
Contributor

@qiluo-msft qiluo-msft May 6, 2022

Choose a reason for hiding this comment

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

start

Could you add new test case which will fail with original code? #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

Copy link
Contributor Author

@ds952811 ds952811 May 9, 2022

Choose a reason for hiding this comment

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

Please refer to timer_ut.cpp: line 43-51

Signed-off-by: Dante Su <dante.su@broadcom.com>
Signed-off-by: Dante Su <dante.su@broadcom.com>
@@ -653,42 +653,6 @@ TEST(DBConnector, selectableevent)
EXPECT_EQ(value, 2);
}

TEST(DBConnector, selectabletimer)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to timer_ut.cpp

ASSERT_EQ(result, Select::OBJECT);
ASSERT_EQ(sel, &timer);

// Check if the timer gets reset by subsequent timer.start()
Copy link
Contributor

Choose a reason for hiding this comment

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

Check if the timer gets reset by subsequent timer.start()

Could you help me understand what is the behavior of original code in this testcase? How does it fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the case of original code, since the timer is created with flag=0, a relative timer is started, and everytime that timer.start() gets invoked, timerfd_settime() will reset the timeout based on the current timestamp, hence it will cause unexpected delay here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mean original code will fail on this line?

ASSERT_EQ(result, Select::OBJECT);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it'll fail at that line without the changes in the PR

@qiluo-msft qiluo-msft merged commit a90b2b7 into sonic-net:master May 11, 2022
itamar-talmon pushed a commit to itamar-talmon/sonic-swss-common that referenced this pull request Jul 19, 2022
Add mutex protection to avoid having the timer expiration reset due to
subsequent calls of start()

Avoid having the timer expiration reset due to subsequent calls of start()

Add mutex protection to start() and stop()
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.

3 participants