All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched,rt,nohz: stop scheduler tick if running realtime task
@ 2015-02-16 20:23 Rik van Riel
  2015-02-18 18:43 ` [tip:sched/core] sched/rt/nohz: Stop " tip-bot for Rik van Riel
  2015-03-03 17:12 ` [PATCH] sched,rt,nohz: stop " Frederic Weisbecker
  0 siblings, 2 replies; 3+ messages in thread
From: Rik van Riel @ 2015-02-16 20:23 UTC (permalink / raw)
  To: peterz; +Cc: lcapitulino, linux-kernel, mtosatti, mingo, fweisbec

If the CPU is running a realtime task that does not round-robin with
another realtime task of equal priority, there is no point in keeping
the scheduler tick going. After all, whenever the scheduler tick runs,
the kernel will just decide not to reschedule.

Extend sched_can_stop_tick to recognize these situations, and inform
the rest of the kernel that the scheduler tick can be stopped.

Signed-off-by: Rik van Riel <riel@redhat.com>
Tested-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 kernel/sched/core.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index ade2958a9197..ad985a632c4d 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -745,6 +745,22 @@ static inline bool got_nohz_idle_kick(void)
 bool sched_can_stop_tick(void)
 {
 	/*
+	 * FIFO realtime policy runs the highest priority task. Other runnable
+	 * tasks are of a lower priority. The scheduler tick does nothing.
+	 */
+	if (current->policy == SCHED_FIFO)
+		return true;
+
+	/*
+	 * Round-robin realtime tasks time slice with other tasks at the same
+	 * realtime priority. Is this task the only one at this priority?
+	 */
+	if (current->policy == SCHED_RR) {
+		struct sched_rt_entity *rt_se = &current->rt;
+		return rt_se->run_list.prev == rt_se->run_list.next;
+	}
+
+	/*
 	 * More than one running task need preemption.
 	 * nr_running update is assumed to be visible
 	 * after IPI is sent from wakers.

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [tip:sched/core] sched/rt/nohz: Stop scheduler tick if running realtime task
  2015-02-16 20:23 [PATCH] sched,rt,nohz: stop scheduler tick if running realtime task Rik van Riel
@ 2015-02-18 18:43 ` tip-bot for Rik van Riel
  2015-03-03 17:12 ` [PATCH] sched,rt,nohz: stop " Frederic Weisbecker
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Rik van Riel @ 2015-02-18 18:43 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: rostedt, hpa, peterz, linux-kernel, tglx, lcapitulino, riel, mingo

Commit-ID:  1e78cdbd9b2266503339accafe0ebdd99b93a531
Gitweb:     http://git.kernel.org/tip/1e78cdbd9b2266503339accafe0ebdd99b93a531
Author:     Rik van Riel <riel@redhat.com>
AuthorDate: Mon, 16 Feb 2015 15:23:49 -0500
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 18 Feb 2015 18:21:19 +0100

sched/rt/nohz: Stop scheduler tick if running realtime task

If the CPU is running a realtime task that does not round-robin
with another realtime task of equal priority, there is no point
in keeping the scheduler tick going. After all, whenever the
scheduler tick runs, the kernel will just decide not to
reschedule.

Extend sched_can_stop_tick() to recognize these situations, and
inform the rest of the kernel that the scheduler tick can be
stopped.

Tested-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Rik van Riel <riel@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: fweisbec@redhat.com
Cc: mtosatti@redhat.com
Link: http://lkml.kernel.org/r/20150216152349.6a8ed824@annuminas.surriel.com
[ Small cleanliness tweak. ]
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/sched/core.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index a4869bd..97fe79c 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -690,6 +690,23 @@ static inline bool got_nohz_idle_kick(void)
 bool sched_can_stop_tick(void)
 {
 	/*
+	 * FIFO realtime policy runs the highest priority task. Other runnable
+	 * tasks are of a lower priority. The scheduler tick does nothing.
+	 */
+	if (current->policy == SCHED_FIFO)
+		return true;
+
+	/*
+	 * Round-robin realtime tasks time slice with other tasks at the same
+	 * realtime priority. Is this task the only one at this priority?
+	 */
+	if (current->policy == SCHED_RR) {
+		struct sched_rt_entity *rt_se = &current->rt;
+
+		return rt_se->run_list.prev == rt_se->run_list.next;
+	}
+
+	/*
 	 * More than one running task need preemption.
 	 * nr_running update is assumed to be visible
 	 * after IPI is sent from wakers.

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] sched,rt,nohz: stop scheduler tick if running realtime task
  2015-02-16 20:23 [PATCH] sched,rt,nohz: stop scheduler tick if running realtime task Rik van Riel
  2015-02-18 18:43 ` [tip:sched/core] sched/rt/nohz: Stop " tip-bot for Rik van Riel
@ 2015-03-03 17:12 ` Frederic Weisbecker
  1 sibling, 0 replies; 3+ messages in thread
From: Frederic Weisbecker @ 2015-03-03 17:12 UTC (permalink / raw)
  To: Rik van Riel; +Cc: peterz, lcapitulino, linux-kernel, mtosatti, mingo, fweisbec

On Mon, Feb 16, 2015 at 03:23:49PM -0500, Rik van Riel wrote:
> If the CPU is running a realtime task that does not round-robin with
> another realtime task of equal priority, there is no point in keeping
> the scheduler tick going. After all, whenever the scheduler tick runs,
> the kernel will just decide not to reschedule.
> 
> Extend sched_can_stop_tick to recognize these situations, and inform
> the rest of the kernel that the scheduler tick can be stopped.
> 
> Signed-off-by: Rik van Riel <riel@redhat.com>
> Tested-by: Luiz Capitulino <lcapitulino@redhat.com>
> ---
>  kernel/sched/core.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index ade2958a9197..ad985a632c4d 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -745,6 +745,22 @@ static inline bool got_nohz_idle_kick(void)
>  bool sched_can_stop_tick(void)
>  {
>  	/*
> +	 * FIFO realtime policy runs the highest priority task. Other runnable
> +	 * tasks are of a lower priority. The scheduler tick does nothing.
> +	 */
> +	if (current->policy == SCHED_FIFO)
> +		return true;
> +
> +	/*
> +	 * Round-robin realtime tasks time slice with other tasks at the same
> +	 * realtime priority. Is this task the only one at this priority?
> +	 */
> +	if (current->policy == SCHED_RR) {
> +		struct sched_rt_entity *rt_se = &current->rt;
> +		return rt_se->run_list.prev == rt_se->run_list.next;
> +	}
> +
> +	/*

I think it should work yes.

There are still many things, that the tick updates, which are broken without it
(rq->rt_avg is supposed to be updated avery tick for example) but it goes way beyond
the scope of this change since SCHED_FIFO tasks are already allowed to stop the tick
when no SCHED_OTHER task is running so the problem is there already before this patch.

So it's a welcome fix, thanks.

>  	 * More than one running task need preemption.
>  	 * nr_running update is assumed to be visible
>  	 * after IPI is sent from wakers.
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-03-03 17:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-16 20:23 [PATCH] sched,rt,nohz: stop scheduler tick if running realtime task Rik van Riel
2015-02-18 18:43 ` [tip:sched/core] sched/rt/nohz: Stop " tip-bot for Rik van Riel
2015-03-03 17:12 ` [PATCH] sched,rt,nohz: stop " Frederic Weisbecker

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.