Re: [PATCH 1/1] sched/fair:Avoid unnecessary assignment to cfs_rq->on_list

From: Vincent Guittot
Date: Thu Jan 07 2021 - 03:28:28 EST


On Thu, 7 Jan 2021 at 02:57, <qianjun.kernel@xxxxxxxxx> wrote:
>
> From: jun qian <qianjun.kernel@xxxxxxxxx>
>
> Obviously, cfs_rq->on_list is already equal to 1 when cfs_rq->on_list
> is assigned a value of 1, so an else branch is needed to avoid unnecessary
> assignment operations.
>
> Signed-off-by: jun qian <qianjun.kernel@xxxxxxxxx>
> ---
> kernel/sched/fair.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 04a3ce20da67..ef6ebd95443d 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -305,8 +305,8 @@ static inline bool list_add_leaf_cfs_rq(struct cfs_rq *cfs_rq)
>
> if (cfs_rq->on_list)
> return rq->tmp_alone_branch == &rq->leaf_cfs_rq_list;

if cfs_rq->on_list == 1, list_add_leaf_cfs_rq() returns and will not
unnecessary set cfs_rq->on_list

so your change is useless but makes the code less readable

> -
> - cfs_rq->on_list = 1;
> + else
> + cfs_rq->on_list = 1;
>
> /*
> * Ensure we either appear before our parent (if already
> --
> 2.18.2
>