Page MenuHomeFreeBSD

SYSINIT: add explicit SI_ORDER_LAST
ClosedPublic

Authored by glebius on Fri, Aug 7, 10:18 PM.
Tags
None
Referenced Files
F168724837: D58709.id183880.diff
Sat, Aug 29, 8:06 PM
F168724258: D58709.id183880.diff
Sat, Aug 29, 8:02 PM
Unknown Object (File)
Fri, Aug 28, 11:05 PM
Unknown Object (File)
Tue, Aug 25, 5:42 AM
Unknown Object (File)
Sat, Aug 22, 3:15 AM
Unknown Object (File)
Fri, Aug 21, 5:02 PM
Unknown Object (File)
Fri, Aug 21, 8:37 AM
Unknown Object (File)
Thu, Aug 20, 4:16 PM

Details

Summary

Working on cleansing use of (SI_SUB_FOO + 1) construct through the kernel
I found a repeating pattern. Often a developer adds a module that depends
on certain subsystem to be fully instantiated and they want to put their
module SYSINIT right at the end of the SI_SUB_FOO. Such module usually
expects that nothing else within this subsystem shall depend on the
module.

The problem with SI_ORDER_ANY which practically was "the last" until this
change is that it is used very widely and people treat it literally as
"any", well, because this is what the name says. This lead to many parts
that could have dependencies later to be added as SI_ORDER_ANY.

So, our developer with the new subsystem that depends on SI_SUB_FOO has
three options:

  1. Use SI_ORDER_ANY, but grep around ther kernel for other SI_SUB_FOO

entries to make sure that no dependencies are set to SI_ORDER_ANY. And in
case they are, shift them up and recheck if dependencies of those
dependencies are met.

  1. Take next subsystem in sysinit list. However, the next one can be

SI_SUB_BAR, that is completely irrelevant from SI_SUB_FOO, and our
developer doesn't want to put his module's SYSINIT into SI_SUB_BAR, cause
it is ugly.

  1. Use the (SI_SUB_FOO + 1) construct that violates -Werror=assign-enum.

The SI_ORDER_LAST solves this hard choice. If you know that nothing is
going to depend on your module within SI_SUB_FOO, but you depend on
SI_SUB_FOO, just use SI_ORDER_LAST.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

I somewhat dislike the name SI_ORDER_LAST because it suggests it should be the final one in the list, and seems to be in conflict if two SYSINITS share a SI_SUB_WHATEVER, SI_ORDER_LAST. Would SI_ORDER_END be reasonable?

I somewhat dislike the name SI_ORDER_LAST because it suggests it should be the final one in the list, and seems to be in conflict if two SYSINITS share a SI_SUB_WHATEVER, SI_ORDER_LAST. Would SI_ORDER_END be reasonable?

I think SI_ORDER_LAST is fine, it mirrors SI_ORDER_FIRST and is neither more nor less ambiguous.

Thanks, Dag-Erling. Yes, END would be good if we had BEGIN and we don't have it.

I'd also like to augment the documentation. Right now SYSINIT(9) doesn't document orders at all. I will write something like:

  1. SI_ORDER_FIRST ... SI_ORDER_FIFTH provide explicit order and should be used for those subsystem parts that are being dependencies of parts that are loaded later.
  2. SI_ORDER_ANY is executed after all explicit orders and those parts may depend on parts with explicit ordering. Parts executed at SI_ORDER_ANY shall not be dependencies of other parts, but there are historical violations of that rule.
  3. SI_ORDER_LAST is executed last and parts under this order shall never be dependencies of other parts within the same subsystem.

I'll add documentation to the diff once I see general agreement with this change.

This revision was not accepted when it landed; it landed in state Needs Review.Tue, Aug 11, 2:41 PM
This revision was automatically updated to reflect the committed changes.

Just a general comment.

This regularization of SI_ORDER and SI_SUB is a very a good improvement.

But based on the descriptions of the changes, it seems that magic numbers (even indirected by magic constants) are not the best way to order dependencies.
Maybe subsystems need the same dependency declaration mechanism that modules have.
Or, perhaps, subsystems can even be defined as some kind of modules.

In D58709#1348972, @avg wrote:

Just a general comment.

This regularization of SI_ORDER and SI_SUB is a very a good improvement.

But based on the descriptions of the changes, it seems that magic numbers (even indirected by magic constants) are not the best way to order dependencies.
Maybe subsystems need the same dependency declaration mechanism that modules have.
Or, perhaps, subsystems can even be defined as some kind of modules.

I was thinking of rcorder(8) for kernel. Of course run at compilation time, not an startup.

I'm not taking this task :) I just want to make kernel -Werror-assing-enum clean.

I was thinking of rcorder(8) for kernel. Of course run at compilation time, not an startup.

I'm not taking this task :) I just want to make kernel -Werror-assing-enum clean.

This is the sort of thing that used to be, or would be a great idea for those old Project Ideas or Kernel Tasks/Wanted Features that used to exist somewhere. A brief with how rcorder works, the code location, how this could done at compile time, similar works, other short ideas on this could get started, what testing would be required, potential pitfalls and whatnot would be great.