public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] 2.5: don't miss a preemption oppurtunity
@ 2002-04-06 19:09 Robert Love
  0 siblings, 0 replies; only message in thread
From: Robert Love @ 2002-04-06 19:09 UTC (permalink / raw)
  To: torvalds; +Cc: linux-kernel

Linus,

The new kernel preemption code in 2.5 is great.  The only missing bit is
a check for need to reschedule at the end of the preemption handling
code in preempt_schedule and entry.S.  Anytime preemption is disabled,
there is a possibility kernel code could set need_resched and try to
preempt.  We need to check need_resched as soon as we reenable
preemption (preempt_count=0) in these code paths.

Right now this window exists anytime after resume_kernel sets
preempt_count to 0 and after return from schedule when preempt_count is
also set to 0.  Note they can last as long as the next interrupt - or
longer if a lock was grabbed in the interim.  This is a decade in
real-time land.

This patch, against 2.4.8-pre2, adds a simple check for need_resched to
the end of these codepaths and jumps back into them if needed.  Please
apply.

	Robert Love

diff -urN linux-2.5.8-pre2/kernel/sched.c linux/kernel/sched.c
--- linux-2.5.8-pre2/kernel/sched.c	Fri Apr  5 20:18:12 2002
+++ linux/kernel/sched.c	Fri Apr  5 21:02:54 2002
@@ -851,10 +851,15 @@
 	if (unlikely(ti->preempt_count))
 		return;
 
+need_resched:
 	ti->preempt_count = PREEMPT_ACTIVE;
 	schedule();
 	ti->preempt_count = 0;
 	barrier();
+
+	/* we could miss a preemption between schedule() and now */
+	if (unlikely(test_thread_flag(TIF_NEED_RESCHED)))
+		goto need_resched;
 }
 #endif /* CONFIG_PREEMPT */

diff -urN linux-2.5.8-pre2/arch/i386/kernel/entry.S linux/arch/i386/kernel/entry.S
--- linux-2.5.8-pre2/arch/i386/kernel/entry.S	Fri Apr  5 20:18:10 2002
+++ linux/arch/i386/kernel/entry.S	Sat Apr  6 01:59:17 2002
@@ -232,6 +232,7 @@
 ENTRY(resume_kernel)
 	cmpl $0,TI_PRE_COUNT(%ebx)
 	jnz restore_all
+need_resched:
 	movl TI_FLAGS(%ebx), %ecx
 	testb $_TIF_NEED_RESCHED, %cl
 	jz restore_all
@@ -241,8 +242,9 @@
 	movl $PREEMPT_ACTIVE,TI_PRE_COUNT(%ebx)
 	sti
 	call SYMBOL_NAME(schedule)
-	movl $0,TI_PRE_COUNT(%ebx) 
-	jmp restore_all
+	movl $0,TI_PRE_COUNT(%ebx)
+	cli
+	jmp need_resched
 #endif
 
 	# system call handler stub




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-04-06 19:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-04-06 19:09 [PATCH] 2.5: don't miss a preemption oppurtunity Robert Love

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox