From: Tim Chen <tim.c.chen@linux.intel.com>
To: WangJinchao <wangjinchao@xfusion.com>,
Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Daniel Bristot de Oliveira <bristot@redhat.com>,
Valentin Schneider <vschneid@redhat.com>,
linux-kernel@vger.kernel.org
Cc: stone.xulei@xfusion.com
Subject: Re: [PATCH] sched/fair: merge same code in enqueue_task_fair
Date: Mon, 11 Dec 2023 14:22:07 -0800 [thread overview]
Message-ID: <471d24f71cc531448572e2fc5964f1231e7ef7b3.camel@linux.intel.com> (raw)
In-Reply-To: <202312101719+0800-wangjinchao@xfusion.com>
On Sun, 2023-12-10 at 17:21 +0800, WangJinchao wrote:
> 1. The code below is duplicated in two for loops and need to be
> consolidated
> 2. Fix the bug where a se's on_rq is true but its parent is not
In the current code, If a se is already on a rq, all the parents would have already been
on rq too. I don't think there's a case where se's on_rq and parent
is not for the current code before your patch. Otherwise the child
would never get scheduled. I don't think we have seen such bug being
reported.
>
> ```c
> cfs_rq->h_nr_running++;
> cfs_rq->idle_h_nr_running += idle_h_nr_running;
>
> if (cfs_rq_is_idle(cfs_rq))
> idle_h_nr_running = 1;
>
> /* end evaluation on encountering a throttled cfs_rq */
> if (cfs_rq_throttled(cfs_rq))
> goto enqueue_throttle;
> ```
>
> Signed-off-by: WangJinchao <wangjinchao@xfusion.com>
> ---
> kernel/sched/fair.c | 31 ++++++++-----------------------
> 1 file changed, 8 insertions(+), 23 deletions(-)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index d7a3c63a2171..e1373bfd4f2e 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -6681,30 +6681,15 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)
> cpufreq_update_util(rq, SCHED_CPUFREQ_IOWAIT);
>
> for_each_sched_entity(se) {
> - if (se->on_rq)
> - break;
> cfs_rq = cfs_rq_of(se);
> - enqueue_entity(cfs_rq, se, flags);
> -
> - cfs_rq->h_nr_running++;
> - cfs_rq->idle_h_nr_running += idle_h_nr_running;
> -
> - if (cfs_rq_is_idle(cfs_rq))
> - idle_h_nr_running = 1;
> -
> - /* end evaluation on encountering a throttled cfs_rq */
> - if (cfs_rq_throttled(cfs_rq))
> - goto enqueue_throttle;
> -
> - flags = ENQUEUE_WAKEUP;
> - }
> -
> - for_each_sched_entity(se) {
> - cfs_rq = cfs_rq_of(se);
> -
> - update_load_avg(cfs_rq, se, UPDATE_TG);
> - se_update_runnable(se);
> - update_cfs_group(se);
> + if (se->on_rq) {
> + update_load_avg(cfs_rq, se, UPDATE_TG);
> + se_update_runnable(se);
> + update_cfs_group(se);
> + } else {
> + enqueue_entity(cfs_rq, se, flags);
> + flags = ENQUEUE_WAKEUP;
> + }
The code change looks like a reasonable simplification. Logic
is the same as the old code, assuming that once a se's on_rq flag
is true, all its parents are too.
Thanks.
Tim
>
> cfs_rq->h_nr_running++;
> cfs_rq->idle_h_nr_running += idle_h_nr_running;
prev parent reply other threads:[~2023-12-11 22:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-10 9:21 [PATCH] sched/fair: merge same code in enqueue_task_fair WangJinchao
2023-12-11 15:23 ` Vincent Guittot
2023-12-13 7:03 ` Wang Jinchao
2023-12-13 8:23 ` Vincent Guittot
2023-12-14 9:47 ` Wang Jinchao
2023-12-14 12:10 ` Abel Wu
2023-12-14 12:42 ` Wang Jinchao
2023-12-11 22:22 ` Tim Chen [this message]
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=471d24f71cc531448572e2fc5964f1231e7ef7b3.camel@linux.intel.com \
--to=tim.c.chen@linux.intel.com \
--cc=bristot@redhat.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=stone.xulei@xfusion.com \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=wangjinchao@xfusion.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