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

Mavlink fixes & perf improvement #9894

Merged
merged 2 commits into from
Jul 12, 2018
Merged

Mavlink fixes & perf improvement #9894

merged 2 commits into from
Jul 12, 2018

Conversation

bkueng
Copy link
Member

@bkueng bkueng commented Jul 12, 2018

  • add optional disable_sharing flag to add_orb_subscription.
    It is a more generic solution for 532a970, and also enables it for vehicle_command_ack's.
  • MavlinkOrbSubscription::update:
    • reorders operations, such that the most expensive one (orb_copy) is done only when really needed.
    • fix corner case: when the topic was not advertised yet, orb_stat() would fail and then update() was called, which succeeds for the first advertisement.
      In that case the timestamp was incorrectly set to 0 and true was returned. The next call would again return true, because the timestamp was updated, but the topic data was still the same.

Reduces CPU load by ~2% on a Pixracer.

bkueng added 2 commits July 12, 2018 20:45
This is a more generic solution for 532a970, and also enables it for
vehicle_command_ack's.

In addition it avoids using a timestamp for subscription update checking,
because it does not work well together with orb queuing.
- reorders operations, such that the most expensive one (orb_copy) is done
  only when really needed.
- corner case: when the topic was not advertised yet, orb_stat() would fail
  and then update() was called, which succeeds for the first advertisement.
  In that case the timestamp was incorrectly set to 0 and true was
  returned.
  The next call would again return true, because the timestamp was updated,
  but the topic data was still the same.

Reduces CPU load by ~2% on a Pixracer.
@LorenzMeier LorenzMeier merged commit e1a7472 into master Jul 12, 2018
@LorenzMeier LorenzMeier deleted the mavlink_fixes branch July 12, 2018 19:31
@jdzerve
Copy link
Contributor

jdzerve commented Mar 28, 2019

This should be revisited.
The behavior has changed but description has not. Strictly speaking description was incorrect before this commit, too.
We are talking about MavlinkOrbSubscription::update(uint64_t *time, void *data)
In particular:

  1. Description "If no data available data buffer will be filled with zeros." is/was not true.
    https://github.com/PX4/Firmware/blob/75f1ad36d1210560f00da8f4fa3bddbb3da9da16/src/modules/mavlink/mavlink_orb_subscription.h#L62

  2. Description part "will still copy the data" is not true any more.
    The problem is that there is a code in MavlinkStreamSysStatus::send which actually relies on the documented behavior (copy even if not updated):
    https://github.com/PX4/Firmware/blob/75f1ad36d1210560f00da8f4fa3bddbb3da9da16/src/modules/mavlink/mavlink_messages.cpp#L571

The result is that sometimes SYS_STATUS message goes out with zeroes in onboard_control_sensors_* fields.

I could provide PR for this particular case but cannot do 100% fix as I'm not that familiar with code to know where else this behavior is relied upon.

@LorenzMeier
Copy link
Member

Thanks for raising this!

@bkueng
Copy link
Member Author

bkueng commented Apr 1, 2019

@jdzerve yes, please send a PR to update the comments and fix SYS_STATUS, thanks!
@eyeam3 are you aware of more places?

@dagar
Copy link
Member

dagar commented Apr 2, 2019

I also stumbled across this when updating the uORB subscription wrappers in mavlink for #11176. In that PR I restored the behavior as described in the comments (zeroing if no data, copy even if not updated) as a precaution, and because it was cheaper with the new interface.

That PR is going to take time to settle after v1.9.0 is released. I would suggest a quick fix for SYS_STATUS right now.

@jdzerve
Copy link
Contributor

jdzerve commented Apr 4, 2019

This is my fix:
jdzerve@4f59cf2
@dagar: Yours is little more involved, so I guess it's more appropriate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants