Re: [PATCH v6 2/3] sched/fair: Remove task_group->se pointer array
From: Josh Don
Date: Thu Jan 15 2026 - 19:56:58 EST
On Mon, Jan 12, 2026 at 10:51 AM Zecheng Li <zli94@xxxxxxxx> wrote:
>
> From: Zecheng Li <zecheng@xxxxxxxxxx>
>
> Now that struct sched_entity is co-located with struct cfs_rq for
> non-root task groups, the task_group->se pointer array is redundant. The
> associated sched_entity can be loaded directly from the cfs_rq.
>
> This patch performs the access conversion with the helpers:
>
> - is_root_task_group(tg): checks if a task group is the root task group.
> It compares the task group's address with the global root_task_group
> variable.
>
> - tg_se(tg, cpu): retrieves the cfs_rq and returns the address of the
> co-located se. This function checks if tg is the root task group to
> ensure behaving the same of previous tg->se[cpu]. Replaces all accesses
> that use the tg->se[cpu] pointer array with calls to the new tg_se(tg,
> cpu) accessor.
>
> - cfs_rq_se(cfs_rq): simplifies access paths like cfs_rq->tg->se[...] to
> use the co-located sched_entity. This function also checks if tg is the
> root task group to ensure same behavior.
>
> Since tg_se is not in very hot code paths, and the branch is a register
> comparison with an immediate value (`&root_task_group`), the performance
> impact is expected to be negligible.
>
> Signed-off-by: Zecheng Li <zecheng@xxxxxxxxxx>
> Signed-off-by: Zecheng Li <zli94@xxxxxxxx>
> ---
> kernel/sched/core.c | 7 ++-----
> kernel/sched/debug.c | 2 +-
> kernel/sched/fair.c | 25 +++++++++----------------
> kernel/sched/sched.h | 29 ++++++++++++++++++++++++-----
> 4 files changed, 36 insertions(+), 27 deletions(-)
[snip]
> +
> +static inline struct sched_entity *cfs_rq_se(struct cfs_rq *cfs_rq)
> +{
> + if (is_root_task_group(cfs_rq->tg))
> + return NULL;
> +
> + struct cfs_rq_with_se *combined =
> + container_of(cfs_rq, struct cfs_rq_with_se, cfs_rq);
> + return &combined->ses.se;
> +}
> #endif
>
This is fine, but just wanted to mention that we could also follow the
pattern of se->my_q and embed the se pointer inside the cfs_rq
instead. I think what you have now is ok though.