Re: [RFC PATCH v4 10/28] sched/rt: Add {alloc/free}_rt_sched_group
From: Juri Lelli
Date: Mon Jan 19 2026 - 08:49:21 EST
Hello,
On 01/12/25 13:41, Yuri Andriaccio wrote:
> From: luca abeni <luca.abeni@xxxxxxxxxxxxxxx>
>
> - Add allocation and deallocation code for rt-cgroups.
> - Declare dl_server specific functions (only skeleton, but no
> implementation yet), needed by the deadline servers to be called when
> trying to schedule.
>
> Co-developed-by: Alessio Balsini <a.balsini@xxxxxxxx>
> Signed-off-by: Alessio Balsini <a.balsini@xxxxxxxx>
> Co-developed-by: Andrea Parri <parri.andrea@xxxxxxxxx>
> Signed-off-by: Andrea Parri <parri.andrea@xxxxxxxxx>
> Co-developed-by: Yuri Andriaccio <yurand2000@xxxxxxxxx>
> Signed-off-by: Yuri Andriaccio <yurand2000@xxxxxxxxx>
> Signed-off-by: luca abeni <luca.abeni@xxxxxxxxxxxxxxx>
> ---
...
> +static inline void __dl_se_free(struct sched_dl_entity **dl_se)
> +{
> + int i;
> +
> + for_each_possible_cpu(i) {
> + kfree(dl_se[i]);
> + }
> +
> + kfree(dl_se);
> }
>
> +DEFINE_FREE(dl_se_free, struct sched_dl_entity **, if (_T) __dl_se_free(_T))
> +
> int alloc_rt_sched_group(struct task_group *tg, struct task_group *parent)
> {
> + /* Instantiate automatic cleanup in event of kalloc fail */
> + struct rt_rq **tg_rt_rq __free(rt_rq_free) = NULL;
> + struct sched_dl_entity *dl_se, **tg_dl_se __free(dl_se_free) = NULL;
> + struct rq *s_rq;
> + int i;
> +
> if (!rt_group_sched_enabled())
> return 1;
>
> + /* Allocate all necessary resources beforehand */
> + tg_rt_rq = kcalloc(nr_cpu_ids, sizeof(struct rt_rq *), GFP_KERNEL);
> + if (!tg_rt_rq)
> + return 0;
> +
> + tg_dl_se = kcalloc(nr_cpu_ids,
> + sizeof(struct sched_dl_entity *), GFP_KERNEL);
> + if (!tg_dl_se)
> + return 0;
> +
> + for_each_possible_cpu(i) {
> + s_rq = kzalloc_node(sizeof(struct rq),
> + GFP_KERNEL, cpu_to_node(i));
> + if (!s_rq)
> + return 0;
> +
> + dl_se = kzalloc_node(sizeof(struct sched_dl_entity),
> + GFP_KERNEL, cpu_to_node(i));
> + if (!dl_se) {
> + kfree(s_rq);
> + return 0;
> + }
Would it be possible and make sense to use the __free() approach in the
above two cases as well?
Thanks,
Juri