Re: [PATCH v2] lib/smp_processor_id: Use is_percpu_thread() check affinity

From: Valentin Schneider
Date: Mon May 10 2021 - 10:39:49 EST


On 10/05/21 21:43, Yejune Deng wrote:
> Use is_percpu_thread() instead of 'current->nr_cpus_allowed == 1',
> and add PF_NO_SETAFFINITY flag in init_idle().This would be nice to
> the sched_setaffinity(), and it also more readable.
>
> v1->v2:
> - add PF_NO_SETAFFINITY flag in init_idle().
>
> Signed-off-by: Yejune Deng <yejunedeng@xxxxxxxxx>
> ---
> kernel/sched/core.c | 2 +-
> lib/smp_processor_id.c | 6 +-----
> 2 files changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 9143163..82e21ea 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -7446,7 +7446,7 @@ void init_idle(struct task_struct *idle, int cpu)
>
> idle->state = TASK_RUNNING;
> idle->se.exec_start = sched_clock();
> - idle->flags |= PF_IDLE;
> + idle->flags |= PF_IDLE | PF_NO_SETAFFINITY;

Thanks for spinning a v2!

Peter reminded me that it's not the only flag the idle task is missing, so
I went and wrote something to make the idle task really look like a run of
the mill pcpu kthread. I'll bundle your v1 with it.