Re: [PATCH 5/6] sched/preempt: add PREEMPT_DYNAMIC using static keys

Frederic Weisbecker
2022-02-02T23:21:53Z

On Tue, Nov 09, 2021 at 05:24:07PM +0000, Mark Rutland wrote:
> diff --git a/include/linux/kernel.h b/include/linux/kernel.h
> index e5359b09de1d..8a94ccfc7dc8 100644
> --- a/include/linux/kernel.h
> +++ b/include/linux/kernel.h
> @@ -93,7 +93,7 @@ struct user;
> extern int __cond_resched(void);
> # define might_resched() __cond_resched()
>
> -#elif defined(CONFIG_PREEMPT_DYNAMIC)
> +#elif defined(CONFIG_PREEMPT_DYNAMIC) && defined(CONFIG_HAVE_PREEMPT_DYNAMIC_CALL)
>
> extern int __cond_resched(void);
>
> @@ -104,6 +104,11 @@ static __always_inline void might_resched(void)
> static_call_mod(might_resched)();
> }
>
> +#elif defined(CONFIG_PREEMPT_DYNAMIC) && defined(CONFIG_HAVE_PREEMPT_DYNAMIC_KEY)
> +
> +extern int dynamic_might_resched(void);
> +# define might_resched() dynamic_might_resched()
> +
> #else
>
> # define might_resched() do { } while (0)
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index 78c351e35fec..7710b6593c72 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -2008,7 +2008,7 @@ static inline int test_tsk_need_resched(struct task_struct *tsk)
> #if !defined(CONFIG_PREEMPTION) || defined(CONFIG_PREEMPT_DYNAMIC)
> extern int __cond_resched(void);
>
> -#ifdef CONFIG_PREEMPT_DYNAMIC
> +#if defined(CONFIG_PREEMPT_DYNAMIC) && defined(CONFIG_HAVE_PREEMPT_DYNAMIC_CALL)
>
> DECLARE_STATIC_CALL(cond_resched, __cond_resched);
>
> @@ -2017,6 +2017,14 @@ static __always_inline int _cond_resched(void)
> return static_call_mod(cond_resched)();
> }
>
> +#elif defined(CONFIG_PREEMPT_DYNAMIC) && defined(CONFIG_HAVE_PREEMPT_DYNAMIC_KEY)
> +extern int dynamic_cond_resched(void);
> +
> +static __always_inline int _cond_resched(void)
> +{
> + return dynamic_cond_resched();

So in the end this is creating an indirect call for every preemption entrypoint.
It seems to me that this loses the whole point of using static keys.

Is there something that prevents from using inlines or macros?

Thanks.