From: Hillf Danton <dhillf@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
LKML <linux-kernel@vger.kernel.org>, Ingo Molnar <mingo@elte.hu>
Subject: Re: [PATCH] sched: correct testing need_resched in mutex_spin_on_owner()
Date: Wed, 8 Jun 2011 02:22:30 +0800 [thread overview]
Message-ID: <BANLkTim-3qPKAbKfshhkVuBJcVoZKXFXQQ@mail.gmail.com> (raw)
In-Reply-To: <20110607150816.GC27245@home.goodmis.org>
On Tue, Jun 7, 2011 at 11:08 PM, Steven Rostedt <rostedt@goodmis.org> wrote:
> On Tue, Jun 07, 2011 at 10:47:21PM +0800, Hillf Danton wrote:
>> On Tue, Jun 7, 2011 at 10:40 PM, Peter Zijlstra <peterz@infradead.org> wrote:
>> > On Tue, 2011-06-07 at 22:36 +0800, Hillf Danton wrote:
>> >
>> >> If you are right, the following comment also in __mutex_lock_common()
>> >>
>> >> for (;;) {
>> >> struct task_struct *owner;
>> >>
>> >> /*
>> >> * If there's an owner, wait for it to either
>> >> * release the lock or go to sleep.
>> >> */
>> >> owner = ACCESS_ONCE(lock->owner);
>> >> if (owner && !mutex_spin_on_owner(lock, owner))
>> >> break;
>> >>
>> >> looks misleading too, but if owner is on this CPU, for what does we wait?
>> >
>> > huh, wtf!? it cannot be on this cpu, if it was we wouldn't be running
>> > the above code but whatever owner was doing.
>> >
>> > So my argument was, it cannot be on this cpu, therefore, by checking it
>> > is on a cpu, we check its on a different cpu.
>> >
>> > And I really don't see how any of that is related to the above.
>> >
>> Oh, it looks you are willing to rethink about testing need_resched?
>
> NO!
>
> Hillf, reading this thread I understand that you have no idea of what is
> happening here. You are totally clueless. Let me give you a clue.
>
> The idea of an adaptive mutex is quite simple. If a mutex is held for a
> short period of time, and on another CPU a task tries to grab the same
> mutex, it would be slower to have that task schedule out than to just
> spin waiting for that mutex to be released.
>
> Ideally, this mutex would then act like a spin lock, and things would
> run very efficiently. But, as it is not a spin lock, there's things we
> must also be aware of.
>
> 1) If the owner we are waiting for to release the mutex schedules out.
>
> 2) If another task wants us to run on the CPU of the waiter that is
> spinning.
>
> 3) If the waiter that is spinning runs out of its time quantum and
> should yield to another task.
>
> #1 is checked by the owner_running(). If that fails, then we should not
> spin anymore and its good to schedule. BTW, the answer why
> owner_running() is safe to check owner, is because it grabs rcu_locks()
> to make sure it is safe.
>
> #2 and #3 are checked by testing NEED_RESCHED on the waiter (NOT THE
> OWNER!). If the waiter that is spinning should be preempted, the waiter
> (not the owner) will have its NEED_RESCHED bit set. That is why the
> waiter's NEED_RESCHED flag is checked and not owners.
>
> And also we don't need to check need_resched() in the above code because
> the loop checks it anyway, or we break out of the loop.
>
> Understand?
>
After hours chewing __mutex_lock_common() and mutex_spin_on_owner(),
and what you and Peter said, the owner is on different CPU from the waiter,
and the patched need_resched is simply meaning the waiter is no longer
willing to wait for whatever reasons.
It is really unlucky tonight:(
Hillf
next prev parent reply other threads:[~2011-06-07 18:22 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-07 13:41 Hillf Danton
2011-06-07 13:47 ` Peter Zijlstra
2011-06-07 13:50 ` Peter Zijlstra
2011-06-07 13:59 ` Peter Zijlstra
2011-06-07 14:14 ` Hillf Danton
2011-06-07 14:10 ` Hillf Danton
2011-06-07 14:24 ` Peter Zijlstra
2011-06-07 14:36 ` Hillf Danton
2011-06-07 14:40 ` Peter Zijlstra
2011-06-07 14:47 ` Hillf Danton
2011-06-07 15:08 ` Steven Rostedt
2011-06-07 18:22 ` Hillf Danton [this message]
2011-06-07 18:34 ` Steven Rostedt
2011-06-07 15:20 ` Peter Zijlstra
2011-06-07 15:43 ` Steven Rostedt
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=BANLkTim-3qPKAbKfshhkVuBJcVoZKXFXQQ@mail.gmail.com \
--to=dhillf@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.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 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®