public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* lock order in O(1) scheduler
@ 2002-01-10  5:10 kevin
  2002-01-10  5:26 ` Robert Love
  2002-01-10  5:51 ` Robert Love
  0 siblings, 2 replies; 8+ messages in thread
From: kevin @ 2002-01-10  5:10 UTC (permalink / raw)
  To: mingo, linux-kernel


Hi Ingo,

I was looking through the new O(1) scheduler (found in linux-2.5.2-pre11),
when I came upon the following code in try_to_wake_up():

        lock_task_rq(rq, p, flags);
        p->state = TASK_RUNNING;
        if (!p->array) {
                if (!rt_task(p) && synchronous && (smp_processor_id() < p->cpu)) {
                        spin_lock(&this_rq()->lock);
                        p->cpu = smp_processor_id();
                        activate_task(p, this_rq());
                        spin_unlock(&this_rq()->lock);
                } else {

I was unable to figure out what the logic of the '(smp_processor_id() <
p->cpu)' test is..  (Why should the CPU number of the process being awoken
matter?)  My best guess is that this is to enforce a locking invariant -
but if so, isn't this test backwards?  If p->cpu > current->cpu then
p->cpu's runqueue is locked first followed by this_rq - locking greatest to
least, where the rest of the code does least to greatest..

Also, this code in set_cpus_allowed() looks bogus:

        if (target_cpu < smp_processor_id()) {
                spin_lock_irq(&target_rq->lock);
                spin_lock(&this_rq->lock);
        } else {
                spin_lock_irq(&target_rq->lock);
                spin_lock(&this_rq->lock);
        }

The lock order is the same regardless of the if statement..


-Kevin

-- 
 ------------------------------------------------------------------------
 | Kevin O'Connor                     "BTW, IMHO we need a FAQ for      |
 | kevin@koconnor.net                  'IMHO', 'FAQ', 'BTW', etc. !"    |
 ------------------------------------------------------------------------

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

end of thread, other threads:[~2002-01-10 11:14 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-01-10  5:10 lock order in O(1) scheduler kevin
2002-01-10  5:26 ` Robert Love
2002-01-10  5:29   ` David S. Miller
2002-01-10  5:49     ` Robert Love
2002-01-10  5:38   ` Davide Libenzi
2002-01-10  6:29   ` kevin
2002-01-10 13:11   ` Ingo Molnar
2002-01-10  5:51 ` Robert Love

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