Page MenuHomeFreeBSD

sched: New scheduler interface definition and implementation scheme
Needs ReviewPublic

Authored by olce on Thu, Sep 24, 2:06 PM.

Details

Reviewers
emaste
kib
Group Reviewers
scheduler
Summary

Development of this new scheme was prompted by the following goals:

  1. The scheduler interface should be defined once and for all (in 'sys/sys/sched.h') and all code duplication related to it (function signatures, slot names, dispatch, scheduler instance declaration) should be removed, making it easier to modify the interface or to add new schedulers.
  2. The implementation functions in all schedulers should be renamed back to their original names. Changing these names was not really necessary technically. It introduced unwanted churn and cognitive burden, and inconsistencies with the existing documentation (mostly in the form of code comments) which had not been updated. Additionally, this was in contradiction with the "shim" (transparent, lightweight) intended nature of the dispatch mechanism.
  3. Re-establish inlining opportunities in internal scheduler code without further cluttering the existing code (which changing it to use scheduler-specific names would do).

The chosen implementation brings additional benefits, which are
described below.

Point 1 is implemented by defining the interface as X macros, so that
lists of function declarations, field names in 'struct sched_instance'
and assignments to these fields, as well as the dispatch code, can be
generated simply from the interface description. These X macros are
passed a macro that is "called" with a variable number of arguments
describing a single function of the interface. The convention used for
a function's parameters is that each parameter is represented with two
macro arguments, the first one being the type and the second one being
the name. Helper macros allow to process arguments described in this
convention in order to generate a list of arguments for function
definitions (currently, up to 4 parameters). The chosen convention
eliminates the need for any specific declaration of functions depending
on their number of arguments. It is future-proof in that it also allows
listing the argument names without their types simply. (It also forces
the use of typedefs for complex argument types, if some ever appear.)

Point 2 and 3 are implemented, on one hand, by declaring interface
functions as having external linkage (in 'sys/sys/sched.h'), providing
corresponding dispatching implementations using ifuncs (as in the
original mechanism; in 'sys/kern/sched_shim.c'), and on the other hand,
by declaring functions with same name but internal linkage when
'sys/sys/sched.h' is included by a scheduler implementation (via the
definition of a specific macro prior to inclusion).

DECLARE_SCHEDULER() has been changed to automatically declare and fill
a 'struct sched_instance' structure. Its number of parameters has been
reduced to the minimum, and the symbol part used to produce distinct
structure names can now start with a digit (useful for 4BSD).

The new implementation has the following additional benefits:

  1. The name of implementations for the interface functions is imposed (same name as the interface function) and checked at compile-time.
  2. Missing functions in an implementation are detected at compile-time (and not at runtime with a NULL dereference).
  3. Failures to fill correctly the 'struct sched_instance' object associated to an implementation are eliminated.

Preserve comments/categories of interface functions by moving comments
that were in the old explicit interface declarations to the SCHED_ITF*()
macros, and while here, marginally improve some (and move the common
documentation for sched_initticks() from the implementations to the
interface). Several of them are not exact, but this will be fixed in
a separate commit.

Fixes: ce38acee8d0b ("Add kern/sched_shim.c") (+ some followups)
Sponsored by: The FreeBSD Foundation

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 77278
Build 74161: arc lint + arc unit