sched/eevdf: fix rb augmented with multi fields
Vincent Guittot
maintainerPATCH v2 1/1 sched/eevdf: fix rb augmented with multi fields
The eevdf rb tree maintains 3 augmented fields but only one is currently copied when balancing the tree.
Add a more generic define that can be used when there are several augmented fields. In this case, we provide a function that takes care of copying all fields.
---
Since v1:
- Removed useless the comment of min_vruntime_copy()
- Added tested and reviewed tags
include/linux/rbtree_augmented.h | 35 +++++++++++++++++++++++++------- kernel/sched/fair.c | 12 +++++++++-- 2 files changed, 38 insertions(+), 9 deletions(-)
include/linux/rbtree_augmented.h +28 -7
@@ -87,18 +87,18 @@ rb_add_augmented_cached(struct rb_node *node, struct rb_root_cached *tree, }/* -* Template for declaring augmented rbtree callbacks (generic case) +* Template for declaring augmented rbtree callbacks (generic multi fields) * * RBSTATIC: 'static' or empty * RBNAME: name of the rb_augment_callbacks structure * RBSTRUCT: struct type of the tree nodes * RBFIELD: name of struct rb_node field within RBSTRUCT -* RBAUGMENTED: name of field within RBSTRUCT holding data for subtree -* RBCOMPUTE: name of function that recomputes the RBAUGMENTED data +* RBCOPY: name of function that copies the RBAUGMENTED datas +* RBCOMPUTE: name of function that recomputes the RBAUGMENTED datas */ -#define RB_DECLARE_CALLBACKS (RBSTATIC ,RBNAME , \ -RBSTRUCT ,RBFIELD ,RBAUGMENTED ,RBCOMPUTE ) \ +#define RB_DECLARE_CALLBACKS_MULTI (RBSTATIC ,RBNAME , \ +RBSTRUCT ,RBFIELD ,RBCOPY ,RBCOMPUTE ) \ static inline void \ RBNAME ## _propagate(struct rb_node *rb, struct rb_node *stop) \ { \
@@ -114,14 +114,14 @@ RBNAME ## _copy(struct rb_node *rb_old, struct rb_node *rb_new) \ { \RBSTRUCT *old =rb_entry (rb_old,RBSTRUCT ,RBFIELD ); \RBSTRUCT *new =rb_entry (rb_new,RBSTRUCT ,RBFIELD ); \ - new->RBAUGMENTED = old->RBAUGMENTED; \ +RBCOPY (new, old); \ } \static void \ RBNAME ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \ { \RBSTRUCT *old =rb_entry (rb_old,RBSTRUCT ,RBFIELD ); \RBSTRUCT *new =rb_entry (rb_new,RBSTRUCT ,RBFIELD ); \ - new->RBAUGMENTED = old->RBAUGMENTED; \ +RBCOPY (new, old); \RBCOMPUTE (old, false); \ } \ RBSTATIC const struct rb_augment_callbacks RBNAME = { \
@@ -130,6 +130,27 @@ RBSTATIC const struct rb_augment_callbacks RBNAME = { \ .rotate = RBNAME ## _rotate \ }; +/* +* Template for declaring augmented rbtree callbacks (generic single field) +* +* RBSTATIC: 'static' or empty +* RBNAME: name of the rb_augment_callbacks structure +* RBSTRUCT: struct type of the tree nodes +* RBFIELD: name of struct rb_node field within RBSTRUCT +* RBAUGMENTED: name of field within RBSTRUCT holding data for subtree +* RBCOMPUTE: name of function that recomputes the RBAUGMENTED data +*/ + +#define RB_DECLARE_CALLBACKS (RBSTATIC ,RBNAME , \ +RBSTRUCT ,RBFIELD ,RBAUGMENTED ,RBCOMPUTE ) \ +static inline void \ +RBNAME ## _copy_single(RBSTRUCT *new, RBSTRUCT *old) \ +{ \ + new->RBAUGMENTED = old->RBAUGMENTED; \ +} \ +RB_DECLARE_CALLBACKS_MULTI(RBSTATIC, RBNAME, \ + RBSTRUCT, RBFIELD, RBNAME ## _copy_single, RBCOMPUTE) +/* * Template for declaring augmented rbtree callbacks, * computing RBAUGMENTED scalar as max(RBCOMPUTE(node)) for all subtree nodes.
kernel/sched/fair.c +10 -2
@@ -1032,6 +1032,13 @@ static inline void __max_slice_update(struct sched_entity *se, struct rb_node *n } } +static inline void min_vruntime_copy (struct sched_entity *new,struct sched_entity *old) +{ + new->min_vruntime = old->min_vruntime; + new->min_slice = old->min_slice; + new->max_slice = old->max_slice; +} +/* * se->min_vruntime = min(se->vruntime, {left,right}->min_vruntime) */
@@ -1059,8 +1066,9 @@ static inline bool min_vruntime_update(struct sched_entity *se, bool exit) se->max_slice == old_max_slice; } -RB_DECLARE_CALLBACKS(static, min_vruntime_cb, struct sched_entity, - run_node, min_vruntime, min_vruntime_update); + +RB_DECLARE_CALLBACKS_MULTI(static, min_vruntime_cb, struct sched_entity, + run_node, min_vruntime_copy, min_vruntime_update);/* * Enqueue an entity into the rb-tree:
Signature · 1 line
2.53.0
[tip: sched/urgent] sched/eevdf: Fix rb augmented with multi fields
The following commit has been merged into the sched/urgent branch of tip:
The following commit has been merged into the sched/urgent branch of tip:
Commit-ID: 51b0e68cfa0ac69e3c3ea9d6753af7e15dfaab22 Gitweb: https://git.kernel.org/tip/51b0e68cfa0ac69e3c3ea9d6753af7e15dfaab22 Author: Vincent Guittot <[email protected]> AuthorDate: Wed, 09 Sep 2026 17:05:22 +02:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Thu, 10 Sep 2026 10:22:52 +02:00
sched/eevdf: Fix rb augmented with multi fields
The eevdf rb tree maintains 3 augmented fields but only one is currently copied when balancing the tree.
Add a more generic define that can be used when there are several augmented fields. In this case, we provide a function that takes care of copying all fields.
--- include/linux/rbtree_augmented.h | 35 ++++++++++++++++++++++++------- kernel/sched/fair.c | 12 +++++++++-- 2 files changed, 38 insertions(+), 9 deletions(-)
include/linux/rbtree_augmented.h +28 -7
@@ -87,18 +87,18 @@ rb_add_augmented_cached(struct rb_node *node, struct rb_root_cached *tree, }/* -* Template for declaring augmented rbtree callbacks (generic case) +* Template for declaring augmented rbtree callbacks (generic multi fields) * * RBSTATIC: 'static' or empty * RBNAME: name of the rb_augment_callbacks structure * RBSTRUCT: struct type of the tree nodes * RBFIELD: name of struct rb_node field within RBSTRUCT -* RBAUGMENTED: name of field within RBSTRUCT holding data for subtree -* RBCOMPUTE: name of function that recomputes the RBAUGMENTED data +* RBCOPY: name of function that copies the RBAUGMENTED datas +* RBCOMPUTE: name of function that recomputes the RBAUGMENTED datas */ -#define RB_DECLARE_CALLBACKS (RBSTATIC ,RBNAME , \ -RBSTRUCT ,RBFIELD ,RBAUGMENTED ,RBCOMPUTE ) \ +#define RB_DECLARE_CALLBACKS_MULTI (RBSTATIC ,RBNAME , \ +RBSTRUCT ,RBFIELD ,RBCOPY ,RBCOMPUTE ) \ static inline void \ RBNAME ## _propagate(struct rb_node *rb, struct rb_node *stop) \ { \
@@ -114,14 +114,14 @@ RBNAME ## _copy(struct rb_node *rb_old, struct rb_node *rb_new) \ { \RBSTRUCT *old =rb_entry (rb_old,RBSTRUCT ,RBFIELD ); \RBSTRUCT *new =rb_entry (rb_new,RBSTRUCT ,RBFIELD ); \ - new->RBAUGMENTED = old->RBAUGMENTED; \ +RBCOPY (new, old); \ } \static void \ RBNAME ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \ { \RBSTRUCT *old =rb_entry (rb_old,RBSTRUCT ,RBFIELD ); \RBSTRUCT *new =rb_entry (rb_new,RBSTRUCT ,RBFIELD ); \ - new->RBAUGMENTED = old->RBAUGMENTED; \ +RBCOPY (new, old); \RBCOMPUTE (old, false); \ } \ RBSTATIC const struct rb_augment_callbacks RBNAME = { \
@@ -131,6 +131,27 @@ RBSTATIC const struct rb_augment_callbacks RBNAME = { \ };/* +* Template for declaring augmented rbtree callbacks (generic single field) +* +* RBSTATIC: 'static' or empty +* RBNAME: name of the rb_augment_callbacks structure +* RBSTRUCT: struct type of the tree nodes +* RBFIELD: name of struct rb_node field within RBSTRUCT +* RBAUGMENTED: name of field within RBSTRUCT holding data for subtree +* RBCOMPUTE: name of function that recomputes the RBAUGMENTED data +*/ + +#define RB_DECLARE_CALLBACKS (RBSTATIC ,RBNAME , \ +RBSTRUCT ,RBFIELD ,RBAUGMENTED ,RBCOMPUTE ) \ +static inline void \ +RBNAME ## _copy_single(RBSTRUCT *new, RBSTRUCT *old) \ +{ \ + new->RBAUGMENTED = old->RBAUGMENTED; \ +} \ +RB_DECLARE_CALLBACKS_MULTI(RBSTATIC, RBNAME, \ + RBSTRUCT, RBFIELD, RBNAME ## _copy_single, RBCOMPUTE) + +/* * Template for declaring augmented rbtree callbacks, * computing RBAUGMENTED scalar as max(RBCOMPUTE(node)) for all subtree nodes. *
kernel/sched/fair.c +10 -2
@@ -1032,6 +1032,13 @@ static inline void __max_slice_update(struct sched_entity *se, struct rb_node *n } } +static inline void min_vruntime_copy (struct sched_entity *new,struct sched_entity *old) +{ + new->min_vruntime = old->min_vruntime; + new->min_slice = old->min_slice; + new->max_slice = old->max_slice; +} +/* * se->min_vruntime = min(se->vruntime, {left,right}->min_vruntime) */
@@ -1059,8 +1066,9 @@ static inline bool min_vruntime_update(struct sched_entity *se, bool exit) se->max_slice == old_max_slice; } -RB_DECLARE_CALLBACKS(static, min_vruntime_cb, struct sched_entity, - run_node, min_vruntime, min_vruntime_update); + +RB_DECLARE_CALLBACKS_MULTI(static, min_vruntime_cb, struct sched_entity, + run_node, min_vruntime_copy, min_vruntime_update);/* * Enqueue an entity into the rb-tree: