All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dimitri Sivanich <sivanich@sgi.com>
To: linux-ia64@vger.kernel.org
Subject: [PATCH] disable irq's and check need_resched before safe_halt
Date: Tue, 07 Aug 2007 13:49:32 +0000	[thread overview]
Message-ID: <20070807134932.GA30447@sgi.com> (raw)

While sending interrupts to a cpu to repeatedly wake a thread, on occasion that thread will take a full timer tick cycle (4002 usec in my case) to wakeup.

The problem concerns a race condition in the code around the safe_halt() call in the default_idle() routine.  Setting 'nohalt' on the kernel command line causes the long wakeups to disappear.

void
default_idle (void)
{
        local_irq_enable();
        while (!need_resched()) {
-->             if (can_do_pal_halt)
-->                     safe_halt();
                else

A timer tick could arrive between the check for !need_resched and the actual call to safe_halt() (which does a pal call to PAL_HALT_LIGHT).  By the time the timer tick completes, a thread that might now need to run could get held up for as long as a timer tick waiting for the halted cpu.

I'm proposing that we disable irq's and check need_resched again before calling safe_halt().  Does anyone see any problem with this approach?


Signed-off-by: Dimitri Sivanich <sivanich@sgi.com>

Index: linux/arch/ia64/kernel/process.c
=================================--- linux.orig/arch/ia64/kernel/process.c	2007-08-02 15:05:56.427236082 -0500
+++ linux/arch/ia64/kernel/process.c	2007-08-06 19:42:20.147944967 -0500
@@ -198,9 +198,13 @@ default_idle (void)
 {
 	local_irq_enable();
 	while (!need_resched()) {
-		if (can_do_pal_halt)
-			safe_halt();
-		else
+		if (can_do_pal_halt) {
+			local_irq_disable();
+			if (!need_resched()) {
+				safe_halt();
+			}
+			local_irq_enable();
+		} else
 			cpu_relax();
 	}
 }

             reply	other threads:[~2007-08-07 13:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-07 13:49 Dimitri Sivanich [this message]
2007-08-07 20:11 ` [PATCH] disable irq's and check need_resched before safe_halt Luck, Tony
2007-08-07 21:26 ` Ken Chen
2007-08-08 15:01 ` Dimitri Sivanich
2007-08-09  3:36 ` Hidetoshi Seto
2007-08-09 12:41 ` Dimitri Sivanich
2007-08-13 20:36 ` Luck, Tony

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=20070807134932.GA30447@sgi.com \
    --to=sivanich@sgi.com \
    --cc=linux-ia64@vger.kernel.org \
    /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 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.