From: Peter Zijlstra <peterz@infradead.org>
To: Zhan Xusheng <zhanxusheng1024@gmail.com>
Cc: vincent.guittot@linaro.org, dietmar.eggemann@arm.com,
linux-sched@vger.kernel.org, linux-kernel@vger.kernel.org,
Zhan Xusheng <zhanxusheng@xiaomi.com>
Subject: Re: [PATCH] sched/fair: factor out common sched_entity stats/task lookup
Date: Thu, 18 Dec 2025 09:14:09 +0100 [thread overview]
Message-ID: <20251218081409.GG3707891@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20251217070040.8723-1-zhanxusheng@xiaomi.com>
On Wed, Dec 17, 2025 at 03:00:40PM +0800, Zhan Xusheng wrote:
> The fair scheduler has several update_stats_*_fair() helpers which
> open-code the same boilerplate to retrieve sched_statistics and the
> associated task (if any) from a sched_entity.
>
> Factor this common logic into a small static inline helper to reduce
> duplication and improve readability, without changing behaviour or
> control flow.
>
> No functional change intended.
>
> Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
> ---
> kernel/sched/fair.c | 24 ++++++++++++------------
> 1 file changed, 12 insertions(+), 12 deletions(-)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index da46c3164537..b4a9319a5753 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -1243,6 +1243,15 @@ static void update_curr_fair(struct rq *rq)
> update_curr(cfs_rq_of(&rq->donor->se));
> }
>
> +static inline void
> +get_se_stats_and_task(struct sched_entity *se,
> + struct sched_statistics **stats,
> + struct task_struct **p)
> +{
> + *stats = __schedstats_from_se(se);
> + *p = entity_is_task(se) ? task_of(se) : NULL;
> +}
> +
> static inline void
> update_stats_wait_start_fair(struct cfs_rq *cfs_rq, struct sched_entity *se)
> {
> @@ -1252,10 +1261,7 @@ update_stats_wait_start_fair(struct cfs_rq *cfs_rq, struct sched_entity *se)
> if (!schedstat_enabled())
> return;
>
> - stats = __schedstats_from_se(se);
> -
> - if (entity_is_task(se))
> - p = task_of(se);
> + get_se_stats_and_task(se, &stats, &p);
>
> __update_stats_wait_start(rq_of(cfs_rq), p, stats);
> }
> @@ -1269,7 +1275,7 @@ update_stats_wait_end_fair(struct cfs_rq *cfs_rq, struct sched_entity *se)
> if (!schedstat_enabled())
> return;
>
> - stats = __schedstats_from_se(se);
> + get_se_stats_and_task(se, &stats, &p);
>
> /*
> * When the sched_schedstat changes from 0 to 1, some sched se
> @@ -1280,9 +1286,6 @@ update_stats_wait_end_fair(struct cfs_rq *cfs_rq, struct sched_entity *se)
> if (unlikely(!schedstat_val(stats->wait_start)))
> return;
>
> - if (entity_is_task(se))
> - p = task_of(se);
> -
> __update_stats_wait_end(rq_of(cfs_rq), p, stats);
> }
>
> @@ -1295,10 +1298,7 @@ update_stats_enqueue_sleeper_fair(struct cfs_rq *cfs_rq, struct sched_entity *se
> if (!schedstat_enabled())
> return;
>
> - stats = __schedstats_from_se(se);
> -
> - if (entity_is_task(se))
> - tsk = task_of(se);
> + get_se_stats_and_task(se, &stats, &p);
>
> __update_stats_enqueue_sleeper(rq_of(cfs_rq), tsk, stats);
> }
Urgh, no. The stats and task things are unrelated, so munging them
together like this makes no sense.
Worse, the helper is terrible for failing to use the return value for
its intended purpose.
next prev parent reply other threads:[~2025-12-18 8:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-17 7:00 Zhan Xusheng
2025-12-18 8:14 ` Peter Zijlstra [this message]
2025-12-21 18:52 ` kernel test robot
2025-12-21 20:54 ` kernel test robot
2025-12-17 18:50 Shubhang Kaushik Prasanna Kumar
2025-12-17 18:50 Shubhang Kaushik Prasanna Kumar
2025-12-17 19:22 Shubhang Kaushik Prasanna Kumar
2025-12-17 19:22 ` Shubhang Kaushik Prasanna Kumar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251218081409.GG3707891@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=dietmar.eggemann@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sched@vger.kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=zhanxusheng1024@gmail.com \
--cc=zhanxusheng@xiaomi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®