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

Remove redundant % size from queue APIs #114

Merged
merged 3 commits into from
May 29, 2024
Merged

Conversation

Ivan-Velickovic
Copy link
Collaborator

Closes #111.

Brought up by @isubasinghe.

isubasinghe
isubasinghe previously approved these changes May 14, 2024
Copy link
Contributor

@isubasinghe isubasinghe left a comment

Choose a reason for hiding this comment

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

Thanks for making this change!

Copy link
Contributor

@Courtney3141 Courtney3141 left a comment

Choose a reason for hiding this comment

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

The issue I discussed in detail in the net queue file applies to the other queue files as well.

@@ -85,7 +85,7 @@ static inline bool net_queue_empty_active(net_queue_handle_t *queue)
*/
static inline bool net_queue_full_free(net_queue_handle_t *queue)
{
return !((queue->free->tail + 1 - queue->free->head) % queue->size);
return !(queue->free->tail + 1 - queue->free->head);
Copy link
Contributor

Choose a reason for hiding this comment

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

Both these changes to the full conditions are incorrect.

Firstly, remember that I haven't yet corrected the issue raised before that if the queue size is S, we currently only use S-1 entries. (This is next on my list of issues to fix.)

Bearing this in mind, the idea with this function is to catch the case when the tail is S-1 greater than the head. E.g.
tail = head + S - 1
Re-arranging this we get:
tail + 1 - head = S
which satisfies the old condition of:
!((tail + 1 - head) % S)

What you have changed it to instead is:
tail + 1 - head != 0, or tail + 1 != head
which means that a queue is only considered full when the tail is UINT16_MAX - 1 greater than the head (much larger than most of our queues :-) ).

I believe the correct condition should be
tail + 1 - head = size

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, my bad. I will fix that.

@Ivan-Velickovic Ivan-Velickovic force-pushed the queue_remove_modulo branch 2 times, most recently from f1b04e4 to 7afc667 Compare May 14, 2024 07:05
@@ -132,7 +132,7 @@ static inline bool blk_resp_queue_empty(blk_queue_handle_t *h)
*/
static inline bool blk_req_queue_full(blk_queue_handle_t *h)
{
return !((h->req_queue->head - h->req_queue->tail + 1) % h->queue_size);
return h->req_queue->head - h->req_queue->tail + 1 == h->req_queue->size;
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume that blk seems to use head/tail in the opposite way to i2c/network/serial?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I noticed that and made a comment #78 (comment).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe @erichchan999 can fix that or I can make another PR later.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep happy to make a separate PR once this is merged

@Ivan-Velickovic
Copy link
Collaborator Author

Ivan-Velickovic commented May 14, 2024

I'll do a benchmark run tomorrow morning and then merge (just to double check the change). Thanks for noticing my mistake @Courtney3141.

@Courtney3141 Courtney3141 force-pushed the queue_remove_modulo branch from 7afc667 to 4661da8 Compare May 29, 2024 07:42
@Courtney3141
Copy link
Contributor

Since you will be away for a while, I re-ran a benchmark for you to check that performance is preserved and everything works as usual. I will merge this now.

@Courtney3141 Courtney3141 merged commit fd9f770 into main May 29, 2024
4 checks passed
@Courtney3141 Courtney3141 deleted the queue_remove_modulo branch May 29, 2024 07:46
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.

Remove % size checks from queue libraries
4 participants