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

dmesg functionality (console buffer) #11792

Merged
merged 4 commits into from
Jun 4, 2019
Merged

dmesg functionality (console buffer) #11792

merged 4 commits into from
Jun 4, 2019

Conversation

bkueng
Copy link
Member

@bkueng bkueng commented Apr 4, 2019

Often it would be helpful to see the boot output, but the console is not available. This PR adds all console output to a buffer (except for NuttX syslog output), so that it can be printed later on via a new dmesg utility.

It is implemented by redirecting stdout to a custom device that keeps a buffer and outputs to stderr (which still goes to the original console). I looked at different options, and this seems the best one and most efficient.
Alternatives:

  • using up_putc instead of stderr is considerably less efficient
  • using NSH_ALTCONDEV does not work, because the mavlink shell would be output to that console as well.
  • I tried redirecting via shell scripting (e.g. sh /etc/init.d/rcS2 > /dev/ramlog), but that did not work properly.
  • NuttX's ramlog is not appropriate because it clears the buffer on every read
  • NuttX provides a tee command, but that uses an additional 1 KB buffer

Since it requires some RAM, I only enabled it for v5 targets. The buffer is 4 KB, and typical boot output is 3 KB. We can reduce that a bit by cleaning up the boot output and maybe reduce the ver all verbosity.

Example

qgc_dmesg

You can also keep it running in the background:

dmesg -f &

TODO

  • find a better way for the v5 ifdef
  • add output to the log as well

@bkueng bkueng requested a review from davids5 April 4, 2019 12:41
@LorenzMeier
Copy link
Member

Awesomeness!

Copy link
Contributor

@julianoes julianoes left a comment

Choose a reason for hiding this comment

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

This is awesome.

platforms/nuttx/src/px4_layer/console_buffer.cpp Outdated Show resolved Hide resolved
platforms/nuttx/src/px4_layer/console_buffer.cpp Outdated Show resolved Hide resolved
platforms/nuttx/src/px4_layer/console_buffer.cpp Outdated Show resolved Hide resolved
LorenzMeier
LorenzMeier previously approved these changes Apr 4, 2019
@bkueng bkueng force-pushed the dmesg_functionality branch 2 times, most recently from 52d848c to 53a3b02 Compare April 5, 2019 08:09
julianoes
julianoes previously approved these changes Apr 5, 2019
@davids5
Copy link
Member

davids5 commented Apr 5, 2019

@bkueng

How much of the motivation for this is wanting a PX4 portable way to do this?

I tried redirecting via shell scripting (e.g. sh /etc/init.d/rcS2 > /dev/ramlog), but that did not work properly.
NuttX's ramlog is not appropriate because it clears the buffer on every read

I am assuming you are referring to the syslog options:

http://nuttx.org/doku.php?id=wiki:nxinternal:syslog Ramlog and dmesg?

Could we just add a backing file store to dmesg? If dmseg RAM has content append it to a file and then cat the file?

@bkueng
Copy link
Member Author

bkueng commented Apr 5, 2019

Could we just add a backing file store to dmesg? If dmseg RAM has content append it to a file and then cat the file?

That would either be the ramlog option (which clears on read, so not what we want), or add a read interface to our console_buf device. We could do the second one, but need a way to handle the follow/not-follow reads. The added abstraction would also add overhead.

@davids5
Copy link
Member

davids5 commented Apr 5, 2019

@bkueng

Would you agree the output to the console has different significance to different developers?

My concern is the loss of information: I.e the diff from this to the actual console output.

There are some early boot messages that are critical to diagnosis an issue. I would like to see these in the output, but as the system boots so grows the capabilities to log. I.E there is no microsd fs in stm32_boardinitialize(). and some fs capabilities at board_app_initialize() there is full capabilities after the script completes in board_app_finalinitialize().

davids5
davids5 previously approved these changes Apr 5, 2019
Copy link
Member

@davids5 davids5 left a comment

Choose a reason for hiding this comment

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

@bkueng - thank you!
Let's add to the Todo list what we discussed on the call:

  1. A plan to enhance the ver command, to capture the Manifest index(HW rev,ver) and Core rev/patch.
  2. consider using the a stream in BBSRAM for the dmsg buffer to not lose the high level information in a fault.

@dagar
Copy link
Member

dagar commented Apr 5, 2019

Questions

  1. Can you add this to the log?
  2. What should we do with current syslog usage? https://github.com/PX4/Firmware/blob/4907b8788267240d665a923a2166fd1d3d77079b/boards/px4/fmu-v5/src/init.c#L294
  3. Ideas for capturing stdout on posix and qurt as well?

@bkueng bkueng dismissed stale reviews from davids5 and julianoes via 3768bac April 6, 2019 03:51
@bkueng bkueng force-pushed the dmesg_functionality branch 2 times, most recently from 3768bac to 434b5a2 Compare April 8, 2019 05:56
@bkueng
Copy link
Member Author

bkueng commented Apr 8, 2019

Can you add this to the log?

Yes, that was already on the way. See e0cccce

What should we do with current syslog usage?

There's only 2: board version (which is also in ver all) and some hardfault log status output. Everything we want should be added to a printf.

Ideas for capturing stdout on posix and qurt as well?

Yes we can use a pipe.

@bkueng
Copy link
Member Author

bkueng commented Jun 3, 2019

Rebased & tested again. Should be good to go if CI passes.

There is one thing to note: output from NuttX's work queues is not captured, because they are started earlier at boot. But since we move away from them, it won't be an issue.

During testing I hit the maximum task limit of 32 (mavlink shell + 1 bg task). This is likely already an issue for VTOL and certain other configurations, due to the additional work queue tasks. @dagar fyi, maybe you're aware already.

@dagar
Copy link
Member

dagar commented Jun 3, 2019

During testing I hit the maximum task limit of 32 (mavlink shell + 1 bg task). This is likely already an issue for VTOL and certain other configurations, due to the additional work queue tasks. @dagar fyi, maybe you're aware already.

No, I didn't realize we were that close on actual configurations. I'll accelerate plans to consolidate some of our tasks, kill off HPWORK/LPWORK (unless used by a NuttX level dependency), and shutdown any unused WQ threads (created probing empty buses at startup).

Copy link
Contributor

@julianoes julianoes left a comment

Choose a reason for hiding this comment

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

I had another glance over this after my previous review, and I'm assuming that @dagar and @davids5 are not opposed to merging this now.

@julianoes julianoes merged commit d68dcb9 into master Jun 4, 2019
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.

None yet

5 participants