mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: kevin@koconnor.net
To: mingo@elte.hu, linux-kernel@vger.kernel.org
Subject: lock order in O(1) scheduler
Date: Thu, 10 Jan 2002 00:10:02 -0500	[thread overview]
Message-ID: <20020110001002.A13456@arizona.localdomain> (raw)


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. !"    |
 ------------------------------------------------------------------------

             reply	other threads:[~2002-01-10  5:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-01-10  5:10 kevin [this message]
2002-01-10  5:26 ` Robert Love
2002-01-10  5:38   ` Davide Libenzi
2002-01-10  5:49   ` Robert Love
2002-01-10  6:29   ` kevin
2002-01-10 13:11   ` Ingo Molnar
2002-01-10  5:29 ` David S. Miller
2002-01-10  5:51 ` Robert Love

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=20020110001002.A13456@arizona.localdomain \
    --to=kevin@koconnor.net \
    --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

all inboxes | Powered by JetHome®