-
Notifications
You must be signed in to change notification settings - Fork 5
Ergonomics: Treat PollCompletionQueueError::CompletionQueueEmpty as an empty iterator to simplify completion polling #86
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @vtta, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the developer experience for handling RDMA completion queues by refactoring the polling mechanism into a more idiomatic Rust iterator pattern. This change eliminates verbose Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a significant ergonomic improvement by treating an empty completion queue as an empty iterator, which greatly simplifies the polling logic in client code. The changes in src/ibverbs/completion.rs are well-conceived, and the updated examples clearly demonstrate the benefits of the new API. I've identified a potential panic in the new iterator implementation and a couple of copy-paste errors in the tests. After addressing these points, this will be a very solid contribution.
| _ => { | ||
| unreachable!() | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The unreachable!() macro here can be reached. The ibv_poll_cq function can return a negative value on error. In that case, this _ match arm will be taken, causing a panic. This would crash the application instead of handling the error gracefully. While the Iterator trait prevents returning a Result from next(), the error should not cause a panic. A better approach would be to stop the iteration, similar to how an empty queue is handled.
_ => {
// This is an error from ibv_poll_cq, so we stop iterating.
self.status = Empty;
None
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please fix this? I think we would reach here when hardware status is broken. @vtta
Codecov Report❌ Patch coverage is
🚀 New features to boost your workflow:
|
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> chore: fix a sq/rq typo Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
dragonJACson
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good to me 👍, thanks for your contribution!
Could you please rebase your commits to squash cd39297 into the preceding functional commit? It’s a small typo fix and fits better together.
Also, please update the commit messages to be a bit more informative and consistent:
For 76455a2
chore(test): rename mr to send_mr for clarity in post send tests
For 250519c, You could mention the API behavior change in the message body.
That should make the history cleaner and commit messages more descriptive. cc @FujiZ
| } | ||
| } | ||
| pub fn iter(&self) -> Result<BasicCompletionQueueIter<'_>, PollCompletionQueueError> { | ||
| BasicCompletionQueueIter::new(self.cq, self.poll_batch.get().try_into().unwrap()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be self.poll_batch.get().try_into().unwrap_unchecked()
| _ => { | ||
| unreachable!() | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please fix this? I think we would reach here when hardware status is broken. @vtta
| let current = self.current; | ||
| if self.status == Empty { | ||
| return None; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means when status is Empty, we would never call ibv_poll_cq again, line 666 should be removed. Does this look good to you? @FujiZ
This patch simplifies completion polling by allowing native iteration over the completion queue using for
wc in cq.iter()?.Previously, callers had to manually invoke
poller.next(), which resulted in verbose and heavily nested code.Treating
PollCompletionQueueError::CompletionQueueEmptyas a natural “end of iterator” condition is appropriate here, an empty CQ simply behaves like an empty iterator. As a result, we now keepPollCompletionQueueErrorfor actualIbverbserrors and let normal iterator semantics handle the empty-queue case.The resulting interface looks like:
instead of