All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch] don't preempt not TASK_RUNNING tasks
@ 2009-03-20  9:43 Miklos Szeredi
  2009-03-20 10:03 ` Peter Zijlstra
  0 siblings, 1 reply; 6+ messages in thread
From: Miklos Szeredi @ 2009-03-20  9:43 UTC (permalink / raw)
  To: mingo
  Cc: peterz, roland, efault, rjw, jdike, user-mode-linux-devel,
	linux-kernel, torvalds, akpm

Ingo,

I tested this one, and I think it makes sense in any case as an
optimization.  It should also be good for -stable kernels.

Does it look OK?

Thanks,
Miklos
----

From: Miklos Szeredi <mszeredi@suse.cz>

This patch fixes bug #12208:

  http://bugzilla.kernel.org/show_bug.cgi?id=12208

Don't preempt tasks in preempt_schedule() if they are already in the
process of going to sleep.  Otherwise the task would wake up only to
go to sleep again.

Due to the way wait_task_inactive() works this can also drastically
slow down ptrace:

 - task A is ptracing task B
 - task B stops on a trace event
 - task A is woken up and preempts task B
 - task A calls ptrace on task B, which does ptrace_check_attach()
 - this calls wait_task_inactive(), which sees that task B is still on the runq
 - task A goes to sleep for a jiffy
 - ...

Since UML does lots of the above sequences, those jiffies quickly add
up to make it slow as hell.

Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
CC: stable@kernel.org
---
 kernel/sched.c |    4 ++++
 1 file changed, 4 insertions(+)

Index: linux.git/kernel/sched.c
===================================================================
--- linux.git.orig/kernel/sched.c	2009-03-20 09:40:47.000000000 +0100
+++ linux.git/kernel/sched.c	2009-03-20 10:28:56.000000000 +0100
@@ -4632,6 +4632,10 @@ asmlinkage void __sched preempt_schedule
 	if (likely(ti->preempt_count || irqs_disabled()))
 		return;
 
+	/* No point in preempting we are just about to go to sleep. */
+	if (current->state != TASK_RUNNING)
+		return;
+
 	do {
 		add_preempt_count(PREEMPT_ACTIVE);
 		schedule();

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

end of thread, other threads:[~2009-03-20 11:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-20  9:43 [patch] don't preempt not TASK_RUNNING tasks Miklos Szeredi
2009-03-20 10:03 ` Peter Zijlstra
2009-03-20 10:37   ` Miklos Szeredi
2009-03-20 10:53     ` Ingo Molnar
2009-03-20 11:25       ` Miklos Szeredi
2009-03-20 11:39         ` Ingo Molnar

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.