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
FIFO mode option for HID OutputReports #11326
FIFO mode option for HID OutputReports #11326
Changes from 8 commits
9b3be50
cd0d4bc
32ab470
c7be39f
a3cc7d5
06ab280
49f5d06
01e60de
6b58048
e3157c6
c6d8937
0a4833e
6d7ba07
95adfca
af6e60a
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.
Is there a naming missmatch beween InReports in the constant and OutputReport in the class name?
Maybe we can avoid input and output which can change form the perspective of different classes and use Received and Transmit or something.
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 think this is a missunderstanding. In is not a abreviation for Input here, its just the word in. The whole code is only for OutputReports.
InReports is the counted unit, like InMillis or InSeconds for times.
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.
dataToSend has the report ID prepended. This is not clear initially.
Can we improve the situation by always putting the report ID at the beginning?
This will also solve the reallocation of the buffer when prepending the report ID before putting it into the buffer.
The same benefit goes for
void HidController::send(QByteArray data, unsigned int reportID)
The we just not store the modified buffer.
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.
Our Javascript API has seperated arguments for ReportID and report data. This is not only needed for backwards compatibility, but is also the cleanest way to define such an API.
I will improve naming and add a comment, to make clear that this variable contains ReportID + data.
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.
Why is the mutex locked and this operation invoked even when using the FIFO strategy? The cache and the mutex should be bypassed. Ideally the dispatch strategy for each reportID would be immutable and configured at construction time. At least the FIFO report IDs need to be known in advance to avoid the locking.
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 call of updateCachedData is always needed to guarantee seamless transitions between both modes.
If a skipable report is cached, it must be cleared, because otherwise it would be send after the report from the non-skipable report from the FIFO - and would overwrite with outdated data. This happens in updateCachedData as well as the check for errors.
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 acknowledge that the current design is not suitable to for this optimization. But in principle the dispatch strategy should be fixed per report ID and not change with every call.
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.
Caching the mode only for the sender would avoid locking the mutex with every call. The cache only needs to be cleared once after changing the mode.
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 only datastructure per output report is currently HidIoOutputReport. Adding a additional data structure per output report would prevent the mutex locking in FIFO mode. But this mutex is only locked for the very short time of looking up the map for the map iterator of the report.
This takes nanoseconds, while the sending of a report takes several milliseconds. And in FIFO mode, calling this function must not be done in higher rate than the HID subsystem can send reports to the device. This ratio makes a mutex blocking very unlikely - and even when it happens, it will block the other thread only for several nanoseconds.
I don't think, that it makes sense to add additional code here, because the impact will be insignificant in practice.
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.
However short and tiny the critical section might be, you have no control over the OS scheduler -> dependency inversion. Generous use of mutexes is always a red herring. They are very often used for compensating architectural deficiencies.
https://twitter.com/EshlemanMatthew/status/1641073049746251782