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)
Tue, Dec 3, 11:21 AM
Unknown Object (File)
Tue, Dec 3, 8:06 AM
Unknown Object (File)
Tue, Nov 19, 12:03 PM
Unknown Object (File)
Oct 7 2024, 4:15 AM
Unknown Object (File)
Sep 24 2024, 9:49 PM
Unknown Object (File)
Sep 24 2024, 9:49 PM
Unknown Object (File)
Sep 24 2024, 9:36 PM
Unknown Object (File)
Sep 18 2024, 10:15 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 .