public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* smp_send_reschedule vs. smp_migrate_task
@ 2002-02-13  7:37 Paul Mackerras
  2002-02-14 22:03 ` Val Henson
  0 siblings, 1 reply; 5+ messages in thread
From: Paul Mackerras @ 2002-02-13  7:37 UTC (permalink / raw)
  To: linux-kernel

I am looking at the updates for PPC that are needed because of the
changes to the scheduler in 2.5.x.  I need to implement
smp_migrate_task(), but I do not have another IPI easily available;
the Open PIC interrupt controller used in a lot of SMP PPC machines
supports 4 IPIs in hardware and we are already using all of them.

Thus I was thinking of using the same IPI for smp_migrate_task and
smp_send_reschedule.  The idea is that smp_send_reschedule(cpu) will
be effectively smp_migrate_task(cpu, NULL), and the code that receives
that IPI will check for the NULL and do set_need_resched() instead of
sched_task_migrated().

At present the i386 version of smp_migrate_task uses a single global
spinlock, thus only one task can be migrating at a time.  If I make
smp_send_reschedule and smp_migrate_task both use the same global
spinlock, is that likely to cause deadlocks or unacceptable
contention?  In fact it would not be hard to have a spinlock per cpu.
Would we ever be likely to do smp_migrate_task and set_need_resched
for the same target cpu at the same time?

Paul.

^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: smp_send_reschedule vs. smp_migrate_task
@ 2002-02-14 23:24 James Bottomley
  0 siblings, 0 replies; 5+ messages in thread
From: James Bottomley @ 2002-02-14 23:24 UTC (permalink / raw)
  To: Paul Mackerras; +Cc: linux-kernel, James.Bottomley

> In that post I was really asking the following questions:
> * how often does smp_send_reschedule get called? * how often does
> smp_migrate_task get called? * if smp_send_reschedule and
> smp_migrate_task were mutually exclusive,
>   i.e. both used the same spinlock, could that lead to deadlock?

> James Bottomley answered the first two for me but not the third.

I think the answer to the third is yes.

The potential deadlock is inherent in smp_migrate_task().  Any code which 
takes a spinlock on one CPU and unlocks it on another via an IPI is asking for 
a deadlock.

Here's the scenario:

CPU 1 does a smp_migrate_task() to CPU 2 at the same time CPU 2 does the same 
thing to CPU 1.  They both contend for the migration lock.  CPU 1 wins, 
acquires the migration lock and sends the IPI to CPU 2.  If CPU 2 is spinning 
on the migration lock *with interrupts disabled* then you have a deadlock (it 
can never accept the IPI and release the lock).

The way out is to make sure interrupts are always enabled when taking the 
migration lock (which is true for all the task migration code paths).  This, 
in turn imposes a condition:  the lock may never be taken from an interrupt 
(otherwise it may deadlock itself).

Since smp_send_reschedule() is called down many process wake up code paths, 
I'm not sure you can comply with the no calling from interrupt requirement if 
you make it share a lock with smp_migrate_task().

James



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

end of thread, other threads:[~2002-02-15  5:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-02-13  7:37 smp_send_reschedule vs. smp_migrate_task Paul Mackerras
2002-02-14 22:03 ` Val Henson
2002-02-14 22:28   ` Paul Mackerras
2002-02-15  5:55     ` Val Henson
  -- strict thread matches above, loose matches on Subject: below --
2002-02-14 23:24 James Bottomley

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