Speeding up the FreeBSD boot process

Description

Using the TSLOG framework, and flamecharts, the objective of this project is to discover, and alleviate any unnecessary, or inefficient processes taking place during the boot process. Some examples of major time-wasters in FreeBSD include the device event management daemon /sbin/devd (especially on aarch64), and dhclient which is responsible for soliciting an IP address from a network's DHCP server.

Deliverables

To prove that the boot process is being sped up, flamecharts are produced, and used to measure the time reductions. This follows patches to the operating system that make the profiling of boot hotspots more verbose, as well as patches to speed up the boot process itself.

Test Plan

In conjunction with the previous paragraph, before, and after flamecharts are used to see the difference made by the changes. To verify that everything works smoothly, the software patches are trialled, and liason is made between the student, mentor, and relevant code owners to see that there are no conflicts with other parts of the system. This usually takes place via a combination of email, Phabricator revisions, and GitHub pull requests.

Bugs Reported

This is a list of some of the bugs I had tripped over, and reported.

SCMI VirtIO Transport Driver

aarch64 kernels wouldn't compile without std.virt included.

Re: git: a87dd74125d2 - main - scmi: Add an SCMI VirtIO transport driver

Patches Delivered

The following is a list of all the patches authored that ended up on the tree for GSoC '24.

TSLOG on aarch64

Initially, TSLOG-enabled kernels on aarch64 would compile, but wouldn't boot. The dynamic linker was being set up after curthread, and the complementary PCPU datastructures, causing the kernel to break. This wasn't an issue on amd64, due to the GDT register being readable early on in the boot, but was on aarch64. Therefore, the initialisation of curthread was moved to precede that of the dynamic linker.

* Phabricator: Changed order of aarch64 events such that TSLOG-enabled kernels are able to boot

* GitHub: Move curthread setup earlier

sysctl to disable NOMATCH events on boot (~ 200 ms)

Any NOMATCH event that occurs before devmatch starts has to be thrown again, making it redundant. A new sysctl was introduced to control the generation of these particular events on boot, allowing for them to be suppressed initially, effectively preventing redundancies.

* Phabricator: Throws exception to block redundant devmatch events

* Phabricator: Enable nomatch events when one_nomatch is empty

* GitHub: New sysctl to disable NOMATCH until devmatch runs

Reduced dhclient timeout for ARP (~ 2000 ms)

The timeout for ARP resolution has traditionally been set to 2 seconds. This could be reduced, or even removed altogether to save time. Thus, this change reduces the default timeout value to 250 ms, and adds a flag to dhclient, allowing for it to be set to 0 ms. The latter is permissible on networks where the DHCP server is certain to know whether an IP address is available, like in a cloud environment.

* GitHub PR: Set default ARP resolution wait to 250 ms, with an option to make it 0 ms

* GitHub: Switch timeouts from time_t to timespec

* GitHub: Timeouts for entering state_selecting

* GitHub: Use clock_gettime() instead of time()

* GitHub: Make arp_timeout configurable

* GitHub: Update dhclient man page for n flag

* GitHub: rc.conf option to disable ARP resolution

* GitHub: Update rc.conf.5 with dhclient_arpwait

Results

The boot process was sped up by about 2.2 seconds on virtualised aarch64!


CategoryGsoc

SummerOfCode2024Projects/SpeedingUpTheFreeBSDBootProcess (last edited 2024-11-18T09:38:15+0000 by IsaacCiliaAttard)