2023-10-09 12:23:20

by Yajun Deng

[permalink] [raw]
Subject: [PATCH v7 0/3] sched/rt: Move sched_rt_entity::back to CONFIG_RT_GROUP_SCHED

The member back in struct sched_rt_entity only related to RT_GROUP_SCHED,
it should not place out of RT_GROUP_SCHED, move back to RT_GROUP_SCHED.
It will save a few bytes.

The 1st patch is introduce for_each_sched_rt_entity_back() & use it,
it no functional changes.

The 2nd patch is init 'back' in init_tg_rt_entry, it remove the call to
back when CONFIG_RT_GROUP_SCHED is disabled.

The 3rd patch is move sched_rt_entity::back to under the
CONFIG_RT_GROUP_SCHED block, it will save a few bytes.

Yajun Deng (3):
sched/rt: Introduce for_each_sched_rt_entity_back() & use it
sched/rt: Init 'back' in init_tg_rt_entry
sched/headers: Move sched_rt_entity::back to under the
CONFIG_RT_GROUP_SCHED block

include/linux/sched.h | 2 +-
kernel/sched/rt.c | 17 ++++++++++++-----
2 files changed, 13 insertions(+), 6 deletions(-)

--
2.25.1


2023-10-09 12:23:30

by Yajun Deng

[permalink] [raw]
Subject: [PATCH v7 1/3] sched/rt: Introduce for_each_sched_rt_entity_back() & use it

Introduce for_each_sched_rt_entity_back() & use it, because it's safe to
call it whether CONFIG_RT_GROUP_SCHED is enabled or disabled.

No functional changes.

Signed-off-by: Yajun Deng <[email protected]>
---
v7: Same with v6.
v6: Independent patch.
v5: Resend it.
v4: Missed rt_se = root in dequeue_rt_stack().
v3: Keep parent is NULL in init_tg_rt_entry().
v2: Add WARN_ON_ONCE in init_tg_rt_entry().
v1: https://lore.kernel.org/all/[email protected]/
---
kernel/sched/rt.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index 88fc98601413..642edbd24ffb 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -520,6 +520,9 @@ static inline struct task_group *next_task_group(struct task_group *tg)
#define for_each_sched_rt_entity(rt_se) \
for (; rt_se; rt_se = rt_se->parent)

+#define for_each_sched_rt_entity_back(rt_se) \
+ for (; rt_se; rt_se = rt_se->back)
+
static inline struct rt_rq *group_rt_rq(struct sched_rt_entity *rt_se)
{
return rt_se->my_q;
@@ -625,6 +628,9 @@ typedef struct rt_rq *rt_rq_iter_t;
#define for_each_sched_rt_entity(rt_se) \
for (; rt_se; rt_se = NULL)

+#define for_each_sched_rt_entity_back(rt_se) \
+ for_each_sched_rt_entity(rt_se)
+
static inline struct rt_rq *group_rt_rq(struct sched_rt_entity *rt_se)
{
return NULL;
@@ -1445,7 +1451,8 @@ static void dequeue_rt_stack(struct sched_rt_entity *rt_se, unsigned int flags)

rt_nr_running = rt_rq_of_se(back)->rt_nr_running;

- for (rt_se = back; rt_se; rt_se = rt_se->back) {
+ rt_se = back;
+ for_each_sched_rt_entity_back(rt_se) {
if (on_rt_rq(rt_se))
__dequeue_rt_entity(rt_se, flags);
}
--
2.25.1

2023-10-09 12:23:41

by Yajun Deng

[permalink] [raw]
Subject: [PATCH v7 2/3] sched/rt: Init 'back' in init_tg_rt_entry

The member 'back' in struct sched_rt_entity only related to
CONFIG_RT_GROUP_SCHED, so there is no need to init it in dequeue_rt_stack.

Init the member 'back' in init_tg_rt_entry.

Signed-off-by: Yajun Deng <[email protected]>
---
v7: Init 'back' in init_tg_rt_entry.
v6: Independent patch.
v5: Resend it.
v4: Missed rt_se = root in dequeue_rt_stack().
v3: Keep parent is NULL in init_tg_rt_entry().
v2: Add WARN_ON_ONCE in init_tg_rt_entry().
v1: https://lore.kernel.org/all/[email protected]/
---
kernel/sched/rt.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index 642edbd24ffb..0d9e83c6fb71 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -233,8 +233,10 @@ void init_tg_rt_entry(struct task_group *tg, struct rt_rq *rt_rq,

if (!parent)
rt_se->rt_rq = &rq->rt;
- else
+ else {
rt_se->rt_rq = parent->my_q;
+ parent->back = rt_se;
+ }

rt_se->my_q = rt_rq;
rt_se->parent = parent;
@@ -1444,10 +1446,8 @@ static void dequeue_rt_stack(struct sched_rt_entity *rt_se, unsigned int flags)
struct sched_rt_entity *back = NULL;
unsigned int rt_nr_running;

- for_each_sched_rt_entity(rt_se) {
- rt_se->back = back;
+ for_each_sched_rt_entity(rt_se)
back = rt_se;
- }

rt_nr_running = rt_rq_of_se(back)->rt_nr_running;

--
2.25.1

2023-10-09 12:23:51

by Yajun Deng

[permalink] [raw]
Subject: [PATCH v7 3/3] sched/headers: Move sched_rt_entity::back to under the CONFIG_RT_GROUP_SCHED block

We already remove the call to the 'back' member when CONFIG_RT_GROUP_SCHED
is disabled.

It's safe to move sched_rt_entity::back to under the
CONFIG_RT_GROUP_SCHED block, it would save a few bytes.

Signed-off-by: Yajun Deng <[email protected]>
---
v7: Only move back under the CONFIG_RT_GROUP_SCHED block.
v6: Independent patch.
v5: Resend it.
v4: Missed rt_se = root in dequeue_rt_stack().
v3: Keep parent is NULL in init_tg_rt_entry().
v2: Add WARN_ON_ONCE in init_tg_rt_entry().
v1: https://lore.kernel.org/all/[email protected]/
---
include/linux/sched.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 292c31697248..d0fe56603e60 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -597,8 +597,8 @@ 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 *back;
struct sched_rt_entity *parent;
/* rq on which this entity is (to be) queued: */
struct rt_rq *rt_rq;
--
2.25.1