Skip to content

[#139] events with bitset #167

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 27 commits into from
Apr 9, 2024

Conversation

elfenpiff
Copy link
Contributor

@elfenpiff elfenpiff commented Apr 4, 2024

Notes for Reviewer

Pre-Review Checklist for the PR Author

  1. Add sensible notes for the reviewer
  2. PR title is short, expressive and meaningful
  3. Relevant issues are linked in the References section
  4. Every source code file has a copyright header with SPDX-License-Identifier: Apache-2.0 OR MIT
  5. Branch follows the naming format (iox2-123-introduce-posix-ipc-example)
  6. Commits messages are according to this guideline
  7. Tests follow the best practice for testing
  8. Changelog updated in the unreleased section including API breaking changes
  9. Assign PR to reviewer
  10. All checks have passed (except task-list-completed)

Checklist for the PR Reviewer

  • Commits are properly organized and messages are according to the guideline
  • Unit tests have been written for new behavior
  • Public API is documented
  • PR title describes the changes

Post-review Checklist for the PR Author

  1. All open points are addressed and tracked via issues

References

Relates to #139

@elfenpiff elfenpiff requested a review from elBoberido April 4, 2024 14:39
@elfenpiff elfenpiff self-assigned this Apr 4, 2024
Copy link

codecov bot commented Apr 4, 2024

Codecov Report

Attention: Patch coverage is 81.74098% with 86 lines in your changes are missing coverage. Please review.

Project coverage is 78.22%. Comparing base (b7f04eb) to head (b426ca7).
Report is 7 commits behind head on main.

❗ Current head b426ca7 differs from pull request most recent head 9ca036a. Consider uploading reports for the commit 9ca036a to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #167      +/-   ##
==========================================
+ Coverage   78.00%   78.22%   +0.21%     
==========================================
  Files         179      181       +2     
  Lines       19363    19749     +386     
==========================================
+ Hits        15105    15448     +343     
- Misses       4258     4301      +43     
Files Coverage Δ
iceoryx2-bb/posix/src/semaphore.rs 77.02% <100.00%> (ø)
iceoryx2-bb/threadsafe/src/trigger_queue.rs 88.17% <100.00%> (ø)
iceoryx2-cal/src/shared_memory/common.rs 86.95% <ø> (ø)
iceoryx2/src/port/listener.rs 59.77% <100.00%> (ø)
iceoryx2/src/service/mod.rs 71.73% <ø> (ø)
iceoryx2/src/service/process_local.rs 66.66% <ø> (ø)
iceoryx2/src/service/zero_copy.rs 66.66% <ø> (ø)
iceoryx2-cal/src/zero_copy_connection/common.rs 91.72% <60.00%> (-0.52%) ⬇️
iceoryx2-cal/src/event/id_tracker/bit_set.rs 85.71% <85.71%> (ø)
iceoryx2-cal/src/event/mod.rs 44.44% <75.00%> (+24.44%) ⬆️
... and 6 more

... and 4 files with indirect coverage changes

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.

First round done. The seven new files will be done tomorrow.

@elfenpiff elfenpiff force-pushed the iox2-139-events-with-bitset branch from 9e4c6bf to d024736 Compare April 5, 2024 01:18
@elfenpiff elfenpiff force-pushed the iox2-139-events-with-bitset branch from d024736 to 66d1d78 Compare April 5, 2024 01:23
@elfenpiff elfenpiff force-pushed the iox2-139-events-with-bitset branch 6 times, most recently from d59a23d to 89be51c Compare April 5, 2024 16:58
@elfenpiff elfenpiff force-pushed the iox2-139-events-with-bitset branch 14 times, most recently from b426ca7 to 66d1d78 Compare April 6, 2024 12:18
@elfenpiff elfenpiff requested a review from elBoberido April 8, 2024 13:50
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.

Mostly nitpicking 😅

@@ -489,7 +496,7 @@ pub mod details {
ListenerCreateError,
> {
let msg = "Failed to create Listener";
let id_tracker_capacity = self.trigger_id_max.as_u64() as usize;
let id_tracker_capacity = self.trigger_id_max.as_u64() as usize + 1;
Copy link
Member

Choose a reason for hiding this comment

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

Why the +1 here and teh -1 in trigger_id_max?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I realized that I assumed that trigger_id_max is the greatest trigger id I can trigger but actually it was the smallest trigger id I can no longer trigger. So it was counter intuitive and I used it wrong right from the beginning.

To support all ids up to - including - trigger id max, the bitset requires a capacity of + 1 and the trigger id max on the other side is then capacity - 1

Copy link
Member

Choose a reason for hiding this comment

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

So it acts kind of like an INVALID_TRIGGER_ID?

Comment on lines +104 to +111
let now = Instant::now();
let result = sut_listener.timed_wait(TIMEOUT).unwrap();

if result.is_some() {
assert_that!(result, eq Some(trigger_id));
} else {
assert_that!(now.elapsed(), time_at_least TIMEOUT );
}
Copy link
Member

Choose a reason for hiding this comment

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

I fail to see why there is an if condition? Shouldn't this be deterministic and always have either a result with a trigger ID or a timeout?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh no no my good friend. Here is where the concept behavior diverges a bit (maybe it is a grave mistake).

In a bitset, you can trigger every id only precisely once. When you trigger it twice, and you wait, you get only one result and the next wait is blocking.

But when the underlying construct is a queue, like in process local, you can pile up the same trigger multiple times and get triggered over and over with the same id.
This could be avoided by having somehow a queue where every element can be stored only exactly once.

At the moment, it looks like we have to support both, the bitset (limited id range but not DoS) and the queue (unlimited id range but DoS possibility).

Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't that be handled a layer further down and the concept behave the same?

In case a queue is used, the timed_wait could drain the queue and store the id's locally. Nothing for this PR but maybe a follow up for v0.4

Comment on lines +64 to +66
std::thread::sleep(std::time::Duration::from_millis(100));
let start = Instant::now();
barrier.wait();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
std::thread::sleep(std::time::Duration::from_millis(100));
let start = Instant::now();
barrier.wait();
barrier.wait();
let start = Instant::now();

Why not just this?

Copy link
Contributor Author

@elfenpiff elfenpiff Apr 8, 2024

Choose a reason for hiding this comment

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

Since it is possible that the OS does not schedule you anymore after the wait call and then you start measuring too late and the numbers are in your favor. So I wanted to be a bit more pessimistic here.

I do the same thing in the publish-subscribe benchmark

Copy link
Member

Choose a reason for hiding this comment

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

In this case two barriers can be used to get rid of the sleep and make it more deterministic ... just a suggestion, not action required

…mic wait seems to be not compatible with shared memory and multiple memory mapping; maybe multiple addresses for the same atomic confuses someone
@elfenpiff elfenpiff requested a review from elBoberido April 8, 2024 20:16
@elfenpiff elfenpiff merged commit 50ed9d5 into eclipse-iceoryx:main Apr 9, 2024
40 of 42 checks passed
@elfenpiff elfenpiff deleted the iox2-139-events-with-bitset branch April 9, 2024 05:04
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.

2 participants