Each scheduling policy (like SCHED_NORMAL, SCHED_FIFO etc..) is implemented as a struct sched_class, and instances like fair_sched_class, rt_sched_class, dl_sched_class, etc., are defined using the DEFINE_SCHED_CLASS() macro:
#define DEFINE_SCHED_CLASS(name) \
const struct sched_class name##_sched_class \
__aligned(__alignof__(struct sched_class)) \
__section("__" #name "_sched_class")
These class instances are then placed in a specific order in memory using the linker script (vmlinux.lds.h) via the SCHED_DATA section:
#define SCHED_DATA \
STRUCT_ALIGN(); \
__sched_class_highest = .; \
*(__stop_sched_class) \
*(__dl_sched_class) \
*(__rt_sched_class) \
*(__fair_sched_class) \
*(__idle_sched_class) \
__sched_class_lowest = .;
Early in the sched_init()
we check the following ?
BUG_ON(&idle_sched_class != &fair_sched_class + 1 ||
&fair_sched_class != &rt_sched_class + 1 ||
&rt_sched_class != &dl_sched_class + 1);
My question: Why is it so critical that these sched_class structures be contiguous in memory?
I understand that for priority purposes it should be ordered. But why the padding is mandatory ? Why is there a hard check on "&a == &b + 1" rather than just relying on the logical order?