public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Robert Love <rml@tech9.net>
To: mingo@elte.hu
Cc: Mike Kravetz <kravetz@us.ibm.com>, linux-kernel@vger.kernel.org
Subject: Re: Scheduler Bug (set_cpus_allowed)
Date: 10 Jun 2002 16:28:06 -0700	[thread overview]
Message-ID: <1023751686.21176.124.camel@sinai> (raw)
In-Reply-To: <Pine.LNX.4.44.0206110123230.4761-100000@elte.hu>

On Mon, 2002-06-10 at 16:24, Ingo Molnar wrote:

> sure, agreed. I've added it to my tree.

What do you think of this?

No more explicit preempt disables...

	Robert Love

diff -urN linux-2.5.21/kernel/sched.c linux/kernel/sched.c
--- linux-2.5.21/kernel/sched.c	Sat Jun  8 22:28:13 2002
+++ linux/kernel/sched.c	Sun Jun  9 13:01:32 2002
@@ -153,17 +153,22 @@
 #define cpu_curr(cpu)		(cpu_rq(cpu)->curr)
 #define rt_task(p)		((p)->prio < MAX_RT_PRIO)
 
+/*
+ * task_rq_lock - lock the runqueue a given task resides on and disable
+ * interrupts.  Note the ordering: we can safely lookup the task_rq without
+ * explicitly disabling preemption.
+ */
 static inline runqueue_t *task_rq_lock(task_t *p, unsigned long *flags)
 {
 	struct runqueue *rq;
 
 repeat_lock_task:
-	preempt_disable();
+	local_irq_save(*flags);
 	rq = task_rq(p);
-	spin_lock_irqsave(&rq->lock, *flags);
+	spin_lock(&rq->lock);
 	if (unlikely(rq != task_rq(p))) {
-		spin_unlock_irqrestore(&rq->lock, *flags);
-		preempt_enable();
+		spin_unlock(&rq->lock);
+		local_irq_restore(*flags);
 		goto repeat_lock_task;
 	}
 	return rq;
@@ -171,8 +176,25 @@
 
 static inline void task_rq_unlock(runqueue_t *rq, unsigned long *flags)
 {
-	spin_unlock_irqrestore(&rq->lock, *flags);
-	preempt_enable();
+	spin_unlock(&rq->lock);
+	local_irq_restore(*flags);
+}
+
+/*
+ * rq_lock - lock a given runqueue and disable interrupts.
+ */
+static inline runqueue_t *rq_lock(runqueue_t *rq)
+{
+	local_irq_disable();
+	rq = this_rq();
+	spin_lock(&rq->lock);
+	return rq;
+}
+
+static inline void rq_unlock(runqueue_t *rq)
+{
+	spin_unlock(&rq->lock);
+	local_irq_enable();
 }
 
 /*
@@ -353,9 +375,7 @@
 {
 	runqueue_t *rq;
 
-	preempt_disable();
-	rq = this_rq();
-	spin_lock_irq(&rq->lock);
+	rq = rq_lock(rq);
 
 	p->state = TASK_RUNNING;
 	if (!rt_task(p)) {
@@ -371,8 +391,7 @@
 	p->thread_info->cpu = smp_processor_id();
 	activate_task(p, rq);
 
-	spin_unlock_irq(&rq->lock);
-	preempt_enable();
+	rq_unlock(rq);
 }
 
 /*
@@ -1342,8 +1361,7 @@
 	runqueue_t *rq;
 	prio_array_t *array;
 
-	preempt_disable();
-	rq = this_rq();
+	rq = rq_lock(rq);
 
 	/*
 	 * Decrease the yielding task's priority by one, to avoid
@@ -1353,7 +1371,6 @@
 	 * If priority is already MAX_PRIO-1 then we still
 	 * roundrobin the task within the runlist.
 	 */
-	spin_lock_irq(&rq->lock);
 	array = current->array;
 	/*
 	 * If the task has reached maximum priority (or is a RT task)
@@ -1371,7 +1388,6 @@
 		__set_bit(current->prio, array->bitmap);
 	}
 	spin_unlock(&rq->lock);
-	preempt_enable_no_resched();
 
 	schedule();
 



  reply	other threads:[~2002-06-10 23:28 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-06 23:20 Scheduler Bug (set_cpus_allowed) Mike Kravetz
2002-06-07 18:36 ` Robert Love
2002-06-07 19:12   ` Mike Kravetz
2002-06-10 20:12     ` Ingo Molnar
2002-06-10 20:57       ` Mike Kravetz
2002-06-10 22:35         ` Ingo Molnar
2002-06-10 23:15           ` Mike Kravetz
2002-06-10 23:24             ` Ingo Molnar
2002-06-10 23:28               ` Robert Love [this message]
2002-06-11  0:05                 ` [patch] current scheduler bits, 2.5.21 Ingo Molnar
2002-06-11  0:27                   ` Robert Love
2002-06-11 17:35                     ` [patch] current scheduler bits #2, 2.5.21 Ingo Molnar
2002-06-11 18:25                       ` Robert Love
2002-06-11 18:33                         ` [patch] current scheduler bits #3, 2.5.21 Ingo Molnar
2002-06-13 21:26                           ` [PATCH] " Robert Love
2002-06-13 22:06                             ` [patch] current scheduler bits #4, 2.5.21 Ingo Molnar
2002-06-07 23:20   ` Scheduler Bug (set_cpus_allowed) J.A. Magallon
2002-06-12  0:00     ` Andrea Arcangeli
2002-06-10 18:50   ` Mike Kravetz
2002-06-10 20:02     ` Ingo Molnar
2002-06-12 11:54       ` David S. Miller
2002-06-12 16:57         ` [patch] switch_mm()'s desire to run without the rq lock Ingo Molnar
2002-06-12 21:54           ` David S. Miller
2002-06-12 22:31           ` David S. Miller

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=1023751686.21176.124.camel@sinai \
    --to=rml@tech9.net \
    --cc=kravetz@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /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