Re: [PATCH RFC] sched: Micro optimization in pick_next_task() and in check_preempt_curr()

From: Kirill Tkhai
Date: Thu Dec 19 2019 - 08:54:01 EST


On 19.12.2019 16:50, Steven Rostedt wrote:
> On Thu, 19 Dec 2019 15:39:14 +0300
> Kirill Tkhai <ktkhai@xxxxxxxxxxxxx> wrote:
>
>> @@ -6569,6 +6558,11 @@ void __init sched_init(void)
>> unsigned long ptr = 0;
>> int i;
>>
>> + BUG_ON(&idle_sched_class > &fair_sched_class ||
>> + &fair_sched_class > &rt_sched_class ||
>> + &rt_sched_class > &dl_sched_class ||
>> + &dl_sched_class > &stop_sched_class);
>> +
>
> Can this be a BUILD_BUG_ON? These address should all be constants.

BUILD_BUG_ON() is compile-time check, while address is assigned
at link time, isn't it?!

Anyway, plain BUILD_BUG_ON() fails here with the following:

In file included from ./arch/x86/include/asm/current.h:5,
from ./include/linux/sched.h:12,
from kernel/sched/sched.h:5,
from kernel/sched/core.c:9:
kernel/sched/core.c: In function âsched_initâ:
./include/linux/compiler.h:394:38: error: call to â__compiletime_assert_6561â declared with attribute error: BUILD_BUG_ON failed: &idle_sched_class > &fair_sched_class || &fair_sched_class > &rt_sched_class || &rt_sched_class > &dl_sched_class || &dl_sched_class > &stop_sched_class
394 | _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
| ^
./include/linux/compiler.h:375:4: note: in definition of macro â__compiletime_assertâ
375 | prefix ## suffix(); \
| ^~~~~~
./include/linux/compiler.h:394:2: note: in expansion of macro â_compiletime_assertâ
394 | _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
| ^~~~~~~~~~~~~~~~~~~
./include/linux/build_bug.h:39:37: note: in expansion of macro âcompiletime_assertâ
39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
| ^~~~~~~~~~~~~~~~~~
./include/linux/build_bug.h:50:2: note: in expansion of macro âBUILD_BUG_ON_MSGâ
50 | BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
| ^~~~~~~~~~~~~~~~
kernel/sched/core.c:6561:2: note: in expansion of macro âBUILD_BUG_ONâ
6561 | BUILD_BUG_ON(&idle_sched_class > &fair_sched_class ||
| ^~~~~~~~~~~~


> -- Steve
>
>
>
>> wait_bit_init();
>>