Module 14 · Lesson 59 of 92

Measuring boot time

Measure a repeatable boot baseline and use kernel, systemd, and process timing to investigate delays before the first visible application frame.

  • Beginner to advanced
  • 8 min read
  • 28 min lab
What you will need

Ubuntu 24.04 in a VM that boots its own kernel and runs systemd as PID 1, with sudo access; an optional Raspberry Pi 4 or 5 with a display and a camera for a physical time-to-first-frame measurement

Your place in the module
By the end you can 4 objectives
  • Define reproducible start and finish events for a boot baseline.
  • Extract kernel message timestamps and identify initcall durations.
  • Interpret systemd activation times, ordering chains, and Bootchart traces.
  • Measure time-to-first-frame and report run-to-run variation.
Video coming soonMeasuring boot time
The video for this lesson is being recorded. Read the lesson below in the meantime.
Recall first from Production test and data security
  • A unit is eligible to ship only after every required test produces a valid pass for its current build and configuration.
  • A non-exportable signing key can remain inside an HSM while the provisioning service receives signatures.
  • Production records enforce uniqueness separately for the serial number and MAC address.
01

Define when boot starts and ends

3 min read

In the last lesson the units shipped, and now the product's boot speed becomes the target. This lesson answers the timestamps, initcall_debug, systemd-analyze and Bootchart tools that give you a baseline.

A display product can reach graphical.target while its application is still preparing the screen. The target describes systemd's progress through unit activation. A customer turning on the product sees the panel and waits for content. The distinction matters when an engineer reports a shorter boot after seeing a lower value from systemd-analyze time. To know whether the customer sees the same improvement, measure the screen as well as the target. systemd-analyze(1)

Revisit from M4-S15. For a display-equipped Raspberry Pi 4 or 5, define the start as applying board power and the finish as the first visible frame of the application screen you specify. Write down what identifies that frame. For example, require the application's title and its main panel to appear together. An illuminated blank screen, a firmware splash, or a frame from the display manager can occur earlier. If the product also has a response-time requirement for the first user input, record that as a separate endpoint.

Power to visible application frameApply powerexternalstartFirmwarestartupLinuxstartupApplicationdrawsFramevisibleexternalfinishApply powerexternalstartFirmwarestartupLinuxstartupApplicationdrawsFramevisibleexternalfinish
An external measurement can include firmware, Linux startup, and the first visible application frame

One way to measure both events on a common timebase is to film the panel and a visible indicator tied to the chosen power event in the same recording. Choose an indicator with a known relationship to power application. If you film the switch movement, use that movement as the stated start event and report it as a proxy for board power. For a constant-frame-rate recording, subtract the start frame index from the finish frame index and divide by the frame rate in frames per second. If frame intervals vary, use the recorded timestamps of those frames. Each event occurs somewhere between sampled frames, so report the measurement at a precision consistent with the camera interval and the start indicator.

An application log can record when rendering begins or when the application submits a buffer. Use that marker to investigate the application interval. The panel can still be waiting for a display refresh after that marker, and an application log starts much later than power-on. Keep the external elapsed time and the software timestamp with their own start and finish definitions. If the display shows the first valid application frame before a systemd target is reached, record both events in the order you observe.

For a , keep the board or VM configuration, image, boot medium, and relevant peripherals fixed. For a network-dependent image, record the network conditions. Decide whether to include first boot after flashing. A boot that provisions the system and a later boot of the provisioned system represent different conditions. Treat a cold power-on and a software reboot as different test cases too. Repeat the chosen test. Save each result and report the number of runs, median, and minimum and maximum so a later comparison can account for ordinary variation.

In an Ubuntu VM, you can baseline systemd's startup to a named target without a camera. State the target and the interval reported by the tool. If the VM shows a desktop, its first visible desktop frame can be a separate visual endpoint with a defined VM start event. The VM result describes that guest under its host conditions. A physical board measurement includes hardware and firmware behavior specific to that board.

02

Read kernel timestamps and initcall durations

3 min read

Use an Ubuntu 24.04 VM that boots its own kernel for this measurement. After a normal boot, read the current kernel command line and save the kernel ring buffer. The default dmesg output prefixes each line with the kernel timestamp in seconds since the kernel started (util-linux 2.39 in Ubuntu 24.04 has no raw value for --time-format, so leave that option off).

bash
cat /proc/cmdline
sudo dmesg > kernel-baseline.log
less kernel-baseline.log

The timestamp beside a message is the time at which the kernel recorded it. Pick two messages that describe identifiable events and subtract the earlier timestamp from the later one. For example, locate the messages that report detection of the root storage device and the mount of the root filesystem if both are present in your log. Record the actual message text so you can recognise the same events on the next run. A gap between messages measures an interval that can contain several activities, including work on other CPUs and time spent waiting. The first logged message also misses any board activity before Linux produces that message. Save the log soon after boot because newer messages can overwrite older records in the finite ring buffer. dmesg(1)

Timing a kernel initcallKernelmessageeventtimestampInitcallentrycall startsInitcallreturnselapsedtime in microsecondsKernelmessageeventtimestampInitcallentrycall startsInitcallreturnselapsedtime in microseconds
Kernel message timestamps locate events, while initcall_debug reports elapsed time for individual calls

To time the calls you met in M14-S04A5, boot once with initcall_debug on the kernel command line. On a GRUB-based VM, select the normal boot entry, press e, append initcall_debug to the line beginning with linux, and boot the edited entry with Ctrl+x. This edit applies to that boot. Verify the argument is present in /proc/cmdline before interpreting the results. On a board, use the method provided by its image and bootloader to append a kernel argument. Save the diagnostic run under a distinct filename.

bash
cat /proc/cmdline
sudo dmesg > kernel-initcalls.log
grep -E 'calling .* @ |initcall .* returned ' kernel-initcalls.log

The initcall trace records when a call begins and reports its return value and elapsed time in microseconds when it returns. Match the entries by function name. Use the duration reported on return to rank calls, and use the message timestamps to see where they occur in startup. A long call measures elapsed time inside that call, including any wait there. Asynchronous work can finish after the initiating call returns. A quick return therefore gives you the duration of the call itself, and a later log event may be needed to time device readiness. A return value is a status to interpret separately from the duration. The kernel's command-line parameters

Keep the normal boot measurement

Enable initcall_debug for diagnostic runs. The extra messages can change timing, especially when a slow serial console prints them. Use repeated boots with the normal command line for your baseline.

03

Explain userspace startup time

4 min read

On the Ubuntu VM, run these commands after the system reaches the target you want to investigate. Use multi-user.target for a typical text-mode system. For a desktop that reaches graphical.target, substitute that name when the desktop startup is what you want to investigate.

bash
systemd-analyze time
systemd-analyze blame --no-pager
systemd-analyze critical-chain multi-user.target --no-pager
systemd-analyze plot > systemd-boot.svg

systemd-analyze time gives the startup intervals that systemd can report on the current boot. Read the labels alongside the elapsed times. The summary can include kernel, initrd, and userspace intervals, with firmware and loader intervals where the corresponding timing information is available. Its endpoint is tied to system startup as measured by systemd. A graphical target and the first visible application frame each supply their own milestone. An unavailable firmware interval leaves that interval unknown. systemd-analyze(1)

systemd-analyze blame sorts units by how long they spent activating. A long activation is worth investigating because the unit could be doing work itself or waiting for a resource. The table omits time jobs spent queued and can miss work that continues after a unit is considered started. For example, a service of Type=simple can be considered started immediately after the process is forked, while its application is still getting ready. Also, units can activate in parallel. Adding the durations would count overlapping intervals more than once.

systemd-analyze critical-chain follows an ordering chain associated with the target you ask about. Read @ as a point in the startup timeline and +, where shown, as the unit's activation duration. Look for a unit ordered before the target whose late activation coincides with the target being reached. Then check the unit's logs and its role in the actual product endpoint. A unit can rank high in blame while a different sequence determines when the selected target is reached. The chain is an interpretation of systemd's recorded unit timings, with limits around queued jobs, parallel startup, and socket activation. Use it to decide where to look next.

Reading startup timing viewsBlameCritical-chainBootchartShowsActivationdurationTargetorderingchainSampledprocessactivityInspectLongactivationsLatepredecessorsConcurrentactivityCheck elsewhereQueued timeFramevisibilityDependencyordering
Unit rankings, ordering chains, and process charts answer different questions about the same startup

Open systemd-boot.svg in a browser to see systemd's unit intervals along a common time axis. Compare when two units activate and whether those intervals overlap. When you need to see activity inside or across units, use a boot-time process trace. Bootchart is the original tool family, and bootchart2 is a separate implementation for recording and rendering boot activity. A bootchart2 run uses an early-started collector configured for the test image. It samples process and system activity during startup, and the recorded data is then rendered as a chart. This is optional on the Ubuntu VM. The systemd plot command above produces a unit chart using data systemd already collected.

Read a Bootchart chart by finding when the processes of interest appear and which processes run during a slow interval. Compare their lifetimes with the sampled CPU and disk activity. A long-lived helper that overlaps heavy disk activity gives you a period to investigate. The chart alone cannot attribute all of that activity to the helper or prove that the target waited for it. Short processes can fall between samples, and the collector observes only the interval during which it runs. Record its start and coverage. As with verbose kernel logging, keep collector runs distinct from the regular baseline because sampling and saving data add work.

When reviewing your baseline, ask which observed interval you would investigate first and what evidence puts it before the endpoint you care about. The practice pack has you record that judgment alongside repeat measurements. The next lesson, Kernel boot optimisation, uses those measurements to decide which kernel startup work to examine and whether a change reduces the measured interval.

Key takeaways

  • Time-to-first-frame ends when the specified application frame becomes visible.
  • Kernel log timestamps measure events on the kernel timeline.
  • The initcall_debug parameter records individual initcall timings and adds logging overhead.
  • Systemd activation times can overlap, and an ordering chain is specific to its target.
Reflect
  1. Explain to a colleague, in two sentences: define reproducible start and finish events for a boot baseline.
  2. Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
  3. What surprised you when you ran the commands yourself?
On a real board

Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.

References and further reading

Find your next step

↑ ↓ to move · Enter to open · Esc to close