[kernel][dlog] Use a Timer to allow printing from within the scheduler

This change resolves an issue that prevented printf from working
within the scheduler, and more generally, whenever there was an active
chainlock transaction.

printf bottoms out in DLog::Write, which places a record in a buffer
and then calls Event::Signal to unblock the notifier thread.  Prior to
this change, if DLog::Write was called from a context with an existing
active chainlock transaction (e.g. from within the scheduler), calling
Event::Signal would trigger an assert (can't start a new transaction
when you've already got one in progress).

To resolve the issue, we update DLog::Write to check for an active
chainlock transaction.  If there is none, it calls Event::Signal as
usual.  If there one, DLog::Write will instead set a Timer that will
immediately fire once the current CPU has re-enabled interrupts after
finishing the current transaction (or during the period in which
interrupts are re-enabled during backoff).  The Timer callback simply
calls Event::Signal on Write's behalf.

~DLog now cancels the Timer to ensure there is no use-after-free.

As a small optimization, DLog tracks whether there is a pending Timer
(pending_deferred_signal_).  Of course, this tracking is not 100%
accurate as the Timer callback could be racing with the write.
However, because the observation is made in a critical section guarded
by the same lock that the dumper thread must ultimately acquire, there
is no risk of a "lost wakeup".

Fixed: 339440805
Fixed: 331847876
Change-Id: Iad837950e9513547b986fd71fc045b3e407d58c5
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1045567
Reviewed-by: John Grossman <johngro@google.com>
Fuchsia-Auto-Submit: Nick Maniscalco <maniscalco@google.com>
Commit-Queue: Auto-Submit <auto-submit@fuchsia-infra.iam.gserviceaccount.com>
4 files changed
tree: 683dc21631984dea3a0a3ccf40594190a5f86977
  1. boards/
  2. build/
  3. bundles/
  4. docs/
  5. examples/
  6. infra/
  7. products/
  8. scripts/
  9. sdk/
  10. src/
  11. third_party/
  12. tools/
  13. zircon/
  14. .clang-format
  15. .clang-tidy
  16. .editorconfig
  17. .git-blame-ignore-revs
  18. .gitattributes
  19. .gitignore
  20. .gitmodules
  21. .gn
  22. .ignore
  23. analysis_options.yaml
  24. AUTHORS
  25. BUILD.gn
  26. CODE_OF_CONDUCT.md
  27. CONTRIBUTING.md
  28. fuchsia.code-workspace
  29. LICENSE
  30. OWNERS
  31. PATENTS
  32. pyproject.toml
  33. pyrightconfig.json
  34. README.md
  35. rustfmt.toml
  36. shac.star
  37. shac.textproto
README.md

Fuchsia

What is Fuchsia?

Fuchsia is an open source, general purpose operating system supporting modern 64-bit Intel and ARM processors.

We expect everyone interacting with our project to respect our code of conduct.

Read more about Fuchsia's principles.

How can I build and run Fuchsia?

See Getting Started.

Where can I learn more about Fuchsia?

See fuchsia.dev.