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

ModuleBase add common base and cleanup #12191

Closed
wants to merge 1 commit into from

Conversation

dagar
Copy link
Member

@dagar dagar commented Jun 5, 2019

This PR updates ModuleBase<T> (px4_module.h) to have a non-template base class ModuleBaseInterface. Then instead of each module having a static _object pointer there's a single LinkedList.

Then methods like ModuleBase<T>::stop_command() have been refactored so that the bulk of the code is common, with each module frontend finding its object pointer by name from the LinkedList, rather than statically. Getting the bulk of this code out of the template is where flash is saved.

This is an incremental step towards expanding ModuleBase to optionally handle multiple instances of a module.

image

@dagar
Copy link
Member Author

dagar commented Jul 4, 2019

@bkueng and @julianoes could I get some initial feedback? I originally did this last year, so I need to review it myself...

@dagar dagar added this to the Release v1.10.0 milestone Jul 4, 2019
@dagar dagar requested review from julianoes and bkueng July 4, 2019 16:02
// search for module again to request stop
object = get_module_instance(name);

if (object != nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a bit confusing because there are checks for object != nullptr in several places.
Could you invert the logic to:

object = get_module_instance(name);
if (object == nullptr) {
    break;
    ...

And with a scoped lock you could even get rid of the do while and just return directly.

Copy link
Member Author

Choose a reason for hiding this comment

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

The locking and structure is a bit weird because it's expecting the task to kill itself cleanly, so it's sleeping, checking, etc in between.

I'll review it again.

Copy link
Contributor

Choose a reason for hiding this comment

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

I still think you could turn that around for better readability.

src/platforms/common/module.cpp Outdated Show resolved Hide resolved
src/platforms/common/module.cpp Outdated Show resolved Hide resolved
@bkueng
Copy link
Member

bkueng commented Jul 5, 2019

The design looks ok - I initially went for a stronger separation between tasks, but since we're generally moving away from that, this works too.
I haven't checked the details or for corner cases.

@dagar dagar force-pushed the pr-modulebase_refactor branch 2 times, most recently from 04d9d6b to 48a2d8d Compare July 26, 2019 21:19
@dagar dagar force-pushed the pr-modulebase_refactor branch 3 times, most recently from e3c9f40 to ce71d52 Compare August 29, 2019 04:30
@dagar dagar force-pushed the pr-modulebase_refactor branch 4 times, most recently from 5cac8ca to b3bad51 Compare September 1, 2019 20:22
@dagar dagar marked this pull request as ready for review September 1, 2019 20:22
@dagar dagar changed the title [WIP] ModuleBase add common base and cleanup ModuleBase add common base and cleanup Sep 1, 2019
@dagar dagar force-pushed the pr-modulebase_refactor branch 8 times, most recently from 70c3f18 to b6e56d8 Compare December 1, 2019 15:33
@dagar
Copy link
Member Author

dagar commented Dec 1, 2019

@bkueng @julianoes can we regroup and start going through this again? It saves a relatively large amount of flash (> 5 kB on fmu-v2) and sets us up for taking the next step in running multiple instances of certain modules (eg multi-EKF).

Notes:

  • I wouldn't really worry about the modules command yet, it's mostly for visibility and to think about doing a full clean shutdown in the future. Currently modules stop-all only does a request_stop() for each, which isn't quite right.
  • As a followup I'm considering creating specialized ModuleBases for WQs and Tasks now that the px4 work queue patterns are becoming clear (including some shutdown holes). I think we'll be able to do a cleaner/better job here for each separate case. With that in mind we need to make sure the core of this change works properly and is safe, but it doesn't need to be perfect (yet).

@dagar dagar added this to the Release v1.11.0 milestone Dec 1, 2019
@dagar dagar self-assigned this Dec 1, 2019
@dagar
Copy link
Member Author

dagar commented Dec 1, 2019

image

@dagar dagar force-pushed the pr-modulebase_refactor branch from b6e56d8 to 3700b55 Compare December 1, 2019 16:09
@bkueng
Copy link
Member

bkueng commented Dec 3, 2019

I will need to go through that in detail. Meanwhile can you check again, I think some of my previous remarks are not resolved yet.

@dagar dagar force-pushed the pr-modulebase_refactor branch from 3700b55 to e327c07 Compare January 18, 2020 00:16
@stale
Copy link

stale bot commented Apr 17, 2020

This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.

@stale stale bot added the stale label Apr 17, 2020
@dagar dagar marked this pull request as draft November 8, 2020 20:29
@stale stale bot removed the stale label Nov 8, 2020
@LorenzMeier
Copy link
Member

Closing as stale.

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.

5 participants