From: zhouchengming <zhouchengming1@huawei.com>
To: Steven Rostedt <rostedt@goodmis.org>, <peterz@infradead.org>
Cc: <linux-kernel@vger.kernel.org>, <mingo@redhat.com>,
<huawei.libin@huawei.com>
Subject: Re: [PATCH] sched/rt.c: pick and check task if double_lock_balance() unlock the rq
Date: Sat, 7 Oct 2017 11:30:19 +0800 [thread overview]
Message-ID: <59D84A4B.70900@huawei.com> (raw)
In-Reply-To: <20170925231843.140d3a21@vmware.local.home>
Hi Steven, Peter,
On 2017/9/26 11:18, Steven Rostedt wrote:
> On Tue, 26 Sep 2017 09:23:20 +0800
> zhouchengming<zhouchengming1@huawei.com> wrote:
>
>> On 2017/9/26 3:40, Steven Rostedt wrote:
>>> On Mon, 11 Sep 2017 14:51:49 +0800
>>> Zhou Chengming<zhouchengming1@huawei.com> wrote:
>>>
>>>> push_rt_task() pick the first pushable task and find an eligible
>>>> lowest_rq, then double_lock_balance(rq, lowest_rq). So if
>>>> double_lock_balance() unlock the rq (when double_lock_balance() return 1),
>>>> we have to check if this task is still on the rq.
>>>>
>>>> The problem is that the check conditions are not sufficient:
>>>>
>>>> if (unlikely(task_rq(task) != rq ||
>>>> !cpumask_test_cpu(lowest_rq->cpu,&task->cpus_allowed) ||
>>>> task_running(rq, task) ||
>>>> !rt_task(task) ||
>>>> !task_on_rq_queued(task))) {
>>>>
>>>> cpu2 cpu1 cpu0
>>>> push_rt_task(rq1)
>>>> pick task_A on rq1
>>>> find rq0
>>>> double_lock_balance(rq1, rq0)
>>>> unlock(rq1)
>>>> rq1 __schedule
>>>> pick task_A run
>>>> task_A sleep (dequeued)
>>>> lock(rq0)
>>>> lock(rq1)
>>>> do_above_check(task_A)
>>>> task_rq(task_A) == rq1
>>>> cpus_allowed unchanged
>>>> task_running == false
>>>> rt_task(task_A) == true
>>>> try_to_wake_up(task_A)
>>>> select_cpu = cpu3
>>>> enqueue(rq3, task_A)
>>> How can this happen? The try_to_wake_up(task_A) needs to grab the rq
>>> that task A is on, and we have that rq lock.
>>>
>>> /me confused.
>>>
>>> -- Steve
>> Thanks for the reply!
>> After the task_A sleep on cpu1, the try_to_wake_up(task_A) on cpu0 select a different cpu3,
>> so it will grab the rq3 lock, not the rq1 lock.
> Ah crap. This is caused by 7608dec2ce20 ("sched: Drop the rq argument
> to sched_class::select_task_rq()"). Because this code depends on
> try_to_wake_up() grabbing the task's rq lock. But it no longer does
> that, and it causes this race.
>
> OK, I need to look at this deeper when I'm not so jetlagged and typing
> this because I can't sleep at 5am.
>
> Thanks for pointing this out!
>
> It may be fixed by simply grabbing the run queue lock on migration, as
> that would sync things up.
Is there any new solution? I don't think grabbing the rq lock without the task->pi_lock
will fix this problem. And I think my patch is correct and the changes are small.
Thanks!
> Peter?
>
>
> -- Steve
>
>
>
> .
>
next prev parent reply other threads:[~2017-10-07 3:34 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-11 6:51 [PATCH] sched/rt.c: pick and check task if double_lock_balance() unlock the rq Zhou Chengming
2017-09-12 2:11 ` zhouchengming
2017-09-25 11:53 ` zhouchengming
2017-09-25 19:40 ` Steven Rostedt
2017-09-26 1:23 ` zhouchengming
2017-09-26 3:18 ` Steven Rostedt
2017-10-07 3:30 ` zhouchengming [this message]
2018-04-10 22:05 ` Steven Rostedt
2018-04-11 10:26 ` Peter Zijlstra
2018-04-12 8:54 ` Libin (Huawei)
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=59D84A4B.70900@huawei.com \
--to=zhouchengming1@huawei.com \
--cc=huawei.libin@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.