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

Reduce kernel boot time to <1s on comma 3/3X #30894

Open
adeebshihadeh opened this issue Jan 3, 2024 · 2 comments
Open

Reduce kernel boot time to <1s on comma 3/3X #30894

adeebshihadeh opened this issue Jan 3, 2024 · 2 comments

Comments

@adeebshihadeh
Copy link
Contributor

adeebshihadeh commented Jan 3, 2024

systemd-analyze reports this for the latest AGNOS:

Startup finished in 3.650s (kernel) + 7.343s (userspace) = 10.994s
graphical.target reached after 7.059s in userspace

Get the kernel part of that down to <1s in a self-contained way that doesn't delay the rest of the openpilot.

  • can't just defer stuff to later and cost boot time at later stages
  • can turn off stuff openpilot doesn't use (NFC, bluetooth, etc.)

AGNOS is built with https://github.com/commaai/agnos-builder

@andiradulescu
Copy link
Contributor

andiradulescu commented Feb 4, 2024

I'm planning to do the following (most of them extracted from the boot-time-slides.pdf from the documentation links):

  • Measure and optimize the kernel initialization functions:
    • Analyze boot.svg from Boot time speedup agnos-builder#110 (comment)
    • Remove unnecessary functionality:
      • Find which kernel configuration parameter compiles the code, by looking at the Makefile in the corresponding source directory.
    • Postpone:
      • Find which module (if any) the function belongs to. Load this module later if possible.
    • Optimize necessary functionality:
      • Look for parameters which could be used to reduce probe time, looking for the module_param macro.
      • Look for delay loops and calls to functions containing delay in their name, which could take more time than needed. You could reduce such delays, and see whether the code still works or not.
  • Cut out unused drivers.
  • Reduce kernel size:
    • Compile everything that is not needed at boot time as a module.
    • Find the biggest symbols in the compiled kernel, for those which could be unnecessary, study the corresponding Makefile to see how not to compile them, if possible.
  • Check which kernel compression option is the fastest (gzip/lzma/xz/lzo/lz4/zstd or uncompressed - I love zstd but most likely lzo or lz4 is the winner, since pretty unclear if zstd support can easily be added and if the benefit is worth it).
  • Deferring drivers and initcalls - If you can’t compile a feature as a module (e.g. networking or block subsystem), you can try to defer its execution.
  • Scale the CPU frequency to maximum (or some thermally limited maximum) during boot. The faster the CPU, the faster the boot.
  • Turning off console output (Disable it by passing the quiet argument on the kernel command line).

Documentation links:

@adeebshihadeh
Copy link
Contributor Author

We already use quiet to get the initial speedup of like 11s -> 3s. I suspect we'll get the most savings from disabling and deferring. Anything openpilot doesn't use is fine to disable. Also keep in mind that deferring something critical but it costs time later in bootup doesn't count, but something non-essential to driving like WiFi is fine.

@adeebshihadeh adeebshihadeh changed the title [$500 bounty] Reduce kernel boot time to <1s on comma 3/3X Reduce kernel boot time to <1s on comma 3/3X Jul 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Open
Development

No branches or pull requests

2 participants