-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
sensors: Implement a vertical decoder API #61022
sensors: Implement a vertical decoder API #61022
Conversation
@teburd please let me know if you want to sync on this (this is just a draft, you can test this out on the akm09918c on the TDK board). I've been talking to several teams internally at Google and I believe that a vertical decoding scheme would benefit a larger majority of applications when compared to our existing horizontal decoding scheme. Please reference #60944 for visualization. |
7fe4a70
to
7ab7b0a
Compare
This now works with the icm42688 one-shot reading. Streaming support will come shortly. |
0932745
to
c260a73
Compare
Based ontop of #61186, so I'll need to rebase this once that PR lands. But this is pretty much ready for review. |
c260a73
to
56001dc
Compare
@teburd Tristan was backed up with breaks from the ISH hal changes and did finish the tests for this PR, they'll come next week. Any chance you can give this change a quick review with the assumption that the tests will pass early next week? This will unblock rebasing the streaming API so we can focus on that review. |
56001dc
to
6352f7e
Compare
df27eb7
to
5c61708
Compare
5c61708
to
b041828
Compare
I will refrain from posting a review since I wrote a decent chunk of this code but am available to answer any questions/concerns. |
0d80a98
to
ee3b5c0
Compare
if (channel == SENSOR_CHAN_ACCEL_X || channel == SENSOR_CHAN_ACCEL_Y || | ||
channel == SENSOR_CHAN_ACCEL_Z || channel == SENSOR_CHAN_GYRO_X || | ||
channel == SENSOR_CHAN_GYRO_Y || channel == SENSOR_CHAN_GYRO_Z || | ||
channel == SENSOR_CHAN_MAGN_X || channel == SENSOR_CHAN_MAGN_Y || | ||
channel == SENSOR_CHAN_MAGN_Z || channel == SENSOR_CHAN_POS_DY || | ||
channel == SENSOR_CHAN_POS_DZ) { |
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.
There seems to be a lot of channel-specific additions like this throughout the PR. Have you measured the impact to code size?
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 have not, specifically because the roadmap is to eventually deprecate the old APIs and then all of these will go away. Happy to measure of you'd like.
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.
OK, I ran: $ west build -p -b tdk_robokit1 samples/sensor/sensor_shell/
. Summary:
- Flash increase: 1,140B
- Ram increase: 0B
I think that with the approach we chose of having this augment the existing API, there's no way to avoid the bloat until we deprecate the old API and do the final steps of migration. At that point the tradeoff should be
- adding RTIO constructs
- adding shared memory pools
- removing buffers from the sensor drivers
- removing dedicated threads for interrupts
I believe the net increase in size should be very minimal, even depending on configurations (since the shared memory pools are shared across all sensors that the application wants) the memory footprint might be smaller than we started.
Without this change:
Memory region Used Size Region Size %age Used
FLASH: 87560 B 2 MB 4.18%
RAM: 19144 B 384 KB 4.87%
IDT_LIST: 0 GB 2 KB 0.00%
With this change:
Memory region Used Size Region Size %age Used
FLASH: 88700 B 2 MB 4.23%
RAM: 19144 B 384 KB 4.87%
IDT_LIST: 0 GB 2 KB 0.00%
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.
Can you show the rom report? If the rom increase is almost entirely in the sensor shell that seems, at least from my perspective, less of an issue and one that can be worked on.
The 1kb rom increase is solely from this vertical decoder change is that right? Can you annotate this with the git sha's?
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.
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 diff is almost entirely in the sensors (since they need to support both code paths) and in the shell
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 expect some overhead in supporting old and new APIs simultaneously. My question was about the code impact in changing from horizontal to vertical decoding in the new API.
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.
@MaureenHelm @teburd OK... I did some more exploring and this increase is 100% a part of supporting 2 data representations. I took the icm42688_decoder.c as the example because we had a good before/after fully implemented decoder. The cost there comes from decoding to the old sensor value then to the q31. When (locally) I changed it directly to the q31 the decoder was actually 264B smaller (27.5%). It's not entirely a fair comparison because the old decoder would also benefit from exactly the same change (converting directly to q31 format).
I'm happy to make the change, but while we support 2 code paths on these sensors I think it's cleaner to use the common representation for readability. Later when we deprecate the old fetch/get we can optimize back down.
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'm ok with this, I think mostly the code size should be about the same. Theoretically the only significant change would be the way the frame iterator becomes an index into the buffer to copy out. That really shouldn't be a big jump in code size if at all. At an application level maybe slight more memory (the size of the decoder context) is used per channel. This again shouldn't make or break a memory budget in my humble opinion, and can be placed on the stack.
Let’s not accidentally merge while discussing
@MaureenHelm can you take a look? This is a big change in sensor.h |
Maureen and I discussed this offline, she requested that I tweak the sensor_shell.c changes a bit so that the print handling isn't per channel but instead per data type |
Introduce PRI style formatting for DSP values. These require the use of another separate macro to set up the argument (PRIq_arg). Signed-off-by: Yuval Peress <peress@google.com>
Update the decoder APIs to vertically decode the raw sensor data. This means that instead of getting each channel on a frame by frame basis, the API takes a channel specifier and returns as many frames of that given channel as there's room. The goal of this is to make the end decoded result the most useful and usable for the Zephyr application. See zephyrproject-rtos#60944 for details. Signed-off-by: Yuval Peress <peress@google.com>
This function is no longer used and causes a compiler error. Signed-off-by: Tristan Honscheid <honscheid@google.com>
Implement the RTIO/Sensors V2/Async API for the AKM09918C. Add a decoder API implementation as well. Signed-off-by: Tristan Honscheid <honscheid@google.com>
Update the code in the generic test to work with the updated sensor decoder API that retrieves data vertically by channel. Signed-off-by: Tristan Honscheid <honscheid@google.com>
ee3b5c0
to
8029e29
Compare
Introduce an alternative decoding scheme that focuses on vertical vs horizontal decoding. This PR is based ontop of #60063 so only the latest commit should be reviewed.
PR was merged, this is ready for review.