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

Iox #337 deprecate posix timer #479

Merged

Conversation

nihalchari
Copy link

@nihalchari nihalchari commented Jan 5, 2021

Pre-Review Checklist for the PR Author

  1. Branch follows the naming format (iox-#123-this-is-a-branch)
  2. Commits messages are according to this guideline
    • Commit messages have the issue ID (iox-#123 commit text)
    • Commit messages are signed (git commit -s)
    • Commit author matches Eclipse Contributor Agreement (and ECA is signed)
  3. Update the PR title
    • Follow the same conventions as for commit messages
    • Link to the relevant issue
  4. Relevant issues are linked
  5. Add sensible notes for the reviewer
  6. All checks have passed
  7. Assign PR to reviewer

Notes for Reviewer

code contributed by @shankar-bosch

Checklist for the PR Reviewer

  • Commits are properly organized and messages are according to the guideline
  • Code according to our coding style and naming conventions
  • Unit tests have been written for new behavior
  • Public API changes are documented via doxygen
  • Copyright owner are updated in the changed files
  • PR title describes the changes

Post-review Checklist for the PR Author

  1. All open points are addressed and tracked via issues

Post-review Checklist for the Eclipse Committer

  1. All checkboxes in the PR checklist are checked or crossed out
  2. Merge

References

@shankar-in
Copy link
Contributor

This PR contains only the code related to the deadline use case. The Keep alive use case from @elBoberido will be adapted in the following PR.

@dkroenke dkroenke requested a review from elBoberido January 5, 2021 17:12
@elBoberido elBoberido requested a review from mossmaurice January 5, 2021 18:37
Comment on lines 328 to 345
class Timer
{
private:
iox::units::Duration m_measuringDuration;
iox::units::Duration m_startTime;

iox::units::Duration getCurrentMonotonicTime() noexcept;

public:
/// @brief Checks if the timer has expired compared to its start time
/// @return Is the elapsed time larger than duration set
bool hasTimerExpired() noexcept;

Timer(const iox::units::Duration) noexcept;

/// @brief reinitializes the starting time for the timer to the current time
void resetDurationTimer() noexcept;
};
Copy link
Member

Choose a reason for hiding this comment

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

could you move this to iceoryx_utils/cxx and rename it to DeadlineTimer. Other frameworks call it also this way, e.g. QDeadlineTimer. I think an additional namespace is not necessary.

@MatthiasKillat @mossmaurice @dkroenke what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I can rename this to deadline timer. The reason behind the new namespace introduction was the time calculations are based on the std::chrono and not using the POSIX apis.

Copy link
Contributor

Choose a reason for hiding this comment

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

DeadlineTimer is fine and reflects its functionality. The namespace cxx is ok for now, but we may need to differentiate between reimplementing STL (like) constructs and creating other useful helper classes in the long run. The DeadlineTimer would then belong into the second category.

Copy link
Member

Choose a reason for hiding this comment

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

@MatthiasKillat you have to think big. The STL has to add the stuff we put into the cxx namespace ;)

@dkroenke what do you think about moving this to cxx? It doesn't have any POSIX dependency anymore

iceoryx_utils/source/posix_wrapper/timer.cpp Outdated Show resolved Hide resolved
iceoryx_utils/source/posix_wrapper/timer.cpp Outdated Show resolved Hide resolved
iceoryx_utils/source/posix_wrapper/timer.cpp Outdated Show resolved Hide resolved
MatthiasKillat
MatthiasKillat previously approved these changes Jan 6, 2021
Copy link
Contributor

@MatthiasKillat MatthiasKillat left a comment

Choose a reason for hiding this comment

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

Looks OK functionally, only optional style remarks from my side.

iceoryx_utils/source/posix_wrapper/timer.cpp Outdated Show resolved Hide resolved
iceoryx_utils/source/posix_wrapper/timer.cpp Outdated Show resolved Hide resolved
iceoryx_utils/test/moduletests/test_posix_mutex.cpp Outdated Show resolved Hide resolved
@@ -321,6 +321,36 @@ class Timer
};

} // namespace posix

// IOX-#337 Alternate Timer to replace the POSIX timer
Copy link
Member

Choose a reason for hiding this comment

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

please make a /// @note of that

Copy link
Member

Choose a reason for hiding this comment

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

or maybe even better make an @brief with a small description. In one year nobody cares that this functionality was in POSIX Timer

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you make the class comment more descriptive ?
What does it mean to be a deadline timer ? How do I use it ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay added more descriptions for the class

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, this file should be renamed to deadline_timer.hpp

Copy link
Member

Choose a reason for hiding this comment

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

no, the functionality needs to be moved to a new file. This file will contain a new timer which just wraps a semaphore and does a blocking wait until it's either interrupted or timed out. It will be used in PeridoicTask, which in combination with the new timer provides the functionality of the execution of a callback from the old timer.
The semaphore might later on be replaced by a timer_create call, but instead of spawning a thread, it will just block, like the semaphore and if someone needs a separate thread, the PeriodicTask should be used.

@elBoberido
Copy link
Member

@shankar-bosch I just noticed that your commit messages are not according our [guidelines] (https://github.com/eclipse-iceoryx/iceoryx/blob/master/CONTRIBUTING.md)

@nihalchari wasn't the PR template shown when created the PR?

Copy link
Contributor

@orecham orecham left a comment

Choose a reason for hiding this comment

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

Logic is fine. Just need to rename the timer file & add class documentation.

@@ -321,6 +321,36 @@ class Timer
};

} // namespace posix

// IOX-#337 Alternate Timer to replace the POSIX timer
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you make the class comment more descriptive ?
What does it mean to be a deadline timer ? How do I use it ?

@@ -321,6 +321,36 @@ class Timer
};

} // namespace posix

// IOX-#337 Alternate Timer to replace the POSIX timer
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, this file should be renamed to deadline_timer.hpp

/// @brief Class which offers the deadline timer functionality
/// @note This class is introduced as an alternate timer functionality for the deprecated POSIX timers
///
/// @code
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice !

@shankar-in
Copy link
Contributor

@ithier I havent renamed the file because currently this PR still keeps the deprecated methods for posix timers. once this is tested and removed the file would be renamed and moved out of the posix wrappers.

@shankar-in
Copy link
Contributor

Working on the failing test.

Copy link
Member

@dkroenke dkroenke left a comment

Choose a reason for hiding this comment

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

please rework the RemainingTimeCheckIfNotExpired test


sut.reset(20_s);
std::this_thread::sleep_for(std::chrono::milliseconds(2 * TIMEOUT.milliSeconds<int>()));
EXPECT_THAT(sut.remainingTime(), Le(TIMEOUT));
Copy link
Member

Choose a reason for hiding this comment

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

This test will not work because you reset the timer with 20 Seconds and expect then a value lower or equal to 20 milliseconds after waiting 40 milliseconds. The logic is also incorrect because the test would also pass if no time has passed (Lower equal)

Proposal:

  1. create a timer and wait for a defined time
  2. get the remaining time
  3. check if the result is in a range ±10 percent from the expected value

You need to make a range because the test could flicker due to the non-deterministic Github CI.
For an example please take a look at TIMING_TEST_F(Timer_test, RestartWithDifferentTiming) in line 237 of this file.

Copy link
Member

@elBoberido elBoberido left a comment

Choose a reason for hiding this comment

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

could you also please remove the obsolete methods like hasExpiredComparedToCreationTime from the old timer class

@nihalchari
Copy link
Author

@shankar-bosch I just noticed that your commit messages are not according our [guidelines] (https://github.com/eclipse-iceoryx/iceoryx/blob/master/CONTRIBUTING.md)

@nihalchari wasn't the PR template shown when created the PR?

@elBoberido it was there.

@shankar-bosch could u please change this commit message "iox-337: initial commit for deadline impl " to "iox-#337 initial commit for deadline impl "
a7517f5

Also hyphen - used after issue no can be replaced with space in following commits
36cc71e
afef470

@shankar-in
Copy link
Contributor

could you also please remove the obsolete methods like hasExpiredComparedToCreationTime from the old timer class

I have 3 stories created for POSIX timer,

  1. part 1 : Introduce alternate timers for keepalive and deadline
  2. part 2 : Check that the already reported posix timer related problems are gone - [iox#243] Segmentation Fault in posix Timer & RouDi stalls when posix timer is used in activation dispatcher
  3. part 3 : full replacement of Posix Timer and Deletion from repo

Removing of the deprecated methods comes in part 3. where the timer will also be moved out of the posix wrapper package to a new class.

Is this okay?

@dkroenke
Copy link
Member

dkroenke commented Jan 8, 2021

I have 3 stories created for POSIX timer,
...
Removing of the deprecated methods comes in part 3. where the timer will also be moved out of the posix wrapper package to a new class.

Is this okay?

@shankar-bosch sounds like a plan, please add these three points to the issue #337 or ask @marthtz to do it, because he is the issue owner.

@shankar-in
Copy link
Contributor

I have 3 stories created for POSIX timer,
...
Removing of the deprecated methods comes in part 3. where the timer will also be moved out of the posix wrapper package to a new class.
Is this okay?

@shankar-bosch sounds like a plan, please add these three points to the issue #337 or ask @marthtz to do it, because he is the issue owner.

@dkroenke Yes discussed with @marthtz during our daily.

@elBoberido
Copy link
Member

could you also please remove the obsolete methods like hasExpiredComparedToCreationTime from the old timer class

I have 3 stories created for POSIX timer,

1. part 1 : Introduce alternate timers for keepalive and deadline

2. part 2 : Check that the already reported posix timer related problems are gone - [iox#243] Segmentation Fault in posix Timer & RouDi stalls when posix timer is used in activation dispatcher

3. part 3 : full replacement of Posix Timer and Deletion from repo

Removing of the deprecated methods comes in part 3. where the timer will also be moved out of the posix wrapper package to a new class.

Is this okay?

@shankar-bosch if this would be a big change I would agree, but since you already ported the code to the new class it doesn't make sense to keep the old code around and it's also not much to delete. I also object to merge this with the new class in the old file. It's not much work to move it to an own file and have it clean from the beginning.

If you plan t do bigger changes I always suggest to create one PR with only the new class and tests and another one with integration of the class and maybe removing of old code.

@shankar-in
Copy link
Contributor

shankar-in commented Jan 8, 2021

could you also please remove the obsolete methods like hasExpiredComparedToCreationTime from the old timer class

I have 3 stories created for POSIX timer,

1. part 1 : Introduce alternate timers for keepalive and deadline

2. part 2 : Check that the already reported posix timer related problems are gone - [iox#243] Segmentation Fault in posix Timer & RouDi stalls when posix timer is used in activation dispatcher

3. part 3 : full replacement of Posix Timer and Deletion from repo

Removing of the deprecated methods comes in part 3. where the timer will also be moved out of the posix wrapper package to a new class.
Is this okay?

@shankar-bosch if this would be a big change I would agree, but since you already ported the code to the new class it doesn't make sense to keep the old code around and it's also not much to delete. I also object to merge this with the new class in the old file. It's not much work to move it to an own file and have it clean from the beginning.

If you plan t do bigger changes I always suggest to create one PR with only the new class and tests and another one with integration of the class and maybe removing of old code.

@elBoberido
yes I agree. But we already have a plan so Can I check with team and @marthtz before i take up this activity?

@elBoberido
Copy link
Member

elBoberido commented Jan 8, 2021

@elBoberido
yes I agree. But we already have a plan so Can I check with team and @marthtz before i take up this activity?

@shankar-bosch sorry, but this is about getting clean code to master and it's not something that takes hours or days to accomplish. It's not additional functionality, just moving new code to a dedicated location and removing dead code.

Sorry if this sounds harsh. It's not intended.

@shankar-in
Copy link
Contributor

@elBoberido
yes I agree. But we already have a plan so Can I check with team and @marthtz before i take up this activity?

@shankar-bosch sorry, but this is about getting clean code to master and it's not something that takes hours or days to accomplish. It's not additional functionality, just moving new code to a dedicated location and removing dead code.

Sorry if this sounds harsh. It's not intended.

@elBoberido Not at all. I was informed that POSIX timers goes for 1.0 which is scheduled for March with low prio. It was planned by splitting in parts during the refinement and take up across sprints.
Sorry if I am arguing too much and not taking up this review point right away. As a team member I have to communicate when there is a deviation in plan and get their feedback too.
I had a chat with @marthtz he is okay with this and I will be taking up this activity in the same PR.

@elBoberido
Copy link
Member

@shankar-bosch so according to your plan this situation might last until march. That's one more reason not to merge this to master in the current form. This increases the technical dept for no good reason. What happens if you get assigned to another task or, hopefully not, get ill? Then this situation remains even longer.

Your PR is neither too big nor does is constantly get merge conflicts due to other PRs nor does it take long to accomplish the requested changes. Seriously, I don't understand the problem.

@shankar-in
Copy link
Contributor

@shankar-bosch so according to your plan this situation might last until march. That's one more reason not to merge this to master in the current form. This increases the technical dept for no good reason. What happens if you get assigned to another task or, hopefully not, get ill? Then this situation remains even longer.
Your PR is neither too big nor does is constantly get merge conflicts due to other PRs nor does it take long to accomplish the requested changes. Seriously, I don't understand the problem.

@elBoberido I dont have. I agree with your points completely. Spoke with the team already. I am working on this review point now. Sorry for any confusion caused.

mossmaurice
mossmaurice previously approved these changes Jan 15, 2021
iceoryx_posh/source/roudi/roudi_process.cpp Outdated Show resolved Hide resolved
@dkroenke dkroenke added the enhancement New feature label Jan 15, 2021
Signed-off-by: Sankara Narayanan Chandrasekar (RBEI/EMT2) <[email protected]>
@shankar-in shankar-in dismissed stale reviews from mossmaurice, dkroenke, and elBoberido via 4c801b3 January 16, 2021 10:00
elBoberido
elBoberido previously approved these changes Jan 16, 2021
@dkroenke dkroenke self-requested a review January 18, 2021 09:15
dkroenke
dkroenke previously approved these changes Jan 18, 2021
orecham
orecham previously approved these changes Jan 18, 2021
@nihalchari nihalchari requested a review from elfenpiff January 19, 2021 06:52
@shankar-in
Copy link
Contributor

Please sign off all commits!

@elfenpiff I have signed all my commits pls verify and approve this PR

Copy link
Contributor

@elfenpiff elfenpiff left a comment

Choose a reason for hiding this comment

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

Could you please add some additional test cases.

const Duration DeadlineTimer_test::TIMEOUT{10_ms};
const int DeadlineTimer_test::SLEEPTIME = DeadlineTimer_test::TIMEOUT.milliSeconds<int>();

TIMING_TEST_F(DeadlineTimer_test, DurationOfNonZeroIsExpiresAfterTimeout, Repeat(5), [&] {
Copy link
Contributor

Choose a reason for hiding this comment

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

What if the Deadline timer has a timeout of zero? Is the Callback then called as fast as possible? We should also always keep the following test ideas in mind:

  • Zero
  • One
  • Many
  • Corner Cases
  • Limits

to cover every aspect of a class.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is only the deadline timer use case. in case if the timer has a duration set to zero the end time will be the current time and the timer will be already expired. I can add a test case for this.

TIMING_TEST_EXPECT_FALSE(sut.hasExpired());
});

TIMING_TEST_F(DeadlineTimer_test, ResetWithCustomizedTimeAfterBeingExpiredIsNotExpired, Repeat(5), [&] {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please write the same test for the case when the time is not being expired.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay

});


TIMING_TEST_F(DeadlineTimer_test, RemainingTimeCheckIfNotExpired, Repeat(5), [&] {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please write a test where you verify that the remaining time is zero when the timer is expired.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay

Signed-off-by: Sankara Narayanan Chandrasekar (RBEI/EMT2) <[email protected]>
@shankar-in shankar-in dismissed stale reviews from orecham, dkroenke, and elBoberido via c4c6c06 January 20, 2021 17:09
…ine timer

Signed-off-by: Sankara Narayanan Chandrasekar (RBEI/EMT2) <[email protected]>
elBoberido
elBoberido previously approved these changes Jan 20, 2021
const int EXPECTED_REMAINING_TIME = PASSED_TIMER_TIME - RANGE_APPROX;

TIMING_TEST_EXPECT_TRUE(remainingTime >= EXPECTED_REMAINING_TIME && remainingTime <= PASSED_TIMER_TIME);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing newline at end of file?

Copy link
Contributor

Choose a reason for hiding this comment

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

Added a new line to the end of file

Signed-off-by: Sankara Narayanan Chandrasekar (RBEI/EMT2) <[email protected]>
@shankar-in
Copy link
Contributor

@elfenpiff Could you pls check whether your review comments are addressed and approve if you are okay with the changes?

Copy link
Contributor

@elfenpiff elfenpiff left a comment

Choose a reason for hiding this comment

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

@shankar-in Thank you for the good work.

@elBoberido elBoberido merged commit b3ae7a4 into eclipse-iceoryx:master Jan 27, 2021
@shankar-in
Copy link
Contributor

@elBoberido Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deprecate posix timer
10 participants