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 &dyn references from GPIO-related HILs and capsules. #1765

Merged
merged 5 commits into from May 6, 2020

Conversation

gendx
Copy link
Contributor

@gendx gendx commented Apr 17, 2020

Pull Request Overview

This pull request experiments with removing &dyn references from GPIO-related capsules, as a supporting example for #1761.

Until now, the capsules were using dynamic references to use GPIO pins, even though for a given board/chip the GPIOs have a type known at compile time. This pull request proposes to replace such dynamic references with explicit types.

The resulting code is a bit more verbose, but surprisingly not so much. Most of the extra code comes from components, where static_init_half is now necessary to instantiate the static types that are now generic.

By applying this refactoring to the most common capsules (GPIO, button, LED), savings of the order of ~1KB can be obtained on the boards (depending on how many GPIOs are declared by the board). More savings could be obtained by extending this refactoring to all capsules using GPIOs. And more generally many HILs in the kernel rely on &dyn references, so removing them from HILs and capsules in general could achieve even bigger savings.

Before:

   text	   data	    bss	    dec	    hex	filename
 102400	   3196	  62336	 167932	  28ffc	/tock/target/thumbv7em-none-eabi/release/hail
 164864	   3272	  54072	 222208	  36400	/tock/target/thumbv7em-none-eabi/release/imix
  68609	   1952	  79968	 150529	  24c01	/tock/target/thumbv7em-none-eabi/release/nucleo_f429zi

After:

   text	   data	    bss	    dec	    hex	filename
 101888	   3196	  62336	 167420	  28dfc	/tock/target/thumbv7em-none-eabi/release/hail
   -512       =       =            -200
 163840	   3272	  54072	 221184	  36000	/tock/target/thumbv7em-none-eabi/release/imix
  -1024       =       =            -400
  66561	   1952	  79968	 148481	  24401	/tock/target/thumbv7em-none-eabi/release/nucleo_f429zi
  -2048       =       =            -800

Testing Strategy

This pull request was tested by building a few boards and checking the binary size. Not much more testing at this stage.

TODO or Help Wanted

This pull request still needs:

  • Feedback about such a revamp of the HIL.
  • Feedback about whether reducing code size by this method is useful (see also [Tracking] Optimizing Tock for code size #1663).
  • Feedback about the components.
  • Updating the documentation.
  • Testing on physical boards.

Documentation Updated

  • Updated the relevant files in /docs, or no updates are required.

Formatting

  • Ran make formatall.

@gendx
Copy link
Contributor Author

gendx commented Apr 17, 2020

Note: it seems that these capsules used to be parameterized by the GPIO pin type before the last revamp of the HIL (#1297). However:

  • At that time, dynamic references were not explicitly marked as such in the code, so this aspect might have been overlooked.
  • The HIL redesign also changed many other things.
  • I here propose some code size measurements that show some gains, and code size is of interest at least for some Tock users ([Tracking] Optimizing Tock for code size #1663).

bradjc
bradjc previously approved these changes Apr 17, 2020
Copy link
Contributor

@bradjc bradjc left a comment

Choose a reason for hiding this comment

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

Note: it seems that these capsules used to be parameterized by the GPIO pin type before the last revamp of the HIL (#1297).

Yes that is what I remember, and since we have generic components either way is fine to me. The dyn approach is cleaner, but the parametrized approach is more in-line with other capsules. If there is some other benefit one way or the other then great.

ppannuto
ppannuto previously approved these changes Apr 20, 2020
Copy link
Member

@ppannuto ppannuto left a comment

Choose a reason for hiding this comment

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

That's a pretty significant improvement, which make sense given the context for the optimizations that can be made with less dynamic dispatch.

I agree that the "visual overhead" is not too bad here, but I really hate the Rust convention of single-letter types (or double, IP is good). I feel as these stack up they really impede the readability of code; though maybe it's something that can be addressed with creative UI in IDEs. The rest of Tock goes to lengths to spell out identifiers and make things readable; I don't really think we should do anything differently here, just.. venting into the void a bit.

@gendx
Copy link
Contributor Author

gendx commented Apr 20, 2020

Awesome!

Before I extend this to the other boards, any feedback on the components changes? I moved the GPIO pins from the finalize() to the new() part, but maybe that's not the intended use (I'm still confused by the semantics of new vs. finalize)?

@ppannuto
Copy link
Member

Before I extend this to the other boards, any feedback on the components changes? I moved the GPIO pins from the finalize() to the new() part, but maybe that's not the intended use (I'm still confused by the semantics of new vs. finalize)?

🤷 it looks fine to me -- then again, I'm also in support of collapsing those into one function as proposed in #1618. Maybe @bradjc has opinions.

@bradjc
Copy link
Contributor

bradjc commented Apr 30, 2020

Awesome!

Before I extend this to the other boards, any feedback on the components changes? I moved the GPIO pins from the finalize() to the new() part, but maybe that's not the intended use (I'm still confused by the semantics of new vs. finalize)?

Looks good to me.

@ppannuto ppannuto added HIL This affects a Tock HIL interface. P-Significant This is a substancial change that requires review from all core developers. labels May 1, 2020
@ppannuto
Copy link
Member

ppannuto commented May 1, 2020

This does technically touch a HIL, so it probably qualifies as significant. It's also been in the review queue for a while though, so I think we can move reasonably quickly on this once updated and fully implemented.

hudson-ayers
hudson-ayers previously approved these changes May 5, 2020
Copy link
Contributor

@hudson-ayers hudson-ayers left a comment

Choose a reason for hiding this comment

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

I agree that the design looks good, and the savings are convincing. I think this just needs to be ported to other boards and rebased.

@gendx
Copy link
Contributor Author

gendx commented May 5, 2020

Rebased and migrated all boards. Where is the size report summary supposed to show?

@hudson-ayers
Copy link
Contributor

Click "details" next to the "benchmarks" check, then click the "size report" step. (I included your change to print the git diff there, but it has made the report a little cluttered).

@gendx
Copy link
Contributor Author

gendx commented May 5, 2020

Click "details" next to the "benchmarks" check, then click the "size report" step. (I included your change to print the git diff there, but it has made the report a little cluttered).

Ok, thanks. I thought there was some pipeline to show the results directly on the pull request page.

@hudson-ayers
Copy link
Contributor

Click "details" next to the "benchmarks" check, then click the "size report" step. (I included your change to print the git diff there, but it has made the report a little cluttered).

Ok, thanks. I thought there was some pipeline to show the results directly on the pull request page.

That pipeline currently only works for PRs submitted from branches on the upstream repo, due to limitations with how Github allows commit status posting. A plan is in the works to get around this limitation by hosting part of the CI on a local server where secrets can safely be stored.

ppannuto
ppannuto previously approved these changes May 5, 2020
Copy link
Member

@ppannuto ppannuto left a comment

Choose a reason for hiding this comment

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

bors d+

This is great! I've confirmed that buttons still happily button on Hail.

I think this is ready to go unless you have any remaining questions on the size improvements Hudson? That conversation looked mechanistic, but I didn't want to prematurely merge.

@bors
Copy link
Contributor

bors bot commented May 5, 2020

✌️ gendx can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

hudson-ayers
hudson-ayers previously approved these changes May 5, 2020
Copy link
Contributor

@hudson-ayers hudson-ayers left a comment

Choose a reason for hiding this comment

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

bors r+

@gendx gendx dismissed stale reviews from hudson-ayers and ppannuto via 0401f78 May 5, 2020 16:59
@bors
Copy link
Contributor

bors bot commented May 5, 2020

Canceled.

@gendx
Copy link
Contributor Author

gendx commented May 5, 2020

I updated the usage of affected components as well. Will wait a day in case anyone has something to say.

@alistair23
Copy link
Contributor

This PR is still marked as RFC. Is it no longer an RFC?

@gendx gendx changed the title [RFC] Remove &dyn references from GPIO-related HILs and capsules. Remove &dyn references from GPIO-related HILs and capsules. May 6, 2020
@gendx
Copy link
Contributor Author

gendx commented May 6, 2020

This PR is still marked as RFC. Is it no longer an RFC?

Indeed.

@gendx
Copy link
Contributor Author

gendx commented May 6, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented May 6, 2020

@bors bors bot merged commit 8a65899 into tock:master May 6, 2020
@bors
Copy link
Contributor

bors bot commented May 6, 2020

@gendx gendx deleted the nodyn-gpio branch May 6, 2020 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
HIL This affects a Tock HIL interface. needs-rebase P-Significant This is a substancial change that requires review from all core developers.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants