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

sensors: Implement a vertical decoder API #61022

Merged
merged 5 commits into from
Sep 25, 2023

Conversation

yperess
Copy link
Collaborator

@yperess yperess commented Aug 1, 2023

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.

@yperess
Copy link
Collaborator Author

yperess commented Aug 1, 2023

@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.

@tristan-google tristan-google self-requested a review August 1, 2023 17:55
@yperess yperess force-pushed the peress/new_decoder branch from 7fe4a70 to 7ab7b0a Compare August 2, 2023 07:25
@yperess
Copy link
Collaborator Author

yperess commented Aug 2, 2023

This now works with the icm42688 one-shot reading. Streaming support will come shortly.

@yperess yperess force-pushed the peress/new_decoder branch 3 times, most recently from 0932745 to c260a73 Compare August 7, 2023 07:05
@yperess
Copy link
Collaborator Author

yperess commented Aug 7, 2023

Based ontop of #61186, so I'll need to rebase this once that PR lands. But this is pretty much ready for review.

@yperess yperess force-pushed the peress/new_decoder branch from c260a73 to 56001dc Compare August 10, 2023 15:09
@yperess
Copy link
Collaborator Author

yperess commented Aug 10, 2023

@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.

@yperess yperess force-pushed the peress/new_decoder branch from 56001dc to 6352f7e Compare August 10, 2023 22:19
@yperess yperess force-pushed the peress/new_decoder branch 3 times, most recently from df27eb7 to 5c61708 Compare August 25, 2023 14:57
@yperess yperess marked this pull request as ready for review August 25, 2023 16:25
@zephyrbot zephyrbot added the area: Sensors Sensors label Aug 25, 2023
@zephyrbot zephyrbot requested review from avisconti and teburd August 25, 2023 16:26
asemjonovs
asemjonovs previously approved these changes Aug 28, 2023
drivers/sensor/akm09918c/akm09918c.c Show resolved Hide resolved
@tristan-google
Copy link
Collaborator

I will refrain from posting a review since I wrote a decent chunk of this code but am available to answer any questions/concerns.

@tristan-google tristan-google removed their request for review August 28, 2023 18:37
asemjonovs
asemjonovs previously approved these changes Aug 28, 2023
@yperess yperess mentioned this pull request Aug 29, 2023
asemjonovs
asemjonovs previously approved these changes Sep 14, 2023
teburd
teburd previously approved these changes Sep 14, 2023
Comment on lines +292 to +275
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) {
Copy link
Member

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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%

Copy link
Collaborator

@teburd teburd Sep 15, 2023

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

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

Copy link
Member

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

@teburd teburd Sep 18, 2023

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.

@teburd teburd dismissed their stale review September 17, 2023 15:58

Let’s not accidentally merge while discussing

teburd
teburd previously approved these changes Sep 18, 2023
@fabiobaltieri
Copy link
Member

@MaureenHelm can you take a look? This is a big change in sensor.h

@yperess
Copy link
Collaborator Author

yperess commented Sep 21, 2023

@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

yperess and others added 5 commits September 20, 2023 23:14
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants