Skip to contentSkip to conversation

sched: Remove some redundancy

PATCH Applied Dietmar Eggemann 4 participants 12 messages Jun 3, 2020 – Jun 16, 2020 Scheduler

lore
Share & tools
lore

Dietmar Eggemann

author reviewer
#0 lore raw

cover sched: Remove some redundancy

Remove redundant functions, parameters and macros from the task scheduler code.

Dietmar Eggemann (4):
sched/pelt: Remove redundant cap_scale() definition sched/core: Remove redundant 'preempt' param from

    sched_class->yield_to_task()

sched/idle,stop: Remove .get_rr_interval from sched_class sched/fair: Remove unused 'sd' parameter from scale_rt_capacity()

 kernel/sched/core.c      | 2 +-
 kernel/sched/fair.c      | 6 +++---
 kernel/sched/idle.c      | 7 -------
 kernel/sched/pelt.c      | 2 --
 kernel/sched/sched.h     | 2 +-
 kernel/sched/stop_task.c | 8 --------
 6 files changed, 5 insertions(+), 22 deletions(-)
Signature · 1 line
2.17.1
author reviewer
#1 lore raw

PATCH 1/4 sched/pelt: Remove redundant cap_scale() definition

Besides in PELT cap_scale() is used in the Deadline scheduler class for scale-invariant bandwidth enforcement.
Remove the cap_scale() definition in kernel/sched/pelt.c and keep the one in kernel/sched/sched.h.

---
 kernel/sched/pelt.c | 2 --
 1 file changed, 2 deletions(-)
kernel/sched/pelt.c +0 -2
index b4b1ff96642f..dea5567e4f72 100644
@@ -83,8 +83,6 @@ static u32 __accumulate_pelt_segments(u64 periods, u32 d1, u32 d3)
 	return c1 + c2 + c3;
 }
 
-#define cap_scale(v, s) ((v)*(s) >> SCHED_CAPACITY_SHIFT)
-
 /*
  * Accumulate the three separate parts of the sum; d1 the remainder
  * of the last (incomplete) period, d2 the span of full periods and d3
Signature · 1 line
2.17.1
maintainer Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] sched/pelt: Remove redundant cap_scale() definition

Quoted 7 lines · Dietmar Eggemann

Besides in PELT cap_scale() is used in the Deadline scheduler class for scale-invariant bandwidth enforcement.
Remove the cap_scale() definition in kernel/sched/pelt.c and keep the one in kernel/sched/sched.h.

Quoted 20 lines
---
 kernel/sched/pelt.c | 2 --
 1 file changed, 2 deletions(-)
kernel/sched/pelt.c +0 -3
index b4b1ff96642f..dea5567e4f72 100644
@@ -83,8 +83,6 @@ static u32 __accumulate_pelt_segments(u64 periods, u32 d1, u32 d3)
        return c1 + c2 + c3;
 }
 
-#define cap_scale(v, s) ((v)*(s) >> SCHED_CAPACITY_SHIFT)
-
 /*
  * Accumulate the three separate parts of the sum; d1 the remainder
  * of the last (incomplete) period, d2 the span of full periods and d3
--

2.17.1

#3 lore raw

[tip: sched/core] sched/pelt: Remove redundant cap_scale() definition

In reply to Dietmar Eggemann
The following commit has been merged into the sched/core branch of tip:

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     844eb6458facb09d4871a480d8bda06550927a80
Gitweb:        https://git.kernel.org/tip/844eb6458facb09d4871a480d8bda06550927a80
Author:        Dietmar Eggemann <[email protected]>
AuthorDate:    Wed, 03 Jun 2020 10:03:01 +02:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Mon, 15 Jun 2020 14:10:01 +02:00

sched/pelt: Remove redundant cap_scale() definition

Besides in PELT cap_scale() is used in the Deadline scheduler class for scale-invariant bandwidth enforcement.
Remove the cap_scale() definition in kernel/sched/pelt.c and keep the one in kernel/sched/sched.h.

---
 kernel/sched/pelt.c | 2 --
 1 file changed, 2 deletions(-)
kernel/sched/pelt.c +0 -2
index b4b1ff9..dea5567 100644
@@ -83,8 +83,6 @@ static u32 __accumulate_pelt_segments(u64 periods, u32 d1, u32 d3)
 	return c1 + c2 + c3;
 }
 
-#define cap_scale(v, s) ((v)*(s) >> SCHED_CAPACITY_SHIFT)
-
 /*
  * Accumulate the three separate parts of the sum; d1 the remainder
  * of the last (incomplete) period, d2 the span of full periods and d3
author reviewer
#4 lore raw

PATCH 2/4 sched/core: Remove redundant 'preempt' param from sched_class->yield_to_task()

In reply to Dietmar Eggemann

Commit 6d1cafd8b56e ("sched: Resched proper CPU on yield_to()") moved the code to resched the CPU from yield_to_task_fair() to yield_to() making the preempt parameter in sched_class->yield_to_task() unnecessary. Remove it. No other sched_class implements yield_to_task().

---
 kernel/sched/core.c  | 2 +-
 kernel/sched/fair.c  | 2 +-
 kernel/sched/sched.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
kernel/sched/core.c +1 -1
index 95e457d4ed1c..687b16047f92 100644
@@ -5812,7 +5812,7 @@ int __sched yield_to(struct task_struct *p, bool preempt)
 	if (task_running(p_rq, p) || p->state)
 		goto out_unlock;
 
-	yielded = curr->sched_class->yield_to_task(rq, p, preempt);
+	yielded = curr->sched_class->yield_to_task(rq, p);
 	if (yielded) {
 		schedstat_inc(rq->yld_count);
 		/*
kernel/sched/fair.c +1 -1
index dda9b194d225..5c4a559d0dae 100644
@@ -7158,7 +7158,7 @@ static void yield_task_fair(struct rq *rq)
 	set_skip_buddy(se);
 }
 
-static bool yield_to_task_fair(struct rq *rq, struct task_struct *p, bool preempt)
+static bool yield_to_task_fair(struct rq *rq, struct task_struct *p)
 {
 	struct sched_entity *se = &p->se;
 
kernel/sched/sched.h +1 -1
index 4b32cff0dcbe..12a0d0c7c164 100644
@@ -1752,7 +1752,7 @@ struct sched_class {
 	void (*enqueue_task) (struct rq *rq, struct task_struct *p, int flags);
 	void (*dequeue_task) (struct rq *rq, struct task_struct *p, int flags);
 	void (*yield_task)   (struct rq *rq);
-	bool (*yield_to_task)(struct rq *rq, struct task_struct *p, bool preempt);
+	bool (*yield_to_task)(struct rq *rq, struct task_struct *p);
 
 	void (*check_preempt_curr)(struct rq *rq, struct task_struct *p, int flags);
 
Signature · 1 line
2.17.1
#5 lore raw

[tip: sched/core] sched/core: Remove redundant 'preempt' param from sched_class->yield_to_task()

The following commit has been merged into the sched/core branch of tip:

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     0900acf2d8273f79432a4ded122ad5a265e85783
Gitweb:        https://git.kernel.org/tip/0900acf2d8273f79432a4ded122ad5a265e85783
Author:        Dietmar Eggemann <[email protected]>
AuthorDate:    Wed, 03 Jun 2020 10:03:02 +02:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Mon, 15 Jun 2020 14:10:01 +02:00

sched/core: Remove redundant 'preempt' param from sched_class->yield_to_task()

Commit 6d1cafd8b56e ("sched: Resched proper CPU on yield_to()") moved the code to resched the CPU from yield_to_task_fair() to yield_to() making the preempt parameter in sched_class->yield_to_task() unnecessary. Remove it. No other sched_class implements yield_to_task().

---
 kernel/sched/core.c  | 2 +-
 kernel/sched/fair.c  | 2 +-
 kernel/sched/sched.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
kernel/sched/core.c +1 -1
index 8f36032..9c89b0e 100644
@@ -5810,7 +5810,7 @@ again:
 	if (task_running(p_rq, p) || p->state)
 		goto out_unlock;
 
-	yielded = curr->sched_class->yield_to_task(rq, p, preempt);
+	yielded = curr->sched_class->yield_to_task(rq, p);
 	if (yielded) {
 		schedstat_inc(rq->yld_count);
 		/*
kernel/sched/fair.c +1 -1
index cbcb2f7..6a4dab2 100644
@@ -7157,7 +7157,7 @@ static void yield_task_fair(struct rq *rq)
 	set_skip_buddy(se);
 }
 
-static bool yield_to_task_fair(struct rq *rq, struct task_struct *p, bool preempt)
+static bool yield_to_task_fair(struct rq *rq, struct task_struct *p)
 {
 	struct sched_entity *se = &p->se;
 
kernel/sched/sched.h +1 -1
index 1d4e94c..8d5d068 100644
@@ -1748,7 +1748,7 @@ struct sched_class {
 	void (*enqueue_task) (struct rq *rq, struct task_struct *p, int flags);
 	void (*dequeue_task) (struct rq *rq, struct task_struct *p, int flags);
 	void (*yield_task)   (struct rq *rq);
-	bool (*yield_to_task)(struct rq *rq, struct task_struct *p, bool preempt);
+	bool (*yield_to_task)(struct rq *rq, struct task_struct *p);
 
 	void (*check_preempt_curr)(struct rq *rq, struct task_struct *p, int flags);
 
author reviewer
#6 lore raw

PATCH 3/4 sched/idle,stop: Remove .get_rr_interval from sched_class

In reply to Dietmar Eggemann

The idle task and stop task sched_classes return 0 in this function.

The single call site in sched_rr_get_interval() calls p->sched_class->get_rr_interval() only conditional in case it is defined. Otherwise time_slice=0 will be used.

The deadline sched class does not define it. Commit a57beec5d427 ("sched: Make sched_class::get_rr_interval() optional") introduced the default time-slice=0 for sched classes which do not provide this function.

So .get_rr_interval for idle and stop sched_class can be removed to shrink the code a little.

---
 kernel/sched/idle.c      | 7 -------
 kernel/sched/stop_task.c | 8 --------
 2 files changed, 15 deletions(-)
kernel/sched/idle.c +0 -7
index b743bf38f08f..70ea8565ae48 100644
@@ -442,11 +442,6 @@ prio_changed_idle(struct rq *rq, struct task_struct *p, int oldprio)
 	BUG();
 }
 
-static unsigned int get_rr_interval_idle(struct rq *rq, struct task_struct *task)
-{
-	return 0;
-}
-
 static void update_curr_idle(struct rq *rq)
 {
 }
@@ -475,8 +470,6 @@ const struct sched_class idle_sched_class = {
 
 	.task_tick		= task_tick_idle,
 
-	.get_rr_interval	= get_rr_interval_idle,
-
 	.prio_changed		= prio_changed_idle,
 	.switched_to		= switched_to_idle,
 	.update_curr		= update_curr_idle,
kernel/sched/stop_task.c +0 -8
index 4c9e9975684f..3e50a6a8f1e5 100644
@@ -102,12 +102,6 @@ prio_changed_stop(struct rq *rq, struct task_struct *p, int oldprio)
 	BUG(); /* how!?, what priority? */
 }
 
-static unsigned int
-get_rr_interval_stop(struct rq *rq, struct task_struct *task)
-{
-	return 0;
-}
-
 static void update_curr_stop(struct rq *rq)
 {
 }
@@ -136,8 +130,6 @@ const struct sched_class stop_sched_class = {
 
 	.task_tick		= task_tick_stop,
 
-	.get_rr_interval	= get_rr_interval_stop,
-
 	.prio_changed		= prio_changed_stop,
 	.switched_to		= switched_to_stop,
 	.update_curr		= update_curr_stop,
Signature · 1 line
2.17.1
#7 lore raw

[tip: sched/core] sched/idle,stop: Remove .get_rr_interval from sched_class

The following commit has been merged into the sched/core branch of tip:

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     e3e76a6a04114ec95b0969cd026e8904c67b431b
Gitweb:        https://git.kernel.org/tip/e3e76a6a04114ec95b0969cd026e8904c67b431b
Author:        Dietmar Eggemann <[email protected]>
AuthorDate:    Wed, 03 Jun 2020 10:03:03 +02:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Mon, 15 Jun 2020 14:10:01 +02:00

sched/idle,stop: Remove .get_rr_interval from sched_class

The idle task and stop task sched_classes return 0 in this function.

The single call site in sched_rr_get_interval() calls p->sched_class->get_rr_interval() only conditional in case it is defined. Otherwise time_slice=0 will be used.

The deadline sched class does not define it. Commit a57beec5d427 ("sched: Make sched_class::get_rr_interval() optional") introduced the default time-slice=0 for sched classes which do not provide this function.

So .get_rr_interval for idle and stop sched_class can be removed to shrink the code a little.

---
 kernel/sched/idle.c      | 7 -------
 kernel/sched/stop_task.c | 8 --------
 2 files changed, 15 deletions(-)
kernel/sched/idle.c +0 -7
index 05deb81..8d75ca2 100644
@@ -446,11 +446,6 @@ prio_changed_idle(struct rq *rq, struct task_struct *p, int oldprio)
 	BUG();
 }
 
-static unsigned int get_rr_interval_idle(struct rq *rq, struct task_struct *task)
-{
-	return 0;
-}
-
 static void update_curr_idle(struct rq *rq)
 {
 }
@@ -479,8 +474,6 @@ const struct sched_class idle_sched_class = {
 
 	.task_tick		= task_tick_idle,
 
-	.get_rr_interval	= get_rr_interval_idle,
-
 	.prio_changed		= prio_changed_idle,
 	.switched_to		= switched_to_idle,
 	.update_curr		= update_curr_idle,
kernel/sched/stop_task.c +0 -8
index 4c9e997..3e50a6a 100644
@@ -102,12 +102,6 @@ prio_changed_stop(struct rq *rq, struct task_struct *p, int oldprio)
 	BUG(); /* how!?, what priority? */
 }
 
-static unsigned int
-get_rr_interval_stop(struct rq *rq, struct task_struct *task)
-{
-	return 0;
-}
-
 static void update_curr_stop(struct rq *rq)
 {
 }
@@ -136,8 +130,6 @@ const struct sched_class stop_sched_class = {
 
 	.task_tick		= task_tick_stop,
 
-	.get_rr_interval	= get_rr_interval_stop,
-
 	.prio_changed		= prio_changed_stop,
 	.switched_to		= switched_to_stop,
 	.update_curr		= update_curr_stop,
author reviewer
#8 lore raw

PATCH 4/4 sched/fair: Remove unused 'sd' parameter from scale_rt_capacity()

In reply to Dietmar Eggemann

Since commit 8ec59c0f5f49 ("sched/topology: Remove unused 'sd' parameter from arch_scale_cpu_capacity()") it is no longer needed.

---
 kernel/sched/fair.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/sched/fair.c +2 -2
index 5c4a559d0dae..7158d4e3c855 100644
@@ -8039,7 +8039,7 @@ static inline void init_sd_lb_stats(struct sd_lb_stats *sds)
 	};
 }
 
-static unsigned long scale_rt_capacity(struct sched_domain *sd, int cpu)
+static unsigned long scale_rt_capacity(int cpu)
 {
 	struct rq *rq = cpu_rq(cpu);
 	unsigned long max = arch_scale_cpu_capacity(cpu);
@@ -8071,7 +8071,7 @@ static unsigned long scale_rt_capacity(struct sched_domain *sd, int cpu)
 
 static void update_cpu_capacity(struct sched_domain *sd, int cpu)
 {
-	unsigned long capacity = scale_rt_capacity(sd, cpu);
+	unsigned long capacity = scale_rt_capacity(cpu);
 	struct sched_group *sdg = sd->groups;
 
 	cpu_rq(cpu)->cpu_capacity_orig = arch_scale_cpu_capacity(cpu);
Signature · 1 line
2.17.1
maintainer Reviewed-by on v1 4/4
#9 lore raw

Re: [PATCH 4/4] sched/fair: Remove unused 'sd' parameter from scale_rt_capacity()

Quoted 9 lines · Dietmar Eggemann

Since commit 8ec59c0f5f49 ("sched/topology: Remove unused 'sd' parameter from arch_scale_cpu_capacity()") it is no longer needed.

---
 kernel/sched/fair.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 25 lines
kernel/sched/fair.c +2 -3
index 5c4a559d0dae..7158d4e3c855 100644
@@ -8039,7 +8039,7 @@ static inline void init_sd_lb_stats(struct sd_lb_stats *sds)
        };
 }
 
-static unsigned long scale_rt_capacity(struct sched_domain *sd, int cpu)
+static unsigned long scale_rt_capacity(int cpu)
 {
        struct rq *rq = cpu_rq(cpu);
        unsigned long max = arch_scale_cpu_capacity(cpu);
@@ -8071,7 +8071,7 @@ static unsigned long scale_rt_capacity(struct sched_domain *sd, int cpu)
 
 static void update_cpu_capacity(struct sched_domain *sd, int cpu)
 {
-       unsigned long capacity = scale_rt_capacity(sd, cpu);
+       unsigned long capacity = scale_rt_capacity(cpu);
        struct sched_group *sdg = sd->groups;
 
        cpu_rq(cpu)->cpu_capacity_orig = arch_scale_cpu_capacity(cpu);
--

2.17.1

#10 lore raw

[tip: sched/core] sched/fair: Remove unused 'sd' parameter from scale_rt_capacity()

In reply to Dietmar Eggemann
The following commit has been merged into the sched/core branch of tip:

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     1ca2034ed798aea72a68d3904bd39a6cbfbdf405
Gitweb:        https://git.kernel.org/tip/1ca2034ed798aea72a68d3904bd39a6cbfbdf405
Author:        Dietmar Eggemann <[email protected]>
AuthorDate:    Wed, 03 Jun 2020 10:03:04 +02:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Mon, 15 Jun 2020 14:10:01 +02:00

sched/fair: Remove unused 'sd' parameter from scale_rt_capacity()

Since commit 8ec59c0f5f49 ("sched/topology: Remove unused 'sd' parameter from arch_scale_cpu_capacity()") it is no longer needed.

---
 kernel/sched/fair.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/sched/fair.c +2 -2
index 6a4dab2..69da576 100644
@@ -8038,7 +8038,7 @@ static inline void init_sd_lb_stats(struct sd_lb_stats *sds)
 	};
 }
 
-static unsigned long scale_rt_capacity(struct sched_domain *sd, int cpu)
+static unsigned long scale_rt_capacity(int cpu)
 {
 	struct rq *rq = cpu_rq(cpu);
 	unsigned long max = arch_scale_cpu_capacity(cpu);
@@ -8070,7 +8070,7 @@ static unsigned long scale_rt_capacity(struct sched_domain *sd, int cpu)
 
 static void update_cpu_capacity(struct sched_domain *sd, int cpu)
 {
-	unsigned long capacity = scale_rt_capacity(sd, cpu);
+	unsigned long capacity = scale_rt_capacity(cpu);
 	struct sched_group *sdg = sd->groups;
 
 	cpu_rq(cpu)->cpu_capacity_orig = arch_scale_cpu_capacity(cpu);
maintainer
#11 lore raw
In reply to Dietmar Eggemann
Quoted 9 lines · Dietmar Eggemann

Remove redundant functions, parameters and macros from the task scheduler code.

Dietmar Eggemann (4):
sched/pelt: Remove redundant cap_scale() definition sched/core: Remove redundant 'preempt' param from

    sched_class->yield_to_task()

sched/idle,stop: Remove .get_rr_interval from sched_class sched/fair: Remove unused 'sd' parameter from scale_rt_capacity()

Thanks!