Page MenuHomeFreeBSD

kernel: Add automation to sort all constructors and destructors at compile time.
AbandonedPublic

Authored by hselasky on May 21 2023, 4:16 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Apr 22, 6:38 PM
Unknown Object (File)
Sat, Apr 20, 2:52 PM
Unknown Object (File)
Sun, Apr 7, 5:06 AM
Unknown Object (File)
Dec 20 2023, 4:02 AM
Unknown Object (File)
Dec 12 2023, 8:28 AM
Unknown Object (File)
Dec 8 2023, 12:38 AM
Unknown Object (File)
Nov 5 2023, 2:25 PM
Unknown Object (File)
Sep 18 2023, 10:27 AM

Details

Reviewers
imp
kib
Summary

List of changes:

  1. Factor out sorting function for all constructors and destructors.
  2. Use insertion sort instead of bubble sort. Because insertion sort is much faster when the data is already sorted.
  3. Add generic automation layer to sort constructors and destructors at compile time.
  4. Invert subsystem and order values for all destructors to reflect actual order. Because then only one sorting function is needed.

MFC after: 1 week
Sponsored by: NVIDIA Networking

Test Plan

Added some prints and verified no sysinit sorting was done during startup, also when loading modules.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

hselasky created this revision.

I'll have to study this in detail... it's a bigger change than I thought it would be...

sys/kern/init_main.c
241

Won't klds create unsorted entries at the end?

In D40193#915024, @imp wrote:

I'll have to study this in detail... it's a bigger change than I thought it would be...

Right. When there is no compiler support.

The problem with the constructor attribute is when you load KLD's that you need to merge two constructor lists. I didn't spend time on that.

hselasky added inline comments.
sys/kern/init_main.c
241

The KLDs loaded at boot, also have a sorted init and uninit section after my change.

That's why I modified sysinit_add() to merge two sorted lists, instead of just concatenating the lists.

When you merge two sorted lists, the resulting list also becomes sorted, and then no further sorting is needed.

hselasky marked an inline comment as done.

This revision is abandoned in favor of D40463 .