Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
HidController: loop until no more messages are available on poll #2970
HidController: loop until no more messages are available on poll #2970
Changes from 7 commits
c2e62c9
fe35428
ec70661
1f84927
a362551
7cdc090
cd281c1
229e9f1
ecc5d33
cea971a
d146e74
a2e3267
26bdbef
cd283de
447a432
2343bbf
018f1e2
dff0202
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
result
does not need to be defined outside the loop. An infinite for loop with explicit return points would be much easier to follow.Setting result to 1 before the loop is also conceptually incorrect and an ugly hack. The value represents the number of received bytes. But we haven't received anything yet and the value 1 is arbitrary, anticipating some assumptions of code in another (though near) context.
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 potential stalls the whole ControllerManager on low end devices. Slots like slotShutdown() are never called.
This is also high priority thread. A burning CPU loop here will also effect GUI performance badly.
Conclusion. This mus behave cooperative and end the loop after a maximum amount of time.
We need to create a kind of time slice.
Unfortunately the hid API does not offer flush() call to start over.
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.
If this loops takes longer than the polling interval, I suggest to flush the remaining messages by reading them without processing, and then add quit the while loop.
This can also happen due to a script issue, so the user should be able to recognize the situation.
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.
I tried that before and it did not work.
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.
Unfortunately the last commit is gone.
It is just that we need a kind of stop condition for this potential endless loop.
You may check if the poll timer has already expired again. If this happen, flush the buffer and break the loop waiting for the next cycle.
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.
Ah, the code that @codecat tested before did not flush the remaining messages. That may be why the state of the controller seemed frozen. But I am not sure how flushing the messages would work because it would only be done when the loop is taking too long, so wouldn't there not be any messages for the next loop? Also, wouldn't the timeout need to slightly less than the polling interval?
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 is not too hypothetical. I think part of the original issue is that the mapping code consumes too much CPU.
The old code was not able to stall Mixxx in this case. This is.
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.
I would start with 50 % idle time vs processing time.
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.
No, the issue this PR fixes is that HID messages were not processed often enough because only one packet was processed every 5 ms. If the mapping code took too long, this branch would make the original problem worse, not better.
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.
Ah, OK I misunderstand that.
This is still against my experience as embedded developer, but if you are confident that we will have no issue with long running scripts here, it is OK for me.
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.
So ready for merge?
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.
"Rotate between two buffers ..." -> "Cycle between disjunct input buffers ..."
"two" depends on the value of the constant
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.
I would use early returns and avoid all the nesting:
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.
Sure, this obviates the need for the hacky
int result = 1
too: 2343bbfThere 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 should be switchable by the mapping.
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.
I will not add complexity to the mapping system to avoid this trivial cost.
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.
memcmp'ing 255 bytes 10 million times takes 4.82 milliseconds with
-O0
on my laptop. I think the cost is neglible.See: #2970 (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.
Are we sure that omitting update suits to all cases? I think this can be surprising.
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.
If we decide not to make this code conditional, we need a more significant comment that a HID telegram is discarded here for all controllers anong with some words why we think that his is universal correct.
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.
I disagree that there is any need for further explanation in the comment. If the current packet is the same as the last, there is no purpose processing it regardless of which controller is doing this.
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.
Additional comments never hurts. It is better to be explicit.
The long discussion shows that there is a need IMHO.
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 code is IMO obvious and explicit already.
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 is normal for the author...
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.
No, that's too terse. It does not explain why duplicates are a problem. There is nothing wrong with a 3 line 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.
Please add this in addition to your 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.
done 447a432
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.
Are the comments sufficient?
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.
ping