From: Chen Yu <yu.c.chen@intel.com>
To: Joel Fernandes <joel@joelfernandes.org>
Cc: Honglei Wang <wanghonglei@didichuxing.com>,
Peter Zijlstra <peterz@infradead.org>,
Vincent Guittot <vincent.guittot@linaro.org>,
"Tim Chen" <tim.c.chen@intel.com>,
Mel Gorman <mgorman@techsingularity.net>,
"Juri Lelli" <juri.lelli@redhat.com>,
Rik van Riel <riel@surriel.com>, Aaron Lu <aaron.lu@intel.com>,
Abel Wu <wuyun.abel@bytedance.com>,
K Prateek Nayak <kprateek.nayak@amd.com>,
Yicong Yang <yangyicong@hisilicon.com>,
"Gautham R . Shenoy" <gautham.shenoy@amd.com>,
Ingo Molnar <mingo@redhat.com>,
"Dietmar Eggemann" <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>,
Daniel Bristot de Oliveira <bristot@redhat.com>,
Valentin Schneider <vschneid@redhat.com>,
Hillf Danton <hdanton@sina.com>, Len Brown <len.brown@intel.com>,
Chen Yu <yu.chen.surf@gmail.com>,
Tianchen Ding <dtcccc@linux.alibaba.com>,
Josh Don <joshdon@google.com>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3 1/2] sched/fair: Introduce short duration task check
Date: Mon, 5 Dec 2022 16:38:55 +0800 [thread overview]
Message-ID: <Y42uH5fglluWYOm7@chenyu5-mobl1> (raw)
In-Reply-To: <3A5DA66F-4330-4FC4-9229-998CF98F663E@joelfernandes.org>
Hi Joel,
On 2022-12-03 at 10:35:46 -0500, Joel Fernandes wrote:
>
>
> > On Dec 3, 2022, at 2:50 AM, Chen Yu <yu.c.chen@intel.com> wrote:
> >
> > Hi Honglei,
> >> On 2022-12-02 at 15:44:18 +0800, Honglei Wang wrote:
> >>
> >>
> >>> On 2022/12/1 16:44, Chen Yu wrote:
> >>> Introduce short-duration task checks, as there is requirement
> >>> to leverage this attribute for better task placement.
> >>>
> >>> There are several choices of metrics that could be used to
> >>> indicate if a task is a short-duration task.
> >>>
> >>> At first thought the (p->se.sum_exec_runtime / p->nvcsw)
> >>> could be used to measure the task duration. However, the
> >>> history long past was factored too heavily in such a formula.
> >>> Ideally, the old activity should decay and not affect
> >>> the current status too much.
> >>>
> >>> Although something based on PELT could be used, se.util_avg might
> >>> not be appropriate to describe the task duration:
> >>> 1. Task p1 and task p2 are doing frequent ping-pong scheduling on
> >>> one CPU, both p1 and p2 have a short duration, but the util_avg
> >>> can be up to 50%.
> >>> 2. Suppose a task lasting less than 4ms is regarded as a short task.
> >>> If task p3 runs for 6ms and sleeps for 32ms, p3 should not be a
> >>> short-duration task. However, PELT would decay p3's accumulated
> >>> running time from 6ms to 3ms, because 32ms is the half-life in PELT.
> >>> As a result, p3 would be incorrectly treated as a short task.
> >>>
> >>> It was found that there was once a similar feature to track the
> >>> duration of a task, which is in Commit ad4b78bbcbab ("sched: Add
> >>> new wakeup preemption mode: WAKEUP_RUNNING"). Unfortunately, it
> >>> was reverted because it was an experiment. So pick the patch up
> >>> again, by recording the average duration when a task voluntarily
> >>> switches out. Introduce SIS_SHORT to control this strategy.
> >>>
> >>> The threshold of short duration reuses sysctl_sched_min_granularity,
> >>> so it can be tuned by the user. Ideally there should be a dedicated
> >>> parameter for the threshold, but that might introduce complexity.
> >>>
> >>> Suggested-by: Tim Chen <tim.c.chen@intel.com>
> >>> Suggested-by: Vincent Guittot <vincent.guittot@linaro.org>
> >>> Signed-off-by: Chen Yu <yu.c.chen@intel.com>
> >>> ---
> >>> include/linux/sched.h | 4 ++++
> >>> kernel/sched/core.c | 2 ++
> >>> kernel/sched/fair.c | 17 +++++++++++++++++
> >>> kernel/sched/features.h | 1 +
> >>> 4 files changed, 24 insertions(+)
> >>>
> >>> diff --git a/include/linux/sched.h b/include/linux/sched.h
> >>> index ffb6eb55cd13..64b7acb77a11 100644
> >>> --- a/include/linux/sched.h
> >>> +++ b/include/linux/sched.h
> >>> @@ -558,6 +558,10 @@ struct sched_entity {
> >>> u64 nr_migrations;
> >>> + u64 prev_sum_exec_runtime_vol;
> >>> + /* average duration of a task */
> >>> + u64 dur_avg;
> >>> +
> >>> #ifdef CONFIG_FAIR_GROUP_SCHED
> >>> int depth;
> >>> struct sched_entity *parent;
> >>> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> >>> index daff72f00385..c5202f1be3f7 100644
> >>> --- a/kernel/sched/core.c
> >>> +++ b/kernel/sched/core.c
> >>> @@ -4348,6 +4348,8 @@ static void __sched_fork(unsigned long clone_flags, struct task_struct *p)
> >>> p->se.prev_sum_exec_runtime = 0;
> >>> p->se.nr_migrations = 0;
> >>> p->se.vruntime = 0;
> >>> + p->se.dur_avg = 0;
> >>> + p->se.prev_sum_exec_runtime_vol = 0;
> >>> INIT_LIST_HEAD(&p->se.group_node);
> >>> #ifdef CONFIG_FAIR_GROUP_SCHED
> >>> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> >>> index e4a0b8bd941c..a4b314b664f8 100644
> >>> --- a/kernel/sched/fair.c
> >>> +++ b/kernel/sched/fair.c
> >>> @@ -6200,6 +6200,16 @@ static int wake_wide(struct task_struct *p)
> >>> return 1;
> >>> }
> >>> +/*
> >>> + * If a task switches in and then voluntarily relinquishes the
> >>> + * CPU quickly, it is regarded as a short duration task.
> >>> + */
> >>> +static inline int is_short_task(struct task_struct *p)
> >>> +{
> >>> + return sched_feat(SIS_SHORT) &&
> >>> + (p->se.dur_avg <= sysctl_sched_min_granularity);
> >>> +}
> >>> +
> >>
> >> Hi Yu,
> >>
> >> I still have a bit concern about the sysctl_sched_min_granularity stuff..
> >> This grab can be set to different value which will impact the action of this
> >> patch and make things not totally under control.
>
> There are already ways to misconfigure sched sysctl to make bad/weird things happen.
>
> >> Not sure if we can add a new grab for this.. The test result shows good
> >> improvement for short task, and with this grab, admins will be able to
> >> custom the system base on their own 'short task' view.
> >>
> > It would be ideal to have a dedicated parameter to tweak this. For example,
> > something under /sys/kernel/debug/sched/, and initilized to sysctl_sched_min_granularity
> > by default.
>
> It would be nice to not have to introduce a new knob for this. IMO, min_granularity is reasonable.
>
OK, got it, thanks for the suggestion.
thanks,
Chenyu
next prev parent reply other threads:[~2022-12-05 8:39 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-01 8:43 [PATCH v3 0/2] sched/fair: Choose the CPU where short task is running during wake up Chen Yu
2022-12-01 8:44 ` [PATCH v3 1/2] sched/fair: Introduce short duration task check Chen Yu
2022-12-02 7:44 ` Honglei Wang
2022-12-03 7:49 ` Chen Yu
2022-12-03 15:35 ` Joel Fernandes
2022-12-05 8:38 ` Chen Yu [this message]
2022-12-05 9:59 ` Vincent Guittot
2022-12-05 14:38 ` Chen Yu
2022-12-07 2:23 ` Josh Don
2022-12-07 14:24 ` Chen Yu
2022-12-12 11:22 ` Yicong Yang
2022-12-12 14:33 ` Chen Yu
2022-12-12 18:17 ` Josh Don
2022-12-13 5:46 ` Chen Yu
2022-12-13 10:06 ` Honglei Wang
2022-12-13 12:24 ` Chen Yu
2022-12-01 8:44 ` [PATCH v3 2/2] sched/fair: Choose the CPU where short task is running during wake up Chen Yu
2022-12-05 2:36 ` Tianchen Ding
2022-12-05 8:40 ` Chen Yu
2022-12-06 13:02 ` Yicong Yang
2022-12-07 3:54 ` Chen Yu
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=Y42uH5fglluWYOm7@chenyu5-mobl1 \
--to=yu.c.chen@intel.com \
--cc=aaron.lu@intel.com \
--cc=bristot@redhat.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=dtcccc@linux.alibaba.com \
--cc=gautham.shenoy@amd.com \
--cc=hdanton@sina.com \
--cc=joel@joelfernandes.org \
--cc=joshdon@google.com \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=len.brown@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@techsingularity.net \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=riel@surriel.com \
--cc=rostedt@goodmis.org \
--cc=tim.c.chen@intel.com \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=wanghonglei@didichuxing.com \
--cc=wuyun.abel@bytedance.com \
--cc=yangyicong@hisilicon.com \
--cc=yu.chen.surf@gmail.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