linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robert Love <rml@tech9.net>
To: torvalds@transmeta.com
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] 2.5: don't miss a preemption oppurtunity
Date: 06 Apr 2002 14:09:49 -0500	[thread overview]
Message-ID: <1018120190.899.100.camel@phantasy> (raw)

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




                 reply	other threads:[~2002-04-06 19:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1018120190.899.100.camel@phantasy \
    --to=rml@tech9.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).