[RFC v2 7/9] sched: Add static key check for cpu_avoid

Yury Norov yury.norov at gmail.com
Thu Jun 26 10:12:08 AEST 2025


On Thu, Jun 26, 2025 at 12:41:06AM +0530, Shrikanth Hegde wrote:
> Checking if a CPU is avoid can add a slight overhead and should be 
> done only when necessary. 
> 
> Add a static key check which makes it almost nop when key is false. 
> Arch needs to set the key when it decides to. Refer to debug patch
> for example. 
> 
> Signed-off-by: Shrikanth Hegde <sshegde at linux.ibm.com>
> ---
> This method avoids additional ifdefs. So kept it that way instead of 
> CONFIG_PARAVIRT. 
> 
> Added a helper function for cpu_avoid, since including sched.h fails in 
> cpumask.h
> 
>  kernel/sched/core.c  | 8 ++++----
>  kernel/sched/fair.c  | 5 +++--
>  kernel/sched/rt.c    | 8 ++++----
>  kernel/sched/sched.h | 9 +++++++++
>  4 files changed, 20 insertions(+), 10 deletions(-)
> 
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index aea4232e3ec4..51426b17ef55 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -148,9 +148,9 @@ __read_mostly int sysctl_resched_latency_warn_once = 1;
>   * Limited because this is done with IRQs disabled.
>   */
>  __read_mostly unsigned int sysctl_sched_nr_migrate = SCHED_NR_MIGRATE_BREAK;
> -
>  __read_mostly int scheduler_running;
>  
> +DEFINE_STATIC_KEY_FALSE(paravirt_cpu_avoid_enabled);
>  #ifdef CONFIG_SCHED_CORE
>  
>  DEFINE_STATIC_KEY_FALSE(__sched_core_enabled);
> @@ -2438,7 +2438,7 @@ static inline bool is_cpu_allowed(struct task_struct *p, int cpu)
>  		return false;
>  
>  	/* CPU marked as avoid, shouldn't chosen to run any task*/
> -	if (cpu_avoid(cpu))
> +	if (cpu_avoid_check(cpu))
>  		return false;

Here you're patching the code that you've just added. Can you simply
add it in a proper way?..


More information about the Linuxppc-dev mailing list