Hierarchical Constant Bandwidth Server
cover Hierarchical Constant Bandwidth Server
Hi,
This is the first set of patches that implements Hierarchical RT scheduling, aimed at replacing the current RT_GROUP_SCHED implementation with something more robust and theoretically sound. The patchset has been presented at OSPM25
(https://retis.sssup.it/ospm-summit/), and a summary of its inner workings can be found at https://lwn.net/Articles/1021332/ .
Summary of the patches:
1-4) Preparation patches, so that the RT classes' code can be used both
for normal and cgroup scheduling.
5) Basic HCBS, no migration and only one level hierarchy.
6) Remove old RT_GROUP_SCHED code.
7) Add support for cgroup v2
8) Remove support for cgroup v1
9) HCBS with deeper hierarchies.
The patchset allows to create bandwidth reservations for cgroups which run SCHED_FIFO/SCHED_RR tasks. Whenever a cgroup is created, N cgroup's local runqueues and N dl_servers are allocated, one for each CPU. The local runqueues emulate standard scheduling for the FIFO/RR classes, as rt.c code is reused on these local runqueues without excessive modifications. Through the cgroup's virtual files it is possible to setup the cgroup's reservation. The dl_servers are started only when there are active tasks, and invoke the RT clasess' scheduler when they are deemed runnable.
Example usage (cgroups v2):
// create the cgroup
mkdir /sys/fs/cgroup/g0
// request a 10/100ms reservation
echo 100000 > /sys/fs/cgroup/g0/cpu.rt_period_us echo 10000 > /sys/fs/cgroup/g0/cpu.rt_runtime_us
// move any process in the cgroup
echo $PID > /sys/fs/cgroup/g0/cgroup.procs
// if not already an RT process
// set scheduling class to FIFO or RR
chrt [-r] -p $PRIORITY $PID
Testing:
The HCBS mechanism has been evaluated on several synthetic tests with RT groups, containing RT tasks with different priorities and the groups bandwidths are limited as expected.
The tests can be found at https://github.com/Yurand2000/HCBS-rust-initrd . They are written in C and Rust and should support any distro without issues, as they are statically compiled. These executables test both functional features and timing guarantees of the HCBS scheduler, but most are tailored to work with future patches which introduce task migration between CPUs.
The Makefile will compile the test suite to a fully functional initramfs, ready to use in qemu, but of course the tests' executables can also be loaded in a fully fledged distro to run tests there. Further comments on the test suite will follow in a future RFC.
Additional comments:
1) As pointed out by Peter Zijlstra at OSPM25, we removed support for cgroups v1 (patch 0008), but the mechanism should work also with cgroups v1 if the control files (i.e. cpu.rt_period_us and cpu.rt_runtime_us) are re-enabled in the legacy controller.
2) In response to
https://lwn.net/ml/all/[email protected]/, the new RT_GROUP_SCHED mechanism solves the issues which are discussed there:
- RT group scheduling for cgroup v2
- RT tasks can be created in the root control group without having to touch any of the hierarchy or reservations altogheter.
Future work:
As we already mentioned at OSPM25, we already have (partially) complete patches for task migration among CPUs and assignment of different runtimes for each individual CPU. The aim of this RFC is also to validate the current foundations before completing and submitting the patchset.
Future patches:
- HCBS with task migration.
- HCBS with different runtimes per CPU.
- capacity aware bandwidth reservation.
- enable/disable dl_servers when a CPU goes online/offline.
Have a nice day,
Yuri
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Yuri Andriaccio (1):
sched/rt: Remove support for cgroups-v1
luca abeni (8):
sched/deadline: Do not access dl_se->rq directly sched/deadline: Make a distinction between dl_rq and my_q sched/rt: Pass an rt_rq instead of an rq where needed sched/rt: Move some inline functions from rt.c to sched.h sched/deadline: Hierarchical scheduling with DL on top of RT sched/rt: Remove unused code
sched/core: Cgroup v2 support
sched/deadline: Allow deeper hierarchies of RT cgroups
include/linux/sched.h | 10 +- kernel/sched/autogroup.c | 4 +- kernel/sched/core.c | 44 +- kernel/sched/deadline.c | 256 ++++++-- kernel/sched/debug.c | 6 - kernel/sched/fair.c | 6 +- kernel/sched/rt.c | 1266 +++++++++++--------------------------- kernel/sched/sched.h | 133 ++-- kernel/sched/syscalls.c | 8 +- 9 files changed, 672 insertions(+), 1061 deletions(-)
Signature · 1 line
2.49.0
RFC PATCH 1/9 sched/deadline: Do not access dl_se->rq directly
From: luca abeni <[email protected]>
Make deadline.c code access the runqueue of a scheduling entity saved in the sched_dl_entity data structure. This allows future patches to save different runqueues in sched_dl_entity other than the global runqueues.
--- kernel/sched/deadline.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)
kernel/sched/deadline.c +13 -12
@@ -935,7 +935,7 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se)* and arm the defer timer. */ if (dl_se->dl_defer && !dl_se->dl_defer_running && -dl_time_before (rq_clock (dl_se->rq), dl_se->deadline - dl_se->runtime)) { +dl_time_before (rq_clock (rq), dl_se->deadline - dl_se->runtime)) {if (!is_dl_boosted (dl_se) && dl_se->server_has_tasks (dl_se)) {/*
@@ -1244,11 +1244,11 @@ static enum hrtimer_restart dl_server_timer(struct hrtimer *timer, struct sched_* of time. The dl_server_min_res serves as a limit to avoid * forwarding the timer for a too small amount of time. */ -if (dl_time_before (rq_clock (dl_se->rq), +if (dl_time_before (rq_clock (rq), (dl_se->deadline - dl_se->runtime - dl_server_min_res))) {/* reset the defer timer */ - fw = dl_se->deadline -rq_clock (dl_se->rq) - dl_se->runtime; + fw = dl_se->deadline -rq_clock (rq) - dl_se->runtime;hrtimer_forward_now (timer,ns_to_ktime (fw));return HRTIMER_RESTART ;
@@ -1259,7 +1259,7 @@ static enum hrtimer_restart dl_server_timer(struct hrtimer *timer, struct sched_enqueue_dl_entity (dl_se,ENQUEUE_REPLENISH ); -if (!dl_task (dl_se->rq->curr) ||dl_entity_preempt (dl_se, &dl_se->rq->curr->dl)) +if (!dl_task (rq->curr) ||dl_entity_preempt (dl_se, &rq->curr->dl))resched_curr (rq);__push_dl_task (rq, rf);
@@ -1527,7 +1527,7 @@ static void update_curr_dl_se(struct rq *rq, struct sched_dl_entity *dl_se, s64hrtimer_try_to_cancel (&dl_se->dl_timer); -replenish_dl_new_period (dl_se, dl_se->rq); +replenish_dl_new_period (dl_se, rq);/* * Not being able to start the timer seems problematic. If it could not
@@ -1640,12 +1640,12 @@ void dl_server_update(struct sched_dl_entity *dl_se, s64 delta_exec) {/* 0 runtime = fair server disabled */ if (dl_se->dl_runtime) -update_curr_dl_se (dl_se->rq, dl_se, delta_exec); +update_curr_dl_se (rq_of_dl_se (dl_se), dl_se, delta_exec); }void dl_server_start (struct sched_dl_entity *dl_se) { -struct rq *rq = dl_se->rq; +struct rq *rq;/* * XXX: the apply do not work fine at the init phase for the
@@ -1656,9 +1656,9 @@ void dl_server_start(struct sched_dl_entity *dl_se)u64 runtime =50 *NSEC_PER_MSEC ;u64 period =1000 *NSEC_PER_MSEC ; + dl_se->dl_server =1 ;dl_server_apply_params (dl_se, runtime, period,1 ); - dl_se->dl_server =1 ; dl_se->dl_defer =1 ;setup_new_dl_entity (dl_se); }
@@ -1668,8 +1668,9 @@ void dl_server_start(struct sched_dl_entity *dl_se) dl_se->dl_server_active =1 ;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); + rq =rq_of_dl_se (dl_se); +if (!dl_task (rq->curr) ||dl_entity_preempt (dl_se, &rq->curr->dl)) +resched_curr (rq); }void dl_server_stop (struct sched_dl_entity *dl_se)
@@ -1712,7 +1713,7 @@ int dl_server_apply_params(struct sched_dl_entity *dl_se, u64 runtime, u64 perio {u64 old_bw = init ?0 :to_ratio (dl_se->dl_period, dl_se->dl_runtime);u64 new_bw =to_ratio (period, runtime); -struct rq *rq = dl_se->rq; +struct rq *rq =rq_of_dl_se (dl_se);int cpu =cpu_of (rq);struct dl_bw *dl_b;unsigned long cap;
@@ -1789,7 +1790,7 @@ static enum hrtimer_restart inactive_task_timer(struct hrtimer *timer) p =dl_task_of (dl_se); rq =task_rq_lock (p, &rf); }else { - rq = dl_se->rq; + rq =rq_of_dl_se (dl_se);rq_lock (rq, &rf); }
Signature · 1 line
2.49.0
RFC PATCH 2/9 sched/deadline: Make a distinction between dl_rq and my_q
In reply to Yuri AndriaccioFrom: luca abeni <[email protected]>
Create two fields for runqueues in sched_dl_entity to make a distinction between the global runqueue and the runqueue which the dl_server serves.
--- include/linux/sched.h | 6 ++++-- kernel/sched/deadline.c | 11 +++++++---- kernel/sched/fair.c | 6 +++--- kernel/sched/sched.h | 3 ++- 4 files changed, 16 insertions(+), 10 deletions(-)
include/linux/sched.h +4 -2
@@ -725,12 +725,14 @@ struct sched_dl_entity {* Bits for DL-server functionality. Also see the comment near * dl_server_update(). * -* @rq the runqueue this server is for +* @dl_rq the runqueue on which this entity is (to be) queued +* @my_q the runqueue "owned" by this entity * * @server_has_tasks() returns true if @server_pick return a * runnable task. */ -struct rq *rq; +struct dl_rq *dl_rq; +struct rq *my_q;dl_server_has_tasks_f server_has_tasks;dl_server_pick_f server_pick_task;
kernel/sched/deadline.c +7 -4
@@ -71,11 +71,12 @@ static inline struct rq *rq_of_dl_rq(struct dl_rq *dl_rq)static inline struct rq *rq_of_dl_se (struct sched_dl_entity *dl_se) { -struct rq *rq = dl_se->rq; +struct rq *rq;if (!dl_server (dl_se)) rq =task_rq (dl_task_of (dl_se)); - +else + rq = container_of(dl_se->dl_rq, struct rq, dl);return rq; }
@@ -1685,11 +1686,13 @@ void dl_server_stop(struct sched_dl_entity *dl_se) dl_se->dl_server_active =0 ; } -void dl_server_init (struct sched_dl_entity *dl_se,struct rq *rq, +void dl_server_init (struct sched_dl_entity *dl_se,struct dl_rq *dl_rq, +struct rq *served_rq,dl_server_has_tasks_f has_tasks,dl_server_pick_f pick_task) { - dl_se->rq = rq; + dl_se->dl_rq = dl_rq; + dl_se->my_q = served_rq; dl_se->server_has_tasks = has_tasks; dl_se->server_pick_task = pick_task; }
kernel/sched/fair.c +3 -3
@@ -8976,12 +8976,12 @@ static struct task_struct *__pick_next_task_fair(struct rq *rq, struct task_strustatic bool fair_server_has_tasks (struct sched_dl_entity *dl_se) { -return !!dl_se->rq->cfs.nr_queued; +return !!dl_se->my_q->cfs.nr_queued; }static struct task_struct *fair_server_pick_task (struct sched_dl_entity *dl_se) { -return pick_task_fair (dl_se->rq); +return pick_task_fair (dl_se->my_q); }void fair_server_init (struct rq *rq)
@@ -8990,7 +8990,7 @@ void fair_server_init(struct rq *rq)init_dl_entity (dl_se); -dl_server_init (dl_se, rq, fair_server_has_tasks, fair_server_pick_task); +dl_server_init (dl_se, &rq->dl, rq, fair_server_has_tasks, fair_server_pick_task); }/*
kernel/sched/sched.h +2 -1
@@ -381,7 +381,8 @@ extern s64 dl_scaled_delta_exec(struct rq *rq, struct sched_dl_entity *dl_se, s6extern void dl_server_update (struct sched_dl_entity *dl_se,s64 delta_exec);extern void dl_server_start (struct sched_dl_entity *dl_se);extern void dl_server_stop (struct sched_dl_entity *dl_se); -extern void dl_server_init (struct sched_dl_entity *dl_se,struct rq *rq, +extern void dl_server_init (struct sched_dl_entity *dl_se,struct dl_rq *dl_rq, +struct rq *served_rq,dl_server_has_tasks_f has_tasks,dl_server_pick_f pick_task);
Signature · 1 line
2.49.0
RFC PATCH 3/9 sched/rt: Pass an rt_rq instead of an rq where needed
In reply to Yuri AndriaccioFrom: luca abeni <[email protected]>
Make rt.c code access the runqueue through the rt_rq data structure rather than passing an rq pointer directly. This allows future patches to define rt_rq data structures which do not refer only to the global runqueue, but also to local cgroup runqueues (rt_rq is not always equal to &rq->rt).
--- kernel/sched/rt.c | 87 +++++++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 41 deletions(-)
kernel/sched/rt.c +46 -41
@@ -371,9 +371,9 @@ static inline void rt_clear_overload(struct rq *rq)cpumask_clear_cpu (rq->cpu, rq->rd->rto_mask); } -static inline int has_pushable_tasks (struct rq *rq) +static inline int has_pushable_tasks (struct rt_rq *rt_rq) { -return !plist_head_empty (&rq->rt.pushable_tasks); +return !plist_head_empty (&rt_rq->pushable_tasks); } static DEFINE_PER_CPU(struct balance_callback, rt_push_head);
@@ -384,7 +384,7 @@ static void pull_rt_task(struct rq *);static inline void rt_queue_push_tasks (struct rq *rq) { -if (!has_pushable_tasks (rq)) +if (!has_pushable_tasks (&rq->rt))return ;queue_balance_callback (rq, &per_cpu (rt_push_head, rq->cpu), push_rt_tasks);
@@ -395,48 +395,48 @@ static inline void rt_queue_pull_task(struct rq *rq)queue_balance_callback (rq, &per_cpu (rt_pull_head, rq->cpu), pull_rt_task); } -static void enqueue_pushable_task (struct rq *rq,struct task_struct *p) +static void enqueue_pushable_task (struct rt_rq *rt_rq,struct task_struct *p) { -plist_del (&p->pushable_tasks, &rq->rt.pushable_tasks); +plist_del (&p->pushable_tasks, &rt_rq->pushable_tasks);plist_node_init (&p->pushable_tasks, p->prio); -plist_add (&p->pushable_tasks, &rq->rt.pushable_tasks); +plist_add (&p->pushable_tasks, &rt_rq->pushable_tasks);/* Update the highest prio pushable task */ -if (p->prio < rq->rt.highest_prio.next) - rq->rt.highest_prio.next = p->prio; +if (p->prio < rt_rq->highest_prio.next) + rt_rq->highest_prio.next = p->prio; -if (!rq->rt.overloaded) { -rt_set_overload (rq); - rq->rt.overloaded =1 ; +if (!rt_rq->overloaded) { +rt_set_overload (rq_of_rt_rq (rt_rq)); + rt_rq->overloaded =1 ; } } -static void dequeue_pushable_task (struct rq *rq,struct task_struct *p) +static void dequeue_pushable_task (struct rt_rq *rt_rq,struct task_struct *p) { -plist_del (&p->pushable_tasks, &rq->rt.pushable_tasks); +plist_del (&p->pushable_tasks, &rt_rq->pushable_tasks);/* Update the new highest prio pushable task */ -if (has_pushable_tasks (rq)) { - p =plist_first_entry (&rq->rt.pushable_tasks, +if (has_pushable_tasks (rt_rq)) { + p =plist_first_entry (&rt_rq->pushable_tasks, struct task_struct, pushable_tasks); - rq->rt.highest_prio.next = p->prio; + rt_rq->highest_prio.next = p->prio; }else { - rq->rt.highest_prio.next =MAX_RT_PRIO -1 ; + rt_rq->highest_prio.next =MAX_RT_PRIO -1 ; -if (rq->rt.overloaded) { -rt_clear_overload (rq); - rq->rt.overloaded =0 ; +if (rt_rq->overloaded) { +rt_clear_overload (rq_of_rt_rq (rt_rq)); + rt_rq->overloaded =0 ; } } }#else -static inline void enqueue_pushable_task (struct rq *rq,struct task_struct *p) +static inline void enqueue_pushable_task (struct rt_rq *rt_rq,struct task_struct *p) { } -static inline void dequeue_pushable_task (struct rq *rq,struct task_struct *p) +static inline void dequeue_pushable_task (struct rt_rq *rt_rq,struct task_struct *p) { }
@@ -1479,6 +1479,7 @@ static void enqueue_task_rt(struct rq *rq, struct task_struct *p, int flags) { struct sched_rt_entity *rt_se = &p->rt; +struct rt_rq *rt_rq =rt_rq_of_se (rt_se);if (flags &ENQUEUE_WAKEUP ) rt_se->timeout =0 ;
@@ -1489,17 +1490,18 @@ enqueue_task_rt(struct rq *rq, struct task_struct *p, int flags)enqueue_rt_entity (rt_se, flags);if (!task_current (rq, p) && p->nr_cpus_allowed >1 ) -enqueue_pushable_task (rq, p); +enqueue_pushable_task (rt_rq, p); }static bool dequeue_task_rt (struct rq *rq,struct task_struct *p,int flags) {struct sched_rt_entity *rt_se = &p->rt; +struct rt_rq *rt_rq =rt_rq_of_se (rt_se);update_curr_rt (rq);dequeue_rt_entity (rt_se, flags); -dequeue_pushable_task (rq, p); +dequeue_pushable_task (rt_rq, p);return true; }
@@ -1688,14 +1690,14 @@ static void wakeup_preempt_rt(struct rq *rq, struct task_struct *p, int flags)static inline void set_next_task_rt (struct rq *rq,struct task_struct *p,bool first) {struct sched_rt_entity *rt_se = &p->rt; -struct rt_rq *rt_rq = &rq->rt; +struct rt_rq *rt_rq =rt_rq_of_se (&p->rt); p->se.exec_start =rq_clock_task (rq);if (on_rt_rq (&p->rt))update_stats_wait_end_rt (rt_rq, rt_se);/* The running task is never eligible for pushing */ -dequeue_pushable_task (rq, p); +dequeue_pushable_task (rt_rq, p);if (!first)return ;
@@ -1759,7 +1761,7 @@ static struct task_struct *pick_task_rt(struct rq *rq)static void put_prev_task_rt (struct rq *rq,struct task_struct *p,struct task_struct *next) {struct sched_rt_entity *rt_se = &p->rt; -struct rt_rq *rt_rq = &rq->rt; +struct rt_rq *rt_rq =rt_rq_of_se (&p->rt);if (on_rt_rq (&p->rt))update_stats_wait_start_rt (rt_rq, rt_se);
@@ -1773,7 +1775,7 @@ static void put_prev_task_rt(struct rq *rq, struct task_struct *p, struct task_s* if it is still active */ if (on_rt_rq (&p->rt) && p->nr_cpus_allowed >1 ) -enqueue_pushable_task (rq, p); +enqueue_pushable_task (rt_rq, p); }#ifdef CONFIG_SMP
@@ -1785,16 +1787,16 @@ static void put_prev_task_rt(struct rq *rq, struct task_struct *p, struct task_s* Return the highest pushable rq's task, which is suitable to be executed * on the CPU, NULL otherwise */ -static struct task_struct *pick_highest_pushable_task (struct rq *rq,int cpu) +static struct task_struct *pick_highest_pushable_task (struct rt_rq *rt_rq,int cpu) { -struct plist_head *head = &rq->rt.pushable_tasks; +struct plist_head *head = &rt_rq->pushable_tasks;struct task_struct *p; -if (!has_pushable_tasks (rq)) +if (!has_pushable_tasks (rt_rq))return NULL ;plist_for_each_entry (p, head, pushable_tasks) { -if (task_is_pushable (rq, p, cpu)) +if (task_is_pushable (rq_of_rt_rq (rt_rq), p, cpu))return p; }
@@ -1894,14 +1896,15 @@ static int find_lowest_rq(struct task_struct *task)return -1 ; } -static struct task_struct *pick_next_pushable_task (struct rq *rq) +static struct task_struct *pick_next_pushable_task (struct rt_rq *rt_rq) { +struct rq *rq =rq_of_rt_rq (rt_rq);struct task_struct *p; -if (!has_pushable_tasks (rq)) +if (!has_pushable_tasks (rt_rq))return NULL ; - p =plist_first_entry (&rq->rt.pushable_tasks, + p =plist_first_entry (&rt_rq->pushable_tasks, struct task_struct, pushable_tasks);BUG_ON (rq->cpu !=task_cpu (p));
@@ -1954,7 +1957,7 @@ static struct rq *find_lock_lowest_rq(struct task_struct *task, struct rq *rq)*/ if (unlikely (is_migration_disabled (task) || !cpumask_test_cpu (lowest_rq->cpu, &task->cpus_mask) || - task !=pick_next_pushable_task (rq))) { + task !=pick_next_pushable_task (&rq->rt))) {double_unlock_balance (rq, lowest_rq); lowest_rq =NULL ;
@@ -1988,7 +1991,7 @@ static int push_rt_task(struct rq *rq, bool pull)if (!rq->rt.overloaded)return 0 ; - next_task =pick_next_pushable_task (rq); + next_task =pick_next_pushable_task (&rq->rt);if (!next_task)return 0 ;
@@ -2063,7 +2066,7 @@ static int push_rt_task(struct rq *rq, bool pull)* run-queue and is also still the next task eligible for * pushing. */ - task =pick_next_pushable_task (rq); + task =pick_next_pushable_task (&rq->rt);if (task == next_task) {/* * The task hasn't migrated, and is still the next
@@ -2251,7 +2254,7 @@ void rto_push_irq_work_func(struct irq_work *work)* We do not need to grab the lock to check for has_pushable_tasks. * When it gets updated, a check is made if a push is possible. */ -if (has_pushable_tasks (rq)) { +if (has_pushable_tasks (&rq->rt)) {raw_spin_rq_lock (rq);while (push_rt_task (rq, true)) ;
@@ -2280,6 +2283,7 @@ static void pull_rt_task(struct rq *this_rq)int this_cpu = this_rq->cpu, cpu;bool resched = false;struct task_struct *p, *push_task; +struct rt_rq *src_rt_rq;struct rq *src_rq;int rt_overload_count =rt_overloaded (this_rq);
@@ -2309,6 +2313,7 @@ static void pull_rt_task(struct rq *this_rq)continue ; src_rq =cpu_rq (cpu); + src_rt_rq = &src_rq->rt;/* * Don't bother taking the src_rq->lock if the next highest
@@ -2317,7 +2322,7 @@ static void pull_rt_task(struct rq *this_rq)* logically higher, the src_rq will push this task away. * And if its going logically lower, we do not care */ -if (src_rq->rt.highest_prio.next >= +if (src_rt_rq->highest_prio.next >= this_rq->rt.highest_prio.curr)continue ;
@@ -2333,7 +2338,7 @@ static void pull_rt_task(struct rq *this_rq)* We can pull only a task, which is pushable * on its rq, and no others. */ - p =pick_highest_pushable_task (src_rq, this_cpu); + p =pick_highest_pushable_task (src_rt_rq, this_cpu);/* * Do we have an RT task that preempts
Signature · 1 line
2.49.0
RFC PATCH 4/9 sched/rt: Move some inline functions from rt.c to sched.h
In reply to Yuri AndriaccioFrom: luca abeni <[email protected]>
Make the following functions be non-static and move them in sched.h, so that they can be used also in other source files:
- rt_task_of()
- rq_of_rt_rq()
- rt_rq_of_se()
- rq_of_rt_se()
There are no functional changes. This is needed by future patches.
--- kernel/sched/rt.c | 52 -------------------------------------------- kernel/sched/sched.h | 51 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 52 deletions(-)
kernel/sched/rt.c +0 -52
@@ -167,34 +167,6 @@ static void destroy_rt_bandwidth(struct rt_bandwidth *rt_b)#define rt_entity_is_task (rt_se) (!(rt_se)->my_q) -static inline struct task_struct *rt_task_of (struct sched_rt_entity *rt_se) -{ -WARN_ON_ONCE (!rt_entity_is_task (rt_se)); - - return container_of(rt_se, struct task_struct, rt); -} - -static inline struct rq *rq_of_rt_rq (struct rt_rq *rt_rq) -{ -/* Cannot fold with non-CONFIG_RT_GROUP_SCHED version, layout */ -WARN_ON (!rt_group_sched_enabled () && rt_rq->tg != &root_task_group); -return rt_rq->rq; -} - -static inline struct rt_rq *rt_rq_of_se (struct sched_rt_entity *rt_se) -{ -WARN_ON (!rt_group_sched_enabled () && rt_se->rt_rq->tg != &root_task_group); -return rt_se->rt_rq; -} - -static inline struct rq *rq_of_rt_se (struct sched_rt_entity *rt_se) -{ -struct rt_rq *rt_rq = rt_se->rt_rq; - -WARN_ON (!rt_group_sched_enabled () && rt_rq->tg != &root_task_group); -return rt_rq->rq; -} -void unregister_rt_sched_group (struct task_group *tg) {if (!rt_group_sched_enabled ())
@@ -295,30 +267,6 @@ int alloc_rt_sched_group(struct task_group *tg, struct task_group *parent)#define rt_entity_is_task (rt_se) (1) -static inline struct task_struct *rt_task_of (struct sched_rt_entity *rt_se) -{ - return container_of(rt_se, struct task_struct, rt); -} - -static inline struct rq *rq_of_rt_rq (struct rt_rq *rt_rq) -{ - return container_of(rt_rq, struct rq, rt); -} - -static inline struct rq *rq_of_rt_se (struct sched_rt_entity *rt_se) -{ -struct task_struct *p =rt_task_of (rt_se); - -return task_rq (p); -} - -static inline struct rt_rq *rt_rq_of_se (struct sched_rt_entity *rt_se) -{ -struct rq *rq =rq_of_rt_se (rt_se); - -return &rq->rt; -} -void unregister_rt_sched_group (struct task_group *tg) { }void free_rt_sched_group (struct task_group *tg) { }
kernel/sched/sched.h +51 -0
57 lines not on this page · raw message
Signature · 1 line
2.49.0
RFC PATCH 5/9 sched/deadline: Hierarchical scheduling with DL on top of RT
In reply to Yuri AndriaccioFrom: luca abeni <[email protected]>
Implement the hierarchical scheduling mechanism:
- Enforce the runtime of RT tasks controlled by cgroups using the dl_server mechanism, based on the runtime and period (the deadline is set equal to the period) parameters.
- Make sched_dl_entity store the cgroups' RT local runqueue, and provide a rt_rq for this runqueue.
- Allow zeroing the runtime of a rt cgroups.
Update dl_server code:
- Make check for the return value of dl_server_apply_params on initialization of the fair server.
- Initialize the dl_server in dl_server_start only if it is a fair server, but do not initialize other types of servers, regardless of its period value.
- Make inc_dl_task and dec_dl_task increase/decrease by one the value of active tasks if a fair_server starts/stops, while ignore rt-cgroups dl_servers in the accounting.
--- kernel/sched/autogroup.c | 4 +- kernel/sched/core.c | 15 +- kernel/sched/deadline.c | 145 ++++++++++++-- kernel/sched/rt.c | 415 ++++++++++++++++++++++++++------------- kernel/sched/sched.h | 59 +++++- kernel/sched/syscalls.c | 4 +- 6 files changed, 471 insertions(+), 171 deletions(-)
kernel/sched/autogroup.c +2 -2
@@ -49,7 +49,7 @@ static inline void autogroup_destroy(struct kref *kref)#ifdef CONFIG_RT_GROUP_SCHED /* We've redirected RT tasks to the root task group... */ - ag->tg->rt_se =NULL ; + ag->tg->dl_se =NULL ; ag->tg->rt_rq =NULL ;#endif sched_release_group (ag->tg);
@@ -106,7 +106,7 @@ static inline struct autogroup *autogroup_create(void)* the policy change to proceed. */ free_rt_sched_group (tg); - tg->rt_se = root_task_group.rt_se; + tg->dl_se = root_task_group.dl_se; tg->rt_rq = root_task_group.rt_rq;#endif tg->autogroup = ag;
kernel/sched/core.c +12 -3
@@ -2196,6 +2196,9 @@ void wakeup_preempt(struct rq *rq, struct task_struct *p, int flags) {struct task_struct *donor = rq->donor; +if (is_dl_group (rt_rq_of_se (&p->rt)) &&task_has_rt_policy (p)) +resched_curr (rq); +if (p->sched_class == donor->sched_class) donor->sched_class->wakeup_preempt (rq, p, flags);else if (sched_class_above (p->sched_class, donor->sched_class))
@@ -8548,7 +8551,7 @@ void __init sched_init(void) root_task_group.scx_weight =CGROUP_WEIGHT_DFL ;#endif /* CONFIG_EXT_GROUP_SCHED */ #ifdef CONFIG_RT_GROUP_SCHED - root_task_group.rt_se = (struct sched_rt_entity **)ptr; + root_task_group.dl_se = (struct sched_dl_entity **)ptr; ptr += nr_cpu_ids *sizeof (void **); root_task_group.rt_rq = (struct rt_rq **)ptr;
@@ -8562,7 +8565,7 @@ void __init sched_init(void)#endif #ifdef CONFIG_RT_GROUP_SCHED -init_rt_bandwidth (&root_task_group.rt_bandwidth, +init_dl_bandwidth (&root_task_group.dl_bandwidth,global_rt_period (),global_rt_runtime ());#endif /* CONFIG_RT_GROUP_SCHED */
@@ -8618,7 +8621,7 @@ void __init sched_init(void)* yet. */ rq->rt.rt_runtime =global_rt_runtime (); -init_tg_rt_entry (&root_task_group, &rq->rt,NULL , i,NULL ); +init_tg_rt_entry (&root_task_group, rq,NULL , i,NULL );#endif #ifdef CONFIG_SMP rq->sd =NULL ;
@@ -9125,6 +9128,12 @@ cpu_cgroup_css_alloc(struct cgroup_subsys_state *parent_css)return &root_task_group.css; } +/* Do not allow cpu_cgroup hierachies with depth greater than 2. */ +#ifdef CONFIG_RT_GROUP_SCHED +if (parent != &root_task_group) +return ERR_PTR (-EINVAL ); +#endif + tg =sched_create_group (parent);if (IS_ERR (tg))return ERR_PTR (-ENOMEM );
kernel/sched/deadline.c +130 -15
214 lines not on this page · raw message
kernel/sched/rt.c +276 -139
744 lines not on this page · raw message
kernel/sched/sched.h +49 -10
138 lines not on this page · raw message
kernel/sched/syscalls.c +2 -2
@@ -635,8 +635,8 @@ int __sched_setscheduler(struct task_struct *p,* assigned. */ if (rt_group_sched_enabled () && -rt_bandwidth_enabled () &&rt_policy (policy) && -task_group (p)->rt_bandwidth.rt_runtime ==0 && +dl_bandwidth_enabled () &&rt_policy (policy) && +task_group (p)->dl_bandwidth.dl_runtime ==0 && !task_group_is_autogroup (task_group (p))) { retval = -EPERM ; goto unlock;
Signature · 1 line
2.49.0
kernel test robot
build botRe: [RFC PATCH 5/9] sched/deadline: Hierarchical scheduling with DL on top of RT
kernel test robot noticed the following build errors:
Hi Yuri,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:
[auto build test ERROR on tip/sched/core]
[also build test ERROR on tip/master linus/master next-20250605] [cannot apply to peterz-queue/sched/core tip/auto-latest v6.15] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Yuri-Andriaccio/sched-deadline-Make-a-distinction-between-dl_rq-and-my_q/20250605-161409 base: tip/sched/core patch link: https://lore.kernel.org/r/20250605071412.139240-6-yurand2000%40gmail.com patch subject: [RFC PATCH 5/9] sched/deadline: Hierarchical scheduling with DL on top of RT config: i386-buildonly-randconfig-003-20250606 (https://download.01.org/0day-ci/archive/20250606/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250606/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All error/warnings (new ones prefixed by >>):
In file included from kernel/sched/build_policy.c:52:
kernel/sched/rt.c: In function 'wakeup_preempt_rt':
>> kernel/sched/rt.c:1688:1: warning: label 'no_group_sched' defined but not used [-Wunused-label]
1688 | no_group_sched:
| ^~~~~~~~~~~~~~
kernel/sched/rt.c: In function 'prio_changed_rt':
>> kernel/sched/rt.c:2584:40: error: 'struct rt_rq' has no member named 'tg'
2584 | rt_rq_of_se(&p->rt)->tg != rt_rq_of_se(&rq->curr->rt)->tg)
| ^~
kernel/sched/rt.c:2584:74: error: 'struct rt_rq' has no member named 'tg'
2584 | rt_rq_of_se(&p->rt)->tg != rt_rq_of_se(&rq->curr->rt)->tg)
| ^~
kernel/sched/rt.c: At top level:
kernel/sched/rt.c:10:18: warning: 'max_rt_runtime' defined but not used [-Wunused-const-variable=]
10 | static const u64 max_rt_runtime = MAX_BW;
| ^~~~~~~~~~~~~~vim +2584 kernel/sched/rt.c
2565
2566 /*
2567 * If there's a higher priority task waiting to run
2568 * then reschedule.
2569 */
2570 if (p->prio > rt_rq->highest_prio.curr)
2571 resched_curr(rq);
2572 #else
2573 /* For UP simply resched on drop of prio */
2574 if (oldprio < p->prio)
2575 resched_curr(rq);
2576 #endif /* CONFIG_SMP */
2577 } else {
2578 /*
2579 * This task is not running, thus we check against the currently
2580 * running task for preemption. We can preempt only if both tasks are
2581 * in the same cgroup or on the global runqueue.
2582 */
2583 if (IS_ENABLED(CONFIG_RT_GROUP_SCHED) &&
> 2584 rt_rq_of_se(&p->rt)->tg != rt_rq_of_se(&rq->curr->rt)->tg)
2585 return;
2586
2587 /*
2588 * This task is not running, but if it is
2589 * greater than the current running task
2590 * then reschedule.
2591 */
2592 if (p->prio < rq->donor->prio)
2593 resched_curr(rq);
2594 }
2595 }
2596
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Juri Lelli
maintainerRe: [RFC PATCH 5/9] sched/deadline: Hierarchical scheduling with DL on top of RT
In reply to Yuri AndriaccioHello,
Quoted 26 lines · Yuri Andriaccio
From: luca abeni <[email protected]>
Implement the hierarchical scheduling mechanism:
- Enforce the runtime of RT tasks controlled by cgroups using thedl_servermechanism, based on the runtime and period (the deadline is set equal to the period) parameters.
- Makesched_dl_entitystore the cgroups' RT local runqueue, and provide art_rqfor this runqueue.
- Allow zeroing the runtime of a rt cgroups.Update
dl_servercode:
- Make check for the return value ofdl_server_apply_paramson initialization of the fair server.
- Initialize thedl_serverindl_server_startonly if it is a fair server, but do not initialize other types of servers, regardless of its period value.
- Makeinc_dl_taskanddec_dl_taskincrease/decrease by one the value of active tasks if afair_serverstarts/stops, while ignore rt-cgroupsdl_serversin the accounting.Co-developed-by Alessio Balsini <[email protected]>Signed-off-by Alessio Balsini <[email protected]>Co-developed-by Andrea Parri <[email protected]>Signed-off-by Andrea Parri <[email protected]>Co-developed-by Yuri Andriaccio <[email protected]>Signed-off-by Yuri Andriaccio <[email protected]>Signed-off-by luca abeni <[email protected]>
Quoted 8 lines
--- kernel/sched/autogroup.c | 4 +- kernel/sched/core.c | 15 +- kernel/sched/deadline.c | 145 ++++++++++++-- kernel/sched/rt.c | 415 ++++++++++++++++++++++++++------------- kernel/sched/sched.h | 59 +++++- kernel/sched/syscalls.c | 4 +- 6 files changed, 471 insertions(+), 171 deletions(-)
From changelog (and confirmed by changed lines), this patch might be doing too many things at once and so it might be harder to review. Do you think it can be split in smaller chunks?
Thanks,
Juri
Re: [RFC PATCH 5/9] sched/deadline: Hierarchical scheduling with DL on top of RT
Hi,
thanks for your feedback.
Quoted 3 lines
From changelog (and confirmed by changed lines), this patch might be doing too many things at once and so it might be harder to review. Do you think it can be split in smaller chunks?
I'm currently working on splitting this patch (and the patch 8) in smaller chunks as you suggested, adding changes bit by bit.
I'll submit the updated version of the patchset for a RFC v2 as soon as I have it done.
Have a nice day,
Yuri
Steven Rostedt
reviewerRe: [RFC PATCH 5/9] sched/deadline: Hierarchical scheduling with DL on top of RT
Quoted 8 lines · On Wed, 11 Jun 2025 15:54:56 +0200 Yuri Andriaccio <[email protected]> wrote:
Hi,
thanks for your feedback.
Quoted 3 lines
From changelog (and confirmed by changed lines), this patch might be doing too many things at once and so it might be harder to review. Do you think it can be split in smaller chunks?
Quoted 5 lines
I'm currently working on splitting this patch (and the patch 8) in smaller chunks as you suggested, adding changes bit by bit.
I'll submit the updated version of the patchset for a RFC v2 as soon as I have it done.
Hi Yuri,
Thanks for doing this. On your next version, please add your own Signed-off-by to each patch you send. Although you may not be the author, you are posting them, which requires a Signed-off-by which basically is you saying you have the right to post these patches.
Thanks,
-- Steve
RFC PATCH 6/9 sched/rt: Remove unused code
In reply to Yuri AndriaccioFrom: luca abeni <[email protected]>
Remove the old RT_GROUP_SCHED code, as it is not used anymore.
--- include/linux/sched.h | 4 - kernel/sched/core.c | 1 - kernel/sched/deadline.c | 34 -- kernel/sched/debug.c | 6 - kernel/sched/rt.c | 698 +--------------------------------------- kernel/sched/sched.h | 32 +- 6 files changed, 11 insertions(+), 764 deletions(-)
include/linux/sched.h +0 -4
@@ -623,13 +623,9 @@ struct sched_rt_entity {unsigned short on_rq;unsigned short on_list; -struct sched_rt_entity *back;#ifdef CONFIG_RT_GROUP_SCHED -struct sched_rt_entity *parent;/* rq on which this entity is (to be) queued: */ struct rt_rq *rt_rq; -/* rq "owned" by this entity/group: */ -struct rt_rq *my_q;#endif } __randomize_layout;
kernel/sched/core.c +0 -1
@@ -8620,7 +8620,6 @@ void __init sched_init(void)* starts working after scheduler_running, which is not the case * yet. */ - rq->rt.rt_runtime =global_rt_runtime ();init_tg_rt_entry (&root_task_group, rq,NULL , i,NULL );#endif #ifdef CONFIG_SMP
kernel/sched/deadline.c +0 -34
@@ -1671,40 +1671,6 @@ static void update_curr_dl_se(struct rq *rq, struct sched_dl_entity *dl_se, s64if (!is_leftmost (dl_se, &rq->dl))resched_curr (rq); } - -/* -* 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 ; - -#ifdef CONFIG_RT_GROUP_SCHED -/* -* 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. -* -* Account to the root rt group for now. -* -* The solution we're working towards is having the RT groups scheduled -* using deadline servers -- however there's a few nasties to figure -* out before that can happen. -*/ -if (rt_bandwidth_enabled ()) { -struct rt_rq *rt_rq = &rq->rt; - -raw_spin_lock (&rt_rq->rt_runtime_lock); -/* -* We'll let actual RT tasks worry about the overflow here, we -* have our own CBS to keep us inline; only account when RT -* bandwidth is relevant. -*/ -if (sched_rt_bandwidth_account (rt_rq)) - rt_rq->rt_time += delta_exec; -raw_spin_unlock (&rt_rq->rt_runtime_lock); - } -#endif }/*
kernel/sched/debug.c +0 -6
@@ -907,12 +907,6 @@ void print_rt_rq(struct seq_file *m, int cpu, struct rt_rq *rt_rq)PU (rt_nr_running); -#ifdef CONFIG_RT_GROUP_SCHED -P (rt_throttled); -PN (rt_time); -PN (rt_runtime); -#endif -#undef PN#undef PU#undef P
kernel/sched/rt.c +9 -689
844 lines not on this page · raw message
kernel/sched/sched.h +2 -30
@@ -309,15 +309,6 @@ struct rt_prio_array {struct list_head queue[MAX_RT_PRIO ]; }; -struct rt_bandwidth { -/* nests inside the rq lock: */ -raw_spinlock_t rt_runtime_lock; -ktime_t rt_period; -u64 rt_runtime; -struct hrtimer rt_period_timer; -unsigned int rt_period_active; -}; -struct dl_bandwidth {raw_spinlock_t dl_runtime_lock;u64 dl_runtime;
@@ -471,7 +462,6 @@ struct task_group {struct sched_dl_entity **dl_se;struct rt_rq **rt_rq; -struct rt_bandwidth rt_bandwidth;struct dl_bandwidth dl_bandwidth;#endif
@@ -797,11 +787,6 @@ struct scx_rq { };#endif /* CONFIG_SCHED_CLASS_EXT */ -static inline int rt_bandwidth_enabled (void ) -{ -return 0 ; -} -/* RT IPI pull logic requires IRQ_WORK */ #if defined(CONFIG_IRQ_WORK ) && defined(CONFIG_SMP )# define HAVE_RT_PUSH_IPI
@@ -825,17 +810,7 @@ struct rt_rq {struct plist_head pushable_tasks;#endif /* CONFIG_SMP */ -int rt_queued; - -#ifdef CONFIG_RT_GROUP_SCHED -int rt_throttled; -u64 rt_time;/* consumed RT time, goes up in update_curr_rt */ -u64 rt_runtime;/* allotted RT time, "slice" from rt_bandwidth, RT sharing/balancing */ -/* Nests inside the rq lock: */ -raw_spinlock_t rt_runtime_lock; -unsigned int rt_nr_boosted; -#endif #ifdef CONFIG_CGROUP_SCHED struct task_group *tg;/* this tg has "this" rt_rq on given CPU for runnable entities */ #endif
@@ -845,7 +820,7 @@ struct rt_rq {static inline bool rt_rq_is_runnable (struct rt_rq *rt_rq) { -return rt_rq->rt_queued && rt_rq->rt_nr_running; +return rt_rq->rt_nr_running; }/* Deadline class' related fields in a runqueue */
@@ -2581,7 +2556,7 @@ static inline bool sched_dl_runnable(struct rq *rq)static inline bool sched_rt_runnable (struct rq *rq) { -return rq->rt.rt_queued >0 ; +return rq->rt.rt_nr_running >0 ; }static inline bool sched_fair_runnable (struct rq *rq)
@@ -2714,9 +2689,6 @@ extern void resched_curr(struct rq *rq);extern void resched_curr_lazy (struct rq *rq);extern void resched_cpu (int cpu); -extern void init_rt_bandwidth (struct rt_bandwidth *rt_b,u64 period,u64 runtime); -extern bool sched_rt_bandwidth_account (struct rt_rq *rt_rq); -void init_dl_bandwidth (struct dl_bandwidth *dl_b,u64 period,u64 runtime);extern void init_dl_entity (struct sched_dl_entity *dl_se);
Signature · 1 line
2.49.0
RFC PATCH 7/9 sched/core: Cgroup v2 support
In reply to Yuri AndriaccioFrom: luca abeni <[email protected]>
Make rt_runtime_us and rt_period_us virtual files accessible also to the cgroup v2 controller, effectively enabling the RT_GROUP_SCHED mechanism to cgroups v2.
--- kernel/sched/core.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
kernel/sched/core.c +12 -0
@@ -10134,6 +10134,18 @@ static struct cftype cpu_files[] = { .seq_show = cpu_uclamp_max_show, .write = cpu_uclamp_max_write, }, +#endif +#ifdef CONFIG_RT_GROUP_SCHED + { + .name = "rt_runtime_us", + .read_s64 = cpu_rt_runtime_read, + .write_s64 = cpu_rt_runtime_write, + }, + { + .name = "rt_period_us", + .read_u64 = cpu_rt_period_read_uint, + .write_u64 = cpu_rt_period_write_uint, + }, #endif { } /* terminate */ };
Signature · 1 line
2.49.0
RFC PATCH 8/9 sched/rt: Remove support for cgroups-v1
In reply to Yuri AndriaccioDisable control files for cgroups-v1, and allow only cgroups-v2. This should simplify maintaining the code, also because cgroups-v1 is deprecated.
Set the default rt-cgroups runtime to zero, otherwise a cgroup-v1 kernel will not be able to start SCHED_DEADLINE tasks.
Allow zeroing the runtime of the root control group. This runtime only affects the available bandwidth of the rt-cgroup hierarchy but not the SCHED_FIFO / SCHED_RR tasks on the global runqueue.
Notes:
Disabling the root control group bandwidth should not cause any side effect, as SCHED_FIFO / SCHED_RR tasks do not depend on it since the introduction of fair_servers.
--- kernel/sched/core.c | 22 ++-------------------- kernel/sched/rt.c | 13 +++++-------- kernel/sched/syscalls.c | 2 +- 3 files changed, 8 insertions(+), 29 deletions(-)
kernel/sched/core.c +2 -20
@@ -8566,7 +8566,7 @@ void __init sched_init(void)#ifdef CONFIG_RT_GROUP_SCHED init_dl_bandwidth (&root_task_group.dl_bandwidth, -global_rt_period (),global_rt_runtime ()); +global_rt_period (),0 );#endif /* CONFIG_RT_GROUP_SCHED */ #ifdef CONFIG_CGROUP_SCHED
@@ -9198,7 +9198,7 @@ static int cpu_cgroup_can_attach(struct cgroup_taskset *tset) goto scx_check;cgroup_taskset_for_each (task, css, tset) { -if (!sched_rt_can_attach (css_tg (css), task)) +if (rt_task (task) && !sched_rt_can_attach (css_tg (css), task))return -EINVAL ; } scx_check:
@@ -9873,20 +9873,6 @@ static struct cftype cpu_legacy_files[] = { };#ifdef CONFIG_RT_GROUP_SCHED -static struct cftype rt_group_files[] = { - { - .name ="rt_runtime_us" , - .read_s64 = cpu_rt_runtime_read, - .write_s64 = cpu_rt_runtime_write, - }, - { - .name ="rt_period_us" , - .read_u64 = cpu_rt_period_read_uint, - .write_u64 = cpu_rt_period_write_uint, - }, - { }/* Terminate */ -}; -# ifdef CONFIG_RT_GROUP_SCHED_DEFAULT_DISABLED DEFINE_STATIC_KEY_FALSE (rt_group_sched);# else
@@ -9912,10 +9898,6 @@ __setup("rt_group_sched=", setup_rt_group_sched);static int __init cpu_rt_group_init (void ) { -if (!rt_group_sched_enabled ()) -return 0 ; - -WARN_ON (cgroup_add_legacy_cftypes (&cpu_cgrp_subsys, rt_group_files));return 0 ; }subsys_initcall (cpu_rt_group_init);
kernel/sched/rt.c +5 -8
@@ -2197,13 +2197,6 @@ static int tg_set_rt_bandwidth(struct task_group *tg, {int i, err =0 ; -/* -* Disallowing the root group RT runtime is BAD, it would disallow the -* kernel creating (and or operating) RT threads. -*/ -if (tg == &root_task_group && rt_runtime ==0 ) -return -EINVAL ; -/* No period doesn't make any sense. */ if (rt_period ==0 )return -EINVAL ;
@@ -2297,8 +2290,12 @@ static int sched_rt_global_constraints(void)int sched_rt_can_attach (struct task_group *tg,struct task_struct *tsk) { +/* Allow executing in the root cgroup regardless of allowed bandwidth */ +if (tg == &root_task_group) +return 1 ; +/* Don't accept real-time tasks when there is no way for them to run */ -if (rt_group_sched_enabled () &&rt_task (tsk) && tg->dl_bandwidth.dl_runtime ==0 ) +if (rt_group_sched_enabled () && tg->dl_bandwidth.dl_runtime ==0 )return 0 ;return 1 ;
kernel/sched/syscalls.c +1 -1
@@ -636,7 +636,7 @@ int __sched_setscheduler(struct task_struct *p,*/ if (rt_group_sched_enabled () &&dl_bandwidth_enabled () &&rt_policy (policy) && -task_group (p)->dl_bandwidth.dl_runtime ==0 && + !sched_rt_can_attach (task_group (p), p) && !task_group_is_autogroup (task_group (p))) { retval = -EPERM ; goto unlock;
Signature · 1 line
2.49.0
Juri Lelli
maintainerRe: [RFC PATCH 8/9] sched/rt: Remove support for cgroups-v1
Hello,
Quoted 2 lines · Yuri Andriaccio
Disable control files for cgroups-v1, and allow only cgroups-v2. This should simplify maintaining the code, also because cgroups-v1 is deprecated.
I wonder if the change above and what below need to be split in separate patches. They look orthogonal and we would have a single separate patch disabling v1 support which is probably desirable.
Quoted 11 lines
Set the default rt-cgroups runtime to zero, otherwise a cgroup-v1 kernel will not be able to start
SCHED_DEADLINEtasks.Allow zeroing the runtime of the root control group. This runtime only affects the available bandwidth of the rt-cgroup hierarchy but not the
SCHED_FIFO/SCHED_RRtasks on the global runqueue.Notes:
Disabling the root control group bandwidth should not cause any side effect, asSCHED_FIFO/SCHED_RRtasks do not depend on it since the introduction offair_servers.
Also, what summarized above needs to be well documented in the kernel docs, as I am pretty sure it will surprise people (actually surprised even myself while playing with the set :).
Thanks,
Juri
RFC PATCH 9/9 sched/deadline: Allow deeper hierarchies of RT cgroups
In reply to Yuri AndriaccioFrom: luca abeni <[email protected]>
Allow creation of cgroup hierachies with depth greater than two. Add check to prevent attaching tasks to a child cgroup of an active cgroup (i.e. with a running FIFO/RR task).
Add check to prevent attaching tasks to cgroups which have children with non-zero runtime.
Update rt-cgroups allocated bandwidth accounting for nested cgroup hierachies.
--- kernel/sched/core.c | 6 ---- kernel/sched/deadline.c | 69 ++++++++++++++++++++++++++++++++++------- kernel/sched/rt.c | 25 +++++++++++++-- kernel/sched/sched.h | 2 +- kernel/sched/syscalls.c | 4 +++ 5 files changed, 84 insertions(+), 22 deletions(-)
kernel/sched/core.c +0 -6
@@ -9127,12 +9127,6 @@ cpu_cgroup_css_alloc(struct cgroup_subsys_state *parent_css)return &root_task_group.css; } -/* Do not allow cpu_cgroup hierachies with depth greater than 2. */ -#ifdef CONFIG_RT_GROUP_SCHED -if (parent != &root_task_group) -return ERR_PTR (-EINVAL ); -#endif - tg =sched_create_group (parent);if (IS_ERR (tg))return ERR_PTR (-ENOMEM );
kernel/sched/deadline.c +57 -12
91 lines not on this page · raw message
kernel/sched/rt.c +22 -3
@@ -106,7 +106,8 @@ void free_rt_sched_group(struct task_group *tg)* Fix this issue by changing the group runtime * to 0 immediately before freeing it. */ -BUG_ON (!dl_init_tg (tg->dl_se[i],0 , tg->dl_se[i]->dl_period)); +if (tg->dl_se[i]->dl_runtime) +BUG_ON (!dl_init_tg (tg, i,0 , tg->dl_se[i]->dl_period));raw_spin_rq_lock_irqsave (cpu_rq (i), flags);BUG_ON (tg->rt_rq[i]->rt_nr_running);raw_spin_rq_unlock_irqrestore (cpu_rq (i), flags);
@@ -2197,6 +2198,14 @@ static int tg_set_rt_bandwidth(struct task_group *tg, {int i, err =0 ; +/* +* Do not allow to set a RT runtime > 0 if the parent has RT tasks +* (and is not the root group) +*/ +if (rt_runtime && (tg != &root_task_group) && (tg->parent != &root_task_group) &&tg_has_rt_tasks (tg->parent)) { +return -EINVAL ; + } +/* No period doesn't make any sense. */ if (rt_period ==0 )return -EINVAL ;
@@ -2220,7 +2229,7 @@ static int tg_set_rt_bandwidth(struct task_group *tg, goto unlock_bandwidth;for_each_possible_cpu (i) { -if (!dl_init_tg (tg->dl_se[i], rt_runtime, rt_period)) { +if (!dl_init_tg (tg, i, rt_runtime, rt_period)) { err = -EINVAL ;break ; }
@@ -2290,6 +2299,9 @@ static int sched_rt_global_constraints(void)int sched_rt_can_attach (struct task_group *tg,struct task_struct *tsk) { +struct task_group *child; +int can_attach =1 ; +/* Allow executing in the root cgroup regardless of allowed bandwidth */ if (tg == &root_task_group)return 1 ;
@@ -2298,7 +2310,14 @@ int sched_rt_can_attach(struct task_group *tg, struct task_struct *tsk)if (rt_group_sched_enabled () && tg->dl_bandwidth.dl_runtime ==0 )return 0 ; - return 1; +/* If one of the children has runtime > 0, cannot attach RT tasks! */ +list_for_each_entry_rcu (child, &tg->children, siblings) { +if (child->dl_bandwidth.dl_runtime) { + can_attach =0 ; + } + } + + return can_attach; }#else /* !CONFIG_RT_GROUP_SCHED */
kernel/sched/sched.h +1 -1
@@ -384,7 +384,7 @@ extern void dl_server_init(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq,dl_server_has_tasks_f has_tasks, dl_server_pick_f pick_task);int dl_check_tg (unsigned long total); -int dl_init_tg (struct sched_dl_entity *dl_se,u64 rt_runtime,u64 rt_period); +int dl_init_tg (struct task_group *tg,int cpu,u64 rt_runtime,u64 rt_period);extern void dl_server_update_idle_time (struct rq *rq,struct task_struct *p);
kernel/sched/syscalls.c +4 -0
@@ -630,6 +630,10 @@ int __sched_setscheduler(struct task_struct *p,if (user) {#ifdef CONFIG_RT_GROUP_SCHED +if (dl_bandwidth_enabled () &&rt_policy (policy) && !sched_rt_can_attach (task_group (p), p)) { + retval = -EPERM ; + goto unlock; + }/* * Do not allow real-time tasks into groups that have no runtime * assigned.
Signature · 1 line
2.49.0
Juri Lelli
maintainerRe: [RFC PATCH 9/9] sched/deadline: Allow deeper hierarchies of RT cgroups
Hello,
Quoted 19 lines · Yuri Andriaccio
From: luca abeni <[email protected]>
Allow creation of cgroup hierachies with depth greater than two. Add check to prevent attaching tasks to a child cgroup of an active cgroup (i.e. with a running FIFO/RR task).
Add check to prevent attaching tasks to cgroups which have children with non-zero runtime.
Update rt-cgroups allocated bandwidth accounting for nested cgroup hierachies.Co-developed-by Yuri Andriaccio <[email protected]>Signed-off-by Yuri Andriaccio <[email protected]>Signed-off-by luca abeni <[email protected]>--- kernel/sched/core.c | 6 ---- kernel/sched/deadline.c | 69 ++++++++++++++++++++++++++++++++++------- kernel/sched/rt.c | 25 +++++++++++++-- kernel/sched/sched.h | 2 +- kernel/sched/syscalls.c | 4 +++ 5 files changed, 84 insertions(+), 22 deletions(-)
...
Quoted 31 lines
kernel/sched/deadline.c +15
-6@@ -434,24 +463,40 @@ int dl_init_tg(struct sched_dl_entity *dl_se, u64 rt_runtime, u64 rt_period)if (rt_period & (1ULL <<63 ))return 0 ; + is_active_group =is_active_sched_group (tg); +raw_spin_rq_lock_irq (rq); is_active = dl_se->my_q->rt.rt_nr_running >0 ; old_runtime = dl_se->dl_runtime; dl_se->dl_runtime = rt_runtime; dl_se->dl_period = rt_period; dl_se->dl_deadline = dl_se->dl_period; -if (is_active) { -sub_running_bw (dl_se, dl_se->dl_rq); - }else if (dl_se->dl_non_contending) { -sub_running_bw (dl_se, dl_se->dl_rq); - dl_se->dl_non_contending =0 ; -hrtimer_try_to_cancel (&dl_se->inactive_timer); +if (is_active_group) { +if (is_active) { +sub_running_bw (dl_se, dl_se->dl_rq); + }else if (dl_se->dl_non_contending) { +sub_running_bw (dl_se, dl_se->dl_rq); + dl_se->dl_non_contending =0 ; +hrtimer_try_to_cancel (&dl_se->inactive_timer); + } +__sub_rq_bw (dl_se->dl_bw, dl_se->dl_rq); + dl_se->dl_bw =to_ratio (dl_se->dl_period, dl_se->dl_runtime); +__add_rq_bw (dl_se->dl_bw, dl_se->dl_rq); + }else { + dl_se->dl_bw =to_ratio (dl_se->dl_period, dl_se->dl_runtime);
kernel/sched/deadline.c int dl_init_tg(struct sched_dl_entity *dl_se, u64 rt_runtime, u64 rt_period) · line 496
Quoted 10 lines
kernel/sched/deadline.c +10
-0+ } + +// add/remove the parent's bw +if (tg->parent && tg->parent != &root_task_group) + { +if (rt_runtime ==0 && old_runtime !=0 && !sched_group_has_active_siblings (tg)) { +__add_rq_bw (tg->parent->dl_se[cpu]->dl_bw, dl_se->dl_rq); + }else if (rt_runtime !=0 && old_runtime ==0 && !sched_group_has_active_siblings (tg)) { +__sub_rq_bw (tg->parent->dl_se[cpu]->dl_bw, dl_se->dl_rq); + }
Don't we need to do something also when rt_runtime changes ({in,de}creases) and old_runtime wasn't zero? Like for example giving a bit of bandwidth back to the parent if a child bandwidth is reduced, but not completely set to zero.
Thanks,
Juri