From: "tip-bot2 for Peter Zijlstra" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: "Peter Zijlstra (Intel)" <peterz@infradead.org>,
Daniel Bristot de Oliveira <bristot@kernel.org>,
Juri Lelli <juri.lelli@redhat.com>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: sched/core] sched/fair: Add trivial fair server
Date: Mon, 29 Jul 2024 10:34:04 -0000 [thread overview]
Message-ID: <172224924449.2215.14087360548232857166.tip-bot2@tip-bot2> (raw)
In-Reply-To: <b6b0bcefaf25391bcf5b6ecdb9f1218de402d42e.1716811044.git.bristot@kernel.org>
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 557a6bfc662c4d560f909b78adb1270c9862efa8
Gitweb: https://git.kernel.org/tip/557a6bfc662c4d560f909b78adb1270c9862efa8
Author: Peter Zijlstra <peterz@infradead.org>
AuthorDate: Mon, 27 May 2024 14:06:50 +02:00
Committer: Peter Zijlstra <peterz@infradead.org>
CommitterDate: Mon, 29 Jul 2024 12:22:36 +02:00
sched/fair: Add trivial fair server
Use deadline servers to service fair tasks.
This patch adds a fair_server deadline entity which acts as a container
for fair entities and can be used to fix starvation when higher priority
(wrt fair) tasks are monopolizing CPU(s).
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Daniel Bristot de Oliveira <bristot@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Juri Lelli <juri.lelli@redhat.com>
Link: https://lore.kernel.org/r/b6b0bcefaf25391bcf5b6ecdb9f1218de402d42e.1716811044.git.bristot@kernel.org
---
kernel/sched/core.c | 1 +
kernel/sched/deadline.c | 23 +++++++++++++++++++++++
kernel/sched/fair.c | 34 ++++++++++++++++++++++++++++++++++
kernel/sched/sched.h | 4 ++++
4 files changed, 62 insertions(+)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 1074ae8..f95600c 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -8336,6 +8336,7 @@ void __init sched_init(void)
#endif /* CONFIG_SMP */
hrtick_rq_init(rq);
atomic_set(&rq->nr_iowait, 0);
+ fair_server_init(rq);
#ifdef CONFIG_SCHED_CORE
rq->core = rq;
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index f59e5c1..f5b5313 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -1382,6 +1382,13 @@ throttle:
}
/*
+ * The fair server (sole dl_server) does not account for real-time
+ * workload because it is running fair work.
+ */
+ if (dl_se == &rq->fair_server)
+ return;
+
+ /*
* Because -- for now -- we share the rt bandwidth, we need to
* account our runtime there too, otherwise actual rt tasks
* would be able to exceed the shared quota.
@@ -1414,15 +1421,31 @@ void dl_server_update(struct sched_dl_entity *dl_se, s64 delta_exec)
void dl_server_start(struct sched_dl_entity *dl_se)
{
+ struct rq *rq = dl_se->rq;
+
if (!dl_server(dl_se)) {
+ /* Disabled */
+ dl_se->dl_runtime = 0;
+ dl_se->dl_deadline = 1000 * NSEC_PER_MSEC;
+ dl_se->dl_period = 1000 * NSEC_PER_MSEC;
+
dl_se->dl_server = 1;
setup_new_dl_entity(dl_se);
}
+
+ if (!dl_se->dl_runtime)
+ return;
+
enqueue_dl_entity(dl_se, ENQUEUE_WAKEUP);
+ if (!dl_task(dl_se->rq->curr) || dl_entity_preempt(dl_se, &rq->curr->dl))
+ resched_curr(dl_se->rq);
}
void dl_server_stop(struct sched_dl_entity *dl_se)
{
+ if (!dl_se->dl_runtime)
+ return;
+
dequeue_dl_entity(dl_se, DEQUEUE_SLEEP);
}
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 99c80ab..aba23b0 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -5765,6 +5765,7 @@ static bool throttle_cfs_rq(struct cfs_rq *cfs_rq)
struct cfs_bandwidth *cfs_b = tg_cfs_bandwidth(cfs_rq->tg);
struct sched_entity *se;
long task_delta, idle_task_delta, dequeue = 1;
+ long rq_h_nr_running = rq->cfs.h_nr_running;
raw_spin_lock(&cfs_b->lock);
/* This will start the period timer if necessary */
@@ -5837,6 +5838,9 @@ static bool throttle_cfs_rq(struct cfs_rq *cfs_rq)
sub_nr_running(rq, task_delta);
done:
+ /* Stop the fair server if throttling resulted in no runnable tasks */
+ if (rq_h_nr_running && !rq->cfs.h_nr_running)
+ dl_server_stop(&rq->fair_server);
/*
* Note: distribution will already see us throttled via the
* throttled-list. rq->lock protects completion.
@@ -5854,6 +5858,7 @@ void unthrottle_cfs_rq(struct cfs_rq *cfs_rq)
struct cfs_bandwidth *cfs_b = tg_cfs_bandwidth(cfs_rq->tg);
struct sched_entity *se;
long task_delta, idle_task_delta;
+ long rq_h_nr_running = rq->cfs.h_nr_running;
se = cfs_rq->tg->se[cpu_of(rq)];
@@ -5929,6 +5934,10 @@ void unthrottle_cfs_rq(struct cfs_rq *cfs_rq)
unthrottle_throttle:
assert_list_leaf_cfs_rq(rq);
+ /* Start the fair server if un-throttling resulted in new runnable tasks */
+ if (!rq_h_nr_running && rq->cfs.h_nr_running)
+ dl_server_start(&rq->fair_server);
+
/* Determine whether we need to wake up potentially idle CPU: */
if (rq->curr == rq->idle && rq->cfs.nr_running)
resched_curr(rq);
@@ -6759,6 +6768,9 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)
*/
util_est_enqueue(&rq->cfs, p);
+ if (!throttled_hierarchy(task_cfs_rq(p)) && !rq->cfs.h_nr_running)
+ dl_server_start(&rq->fair_server);
+
/*
* If in_iowait is set, the code below may not trigger any cpufreq
* utilization updates, so do it here explicitly with the IOWAIT flag
@@ -6903,6 +6915,9 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags)
rq->next_balance = jiffies;
dequeue_throttle:
+ if (!throttled_hierarchy(task_cfs_rq(p)) && !rq->cfs.h_nr_running)
+ dl_server_stop(&rq->fair_server);
+
util_est_update(&rq->cfs, p, task_sleep);
hrtick_update(rq);
}
@@ -8602,6 +8617,25 @@ static struct task_struct *__pick_next_task_fair(struct rq *rq)
return pick_next_task_fair(rq, NULL, NULL);
}
+static bool fair_server_has_tasks(struct sched_dl_entity *dl_se)
+{
+ return !!dl_se->rq->cfs.nr_running;
+}
+
+static struct task_struct *fair_server_pick(struct sched_dl_entity *dl_se)
+{
+ return pick_next_task_fair(dl_se->rq, NULL, NULL);
+}
+
+void fair_server_init(struct rq *rq)
+{
+ struct sched_dl_entity *dl_se = &rq->fair_server;
+
+ init_dl_entity(dl_se);
+
+ dl_server_init(dl_se, rq, fair_server_has_tasks, fair_server_pick);
+}
+
/*
* Account for a descheduled task:
*/
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 8a07102..7416bcd 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -363,6 +363,8 @@ extern void dl_server_init(struct sched_dl_entity *dl_se, struct rq *rq,
dl_server_has_tasks_f has_tasks,
dl_server_pick_f pick);
+extern void fair_server_init(struct rq *rq);
+
#ifdef CONFIG_CGROUP_SCHED
extern struct list_head task_groups;
@@ -1039,6 +1041,8 @@ struct rq {
struct rt_rq rt;
struct dl_rq dl;
+ struct sched_dl_entity fair_server;
+
#ifdef CONFIG_FAIR_GROUP_SCHED
/* list of leaf cfs_rq on this CPU: */
struct list_head leaf_cfs_rq_list;
next prev parent reply other threads:[~2024-07-29 10:34 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-27 12:06 [PATCH V7 0/9] SCHED_DEADLINE server infrastructure Daniel Bristot de Oliveira
2024-05-27 12:06 ` [PATCH V7 1/9] sched/deadline: Comment sched_dl_entity::dl_server variable Daniel Bristot de Oliveira
2024-07-29 10:34 ` [tip: sched/core] " tip-bot2 for Daniel Bristot de Oliveira
2024-05-27 12:06 ` [PATCH V7 2/9] sched/core: Add clearing of ->dl_server in put_prev_task_balance() Daniel Bristot de Oliveira
2024-07-29 10:34 ` [tip: sched/core] " tip-bot2 for Joel Fernandes (Google)
2024-05-27 12:06 ` [PATCH V7 3/9] sched/core: Clear prev->dl_server in CFS pick fast path Daniel Bristot de Oliveira
2024-07-29 10:34 ` [tip: sched/core] " tip-bot2 for Youssef Esmat
2024-05-27 12:06 ` [PATCH V7 4/9] sched/fair: Add trivial fair server Daniel Bristot de Oliveira
2024-07-29 10:34 ` tip-bot2 for Peter Zijlstra [this message]
2024-05-27 12:06 ` [PATCH V7 5/9] sched/deadline: Deferrable dl server Daniel Bristot de Oliveira
2024-07-29 10:34 ` [tip: sched/core] " tip-bot2 for Daniel Bristot de Oliveira
2024-05-27 12:06 ` [PATCH V7 6/9] sched/fair: Fair server interface Daniel Bristot de Oliveira
2024-07-29 10:34 ` [tip: sched/core] " tip-bot2 for Daniel Bristot de Oliveira
2024-05-27 12:06 ` [PATCH V7 7/9] sched/core: Fix priority checking for DL server picks Daniel Bristot de Oliveira
2024-07-29 10:34 ` [tip: sched/core] " tip-bot2 for Joel Fernandes (Google)
2024-05-27 12:06 ` [PATCH V7 8/9] sched/core: Fix picking of tasks for core scheduling with DL server Daniel Bristot de Oliveira
2024-07-29 10:34 ` [tip: sched/core] " tip-bot2 for Joel Fernandes (Google)
2024-05-27 12:06 ` [PATCH V7 9/9] sched/rt: Remove default bandwidth control Daniel Bristot de Oliveira
2024-07-29 10:34 ` [tip: sched/core] " tip-bot2 for Peter Zijlstra
2024-11-27 10:55 ` [PATCH V7 9/9] " Michal Koutný
2024-11-27 15:35 ` Juri Lelli
2024-11-29 10:02 ` Michal Koutný
2024-11-29 14:44 ` Juri Lelli
2024-11-29 20:21 ` Michal Koutný
2024-12-02 9:39 ` Juri Lelli
2024-06-21 13:37 ` [PATCH V7 0/9] SCHED_DEADLINE server infrastructure Juri Lelli
2024-06-21 13:43 ` Daniel Bristot de Oliveira
2024-06-21 13:50 ` Juri Lelli
2024-06-21 14:41 ` Vineeth Remanan Pillai
2024-06-21 14:59 ` Daniel Bristot de Oliveira
2024-06-21 15:09 ` Vineeth Remanan Pillai
2024-06-21 15:16 ` Daniel Bristot de Oliveira
2024-07-29 10:32 ` Peter Zijlstra
2024-07-29 20:42 ` Vineeth Remanan Pillai
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=172224924449.2215.14087360548232857166.tip-bot2@tip-bot2 \
--to=tip-bot2@linutronix.de \
--cc=bristot@kernel.org \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=x86@kernel.org \
/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®