From: Pierre Gondois <pierre.gondois@arm.com>
To: Vincent Guittot <vincent.guittot@linaro.org>,
mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com,
dietmar.eggemann@arm.com, rostedt@goodmis.org,
bsegall@google.com, mgorman@suse.de, vschneid@redhat.com,
lukasz.luba@arm.com, rafael.j.wysocki@intel.com,
linux-kernel@vger.kernel.org
Cc: qyousef@layalina.io, hongyan.xia2@arm.com
Subject: Re: [RFC PATCH 5/5] sched/fair: Add push task callback for EAS
Date: Wed, 11 Sep 2024 16:03:11 +0200 [thread overview]
Message-ID: <ccf4095f-5fca-42f4-b9fe-aa93e703016e@arm.com> (raw)
In-Reply-To: <20240830130309.2141697-6-vincent.guittot@linaro.org>
Hello Vincent,
On 8/30/24 15:03, Vincent Guittot wrote:
> EAS is based on wakeup events to efficiently place tasks on the system, but
> there are cases where a task will not have wakeup events anymore or at a
> far too low pace. For such situation, we can take advantage of the task
> being put back in the enqueued list to check if it should be migrated on
> another CPU. When the task is the only one running on the CPU, the tick
> will check it the task is stuck on this CPU and should migrate on another
> one.
>
> Wake up events remain the main way to migrate tasks but we now detect
> situation where a task is stuck on a CPU by checking that its utilization
> is larger than the max available compute capacity (max cpu capacity or
> uclamp max setting)
>
> Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
> ---
> kernel/sched/fair.c | 211 +++++++++++++++++++++++++++++++++++++++++++
> kernel/sched/sched.h | 2 +
> 2 files changed, 213 insertions(+)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index e46af2416159..41fb18ac118b 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
[snip]
> +
> +static inline void check_misfit_cpu(struct task_struct *p, struct rq *rq)
> +{
> + int new_cpu, cpu = cpu_of(rq);
> +
> + if (!sched_energy_enabled())
> + return;
> +
> + if (WARN_ON(!p))
> + return;
> +
> + if (WARN_ON(p != rq->curr))
> + return;
> +
> + if (is_migration_disabled(p))
> + return;
> +
> + if ((rq->nr_running > 1) || (p->nr_cpus_allowed == 1))
> + return;
I tried the code on a Pixel6 with the following setup:
- without the above (rq->nr_running > 1) condition
- without the push task mechanism
i.e. tasks without regular wakeups only have the opportunity to
run feec() via the sched_tick. It seemed sufficient to avoid
the problematic you mentioned:
- having unbalanced UCLAMP_MAX tasks in a pd, e.g. 1 UCLAMP_MAX task
per little CPU, except one little CPU with N UCLAMP_MAX tasks
- downgrading UCLAMP_MAX tasks that could run on smaller CPUs
but have no wakeups and thus don't run feec()
Thus I was wondering it it would not be better to integrate the
EAS to the load balancer instead (not my idea, but don't remember
who suggested that).
Or otherwise if just running feec() through the sched_tick path
would not be sufficient (i.e. this patch minus the push mechanism).
> +
> + if (!task_misfit_cpu(p, cpu))
> + return;
> +
> + new_cpu = find_energy_efficient_cpu(p, cpu);
> +
> + if (new_cpu == cpu)
> + return;
> +
> + /*
> + * ->active_balance synchronizes accesses to
> + * ->active_balance_work. Once set, it's cleared
> + * only after active load balance is finished.
> + */
> + if (!rq->active_balance) {
> + rq->active_balance = 1;
> + rq->push_cpu = new_cpu;
> + } else
> + return;
> +
> + raw_spin_rq_unlock(rq);
> + stop_one_cpu_nowait(cpu,
> + active_load_balance_cpu_stop, rq,
> + &rq->active_balance_work);
> + raw_spin_rq_lock(rq);
I didn't hit any error, but isn't it eligible to the following ?
commit f0498d2a54e7 ("sched: Fix stop_one_cpu_nowait() vs hotplug")
> +}
> +
> +static inline int has_pushable_tasks(struct rq *rq)
> +{
> + return !plist_head_empty(&rq->cfs.pushable_tasks);
> +}
> +
> +static struct task_struct *pick_next_pushable_fair_task(struct rq *rq)
> +{
> + struct task_struct *p;
> +
> + if (!has_pushable_tasks(rq))
> + return NULL;
> +
> + p = plist_first_entry(&rq->cfs.pushable_tasks,
> + struct task_struct, pushable_tasks);
> +
> + WARN_ON_ONCE(rq->cpu != task_cpu(p));
> + WARN_ON_ONCE(task_current(rq, p));
> + WARN_ON_ONCE(p->nr_cpus_allowed <= 1);
> +
> + WARN_ON_ONCE(!task_on_rq_queued(p));
> +
> + /*
> + * Remove task from the pushable list as we try only once after
> + * task has been put back in enqueued list.
> + */
> + plist_del(&p->pushable_tasks, &rq->cfs.pushable_tasks);
> +
> + return p;
> +}
> +
> +/*
> + * See if the non running fair tasks on this rq
> + * can be sent to some other CPU that fits better with
> + * their profile.
> + */
> +static int push_fair_task(struct rq *rq)
> +{
> + struct task_struct *next_task;
> + struct rq *new_rq;
> + int prev_cpu, new_cpu;
> + int ret = 0;
> +
> + next_task = pick_next_pushable_fair_task(rq);
> + if (!next_task)
> + return 0;
> +
> + if (is_migration_disabled(next_task))
> + return 0;
> +
> + if (WARN_ON(next_task == rq->curr))
> + return 0;
> +
> + /* We might release rq lock */
> + get_task_struct(next_task);
> +
> + prev_cpu = rq->cpu;
> +
> + new_cpu = find_energy_efficient_cpu(next_task, prev_cpu);
> +
> + if (new_cpu == prev_cpu)
> + goto out;
> +
> + new_rq = cpu_rq(new_cpu);
> +
> + if (double_lock_balance(rq, new_rq)) {
I think it might be necessary to check the following:
if (task_cpu(next_task) != rq->cpu) {
double_unlock_balance(rq, new_rq);
goto out;
}
Indeed I've been hitting the following warnings:
- uclamp_rq_dec_id():SCHED_WARN_ON(!bucket->tasks)
- set_task_cpu()::WARN_ON_ONCE(state == TASK_RUNNING &&
p->sched_class == &fair_sched_class &&
(p->on_rq && !task_on_rq_migrating(p)))
- update_entity_lag()::SCHED_WARN_ON(!se->on_rq)
and it seemed to be caused by the task not being on the initial rq anymore.
> +
> + deactivate_task(rq, next_task, 0);
> + set_task_cpu(next_task, new_cpu);
> + activate_task(new_rq, next_task, 0);
> + ret = 1;
> +
> + resched_curr(new_rq);
> +
> + double_unlock_balance(rq, new_rq);
> + }
> +
> +out:
> + put_task_struct(next_task);
> +
> + return ret;
> +}
> +
Regards,
Pierre
next prev parent reply other threads:[~2024-09-11 14:03 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-30 13:03 [PATCH 0/5] sched/fair: Rework EAS to handle more cases Vincent Guittot
2024-08-30 13:03 ` [PATCH 1/5] sched/fair: Filter false overloaded_group case for EAS Vincent Guittot
2024-09-02 9:01 ` Hongyan Xia
2024-09-06 6:51 ` Vincent Guittot
2024-09-13 13:21 ` Pierre Gondois
2024-08-30 13:03 ` [PATCH 2/5] energy model: Add a get previous state function Vincent Guittot
2024-09-05 9:21 ` Lukasz Luba
2024-09-06 6:55 ` Vincent Guittot
2024-08-30 13:03 ` [PATCH 3/5] sched/fair: Rework feec() to use cost instead of spare capacity Vincent Guittot
2024-09-02 9:11 ` kernel test robot
2024-09-02 11:03 ` Hongyan Xia
2024-09-06 7:08 ` Vincent Guittot
2024-09-06 15:32 ` Hongyan Xia
2024-09-12 12:12 ` Vincent Guittot
2024-09-04 15:07 ` Pierre Gondois
2024-09-06 7:08 ` Vincent Guittot
2024-09-11 14:02 ` Pierre Gondois
2024-09-11 16:51 ` Pierre Gondois
2024-09-12 12:22 ` Vincent Guittot
2024-12-05 16:23 ` Pierre Gondois
2024-08-30 13:03 ` [RFC PATCH 4/5] sched/fair: Use EAS also when overutilized Vincent Guittot
2024-09-17 20:24 ` Christian Loehle
2024-09-19 8:25 ` Pierre Gondois
2024-09-25 13:28 ` Vincent Guittot
2024-10-07 7:03 ` Pierre Gondois
2024-10-09 8:53 ` Vincent Guittot
2024-10-11 12:52 ` Pierre Gondois
2024-10-15 12:47 ` Vincent Guittot
2024-10-31 15:21 ` Pierre Gondois
2024-09-25 13:07 ` Vincent Guittot
2024-09-20 16:17 ` Quentin Perret
2024-09-25 13:27 ` Vincent Guittot
2024-09-26 9:10 ` Quentin Perret
2024-10-01 16:20 ` Vincent Guittot
2024-10-01 17:50 ` Quentin Perret
2024-10-02 7:11 ` Lukasz Luba
2024-10-02 7:55 ` Quentin Perret
2024-10-02 9:54 ` Lukasz Luba
2024-10-03 6:27 ` Vincent Guittot
2024-10-03 8:15 ` Lukasz Luba
2024-10-03 8:26 ` Quentin Perret
2024-10-03 8:52 ` Vincent Guittot
2024-10-03 8:21 ` Quentin Perret
2024-10-03 8:57 ` Vincent Guittot
2024-10-03 9:52 ` Quentin Perret
2024-10-03 13:26 ` Vincent Guittot
2024-11-19 14:46 ` Christian Loehle
2024-08-30 13:03 ` [RFC PATCH 5/5] sched/fair: Add push task callback for EAS Vincent Guittot
2024-09-09 9:59 ` Christian Loehle
2024-09-09 12:54 ` Vincent Guittot
2024-09-11 14:03 ` Pierre Gondois [this message]
2024-09-12 12:30 ` Vincent Guittot
2024-09-13 9:09 ` Pierre Gondois
2024-09-24 12:37 ` Vincent Guittot
2024-09-13 16:08 ` Pierre Gondois
2024-09-24 13:00 ` Vincent Guittot
2024-11-07 10:14 ` [PATCH 0/5] sched/fair: Rework EAS to handle more cases Pierre Gondois
2024-11-08 9:27 ` Vincent Guittot
2024-11-08 13:10 ` Pierre Gondois
2024-11-11 19:08 ` Vincent Guittot
2024-11-28 17:24 ` Hongyan Xia
2024-11-30 10:50 ` Vincent Guittot
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=ccf4095f-5fca-42f4-b9fe-aa93e703016e@arm.com \
--to=pierre.gondois@arm.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=hongyan.xia2@arm.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lukasz.luba@arm.com \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=qyousef@layalina.io \
--cc=rafael.j.wysocki@intel.com \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.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
Powered by JetHome